mborgerson
Well-known member
I've downloaded a JPEG compression program and adapted it to run on the T4.1 to which I've connected my OV7670 camera. The original code used malloc() to allocate 256KB of buffers that hold pre-computed constants used during the compression. I moved these tables to arrays DMAMEM. The fact that DMAMEM doesn't get initialized is not an issue as an initialization function called from setup() fills the tables.
The JPEG compressor needs an RGB888 bitmap as input. In the original code, the bitmap was read from a .BMP file. I changed the code to use a bitmap in EXTMEM as the input data.
The process goes like this:
* Capture a VGA-sized image to a buffer in EXTMEM. The image can be either RGB565 or YUV422 encoded. YUV images compress to smaller files due to the reduced spatial color resolution.
* Use the Pixel Pipeline to convert the captured image from the original format to the RGB888 format the encoder wants. The converted image is now 921KB.
* Call the JPG encoder with a pointer to the RGB888 buffer and a file name.
* The encoder compresses the file and writes it to SD card with .jpg extension.
An uncompressed VGA image in RGB565 format is 614KBytes. My compressed test images are about 40KBytes. Here is a test image:

The original 600KB RGB565 image is too large to upload to the forum which only allows .bmp files under 390KB in size.
Compressing and writing a VGA image takes about 180MSec. The compression code first converts the RGB888 to YUV, then compresses the YUV data. Since the OV7670 can generate YUV images, I hope to eliminate the code and execution time needed to do the RGB888 to YUV conversion by having the compressor work directly on the YUV data from the camera. The compression code also writes the output to the SD card with one or two-byte writes. I hope to speed this up by writing the output to a buffer, then writing the full buffer to SD Card.
I've got last-minute shopping and wrapping to do, so I probably won't post example code until the weekend.
The JPEG compressor needs an RGB888 bitmap as input. In the original code, the bitmap was read from a .BMP file. I changed the code to use a bitmap in EXTMEM as the input data.
The process goes like this:
* Capture a VGA-sized image to a buffer in EXTMEM. The image can be either RGB565 or YUV422 encoded. YUV images compress to smaller files due to the reduced spatial color resolution.
* Use the Pixel Pipeline to convert the captured image from the original format to the RGB888 format the encoder wants. The converted image is now 921KB.
* Call the JPG encoder with a pointer to the RGB888 buffer and a file name.
* The encoder compresses the file and writes it to SD card with .jpg extension.
An uncompressed VGA image in RGB565 format is 614KBytes. My compressed test images are about 40KBytes. Here is a test image:

The original 600KB RGB565 image is too large to upload to the forum which only allows .bmp files under 390KB in size.
Compressing and writing a VGA image takes about 180MSec. The compression code first converts the RGB888 to YUV, then compresses the YUV data. Since the OV7670 can generate YUV images, I hope to eliminate the code and execution time needed to do the RGB888 to YUV conversion by having the compressor work directly on the YUV data from the camera. The compression code also writes the output to the SD card with one or two-byte writes. I hope to speed this up by writing the output to a buffer, then writing the full buffer to SD Card.
I've got last-minute shopping and wrapping to do, so I probably won't post example code until the weekend.