- SDL_FreeSurface(img);
-
- // Try encoding using a single RLE stream
- rle32length = RLE1_7(NULL, buffer, img->w * img->h, 4, 4, 3);
-
- // Try encoding using separate RLE streams for each channel
- rle4x8length = RLE1_7(NULL, buffer, img->w * img->h, 1, 4, 2);
- rle4x8length += RLE1_7(NULL, ((uint8_t*)buffer)+1, img->w * img->h, 1, 4, 2);
- rle4x8length += RLE1_7(NULL, ((uint8_t*)buffer)+2, img->w * img->h, 1, 4, 2);
- rle4x8length += RLE1_7(NULL, ((uint8_t*)buffer)+3, img->w * img->h, 1, 4, 2);
-
- printf("raw length = %i\n", img->w * img->h * 4);
- printf("rle32length = %i\n", rle32length);
- printf("rle4x8length = %i\n", rle4x8length);
-
- if( rle32length < rle4x8length ) {
- comp = 1; // 32-bit RLE
- buffer2 = malloc( rle32length );
- bufLen = RLE1_7(buffer2, buffer, img->w * img->h, 4, 4, 2);
+ if( comp == COMP_AUTO )
+ {
+ // Try encoding using a single RLE stream
+ size_t rle32length = CompressRLE1x32(NULL, buffer, pixel_count);
+ // Try encoding using separate RLE streams for each channel
+ size_t rle4x8length = CompressRLE4x8(NULL, buffer, pixel_count);
+
+ // printf("raw length = %i\n", pixel_count * 4);
+ // printf("rle32length = %u\n", (unsigned int)rle32length);
+ // printf("rle4x8length = %u\n", (unsigned int)rle4x8length);
+
+ if( rle32length <= rle4x8length ) {
+ comp = COMP_RLE1x32; // 32-bit RLE
+ }
+ else {
+ comp = COMP_RLE4x8; // 4x8 bit RLE
+ }