JPEG support with ijg - getting access violation

前端 未结 7 1294
余生分开走
余生分开走 2021-01-06 12:00

I was recently trying to update my game to store graphics in compressed formats (JPEG and PNG).

Whilst I ended up settling on a different library, my initial attempt

7条回答
  •  暖寄归人
    2021-01-06 12:23

    here is a tested function

    void test(char FileName[])
    {
        unsigned long x, y;
        struct jpeg_decompress_struct info; //for our jpeg info
        struct jpeg_error_mgr err;           //the error handler
        JSAMPARRAY buffer;
        FILE* infile;
        //initialize error handling
        info.err = jpeg_std_error(& err);     
    
        infile = fopen(FileName, "rb");  //open the file
    
        //if the jpeg file doesn't load
        if(!infile) {
        fprintf(stderr, "Error reading JPEG file %s!", FileName);
            // printf("Error reading JPEG file %s!", FileName);
            //return 0;
        }
    
        //initialize the decompression
        jpeg_create_decompress(&info);
    
    
        //specify the input
        jpeg_stdio_src(&info, infile);    
    
        //read headers
        jpeg_read_header(&info, TRUE);   // read jpeg file header
    
        jpeg_start_decompress(&info);    // decompress the file
    
        //set width and height
        x = info.output_width;
        y = info.output_height;
    
        printf("x value is %ul", x);
        printf("x value is %ul", y);
    }
    

提交回复
热议问题