Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > reproducing c function in java

Reply
Thread Tools

reproducing c function in java

 
 
jimgardener
Guest
Posts: n/a
 
      06-26-2008
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))!= 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 ;
} ;


 
Reply With Quote
 
 
 
 
Mark Space
Guest
Posts: n/a
 
      06-26-2008
jimgardener wrote:
> 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!
 
Reply With Quote
 
 
 
 
Joshua Cranmer
Guest
Posts: n/a
 
      06-26-2008
jimgardener wrote:
> 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?

--
Beware of bugs in the above code; I have only proved it correct, not
tried it. -- Donald E. Knuth
 
Reply With Quote
 
Arne Vajh°j
Guest
Posts: n/a
 
      06-26-2008
jimgardener wrote:
> 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))!= 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
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Reproducing white at ISO 100 ronviers@gmail.com Digital Photography 22 03-24-2006 06:23 AM
Trouble Reproducing the Color Purple powrwrap@aol.com Digital Photography 29 01-01-2006 08:53 PM
Reproducing du/ls in Java Oreo Java 5 11-30-2004 02:35 AM
Size of digital images for reproducing in newspapers and magazines. Eric Clive Digital Photography 3 07-28-2004 04:01 PM
reproducing HttpContext behavior John ASP .Net 0 12-14-2003 04:00 PM



Advertisments