[RVB2601 Creative Application Development] Dynamically loading MBRE JPEG decoder transplant source code and test results
[Copy link]
JPEG is a common method of lossy compression of digital images, especially for images produced by digital photography. JPEG (Joint Photographic Experts Group) is a committee under the leadership of the International Organization for Standardization (ISO) that develops static image compression standards. The first set of international static image compression standards ISO 10918-1 (JPEG) was developed by this committee. Due to the excellent quality of JPEG, it has achieved success in just a few years and is widely used in the Internet and digital camera fields. 80% of the images on the website use the JPEG compression standard. Compared with lossless compression formats such as PNG and GIF, JPEG provides storage capabilities with high compression ratios under controllable quality loss.
TJpgDec is a highly optimized PEG image decoding module specifically designed for small embedded systems, with several very obvious features:
- Platform-independent. Written in ANSI-C, it can be ported to platforms that support ANSI-C without any problems.
- Easy-to-use operation mode, output can be configured in YUV or RGB888, 565 format, and the output is completed by callback method;
-
Fully reentrant architecture, after successful decoding, you can directly reenter and perform new decoding without any restart operation
-
Ultra-small memory usage, only 3100 bytes of working memory are needed in the minimum configuration. Due to the block decoding design, no matter how large the original image size is, it will not consume more working memory. The ROM usage is less than 10K
Bodmer , the author of TJpgDec, is also the author of TFT-espi, so the combination of the two is seamless and very easy to use.
During the dynamic loading of the MBRE test, JPG, as one of the supporting libraries of the small TV project, was also ported and tested. Because RVB2601 does not directly provide spiffs, only the principle test of memory array decoding was done (the operation from the file system is essentially the same, and only the access interface to the file system needs to be added). The porting process mainly involves modifying some included header files to ensure that the compilation is successful. Please refer to the attachment for the decoder source code.
TJpg_Decoder.rar
(15.01 KB, downloads: 2)
Basically, no problems were encountered.
The decoder is very easy to use with TFT-ESPI, because the decoder is configured to output RGB 565, which is consistent with the output format of ILI9341 used in the experiment. Therefore, you only need to specify the output callback function during initialization and paste the decoded bitmap onto the TFT in the callback function. Here is a small example:
//JPG Decoder的初始化设置
TJpgDec.thisPtr = &TJpgDec; //移植版本去掉了构造函数,手工处理原构造函数中的指针赋值操作
TJpgDec.setJpgScale(1); //缩放比例,设置为1
TJpgDec.setSwapBytes(false); //565标准格式,无需交换RGB bytes
TJpgDec.setCallback(tft_output); //解码输出回调,每解码一部分,产生小块位图,就会回调一次
//以下解码RAM中的JPG数组,并计算解码,刷新时间显示在屏幕中
time_t t0 = millis();
TJpgDec.drawJpg(0, 0, testjpg_data, sizeof(testjpg_data));
time_t t1 = millis();
char buf[128];
sprintf(buf, "JPG解码测试 %dms", t1 - t0);
//使用TFT-espi的API显示文字
gpTft->drawString(buf, 8, 10, MBRE_FIXED_FONT);
In the above code, tft_output is a callback function. The JPG decoder decodes in small blocks (so that RAM usage can be controlled). After decoding a block, the set callback function will be called to perform actual drawing processing. Here is a reference implementation of tft_output using tft_espi:
// TFT屏幕输出函数
bool tft_output(int16_t x, int16_t y, uint16_t w, uint16_t h, uint16_t* bitmap)
{
//简单的裁剪保护,超过屏幕Y最大值不用绘制了
//并返回0,通知解码器不用再进行后续解码
if(y >= gpTft->height()) return 0;
//将位图通过Tft-espi绘制到屏幕上, tft-espi会对位图做基本的裁剪保护
gpTft->pushImage(x, y, w, h, bitmap);
// 返回1告诉解码器继续解码
return 1;
}
Finally, the above figure shows the actual test results of decoding 320x240 QVGA resolution JPEG on RVB2601. The JPEG decoding and screen refresh time shown in the figure is about 190MS. Considering that the single screen refresh time is between 60-100ms, the decoding time is about 90-130ms, which is an acceptable indicator. For more practical use of JPG DECODER, it is recommended that you refer to the open source code of the small TV project mentioned in MBRE's previous sharing. The astronaut flying animation is a smooth animation effect achieved by using JPG continuous decoding + TSprite off-screen buffering.
|