Skip to content

Instantly share code, notes, and snippets.

@xeecos
Last active March 8, 2023 08:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save xeecos/986b119106996ad7766e1a2e6777ee01 to your computer and use it in GitHub Desktop.
Save xeecos/986b119106996ad7766e1a2e6777ee01 to your computer and use it in GitHub Desktop.
jpeg encode test @https://github.com/espressif/esp-adf-libs/tree/master/esp_codec
#include <Arduino.h>
#include "esp_jpeg_enc.h"
int esp_jpeg_enc_demo1()
{
/// configure encoder
jpeg_enc_info_t info = DEFAULT_JPEG_ENC_CONFIG();
info.quality = 80;
info.src_type = JPEG_RAW_TYPE_RGB888;
/// allocate input buffer to fill original image stream.
int in_len = info.width * info.height * 3;
uint8_t *inbuf = (uint8_t *)ps_malloc(in_len);
for(int i=0;i<in_len;i++)
{
inbuf[i] = i%255;
}
if (inbuf == NULL)
{
return 0;
}
/// allocate output buffer to fill encoded image stream.
int out_len = info.width * info.height * 2;
uint8_t *outbuf = (uint8_t *)ps_malloc(out_len);
if (inbuf == NULL)
{
return 0;
}
int out_size = 0;
void *el = jpeg_enc_open(&info);
if (el == NULL)
{
return 0;
}
jpeg_enc_process(el, inbuf, in_len, outbuf, out_len, &out_size);
return 1;
}
void setup()
{
USBSerial.begin(115200);
}
void loop()
{
delay(1000);
long time = millis();
USBSerial.printf("start\n");
int err = esp_jpeg_enc_demo1();
USBSerial.printf("time:%d, %d\n", err, millis() - time);
}
[env:esp32s3]
platform = espressif32
board = esp32-s3-wroom-1
board_build.partitions = default_8MB.csv
board_build.flash_mode = qio
board_upload.flash_size = 8MB
build_flags =
-Llib/codec -lesp_codec
-DBOARD_HAS_PSRAM
-mfix-esp32-psram-cache-issue
framework = arduino
upload_port = COM4
upload_speed = 921600
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment