mirror of
https://github.com/jomjol/AI-on-the-edge-device.git
synced 2025-12-08 20:46:52 +03:00
v10.2.0
This commit is contained in:
@@ -17,7 +17,11 @@
|
||||
#if ESP_IDF_VERSION_MAJOR >= 4 // IDF 4+
|
||||
#if CONFIG_IDF_TARGET_ESP32 // ESP32/PICO-D4
|
||||
#include "esp32/rom/tjpgd.h"
|
||||
#else
|
||||
#elif CONFIG_IDF_TARGET_ESP32S2
|
||||
#include "tjpgd.h"
|
||||
#elif CONFIG_IDF_TARGET_ESP32S3
|
||||
#include "esp32s3/rom/tjpgd.h"
|
||||
#else
|
||||
#error Target CONFIG_IDF_TARGET is not supported
|
||||
#endif
|
||||
#else // ESP32 Before IDF 4.0
|
||||
|
||||
@@ -22,6 +22,7 @@ extern "C" {
|
||||
#include <stdint.h>
|
||||
#include <stdbool.h>
|
||||
#include "esp_camera.h"
|
||||
#include "esp_jpg_decode.h"
|
||||
|
||||
typedef size_t (* jpg_out_cb)(void * arg, size_t index, const void* data, size_t len);
|
||||
|
||||
@@ -120,6 +121,8 @@ bool frame2bmp(camera_fb_t * fb, uint8_t ** out, size_t * out_len);
|
||||
*/
|
||||
bool fmt2rgb888(const uint8_t *src_buf, size_t src_len, pixformat_t format, uint8_t * rgb_buf);
|
||||
|
||||
bool jpg2rgb565(const uint8_t *src, size_t src_len, uint8_t * out, jpg_scale_t scale);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -24,6 +24,10 @@
|
||||
#if ESP_IDF_VERSION_MAJOR >= 4 // IDF 4+
|
||||
#if CONFIG_IDF_TARGET_ESP32 // ESP32/PICO-D4
|
||||
#include "esp32/spiram.h"
|
||||
#elif CONFIG_IDF_TARGET_ESP32S2
|
||||
#include "esp32s2/spiram.h"
|
||||
#elif CONFIG_IDF_TARGET_ESP32S3
|
||||
#include "esp32s3/spiram.h"
|
||||
#else
|
||||
#error Target CONFIG_IDF_TARGET is not supported
|
||||
#endif
|
||||
@@ -115,6 +119,54 @@ static bool _rgb_write(void * arg, uint16_t x, uint16_t y, uint16_t w, uint16_t
|
||||
return true;
|
||||
}
|
||||
|
||||
static bool _rgb565_write(void * arg, uint16_t x, uint16_t y, uint16_t w, uint16_t h, uint8_t *data)
|
||||
{
|
||||
rgb_jpg_decoder * jpeg = (rgb_jpg_decoder *)arg;
|
||||
if(!data){
|
||||
if(x == 0 && y == 0){
|
||||
//write start
|
||||
jpeg->width = w;
|
||||
jpeg->height = h;
|
||||
//if output is null, this is BMP
|
||||
if(!jpeg->output){
|
||||
jpeg->output = (uint8_t *)_malloc((w*h*3)+jpeg->data_offset);
|
||||
if(!jpeg->output){
|
||||
return false;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
//write end
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
size_t jw = jpeg->width*3;
|
||||
size_t jw2 = jpeg->width*2;
|
||||
size_t t = y * jw;
|
||||
size_t t2 = y * jw2;
|
||||
size_t b = t + (h * jw);
|
||||
size_t l = x * 2;
|
||||
uint8_t *out = jpeg->output+jpeg->data_offset;
|
||||
uint8_t *o = out;
|
||||
size_t iy, iy2, ix, ix2;
|
||||
|
||||
w = w * 3;
|
||||
|
||||
for(iy=t, iy2=t2; iy<b; iy+=jw, iy2+=jw2) {
|
||||
o = out+iy2+l;
|
||||
for(ix2=ix=0; ix<w; ix+= 3, ix2 +=2) {
|
||||
uint16_t r = data[ix];
|
||||
uint16_t g = data[ix+1];
|
||||
uint16_t b = data[ix+2];
|
||||
uint16_t c = ((r & 0xF8) << 8) | ((g & 0xFC) << 3) | (b >> 3);
|
||||
o[ix2+1] = c>>8;
|
||||
o[ix2] = c&0xff;
|
||||
}
|
||||
data+=w;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
//input buffer
|
||||
static uint32_t _jpg_read(void * arg, size_t index, uint8_t *buf, size_t len)
|
||||
{
|
||||
@@ -140,6 +192,21 @@ static bool jpg2rgb888(const uint8_t *src, size_t src_len, uint8_t * out, jpg_sc
|
||||
return true;
|
||||
}
|
||||
|
||||
bool jpg2rgb565(const uint8_t *src, size_t src_len, uint8_t * out, jpg_scale_t scale)
|
||||
{
|
||||
rgb_jpg_decoder jpeg;
|
||||
jpeg.width = 0;
|
||||
jpeg.height = 0;
|
||||
jpeg.input = src;
|
||||
jpeg.output = out;
|
||||
jpeg.data_offset = 0;
|
||||
|
||||
if(esp_jpg_decode(src_len, scale, _jpg_read, _rgb565_write, (void*)&jpeg) != ESP_OK){
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
bool jpg2bmp(const uint8_t *src, size_t src_len, uint8_t ** out, size_t * out_len)
|
||||
{
|
||||
|
||||
@@ -317,7 +384,7 @@ bool fmt2bmp(uint8_t *src, size_t src_len, uint16_t width, uint16_t height, pixf
|
||||
}
|
||||
*out = out_buf;
|
||||
*out_len = out_size;
|
||||
return true;
|
||||
return true;
|
||||
}
|
||||
|
||||
bool frame2bmp(camera_fb_t * fb, uint8_t ** out, size_t * out_len)
|
||||
|
||||
@@ -25,6 +25,10 @@
|
||||
#if ESP_IDF_VERSION_MAJOR >= 4 // IDF 4+
|
||||
#if CONFIG_IDF_TARGET_ESP32 // ESP32/PICO-D4
|
||||
#include "esp32/spiram.h"
|
||||
#elif CONFIG_IDF_TARGET_ESP32S2
|
||||
#include "esp32s2/spiram.h"
|
||||
#elif CONFIG_IDF_TARGET_ESP32S3
|
||||
#include "esp32s3/spiram.h"
|
||||
#else
|
||||
#error Target CONFIG_IDF_TARGET is not supported
|
||||
#endif
|
||||
@@ -195,7 +199,7 @@ public:
|
||||
return true;
|
||||
}
|
||||
if ((size_t)len > (max_len - index)) {
|
||||
ESP_LOGW(TAG, "JPG output overflow: %d bytes", len - (max_len - index));
|
||||
//ESP_LOGW(TAG, "JPG output overflow: %d bytes (%d,%d,%d)", len - (max_len - index), len, index, max_len);
|
||||
len = max_len - index;
|
||||
}
|
||||
if (len) {
|
||||
@@ -215,7 +219,7 @@ bool fmt2jpg(uint8_t *src, size_t src_len, uint16_t width, uint16_t height, pixf
|
||||
{
|
||||
//todo: allocate proper buffer for holding JPEG data
|
||||
//this should be enough for CIF frame size
|
||||
int jpg_buf_len = 64*1024;
|
||||
int jpg_buf_len = 128*1024;
|
||||
|
||||
|
||||
uint8_t * jpg_buf = (uint8_t *)_malloc(jpg_buf_len);
|
||||
|
||||
Reference in New Issue
Block a user