Skip to content

Cannot change jpeg_width and jpeg_height without reflection #9

@Dwedit

Description

@Dwedit

I was working on a tool that let you losslessly merge two JPEGs together by putting one on top of the other. This can be done if they were saved with the same compression settings.

I did manage to get it working correctly, but I encountered one problem with the library when I had to save the JPEG file.

var decompress1 = new jpeg_decompress_struct();  //Create 'decompress' object
decompress1.jpeg_stdio_src(inputFileStream1);  //Load a JPEG file
decompress1.jpeg_read_header(true);  //Load the header
var compress = new jpeg_compress_struct();  //Create 'compress' object
compress.jpeg_stdio_dest(outputStream);  //Assign the output stream
decompress1.jpeg_copy_critical_parameters(compress);  //Copy the critical parameters
compress.Image_width = outputWidth;  //Set output width
compress.Image_height = outputHeight;  //Set output height
compress.jpeg_write_coefficients(outputBlocks);  //Set Output DCT blocks
compress.jpeg_finish_compress();  //Output the JPEG file

The problem happens when you call jpeg_finish_compress, it ignores the public Image_width and Image_height fields. Instead, it uses the private fields jpeg_width and jpeg_height to determine what dimensions to use for the output file.

In order to get the program to work, I needed to use reflection to write to those private members.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions