2016-11-17 03:36:10 -05:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <stdio.h>
|
2020-04-03 04:53:11 -04:00
|
|
|
#include "sdkconfig.h"
|
2016-11-17 03:36:10 -05:00
|
|
|
#include "unity.h"
|
|
|
|
|
2021-08-27 03:28:48 -04:00
|
|
|
#include "esp_rom_tjpgd.h"
|
2016-11-17 03:36:10 -05:00
|
|
|
#include "test_tjpgd_logo.h"
|
|
|
|
|
|
|
|
typedef struct {
|
|
|
|
const unsigned char *inData;
|
|
|
|
int inPos;
|
|
|
|
unsigned char *outData;
|
|
|
|
int outW;
|
|
|
|
int outH;
|
|
|
|
} JpegDev;
|
|
|
|
|
2021-08-27 03:28:48 -04:00
|
|
|
static uint32_t infunc(esp_rom_tjpgd_dec_t *decoder, uint8_t *buf, uint32_t len)
|
2016-11-17 03:36:10 -05:00
|
|
|
{
|
|
|
|
JpegDev *jd = (JpegDev *)decoder->device;
|
|
|
|
printf("Reading %d bytes from pos %d\n", len, jd->inPos);
|
|
|
|
if (buf != NULL) {
|
|
|
|
memcpy(buf, jd->inData + jd->inPos, len);
|
|
|
|
}
|
|
|
|
jd->inPos += len;
|
|
|
|
return len;
|
|
|
|
}
|
|
|
|
|
2021-08-27 03:28:48 -04:00
|
|
|
static uint32_t outfunc(esp_rom_tjpgd_dec_t *decoder, void *bitmap, esp_rom_tjpgd_rect_t *rect)
|
2016-11-17 03:36:10 -05:00
|
|
|
{
|
|
|
|
unsigned char *in = (unsigned char *)bitmap;
|
|
|
|
unsigned char *out;
|
|
|
|
int y;
|
|
|
|
printf("Rect %d,%d - %d,%d\n", rect->top, rect->left, rect->bottom, rect->right);
|
|
|
|
JpegDev *jd = (JpegDev *)decoder->device;
|
|
|
|
for (y = rect->top; y <= rect->bottom; y++) {
|
|
|
|
out = jd->outData + ((jd->outW * y) + rect->left) * 3;
|
|
|
|
memcpy(out, in, ((rect->right - rect->left) + 1) * 3);
|
|
|
|
in += ((rect->right - rect->left) + 1) * 3;
|
|
|
|
}
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
#define TESTW 48
|
|
|
|
#define TESTH 48
|
|
|
|
#define WORKSZ 3100
|
|
|
|
|
2020-04-03 04:53:11 -04:00
|
|
|
TEST_CASE("Test JPEG decompression library", "[rom][tjpgd]")
|
2016-11-17 03:36:10 -05:00
|
|
|
{
|
|
|
|
char aapix[] = " .:;+=xX$$";
|
|
|
|
unsigned char *decoded, *p;
|
|
|
|
char *work;
|
|
|
|
int r;
|
|
|
|
int x, y, v;
|
2021-08-27 03:28:48 -04:00
|
|
|
esp_rom_tjpgd_dec_t decoder;
|
2016-11-17 03:36:10 -05:00
|
|
|
JpegDev jd;
|
2021-08-27 03:28:48 -04:00
|
|
|
decoded = malloc(TESTW * TESTH * 3);
|
|
|
|
for (x = 0; x < TESTW * TESTH * 3; x += 2) {
|
2020-04-03 04:53:11 -04:00
|
|
|
decoded[x] = 0;
|
|
|
|
decoded[x + 1] = 0xff;
|
2016-11-17 03:36:10 -05:00
|
|
|
}
|
|
|
|
work = malloc(WORKSZ);
|
|
|
|
memset(work, 0, WORKSZ);
|
|
|
|
|
|
|
|
jd.inData = logo_jpg;
|
|
|
|
jd.inPos = 0;
|
|
|
|
jd.outData = decoded;
|
|
|
|
jd.outW = TESTW;
|
|
|
|
jd.outH = TESTH;
|
|
|
|
|
2021-08-27 03:28:48 -04:00
|
|
|
r = esp_rom_tjpgd_prepare(&decoder, infunc, work, WORKSZ, (void *)&jd);
|
2016-11-17 03:36:10 -05:00
|
|
|
TEST_ASSERT_EQUAL(r, JDR_OK);
|
2021-08-27 03:28:48 -04:00
|
|
|
r = esp_rom_tjpgd_decomp(&decoder, outfunc, 0);
|
2016-11-17 03:36:10 -05:00
|
|
|
TEST_ASSERT_EQUAL(r, JDR_OK);
|
|
|
|
|
|
|
|
p = decoded + 2;
|
|
|
|
for (y = 0; y < TESTH; y++) {
|
|
|
|
for (x = 0; x < TESTH; x++) {
|
|
|
|
v = ((*p) * (sizeof(aapix) - 2) * 2) / 256;
|
|
|
|
printf("%c%c", aapix[v / 2], aapix[(v + 1) / 2]);
|
|
|
|
p += 3;
|
|
|
|
}
|
|
|
|
printf("%c%c", ' ', '\n');
|
|
|
|
}
|
|
|
|
|
|
|
|
free(work);
|
|
|
|
free(decoded);
|
|
|
|
}
|