Wednesday, August 22, 2012

Got basic hardware accelerated JPEG decoding working on Raspberry Pi!

I've got OpenMAX hardware JPEG decoding working on the Raspberry Pi!  I wrote a bunch of .cpp/.h files to make doing the OpenMAX API calls nice and organized so I should be able to use this in the Dexter source code.

Things left to do before I can say that the JPEG decoding problem is conquered:
- decode multiple images in sequence and verify that the speed is acceptable.
- decode the "abbreviated" JPEGs that I am using inside the LDImage file format.  The pi hardware can't handle these abbreviated JPEGs so I will need to figure out how to construct a "regular" JPEG from the "abbreviated" JPEG.  Concatenating the JPEG headers with the abbreviated JPEG does not do the trick unfortunately.
- (optional) decode to RGBA format instead of YV12 just to see if I can.  Then I can easily compare the pixel values with what I see inside something like GIMP.

Here's all of the files I wrote to accomplish this (it's an impressive amount of work in a short period of time!)

pi@raspberrypi /opt/vc/src/hello_pi/hello_jpeg $ ls -l *.cpp *.h
-rw-r--r-- 1 pi pi 5983 Aug 23 03:19 hello_jpeg.cpp
-rw-r--r-- 1 pi pi  139 Aug 22 17:33 ILocker.h
-rw-r--r-- 1 pi pi  166 Aug 22 19:15 ILogger.h
-rw-r--r-- 1 pi pi  820 Aug 22 17:11 Locker.cpp
-rw-r--r-- 1 pi pi  496 Aug 22 16:54 Locker.h
-rw-r--r-- 1 pi pi  128 Aug 22 19:31 Logger.cpp
-rw-r--r-- 1 pi pi  159 Aug 22 19:29 Logger.h
-rw-r--r-- 1 pi pi  381 Aug 22 17:07 MyDeleter.h
-rw-r--r-- 1 pi pi 6111 Aug 23 03:16 OMXComponent.cpp
-rw-r--r-- 1 pi pi 3136 Aug 23 03:10 OMXComponent.h
-rw-r--r-- 1 pi pi 1365 Aug 22 19:26 OMXCore.cpp
-rw-r--r-- 1 pi pi  826 Aug 22 19:26 OMXCore.h

And here is what it looks like to run my hello_jpeg.bin program on an arbitrary JPEG:

pi@raspberrypi /opt/vc/src/hello_pi/hello_jpeg $ ./hello_jpeg.bin lair1.jpg
Got event: 0
Got event: 0
Got event: 0
Got event: 0
Got event: 0
Got EmptyBufferDone
Got EmptyBufferDone
Got event: 3
Width: 640 Height: 480 Output Color Format: 20 Buffer Size: 460800
Got event: 0
Got event: 4
Got FillBufferDone

Color format "20" is YUV420Planar mode.

pi@raspberrypi /opt/vc/src/hello_pi/hello_jpeg $ ls -l output.raw
-rw-r--r-- 1 pi pi 460800 Aug 23 04:36 output.raw

This means that the file is organized with the Y plane coming first at a full resolution of 640x480, 8 bits per pixel.  So that takes up 307200 bytes.  Then comes the V plane (I believe) at a half resolution of 320x480, so that is 76800 bytes.  Then the U plane, also at half resolution of 320x480 for another 76800.  307200 + 76800 + 76800 does indeed equal 460800 bytes.  So it appears to be wookin' perfectly!

No comments:

Post a Comment