Part of the Khronos Group
OpenGL.org

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Results 1 to 8 of 8

Thread: JPEGLIB

  1. #1
    Member Regular Contributor
    Join Date
    Aug 2001
    Posts
    259

    JPEGLIB

    My engine needs to be able to read JPEG files the best LIB ive found for this is the JPEGLIB. I was wondering if anyone knew of a site that has a good example of using JPEGLIB to draw the image on a square/cube in OpenGL and maybe has a tutorial explaining it.

    Thanks
    Nuke

  2. #2
    Advanced Member Frequent Contributor
    Join Date
    Apr 2003
    Posts
    680

  3. #3
    Member Regular Contributor
    Join Date
    Aug 2001
    Posts
    259

    Re: JPEGLIB

    Thanks for the link it was very usefull but im still having some problems, I was wondering if you could help out.

    g++ gives me this when I compile

    /usr/include/jpeglib.h:719: 'size_t' is used as a type, but is not defined as a
    type.
    /usr/include/jpeglib.h:731: 'size_t' is used as a type, but is not defined as a
    type.
    /usr/include/jpeglib.h:763: type specifier omitted for parameter `size_t'
    /usr/include/jpeglib.h:763: parse error before `)' token
    /usr/include/jpeglib.h:765: type specifier omitted for parameter `size_t'
    /usr/include/jpeglib.h:765: parse error before `)' token
    /usr/include/jpeglib.h:905: type specifier omitted for parameter `size_t'
    /usr/include/jpeglib.h:905: parse error before `)' token
    /usr/include/jpeglib.h:907: type specifier omitted for parameter `size_t'
    /usr/include/jpeglib.h:907: parse error before `)' token
    /usr/include/jpeglib.h:914: type specifier omitted for parameter `FILE'
    /usr/include/jpeglib.h:914: parse error before `*' token
    /usr/include/jpeglib.h:915: type specifier omitted for parameter `FILE'
    /usr/include/jpeglib.h:915: parse error before `*' token

    Any idea what thats all about?

    Also Im not sure Im loading the file correctly. I think i screwed up jpeg_read_scanlines, the docs didnt really cover how to turn this into something OGL could read. Also the docs said to delete the jpeg header with jpeg_destory_decompress but its undefined. Can you take a look at the code please and tell me if anything is wrong?

    Code :
      unsigned long x;
      unsigned long y;
      char* data;
     
      bool LoadJPEG(char* FileName, bool Fast)
      {
        FILE* file = fopen(FileName, "rb");  //open the file
        struct jpeg_decompress_struct info;  //the jpeg decompress info
        struct jpeg_error_mgr err;           //the error handler
     
        info.err = jpeg_std_error(&err);     //tell the jpeg decompression handler to send the errors to err
        jpeg_create_decompress(&info);       //sets info to all the default stuff
     
        //if the jpeg file didnt load exit
        if(!file)
        {
          fprintf(stderr, "Error reading JPEG file %s!!!", FileName);
          return false;
        }
     
        jpeg_stdio_src(&info, &file);    //tell the jpeg lib the file we'er reading
     
        jpeg_read_header(&info, TRUE);   //tell it to start reading it
     
        //if it wants to be read fast or not
        if(Fast)
        {
          info.do_fancy_upsampling = FALSE;
        }
     
        jpeg_start_decompress(&info);    //decompress the file
     
        //set the x and y
        x = info.output_width;
        y = info.output_height;
     
        //get the size of the file
        unsigned long size = x * y * 3;
     
        data = (char*)malloc(size);      //setup data for the data its going to be handling
     
        //read the scan lines
        jpeg_read_scanlines(&info, (JSAMPROW*)data, size);
     
        jpeg_finish_decompress(&info);   //finish decompressing this file
     
        fclose(file);                    //close the file
     
        //jpeg_destory_decompress(&info);  //free info's mem space
     
        return true;
      }
    Thanks for your help!!!

    Nuke

    [This message has been edited by nukem (edited 04-30-2003).]

  4. #4
    Advanced Member Frequent Contributor
    Join Date
    Apr 2000
    Location
    Melbourne,Victoria,Australia
    Posts
    748

    Re: JPEGLIB

    From the link given above...

    Applications using the JPEG library should include the header file jpeglib.h to obtain declarations of data types and routines. Before including jpeglib.h, include system headers that define at least the typedefs FILE and size_t. On ANSI-conforming systems, including <stdio.h> is sufficient; on older Unix systems, you may need <sys/types.h> to define size_t.
    Perhaps that's your problem?

    Have you tried looking at OpenIL?

  5. #5
    Senior Member OpenGL Guru
    Join Date
    Dec 2000
    Location
    Reutlingen, Germany
    Posts
    2,042

    Re: JPEGLIB

    OpenIL is called DevIL now. And thatīs really a helpful lib:
    http://openil.sourceforge.net/

    Jan.
    GLIM - Immediate Mode Emulation for GL3

  6. #6
    Member Regular Contributor
    Join Date
    Jan 2002
    Posts
    292

    Re: JPEGLIB

    That error is because it is looking for the header in a linux (unix) file system...
    Put the headers wherever you want, and make sure you have the right path for the header in your include statements...

    Well, I am not sure if you are using linux already, since you are using g++. But is just an assumption.

    [This message has been edited by mancha (edited 05-01-2003).]

    [This message has been edited by mancha (edited 05-01-2003).]

  7. #7
    Member Regular Contributor
    Join Date
    Aug 2001
    Posts
    259

    Re: JPEGLIB

    I moved the #include <jpeglib.h> and #include <jerror.h> to the bottom of my header list and it cleared that up. I forgot about the order. Im still getting a segment fault when I run. I think its because of the way I use jpeg_read_scanline if anyone could help me with that it would be great.

    OpenIL seems like a good thing to use I might goto if I cannt get this to work. I just want to see if I can get this working.

    Thanks
    Nuke

  8. #8
    Member Regular Contributor
    Join Date
    Aug 2001
    Posts
    259

    Re: JPEGLIB

    Ok I got it to work

    Thanks for your help!!!

    Code :
      bool LoadJPEG(char* FileName, bool Fast)
      {
        FILE* file = fopen(FileName, "rb");  //open the file
        struct jpeg_decompress_struct info;  //the jpeg decompress info
        struct jpeg_error_mgr err;           //the error handler
     
        info.err = jpeg_std_error(&amp;err);     //tell the jpeg decompression handler to send the errors to err
        jpeg_create_decompress(&amp;info);       //sets info to all the default stuff
     
        //if the jpeg file didnt load exit
        if(!file)
        {
          fprintf(stderr, "Error reading JPEG file %s!!!", FileName);
          return false;
        }
     
        jpeg_stdio_src(&amp;info, file);    //tell the jpeg lib the file we'er reading
     
        jpeg_read_header(&amp;info, TRUE);   //tell it to start reading it
     
        //if it wants to be read fast or not
        if(Fast)
        {
          info.do_fancy_upsampling = FALSE;
        }
     
        jpeg_start_decompress(&amp;info);    //decompress the file
     
        //set the x and y
        x = info.output_width;
        y = info.output_height;
     
        size = x * y * 3;
     
        data = new BYTE[size];      //setup data for the data its going to be handling
     
        //read the scan lines
        BYTE* p1 = data;
        BYTE** p2 = &amp;p1;
        int numlines = 0;
     
        while(info.output_scanline < info.output_height)
        {
          numlines = jpeg_read_scanlines(&amp;info, p2, 1);
          *p2 += numlines * 3 * info.output_width;
        }
     
        jpeg_finish_decompress(&amp;info);   //finish decompressing this file
     
        fclose(file);                    //close the file
     
        return true;
      }

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •