JPEG decompression from main memory into VRAM is slow. FIXED

support for the ARM toolchain
Post Reply
yrro
Posts: 12
Joined: Thu Jul 10, 2008 4:50 pm

JPEG decompression from main memory into VRAM is slow. FIXED

Post by yrro » Tue Dec 09, 2008 2:56 pm

I am writing a simple app for the DS that loads jpegs from cart (via libfat) and then, using Burt Radons JPEG decompression library, displays the result in BG_GFX.

My problem is that this process is too slow (somewhere in the order of 18 seconds). If I link the jpeg directly into the binary using bin2s, however, then the process very quick. Below is some example code:

Code: Select all

 FILE* file = fopen("files/my_image.jpg", "rb");
 uint8* buffer1 = new uint8[256*192*4];
 uint16* buffer2 = new uint16[256*192*4];

 while (!feof(file)){
     fread(buffer1, sizeof(unsigned char), 1, file);
 }

 JPEG_DecompressImage (buffer1, buffer2, 256, 192);
 dmaCopy(buffer2, BG_GFX, 256*192); 
So, most excellent code gurus, WTF? Am I doing it wrong?

Thanks
Last edited by yrro on Mon Dec 15, 2008 1:42 pm, edited 1 time in total.

yrro
Posts: 12
Joined: Thu Jul 10, 2008 4:50 pm

Re: JPEG decompression from main memory into VRAM is slow. why?

Post by yrro » Wed Dec 10, 2008 4:35 pm

*ahem*

I was doing it wrong :)

instead of messing about with a while loop, just read the file into the buffer thus:

Code: Select all

    //get file size
    fseek(file, 0L, SEEK_END);
    int size = ftell(file);
    fseek(file, 0L, SEEK_SET);

    //allocate buffers
    unsigned char* buffer1 = new unsigned char[size];
    uint16* buffer2 = new uint16[256*192*2];

    //read file into buffer
    fread(buffer1, sizeof(unsigned char), size, file);

    //decompress the JPEG
    JPEG_DecompressImage (buffer1, buffer2, 256, 192);

    //copy to VRAM
    memmove(BG_GFX, buffer2, 256*192);
See, aint that easy?

*sheesh*

albert
Posts: 3
Joined: Mon Nov 10, 2008 12:37 am

Re: JPEG decompression from main memory into VRAM is slow. FIXED

Post by albert » Sat Mar 14, 2009 2:22 pm

Hello,
I need to know if you could show here your code about how to load jpeg image into devkitpro because bmp image have big size. Besides I want to know if the quality of your image is good. Thx

Post Reply

Who is online

Users browsing this forum: Google [Bot] and 5 guests