reproducing c function in java

Discussion in 'Java' started by jimgardener, Jun 26, 2008.

  1. jimgardener

    jimgardener Guest

    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 ;
    } ;
     
    jimgardener, Jun 26, 2008
    #1
    1. Advertising

  2. jimgardener

    Mark Space Guest

    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!
     
    Mark Space, Jun 26, 2008
    #2
    1. Advertising

  3. 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
     
    Joshua Cranmer, Jun 26, 2008
    #3
  4. jimgardener

    Arne Vajhøj Guest

    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))!=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
     
    Arne Vajhøj, Jun 26, 2008
    #4
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. John
    Replies:
    0
    Views:
    655
  2. Oreo

    Reproducing du/ls in Java

    Oreo, Nov 29, 2004, in forum: Java
    Replies:
    5
    Views:
    1,235
  3. Sweety

    Is any self reproducing code in C ?

    Sweety, Aug 23, 2004, in forum: C Programming
    Replies:
    6
    Views:
    421
    bogonic
    Aug 26, 2004
  4. Replies:
    11
    Views:
    759
    Tor Rustad
    May 18, 2007
  5. LaundroMat
    Replies:
    4
    Views:
    395
    LaundroMat
    Apr 8, 2008
Loading...

Share This Page