1. This forum section is a read-only archive which contains old newsgroup posts. If you wish to post a query, please do so in one of our main forum sections (here). This way you will get a faster, better response from the members on Motherboard Point.

gif to binary data

Discussion in 'Embedded' started by tanu, Sep 13, 2006.

  1. tanu

    tanu Guest

    hi all
    i m using a 240*128 pix lcd with t6963c controller
    wanna see the graphics in it
    lcd is interfaced with atmega 128 microcontroller

    for graphics i thougt of converting the gif file to binary data so did
    this
    i had 1st save the gif file in to the txt
    so to get ascii data
    before i aslo tried direct gif to binary
    i m getting binary data rite acording to the txt file but when i m
    seeing this data
    in the lcd i m not getting that image
    infact i had discarded the 22 bytes from the data


    #include <stdlib.h>
    #include <stdio.h>
    #include<conio.h>
    typedef unsigned char byte;
    #define SIZEBMP 3840
    #define SIZELCD 42240
    static int i;
    int ig,jg;
    unsigned char tg;
    int y;
    char kg[8];
    void convert(void);
    //byte getvertByte(int ,int bit);
    unsigned char getbits(unsigned x, int p, int n);
    byte count, arrayLCD[SIZELCD], arrayBmp[SIZEBMP];
    main()
    {
    clrscr();
    FILE *fp;

    /* open the bitmap for reading in binary mode */

    if ( (fp = fopen("\\compass22.txt", "r")) == NULL)
    {
    fprintf(stderr, "Error opening file.");
    }

    fp = fopen("\\compass22.txt", "r");
    fread(arrayBmp, sizeof( byte), SIZEBMP, fp);
    for(ig=0;ig<SIZEBMP;ig++)
    {
    printf("%c",arrayBmp[ig]);
    for(y=0;y<sizeof(char)*8;y++)
    {
    kg[y]=arrayBmp[ig] & (1<<y)?'1':'0';
    }
    for(y=7,jg=0;y>=0,jg<8;y--,jg++)
    {
    printf("%c",kg[y]);
    arrayLCD[11*ig+jg]=kg[y];
    }
    if(jg==8)
    {arrayLCD[11*ig+jg]=',';
    jg++;
    arrayLCD[11*ig+jg]='0';
    jg++;
    arrayLCD[11*ig+jg]='b';}
    }
    printf("\n\n\n");

    fclose(fp);

    if ( (fp = fopen("\\compass234.txt", "w+b")) == NULL)
    {
    fprintf(stderr, "Error opening file.");
    exit(1);
    }
    fp = fopen("\\compass234.txt", "wb");
    fwrite(arrayLCD, sizeof(byte), SIZELCD, fp);
    for(ig=0;ig<SIZELCD;ig++)
    {
    printf("%c",arrayLCD[ig]);
    }
    fclose(fp);

    return(0);
    }





    so do tell me where m i wrong
    and do tell if there is any other way to find the binary data
     
    tanu, Sep 13, 2006
    #1
    1. Advertisements

  2. Is that a question? If not, and you omitted an "I" then the obvious
    remedy is: try looking at the display while it is faced upwards.
    Which gif file? Which binary format do you intend to use?
    Which txt? How?
    Please rephrase this part, using proper sentences and without "rite",
    which is not a word.
    Which 22 bytes? Why did you discard them?
    Which platform was this code designed to run on? What did you expect of
    the program?
    You are wrong in the assumption that we are your personal slaves. You are
    wrong in the assumption that most people will easily understand what you
    are talking about.
     
    Boudewijn Dijkstra, Sep 13, 2006
    #2
    1. Advertisements

  3. tanu

    Stef Guest

    In comp.arch.embedded,
    I am sorry, but I'm unable to understand what exactly you have tried
    to do here.

    A GIF file is a graphics file in a specific format that you need to
    parse to get the image. See www.wotsit.org for the GIF file format.
    But you may want to start of with something like the BMP format as
    it is much easier to decode (also see wotsit for the format).
    This is a non-standard header, what is your platform?
    240 * 128 / 8

    Where does this number come from?
    Why are these variable global?
    int main(void)
    Binary mode? --> "rb"
    Program gets here if open suceeded or not
    Open again? That will probably fail.
    Ok file now closed, your indentation makes it seem like it's in
    a loop, but it's not.

    Now you do something on an error,
    But you als open the file twice, why? And in different modes this time.
    You are not parsing the graphics file properly, read the stuff on wotsit.
    Your variable names seem to suggest you are using the BMP format but you
    say you are using GIF.
     
    Stef, Sep 13, 2006
    #3
  4. tanu

    Tom Lucas Guest

    By assigning 3840 bytes for the Bitmap buffer I assume you are using 1
    bit per pixel black and white. I can't see a reason why the LCD array is
    the size it is 42240 bytes or why you need to define it. A frame buffer
    of 3840 will be plenty by itself.
    The files would definitely have to be treated as binaries when opening,
    although you shouldn't have to convert anything - fopen will handle
    that.
    The gif won't map directly to your bitmap buffer - you will need to
    decode it. Why don't you start with a bitmap file until you get the hang
    of the display and then move onto compressed formats like gif.
    Do you mean that 22 bytes of the data were missing from the buffer or
    did you purposefully discard them. If so, why? Is this you stripping off
    the header?

    If you use bitmap data then you can just copy the data section of the
    file straight to the buffer. In windows bitmaps, the 32bit word in the
    11th, 12th, 13th and 14th bytes of the file tells you how far from the
    start of the file the data begins.

    <snip code>

    Your code could really use some comments and some more meaningful
    variable names.
    You may need "rb" in your fopen to open the file as a binary file. Other
    than that then you should have the binary data where you want it but I'm
    not convinced it will be data in the form you think it should be.

    And for goodness sake use capital letters and apostrophes - you're a big
    boy now.
     
    Tom Lucas, Sep 13, 2006
    #4
  5. tanu

    tanu Guest

    Thanks alot for help
    and ur suggetion to me
    now i'll take care while wrtiting anything
    actually i m new to google group so dont know and was bit in hurry to
    write here
    now ll xplain all the thing properly
    after 3 hr bye thanx a lot bye
     
    tanu, Sep 14, 2006
    #5
  6. tanu

    CBFalconer Guest

    Don't use silly abbreviations in usenet. Do capitalize the first
    letters in sentences and the personal pronoun I. Do terminate
    sentences with periods. Failure to spell things properly simply
    marks you as childish and makes your articles hard to read. Most
    won't bother to read them.

    You are not using google groups, you are using usenet. Google only
    supplies a very poor interface to the usenet system.
     
    CBFalconer, Sep 14, 2006
    #6
    1. Advertisements

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 (here). After that, you can post your question and our members will help you out.