Join Today
+ Reply to Thread
Results 1 to 6 of 6

Thread: GIF image

  1. #1

    Default GIF image

    I have this little problem with reading GIF files. Now I'm trying to determine if a specific file is a GIF or not, I simply open the file in binary (fopen) and read the first few bytes (fread) which must contain the characters "GIF" for this file to a valid GIF file. This is exactly what I get with an "english" filename. However if that same file is renamed to a "chinese" name, the very same first bytes are completely different! What I mean is the following:

    Reading the english GIF file yields the following for the first 3 bytes:
    71 73 70 (equivalent to the GIF characters in unicode, 0x47 0x49 0x46 in hex)

    Reading the very same GIF file but with a chinese filename yields the following for the first 3 bytes:
    228 99 24 (equivalent to something meaningless)

    I can't seem to find a connection between the two, not even a reason for these values to look like that cause with vi, opening both files I can see GIF at the top but not when I use fread. The only way I can think of round this is to copy the chinese file somewhere else renaming it to something english (that would give me the GIF characters) but that's way too expensive... Any ideas?

  2. #2

    Default Re: GIF image

    I think it has to do with the Character-Encoding. Maybe Chinese filenames will directly match to be UTF-8 or some other chinese encoding.

    How do you use fread? do you read bytes or characters?

  3. #3

    Default Re: GIF image

    Code:
    FILE* fd = fopen(aPath, "rb");
    char* tBuffer;
    tBuffer = (char*)malloc(4);
    // copy the bytes into the buffer.
    fread(tBuffer, 1, 4, fd);
    I read bytes. You mean the OS itself is responsible for matching any chinese file (with a chinese filename) to its appropriate encoding? I mean I did rename an english gif file to chinese and that definitely didn't change the data in the file itself, yet I get the "gif" characters when I fread the english named file but not the chinese one. However how come "vi", an editor under linux, displays the "gif" when used to open both files?

  4. #4

    Default Re: GIF image

    I didn't programm C for many years now. But can't you use a byte-array for reading data? You read chars! Maybe the compiler (or OS) is "intelligent" enough to use UTF (or any other encoding) automatically when reading char from a file.
    Even there is no real definition of what is a char in C. It maybe 8Bit, but could also be 32Bit, depending on the compiler and OS.
    I think the only definition is byte <= word <= int <= long and char???.

    So here are some ideas:
    - use byte instead of char
    - use malloc(4*sizeof(byte))
    - print the values of the read bytes
    - print the value of sizeof(char) // maybe it is not 1
    if all that does not help you could send a more complete code.

  5. #5

    Default Re: GIF image

    Indeed! I took C's char as 8bit for granted and that was exactly the problem; it isn't. Instead I tried reading actual bytes and now it works. I always thought char was 8bit... Thanks for the tip!

  6. #6

    Default Re: GIF image



 
+ Reply to Thread

Similar Threads

  1. Req: Boot Image and Animations from Image
    By tanmayjindal in forum MotoTheme
    Replies: 10
    Last Post: 01-15-2010, 12:25 PM
  2. Nice boot image and animation image for e6
    By drhardik in forum Moto Media
    Replies: 18
    Last Post: 06-19-2009, 04:44 PM
  3. GIF image for wallpaper
    By honest_boy828 in forum E6 General Chat
    Replies: 7
    Last Post: 01-20-2009, 11:03 AM
  4. my own on.gif image problem
    By tojo_friend in forum E6 General Chat
    Replies: 4
    Last Post: 07-24-2008, 02:47 PM
  5. png,gif image creator....!!???
    By Ghost-Rider13 in forum Moto Skins Technical Forum
    Replies: 8
    Last Post: 07-22-2008, 08:21 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
Single Sign On provided by vBSSO

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1