Thread: Char [] to Image File (JPEG)

  1. #16
    Registered User
    Join Date
    Jun 2009
    Posts
    14
    I will try to join the 2 imageinfo+picture to see if works..

    I tried to do that print u made and i got this weird result:

    for pic->imageinfo[0] = 2 and pic->imageinfo[1]=1

    for pic->picture[0]=0 and pic->picture[2]=0 and pic->picture[3]=0

    :S

  2. #17
    Registered User
    Join Date
    Jun 2009
    Posts
    14
    JPEG 2000 payload header

    As i saw i must get that 32bit offset. How am i suposed to copy data from the picture buffer starting on that offset?

  3. #18
    spurious conceit MK27's Avatar
    Join Date
    Jul 2008
    Location
    segmentation fault
    Posts
    8,300
    Quote Originally Posted by TranT View Post
    I will try to join the 2 imageinfo+picture to see if works..

    I tried to do that print u made and i got this weird result:

    for pic->imageinfo[0] = 2 and pic->imageinfo[1]=1

    for pic->picture[0]=0 and pic->picture[2]=0 and pic->picture[3]=0

    :S
    Hmmm. Well, I tried this on a bunch of jpegs and they all have the same first two bytes (0xffffffff then 0xffffffd8). For an unsigned char, that means 255 and 216, for a (signed) char -1 and -40.

    I'll check and see if these are prone to repeat inside of the image; if not, you could just scan the whole thing to find the start of the jpeg.

    Part of the reason why I asked if you are "hacking" (in the good sense) is because if you don't have an API which explicitly says these structs will deliver a jpeg encoded image, you might have made a conceptual leap. It may be true that "the picture is compressed in JPEG/JPEG2000", but that does not mean that the struct delivered by PTEID_GetPic() keeps it that way.
    C programming resources:
    GNU C Function and Macro Index -- glibc reference manual
    The C Book -- nice online learner guide
    Current ISO draft standard
    CCAN -- new CPAN like open source library repository
    3 (different) GNU debugger tutorials: #1 -- #2 -- #3
    cpwiki -- our wiki on sourceforge

  4. #19
    {Jaxom,Imriel,Liam}'s Dad Kennedy's Avatar
    Join Date
    Aug 2006
    Location
    Alabama
    Posts
    1,065
    Quote Originally Posted by MK27 View Post
    I was just looking at your pastebin code again. I don't think "wb" is a proper argument to fwrite() -- it is just for the lowest level write(). Anyway, going by my example, it is not necessary, so try with just "w".
    If you are talking about these two lines of code:
    Code:
    img = fopen("teste.jpeg","wb");
    fwrite(pic.picture,1,pic.piclength,img);
    Sure it is. "wb" in the WINDOWS world means "write binary" and ONLY tells that stupid OS to NOT convert "\n" to "\r\n". In the Linux world, it is completely pointless and ignored by the OS (as all files are written without EVER being converted by the OS, just the app).

  5. #20
    spurious conceit MK27's Avatar
    Join Date
    Jul 2008
    Location
    segmentation fault
    Posts
    8,300
    Quote Originally Posted by TranT View Post
    As i saw i must get that 32bit offset. How am i suposed to copy data from the picture buffer starting on that offset?
    You don't have to, but if you did this is how it would work: supposedly there is a 4-byte integer (32 bits!) starting at bit 29 (that's crazy) which contains the offset. However, I think you are looking at something to do with jpeg video...but you would want to create a struct corresponding to all that:
    Code:
    struct jpeg2000 {
          unsigned char type;
          unsigned char type-specific;
          unsigned char priority;
          int X_id:5;   /* :5 is the bit length */
          int offset;
    }
    "offset" would be that number, altho there may be some complications with compiler padding. But again: you don't have to do this!

    Anyway, those things are part of the header which your image viewer program needs to interpret the image correctly. You want to include, not exclude the header, so you don't have to worry about separating it.
    Last edited by MK27; 06-30-2009 at 08:21 AM.
    C programming resources:
    GNU C Function and Macro Index -- glibc reference manual
    The C Book -- nice online learner guide
    Current ISO draft standard
    CCAN -- new CPAN like open source library repository
    3 (different) GNU debugger tutorials: #1 -- #2 -- #3
    cpwiki -- our wiki on sourceforge

  6. #21
    Registered User
    Join Date
    Jun 2009
    Posts
    14
    OK then .. I got both imageinfo and picture into separate buffers.. now how can i merge them as in array.copy in JAVA : )?

  7. #22
    Registered User
    Join Date
    Jun 2009
    Posts
    14
    nvm the question lol i did it manually : pastebin - collaborative debugging tool but still not working :x

  8. #23
    spurious conceit MK27's Avatar
    Join Date
    Jul 2008
    Location
    segmentation fault
    Posts
    8,300
    Quote Originally Posted by TranT View Post
    OK then .. I got both imageinfo and picture into separate buffers.. now how can i merge them as in array.copy in JAVA : )?
    Why don't you check them first to see if this is jpeg data at all? I just used this on a whole directory of photographs:
    Code:
    #include <stdio.h>
    #include <stdlib.h>
    
    int main(int argc, char *argv[]) {
    	int size, i=0;
    	unsigned char image[1000000] = {0};
    	FILE *in = fopen(argv[1],"r");
    	size = fread(image,1,1000000,in);
    	fclose(in);
    	
    	while (i<size-1) {
    		if ((image[i]==255) && (image[i+1]==216)) 
    			printf("byte %d\n",i); 		
    		i++;
    	}
    
    	return 0;
    }
    12 megs, 265 files and every single one printed "byte 0", meaning all jpegs begin that way, and that sequence does not repeat anywhere inside the file.

    So adapt that while loop and try it.

    As for concatenating char arrays, just make one big buffer and then use memcpy(). You cannot use strcpy() or strcat() because the image data will have '\0' bytes in it. For the second memcpy, you want the destination to be an offset into the big buffer, eg.
    Code:
    memcpy(&buffer[666], from, size);
    Where "666" is the end of the first memcpy.

    [edit] looks like you already did this last part, or something sufficiently similar. So look for those two bytes...
    Last edited by MK27; 06-30-2009 at 08:46 AM.
    C programming resources:
    GNU C Function and Macro Index -- glibc reference manual
    The C Book -- nice online learner guide
    Current ISO draft standard
    CCAN -- new CPAN like open source library repository
    3 (different) GNU debugger tutorials: #1 -- #2 -- #3
    cpwiki -- our wiki on sourceforge

  9. #24
    Registered User
    Join Date
    Jun 2009
    Posts
    14
    i made prints for all the PTEID_PIC data: pastebin - collaborative debugging tool

    I scanned the whole picture data and didn't found any 0xFFD8 from JPEG :X but this has to be some kind of image :/ lol

  10. #25
    spurious conceit MK27's Avatar
    Join Date
    Jul 2008
    Location
    segmentation fault
    Posts
    8,300
    Quote Originally Posted by TranT View Post
    I scanned the whole picture data and didn't found any 0xFFD8 from JPEG :X but this has to be some kind of image :/ lol
    Sigh. That's what I was afraid of. You may have to email the people who wrote the software at this point; just be succinct and say what you want to do, what you've tried, and in what format does that function return?

    If it is software that came with hardware, you probably won't get an answer because manufacturers aren't programmers and they are usually not interested in your problems. Otherwise you probably will get some advice, since evidently the source is open.
    Last edited by MK27; 06-30-2009 at 09:10 AM.
    C programming resources:
    GNU C Function and Macro Index -- glibc reference manual
    The C Book -- nice online learner guide
    Current ISO draft standard
    CCAN -- new CPAN like open source library repository
    3 (different) GNU debugger tutorials: #1 -- #2 -- #3
    cpwiki -- our wiki on sourceforge

  11. #26
    Registered User
    Join Date
    Jun 2009
    Posts
    14
    The stupid thing about this is that this is the Portuguese Citizen Smartcard so this was "done" by the government lol will try to contact the developers then

    Thanks for all the help : )

  12. #27
    spurious conceit MK27's Avatar
    Join Date
    Jul 2008
    Location
    segmentation fault
    Posts
    8,300
    Quote Originally Posted by TranT View Post
    The stupid thing about this is that this is the Portuguese Citizen Smartcard so this was "done" by the government lol will try to contact the developers then

    Thanks for all the help : )
    I just want to make it clear at this point to any interested international authorities that I was *not* knowingly involved in this event.

    ps. @ TranT -- you need to get a new cboard id and start a different thread.
    C programming resources:
    GNU C Function and Macro Index -- glibc reference manual
    The C Book -- nice online learner guide
    Current ISO draft standard
    CCAN -- new CPAN like open source library repository
    3 (different) GNU debugger tutorials: #1 -- #2 -- #3
    cpwiki -- our wiki on sourceforge

  13. #28
    Registered User
    Join Date
    Sep 2008
    Location
    Toronto, Canada
    Posts
    1,834
    You should open the file with
    Code:
    fopen(argv[1],"rb")
    And likewise create/open the destination file with "wb". Plus it's always good practice to fclose() the new file as well.

  14. #29
    Registered User
    Join Date
    Jun 2009
    Posts
    14
    MK27 I am not exploiting in any way the smartcard i am just trying to get the image of it and thats legal so you don't have to be worrying about anything lol

    cheers

  15. #30
    Guest Sebastiani's Avatar
    Join Date
    Aug 2001
    Location
    Waterloo, Texas
    Posts
    5,708
    >> MK27 I am not exploiting in any way the smartcard i am just trying to get the image of it and thats legal so you don't have to be worrying about anything

    I'm afraid you're too late. He's already changed his name and moved to Yonkers, holed up in a little cabin by the river. But no worries, I'm sure he's much happier there.
    Code:
    #include <cmath>
    #include <complex>
    bool euler_flip(bool value)
    {
        return std::pow
        (
            std::complex<float>(std::exp(1.0)), 
            std::complex<float>(0, 1) 
            * std::complex<float>(std::atan(1.0)
            *(1 << (value + 2)))
        ).real() < 0;
    }

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Another syntax error
    By caldeira in forum C Programming
    Replies: 31
    Last Post: 09-05-2008, 01:01 AM
  2. C++ ini file reader problems
    By guitarist809 in forum C++ Programming
    Replies: 7
    Last Post: 09-04-2008, 06:02 AM
  3. Game Pointer Trouble?
    By Drahcir in forum C Programming
    Replies: 8
    Last Post: 02-04-2006, 02:53 AM
  4. Need help understanding info in a header file
    By hicpics in forum C Programming
    Replies: 8
    Last Post: 12-02-2005, 12:36 PM
  5. File Input / Output Help?
    By Unregistered in forum C Programming
    Replies: 3
    Last Post: 05-18-2002, 10:20 AM