Skip to content

Commit df3330d

Browse files
committed
stbi: disable unused img decoders
saves a little space - STBI_REALLOC_SIZED actually unneeded by remaining code - fix unused warnings in stb_image.h when features disabled
1 parent 3c8db69 commit df3330d

File tree

2 files changed

+13
-3
lines changed

2 files changed

+13
-3
lines changed

src/utils/image_delegate.c

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,12 +54,17 @@
5454

5555
static void
5656
gpujpeg_cuda_free_host(void* ptr);
57-
static void*
58-
gpujpeg_cuda_realloc_sized_host(void* ptr, int oldsz, int newsz);
57+
#define STBI_NO_JPEG
58+
#define STBI_NO_PNG
59+
#define STBI_NO_PSD
60+
#define STBI_NO_GIF
61+
#define STBI_NO_HDR
62+
#define STBI_NO_PIC
63+
#define STBI_NO_PNM
5964
// we want use custom allocator but only way to do this in stbi is to define the below
6065
#define STBI_MALLOC gpujpeg_cuda_malloc_host
6166
#define STBI_FREE gpujpeg_cuda_free_host
62-
#define STBI_REALLOC_SIZED gpujpeg_cuda_realloc_sized_host
67+
#define STBI_REALLOC_SIZED unneeded_so_undefined
6368
#define STB_IMAGE_IMPLEMENTATION
6469
#include "stb_image.h"
6570

@@ -74,6 +79,7 @@ gpujpeg_cuda_free_host(void* ptr)
7479
GPUJPEG_CHECK_EX(cudaFreeHost(ptr), "Could not free host pointer", );
7580
}
7681

82+
#if 0
7783
static void*
7884
gpujpeg_cuda_realloc_sized_host(void* ptr, int oldsz, int newsz)
7985
{
@@ -85,6 +91,7 @@ gpujpeg_cuda_realloc_sized_host(void* ptr, int oldsz, int newsz)
8591
gpujpeg_cuda_free_host(ptr);
8692
return nptr;
8793
}
94+
#endif
8895

8996
static int
9097
stbi_load_delegate(const char* filename, size_t* image_size, void** image_data, allocator_t alloc)

src/utils/stb_image.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1066,6 +1066,7 @@ static void *stbi__malloc_mad4(int a, int b, int c, int d, int add)
10661066
}
10671067
#endif
10681068

1069+
#ifndef STBI_NO_JPEG
10691070
// returns 1 if the sum of two signed ints is valid (between -2^31 and 2^31-1 inclusive), 0 on overflow.
10701071
static int stbi__addints_valid(int a, int b)
10711072
{
@@ -1082,6 +1083,7 @@ static int stbi__mul2shorts_valid(int a, int b)
10821083
if (b < 0) return a <= SHRT_MIN / b; // same as a * b >= SHRT_MIN
10831084
return a >= SHRT_MIN / b;
10841085
}
1086+
#endif
10851087

10861088
// stbi__err - error
10871089
// stbi__errpf - error returning pointer to float
@@ -7673,6 +7675,7 @@ static int stbi__info_main(stbi__context *s, int *x, int *y, int *comp)
76737675

76747676
static int stbi__is_16_main(stbi__context *s)
76757677
{
7678+
(void) s;
76767679
#ifndef STBI_NO_PNG
76777680
if (stbi__png_is16(s)) return 1;
76787681
#endif

0 commit comments

Comments
 (0)