orangeduck / Corange

Pure C Game Engine
http://www.youtube.com/watch?v=482GxqTWXtA
Other
1.78k stars 199 forks source link

Add RLE decode support for TGA image format #73

Closed blogdron closed 1 year ago

blogdron commented 2 years ago

Many image editors with exports apply RLE compression for TGA format. I initially could not understand why I had noise instead of images, it turned out that the images were compressed :D. There is slow (but simple) realization of unpacking.

Plus for images with channels less than 3 I added duplication of the channels. This allows forcibly loading them, albeit with costs.

The test program for unpacking works well.

#include "corange.h"
/*    TGA RLE Decode Test    */
int main(int argc, char *argv[])
{
    //load rle image and decode
    image * i = image_tga_load_file("./rle-image.tga");
    //write no rle image
    image_tga_save_file(i,"./output.tga");
};

I hope it will be useful

IMPORTANT: If you used, for example, GIMP and created a compressed RLE TGA image in it, and then you unpacked it through the Corange back to the file files will not be the same bit in the bit. This is not an error just at the end there will not be 26 bytes of the image basement. This does not affect anything simply when saving the basement is not added. Therefore, the file size is always equal to 18 bytes header + Size X + Size Y * Number of channels.

blogdron commented 1 year ago

I wrote the code badly, so I should probably close the pull request. I'll try to fix it and make everything good, but maybe someone will do it for me, because I'm a lazy hedgehog =)