Skip to content

Commit f130e91

Browse files
committed
Update to PAX Graphics v2.0.0
1 parent 67c96d1 commit f130e91

3 files changed

Lines changed: 56 additions & 11 deletions

File tree

components/gui/idf_component.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,5 @@ repository: git://git@github.com:nicolai-electronics/esp32-component-gui-menu.gi
44
issues: https://github.com/nicolai-electronics/esp32-component-gui-menu/issues
55
dependencies:
66
idf: ">=5.3"
7-
robotman2412/pax-gfx: ^1.1.2
7+
robotman2412/pax-gfx: ^2.0.0
88
license: "MIT"

components/pax-codecs/src/pax_codecs.c

Lines changed: 54 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,11 @@ bool pax_encode_png_fd(const pax_buf_t *buf, FILE *fd, int x, int y, int width,
7777
if (err) {
7878
PAX_LOGE(TAG, "%s", spng_strerror(err));
7979
spng_ctx_free(ctx);
80+
#if PAX_VERSION_MAJOR >= 2
81+
pax_set_err(PAX_ERR_ENCODE);
82+
#else
8083
pax_last_error = PAX_ERR_ENCODE;
84+
#endif
8185
return false;
8286
}
8387
bool ret = png_encode(buf, ctx, x, y, width, height);
@@ -93,7 +97,11 @@ bool pax_encode_png_buf(const pax_buf_t *buf, void **outbuf, size_t *len, int x,
9397
bool ret = png_encode(buf, ctx, x, y, width, height);
9498
if (!ret) {
9599
spng_ctx_free(ctx);
100+
#if PAX_VERSION_MAJOR >= 2
101+
pax_set_err(PAX_ERR_ENCODE);
102+
#else
96103
pax_last_error = PAX_ERR_ENCODE;
104+
#endif
97105
return 0;
98106
}
99107

@@ -102,7 +110,11 @@ bool pax_encode_png_buf(const pax_buf_t *buf, void **outbuf, size_t *len, int x,
102110
spng_ctx_free(ctx);
103111
if (err) {
104112
PAX_LOGE(TAG, "%s", spng_strerror(err));
113+
#if PAX_VERSION_MAJOR >= 2
114+
pax_set_err(PAX_ERR_ENCODE);
115+
#else
105116
pax_last_error = PAX_ERR_ENCODE;
117+
#endif
106118
*outbuf = NULL;
107119
*len = 0;
108120
}
@@ -195,7 +207,11 @@ static bool png_encode(const pax_buf_t *framebuffer, spng_ctx *ctx, int dx, int
195207
}
196208
if (dx > pax_buf_get_width(framebuffer)) {
197209
// Out of bounds error.
210+
#if PAX_VERSION_MAJOR >= 2
211+
pax_set_err(PAX_ERR_BOUNDS);
212+
#else
198213
pax_last_error = PAX_ERR_BOUNDS;
214+
#endif
199215
return 0;
200216
}
201217
if (dx + width > pax_buf_get_width(framebuffer)) {
@@ -209,7 +225,11 @@ static bool png_encode(const pax_buf_t *framebuffer, spng_ctx *ctx, int dx, int
209225
}
210226
if (dy > pax_buf_get_height(framebuffer)) {
211227
// Out of bounds error.
228+
#if PAX_VERSION_MAJOR >= 2
229+
pax_set_err(PAX_ERR_BOUNDS);
230+
#else
212231
pax_last_error = PAX_ERR_BOUNDS;
232+
#endif
213233
return 0;
214234
}
215235
if (dy + height > pax_buf_get_height(framebuffer)) {
@@ -231,7 +251,11 @@ static bool png_encode(const pax_buf_t *framebuffer, spng_ctx *ctx, int dx, int
231251
size_t rowbufcap = sizeof(uint8_t) * 4 * width;
232252
uint8_t *rowbuf = malloc(rowbufcap);
233253
if (!rowbuf) {
254+
#if PAX_VERSION_MAJOR >= 2
255+
pax_set_err(PAX_ERR_NOMEM);
256+
#else
234257
pax_last_error = PAX_ERR_NOMEM;
258+
#endif
235259
return 0;
236260
}
237261

@@ -253,7 +277,11 @@ static bool png_encode(const pax_buf_t *framebuffer, spng_ctx *ctx, int dx, int
253277

254278
if (err != SPNG_EOI) {
255279
PAX_LOGE(TAG, "%s", spng_strerror(err));
280+
#if PAX_VERSION_MAJOR >= 2
281+
pax_set_err(PAX_ERR_ENCODE);
282+
#else
256283
pax_last_error = PAX_ERR_ENCODE;
284+
#endif
257285
return 0;
258286
}
259287

@@ -288,10 +316,20 @@ static bool png_decode(pax_buf_t *framebuffer, spng_ctx *ctx, pax_buf_type_t buf
288316
pax_mark_dirty2(framebuffer, x_offset, y_offset, width, height);
289317
}
290318

319+
#if PAX_VERSION_MAJOR >= 2
320+
bool is_palette = pax_buf_type_info(buf_type).fmt_type == PAX_BUF_SUBTYPE_PALETTE;
321+
#else
322+
bool is_palette = PAX_IS_PALETTE(buf_type);
323+
#endif
324+
291325
// Select a good buffer type.
292-
if (do_alloc && PAX_IS_PALETTE(buf_type) && ihdr.color_type != 3) {
326+
if (do_alloc && is_palette && ihdr.color_type != 3) {
293327
// This is not a palleted image, change the output type.
328+
#if PAX_VERSION_MAJOR >= 2
329+
int bpp = pax_buf_type_info(buf_type).bpp;
330+
#else
294331
int bpp = PAX_GET_BPP(buf_type);
332+
#endif
295333
if (bpp == 1) {
296334
// For 1BPP, the only option is greyscale.
297335
buf_type = PAX_BUF_1_GREY;
@@ -336,8 +374,12 @@ static bool png_decode(pax_buf_t *framebuffer, spng_ctx *ctx, pax_buf_type_t buf
336374
if (do_alloc) {
337375
// Allocate some funny.
338376
PAX_LOGD(TAG, "Decoding PNG %dx%d to %08x", (int) width, (int) height, buf_type);
377+
#if PAX_VERSION_MAJOR >= 2
378+
if (!pax_buf_init(framebuffer, NULL, width, height, buf_type)) return false;
379+
#else
339380
pax_buf_init(framebuffer, NULL, width, height, buf_type);
340381
if (pax_last_error) return false;
382+
#endif
341383
}
342384

343385
// Decd.
@@ -390,6 +432,12 @@ static bool png_decode_progressive(pax_buf_t *framebuffer, spng_ctx *ctx, struct
390432
struct spng_plte *plte = NULL;
391433
struct spng_trns *trns = NULL;
392434

435+
#if PAX_VERSION_MAJOR >= 2
436+
bool is_palette = pax_buf_type_info(buf_type).fmt_type == PAX_BUF_SUBTYPE_PALETTE;
437+
#else
438+
bool is_palette = PAX_IS_PALETTE(buf_type);
439+
#endif
440+
393441
PAX_LOGD(TAG, "Decode with flags 0x%08x", flags);
394442

395443
// Get image parameters.
@@ -473,9 +521,6 @@ static bool png_decode_progressive(pax_buf_t *framebuffer, spng_ctx *ctx, struct
473521
if (err == SPNG_ECHUNKAVAIL) has_trns = false;
474522
else if (err) goto error;
475523
}
476-
if (PAX_IS_PALETTE(buf_type)) {
477-
PAX_LOGD(TAG, "Buf has palette");
478-
}
479524

480525
// Set the image to decode progressive.
481526
err = spng_decode_image(ctx, NULL, 0, png_fmt, SPNG_DECODE_PROGRESSIVE);
@@ -517,7 +562,7 @@ static bool png_decode_progressive(pax_buf_t *framebuffer, spng_ctx *ctx, struct
517562

518563
// Decode color information.
519564
pax_col_t color = 0;
520-
if (has_palette && PAX_IS_PALETTE(buf_type)) {
565+
if (has_palette && is_palette) {
521566
color = raw;
522567
} else if (has_palette) {
523568
if (raw >= plte->n_entries) raw = 0;
@@ -545,10 +590,10 @@ static bool png_decode_progressive(pax_buf_t *framebuffer, spng_ctx *ctx, struct
545590
}
546591

547592
// Output the pixel to the right spot.
548-
if (!has_palette && PAX_IS_PALETTE(buf_type)) {
593+
if (!has_palette && is_palette) {
549594
color = closest_palette_index(framebuffer, color, true);
550595
pax_set_pixel(framebuffer, color, x_offset + x, y_offset + info.row_num);
551-
} else if (flags & CODEC_FLAG_EXISTING && !(has_palette && PAX_IS_PALETTE(buf_type))) {
596+
} else if (flags & CODEC_FLAG_EXISTING && !(has_palette && is_palette)) {
552597
pax_merge_pixel(framebuffer, color, x_offset + x, y_offset + info.row_num);
553598
} else {
554599
pax_set_pixel(framebuffer, color, x_offset + x, y_offset + info.row_num);
@@ -573,7 +618,7 @@ static bool png_decode_progressive(pax_buf_t *framebuffer, spng_ctx *ctx, struct
573618
}
574619

575620
// Re-map palette written from IDAT.
576-
if (PAX_IS_PALETTE(buf_type) && (flags & CODEC_FLAG_EXISTING) && !(flags & CODEC_FLAG_KEEP_PAL)) {
621+
if (is_palette && (flags & CODEC_FLAG_EXISTING) && !(flags & CODEC_FLAG_KEEP_PAL)) {
577622
// Search for closest fitting palette.
578623
uint16_t *remap = malloc(sizeof(uint16_t) * plte->n_entries);
579624
PAX_LOGD(TAG, "Remapping palette");
@@ -603,7 +648,7 @@ static bool png_decode_progressive(pax_buf_t *framebuffer, spng_ctx *ctx, struct
603648
}
604649
}
605650

606-
if (has_palette && PAX_IS_PALETTE(buf_type) && !(flags & CODEC_FLAG_EXISTING)) {
651+
if (has_palette && is_palette && !(flags & CODEC_FLAG_EXISTING)) {
607652
// Copy over the palette.
608653
pax_col_t *palette = malloc(sizeof(pax_col_t) * plte->n_entries);
609654
for (size_t i = 0; i < plte->n_entries; i++) {

main/idf_component.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ dependencies:
44
badgeteam/badge-bsp:
55
version: ">=0.3.2"
66
robotman2412/pax-gfx:
7-
version: ^1.1.2
7+
version: '^2.0.0'
88
badgeteam/appfs:
99
version: ">=1.0.1"
1010
nicolaielectronics/rvswd:

0 commit comments

Comments
 (0)