reproducing c function in java

J

jimgardener

hi
i am trying to reproduce this following function in java

in c i have a function tiffwrite_head() as below
____________________________________________
static unsigned long int lastifd ;//is ouside the function
static struct IFD ifd =
{
.......//some fields initialised
};

struct IFD * tiffwrite_head (FILE *outfile)

{
struct
{
unsigned short int order_id ;
unsigned short int tiff_id ;
unsigned long int first_ifd ;
} header ;


header.tiff_id=42 ;
if ((char)header.tiff_id==42) header.order_id=0x4949 ;
else header.order_id=0x4D4D ;
rewind (outfile) ;
header.first_ifd=0 ;
ifd.StripOffsets.value=8 ;
ifd.ImageLength.value=0 ;
lastifd=4 ;

if ((fwrite (&header,1,sizeof(header),outfile))!=8) return (NULL) ;
return (&ifd) ;
}
___________________________________________________
I would like to know if it is possible to reproduce this above
function in java .can someone help?
jim


Also IFD is =>
struct IFD
{
unsigned short int ifd_count ;
struct IFDENTRY NewSubfileType ;
struct IFDENTRY ImageWidth ;
struct IFDENTRY ImageLength ;
struct IFDENTRY BitsPerSample ;
struct IFDENTRY Compression ;
struct IFDENTRY PhotometricInterpretation ;
struct IFDENTRY FillOrder ;
struct IFDENTRY StripOffsets ;
struct IFDENTRY SamplesPerPixel ;
struct IFDENTRY RowsPerStrip ;
struct IFDENTRY StripByteCounts ;
struct IFDENTRY Xresolution ;
struct IFDENTRY Yresolution ;
struct IFDENTRY T4Options ;
struct IFDENTRY ResolutionUnit ;
struct IFDENTRY PageNumber ;
unsigned long int nextifd ;
unsigned long int Xres[2] ;
unsigned long int Yres[2] ;
} ;

struct IFDENTRY
{
unsigned short int tag ;
unsigned short int type ;
unsigned long int count ;
unsigned long int value ;
} ;
 
M

Mark Space

jimgardener said:
hi
i am trying to reproduce this following function in java

in c i have a function tiffwrite_head() as below

Here's a few thoughts I have:

1. Use DataInput/OutputStream to do IO for "write_head".

2. Make the TIFF header a Java bean: private fields, with getters and
setters.

3. Add a "read" and "write" method to the TIFF bean to do IO. Consider
over-riding writeObject, although that might not be the best, just a
thought.

4. Compose your TIFF image object to include the header and any other
bits you need. Write the whole thing in a "write" method applied to the
whole object. Same with "read".

public class TIFF {
private TiffHeader header;
private byte [] imageData; // or whatever
private more stuff here;

...

}

Good luck!
 
J

Joshua Cranmer

jimgardener said:
hi
i am trying to reproduce this following function in java

in c i have a function tiffwrite_head() as below

Are you on a little-endian or big-endian machine?

How much will you charge for consultancy rates?

And most importantly, why can you not use the javax.imageio API?
 
A

Arne Vajhøj

jimgardener said:
i am trying to reproduce this following function in java
static struct IFD ifd =
{
......//some fields initialised
};

struct IFD * tiffwrite_head (FILE *outfile)

{
struct
{
unsigned short int order_id ;
unsigned short int tiff_id ;
unsigned long int first_ifd ;
} header ;


header.tiff_id=42 ;
if ((char)header.tiff_id==42) header.order_id=0x4949 ;
else header.order_id=0x4D4D ;
rewind (outfile) ;
header.first_ifd=0 ;
ifd.StripOffsets.value=8 ;
ifd.ImageLength.value=0 ;
lastifd=4 ;

if ((fwrite (&header,1,sizeof(header),outfile))!=8) return (NULL) ;
return (&ifd) ;
}
Also IFD is =>
struct IFD
{
unsigned short int ifd_count ;
struct IFDENTRY NewSubfileType ;
struct IFDENTRY ImageWidth ;

Java does not have the capability to read and write structs. Well - it
does not even have structs.

Instead you need to create two method per struct, one that reads from
a DataInputStream and one that writes to a DataOutputStream.

Arne
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,768
Messages
2,569,575
Members
45,053
Latest member
billing-software

Latest Threads

Top