Skip to content

Commit d98e75e

Browse files
committed
textures: Update libnsgif to v1.00
1 parent 87af18b commit d98e75e

9 files changed

Lines changed: 3097 additions & 3215 deletions

File tree

app/source/textures.cpp

Lines changed: 37 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
#include "fs.h"
88
#include "libnsbmp.h"
9-
#include "libnsgif.h"
9+
#include "nsgif.h"
1010
#include "log.h"
1111
#include "textures.h"
1212
#include "utils.h"
@@ -59,61 +59,43 @@ g2dTexture *file_icons[NUM_FILE_ICONS], *icon_dir[NUM_THEMES], *icon_check[NUM_T
5959
*bg_header, *icon_sd[NUM_THEMES], *icon_secure[NUM_THEMES], *ic_play_btn, *ftp_icon[NUM_THEMES], *sort_icon[NUM_THEMES], \
6060
*dark_theme_icon[NUM_THEMES], *dev_options_icon[NUM_THEMES], *about_icon[NUM_THEMES];
6161

62-
namespace Image {
62+
namespace Bitmap {
6363
static void *Create(int width, int height, [[maybe_unused]] unsigned int state) {
64-
/* ensure a stupidly large (>50Megs or so) bitmap is not created */
65-
if ((static_cast<long long>(width) * static_cast<long long>(height)) > (MAX_IMAGE_BYTES/BYTES_PER_PIXEL)) {
64+
if (width > 512 && height > 512) {
6665
return nullptr;
6766
}
6867

6968
return std::calloc(width * height, BYTES_PER_PIXEL);
7069
}
7170

7271
static void *Create(int width, int height) {
73-
/* ensure a stupidly large bitmap is not created */
74-
if ((static_cast<long long>(width) * static_cast<long long>(height)) > (MAX_IMAGE_BYTES/BYTES_PER_PIXEL)) {
72+
if (width > 512 && height > 512) {
7573
return nullptr;
7674
}
7775

7876
return std::calloc(width * height, BYTES_PER_PIXEL);
7977
}
80-
81-
static void SetOpaque([[maybe_unused]] void *bitmap, [[maybe_unused]] bool opaque) {
82-
assert(bitmap);
83-
}
84-
85-
static bool TestOpaque([[maybe_unused]] void *bitmap) {
86-
assert(bitmap);
87-
return false;
88-
}
8978

9079
static unsigned char *GetBuffer(void *bitmap) {
91-
assert(bitmap);
9280
return static_cast<unsigned char *>(bitmap);
9381
}
9482

9583
static void Destroy(void *bitmap) {
96-
assert(bitmap);
9784
std::free(bitmap);
9885
}
99-
100-
static void Modified([[maybe_unused]] void *bitmap) {
101-
assert(bitmap);
102-
return;
103-
}
10486
}
10587

10688
namespace Textures {
10789
static g2dTexture *LoadImageBufferBMP(unsigned char *data, int size) {
108-
bmp_bitmap_callback_vt bitmap_callbacks = {
109-
Image::Create,
110-
Image::Destroy,
111-
Image::GetBuffer
90+
bmp_bitmap_callback_vt callbacks = {
91+
.bitmap_create = Bitmap::Create,
92+
.bitmap_destroy = Bitmap::Destroy,
93+
.bitmap_get_buffer = Bitmap::GetBuffer,
11294
};
11395

11496
bmp_result code = BMP_OK;
11597
bmp_image bmp;
116-
bmp_create(&bmp, &bitmap_callbacks);
98+
bmp_create(&bmp, &callbacks);
11799

118100
code = bmp_analyse(&bmp, size, data);
119101
if (code != BMP_OK) {
@@ -132,7 +114,6 @@ namespace Textures {
132114

133115
/* skip if the decoded image would be ridiculously large */
134116
if ((bmp.width * bmp.height) > 200000) {
135-
Log::Error("bmp_decode failed: width*height is over 200000\n");
136117
Log::Error("%s(bmp_decode) failed: width*height is over 200000\n", __func__);
137118
bmp_finalise(&bmp);
138119
return nullptr;
@@ -145,36 +126,37 @@ namespace Textures {
145126
}
146127

147128
static g2dTexture *LoadImageBufferGIF(unsigned char *data, int size) {
148-
gif_bitmap_callback_vt bitmap_callbacks = {
149-
Image::Create,
150-
Image::Destroy,
151-
Image::GetBuffer,
152-
Image::SetOpaque,
153-
Image::TestOpaque,
154-
Image::Modified
129+
const nsgif_bitmap_cb_vt callbacks = {
130+
.create = Bitmap::Create,
131+
.destroy = Bitmap::Destroy,
132+
.get_buffer = Bitmap::GetBuffer,
155133
};
156-
157-
gif_animation gif;
158-
gif_result code = GIF_OK;
159-
gif_create(&gif, &bitmap_callbacks);
160-
161-
do {
162-
code = gif_initialise(&gif, size, data);
163-
if (code != GIF_OK && code != GIF_WORKING) {
164-
Log::Error("%s(gif_initialise) failed: %d\n", __func__, code);
165-
gif_finalise(&gif);
166-
return nullptr;
167-
}
168-
} while (code != GIF_OK);
169-
170-
code = gif_decode_frame(&gif, 0);
171-
if (code != GIF_OK) {
172-
Log::Error("%s(gif_decode_frame) failed: %d\n", __func__, code);
134+
135+
nsgif_t *gif;
136+
nsgif_error err = nsgif_create(&callbacks, NSGIF_BITMAP_FMT_ABGR8888, &gif);
137+
if (err != NSGIF_OK) {
138+
Log::Error("%s(nsgif_create) failed: %d\n", __func__, err);
173139
return nullptr;
174140
}
175-
176-
g2dTexture *tex = g2dTexLoad(static_cast<unsigned char *>(gif.frame_image), gif.width, gif.height, G2D_SWIZZLE);
177-
gif_finalise(&gif);
141+
142+
err = nsgif_data_scan(gif, size, data);
143+
if (err != NSGIF_OK) {
144+
Log::Error("%s(nsgif_data_scan) failed: %d\n", __func__, err);
145+
nsgif_destroy(gif);
146+
return nullptr;
147+
}
148+
149+
nsgif_bitmap_t *bitmap;
150+
const nsgif_info_t *info = nsgif_get_info(gif);
151+
err = nsgif_frame_decode(gif, 0, &bitmap);
152+
if (err != NSGIF_OK) {
153+
Log::Error("%s(nsgif_frame_decode) failed: %d\n", __func__, err);
154+
nsgif_destroy(gif);
155+
return nullptr;
156+
}
157+
158+
g2dTexture *tex = g2dTexLoad(static_cast<u8 *>(bitmap), info->width, info->height, G2D_SWIZZLE);
159+
nsgif_destroy(gif);
178160
return tex;
179161
}
180162

libs/include/turbojpeg/jconfig.h

Lines changed: 0 additions & 74 deletions
This file was deleted.

0 commit comments

Comments
 (0)