mirror of
https://github.com/nothings/stb
synced 2025-03-30 22:42:56 +03:00
Merge 2b25f2f8cd75208cedb424dcca375925f642b37c into 5c205738c191bcb0abc65c4febfa9bd25ff35234
This commit is contained in:
commit
1d5ae1078d
75
stb_image.h
75
stb_image.h
@ -1019,7 +1019,7 @@ static int stbi__mul2sizes_valid(int a, int b)
|
||||
return a <= INT_MAX/b;
|
||||
}
|
||||
|
||||
#if !defined(STBI_NO_JPEG) || !defined(STBI_NO_PNG) || !defined(STBI_NO_TGA) || !defined(STBI_NO_HDR)
|
||||
#if !defined(STBI_NO_JPEG) || !defined(STBI_NO_PNG) || !defined(STBI_NO_TGA) || !defined(STBI_NO_HDR) || !defined(STBI_NO_PNM)
|
||||
// returns 1 if "a*b + add" has no negative terms/factors and doesn't overflow
|
||||
static int stbi__mad2sizes_valid(int a, int b, int add)
|
||||
{
|
||||
@ -1043,7 +1043,7 @@ static int stbi__mad4sizes_valid(int a, int b, int c, int d, int add)
|
||||
}
|
||||
#endif
|
||||
|
||||
#if !defined(STBI_NO_JPEG) || !defined(STBI_NO_PNG) || !defined(STBI_NO_TGA) || !defined(STBI_NO_HDR)
|
||||
#if !defined(STBI_NO_JPEG) || !defined(STBI_NO_PNG) || !defined(STBI_NO_TGA) || !defined(STBI_NO_HDR) || !defined(STBI_NO_PNM)
|
||||
// mallocs with size overflow checking
|
||||
static void *stbi__malloc_mad2(int a, int b, int add)
|
||||
{
|
||||
@ -7496,7 +7496,7 @@ static int stbi__pnm_test(stbi__context *s)
|
||||
char p, t;
|
||||
p = (char) stbi__get8(s);
|
||||
t = (char) stbi__get8(s);
|
||||
if (p != 'P' || (t != '5' && t != '6')) {
|
||||
if (p != 'P' || (t != '4' && t != '5' && t != '6')) {
|
||||
stbi__rewind( s );
|
||||
return 0;
|
||||
}
|
||||
@ -7506,12 +7506,12 @@ static int stbi__pnm_test(stbi__context *s)
|
||||
static void *stbi__pnm_load(stbi__context *s, int *x, int *y, int *comp, int req_comp, stbi__result_info *ri)
|
||||
{
|
||||
stbi_uc *out;
|
||||
int bytes_per_channel;
|
||||
STBI_NOTUSED(ri);
|
||||
|
||||
ri->bits_per_channel = stbi__pnm_info(s, (int *)&s->img_x, (int *)&s->img_y, (int *)&s->img_n);
|
||||
if (ri->bits_per_channel == 0)
|
||||
return 0;
|
||||
|
||||
if (s->img_y > STBI_MAX_DIMENSIONS) return stbi__errpuc("too large","Very large image (corrupt?)");
|
||||
if (s->img_x > STBI_MAX_DIMENSIONS) return stbi__errpuc("too large","Very large image (corrupt?)");
|
||||
|
||||
@ -7522,11 +7522,65 @@ static void *stbi__pnm_load(stbi__context *s, int *x, int *y, int *comp, int req
|
||||
if (!stbi__mad4sizes_valid(s->img_n, s->img_x, s->img_y, ri->bits_per_channel / 8, 0))
|
||||
return stbi__errpuc("too large", "PNM too large");
|
||||
|
||||
out = (stbi_uc *) stbi__malloc_mad4(s->img_n, s->img_x, s->img_y, ri->bits_per_channel / 8, 0);
|
||||
if (ri->bits_per_channel == 16) bytes_per_channel = 2; else bytes_per_channel = 1;
|
||||
out = (stbi_uc *) stbi__malloc_mad4(s->img_n, s->img_x, s->img_y, bytes_per_channel, 0);
|
||||
if (!out) return stbi__errpuc("outofmem", "Out of memory");
|
||||
if (!stbi__getn(s, out, s->img_n * s->img_x * s->img_y * (ri->bits_per_channel / 8))) {
|
||||
STBI_FREE(out);
|
||||
return stbi__errpuc("bad PNM", "PNM file truncated");
|
||||
if (ri->bits_per_channel == 1) {
|
||||
stbi_uc *filebuf, *p_in, *p_out;
|
||||
stbi__uint32 line, x, y, offset;
|
||||
|
||||
ri->bits_per_channel = 8;
|
||||
line = s->img_x/8+((s->img_x%8>0)?1:0);
|
||||
|
||||
filebuf = (stbi_uc *) stbi__malloc_mad2(line, s->img_y, 0);
|
||||
if (!filebuf) {
|
||||
STBI_FREE(out);
|
||||
return stbi__errpuc("outofmem", "Out of memory");
|
||||
}
|
||||
if (!stbi__getn(s, filebuf, line*s->img_y)) {
|
||||
STBI_FREE(out);
|
||||
STBI_FREE(filebuf);
|
||||
return stbi__errpuc("bad PNM", "PNM file truncated");
|
||||
}
|
||||
|
||||
p_in = filebuf;
|
||||
p_out = out;
|
||||
offset = 8;
|
||||
for(y = 0; y < s->img_y; y++) {
|
||||
for(x = 0; x < s->img_x; x++) {
|
||||
offset--;
|
||||
*(p_out++) = ((*p_in>>offset)&0x1)?0:255;
|
||||
if(offset == 0) {
|
||||
offset = 8;
|
||||
p_in++;
|
||||
}
|
||||
}
|
||||
if(offset != 8) {
|
||||
offset = 8;
|
||||
p_in++;
|
||||
}
|
||||
}
|
||||
|
||||
STBI_FREE(filebuf);
|
||||
} else {
|
||||
if (!stbi__getn(s, out, s->img_n * s->img_x * s->img_y * (ri->bits_per_channel / 8))) {
|
||||
STBI_FREE(out);
|
||||
return stbi__errpuc("bad PNM", "PNM file truncated");
|
||||
}
|
||||
if (ri->bits_per_channel == 16) {
|
||||
stbi_uc *p8;
|
||||
stbi__uint16 *p16;
|
||||
size_t filesize;
|
||||
|
||||
p8 = out;
|
||||
p16 = (stbi__uint16 *) out;
|
||||
filesize = s->img_n * s->img_x * s->img_y;
|
||||
while(filesize--) {
|
||||
// Convert from BIG-ENDIAN
|
||||
*(p16++) = p8[1] + p8[0]*256;
|
||||
p8 += 2;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (req_comp && req_comp != s->img_n) {
|
||||
@ -7592,12 +7646,12 @@ static int stbi__pnm_info(stbi__context *s, int *x, int *y, int *comp)
|
||||
// Get identifier
|
||||
p = (char) stbi__get8(s);
|
||||
t = (char) stbi__get8(s);
|
||||
if (p != 'P' || (t != '5' && t != '6')) {
|
||||
if (p != 'P' || (t != '4' && t != '5' && t != '6')) {
|
||||
stbi__rewind(s);
|
||||
return 0;
|
||||
}
|
||||
|
||||
*comp = (t == '6') ? 3 : 1; // '5' is 1-component .pgm; '6' is 3-component .ppm
|
||||
*comp = (t == '6') ? 3 : 1; // '4' is monochrome .pbm, '5' is 1-component .pgm; '6' is 3-component .ppm
|
||||
|
||||
c = (char) stbi__get8(s);
|
||||
stbi__pnm_skip_whitespace(s, &c);
|
||||
@ -7610,6 +7664,7 @@ static int stbi__pnm_info(stbi__context *s, int *x, int *y, int *comp)
|
||||
*y = stbi__pnm_getinteger(s, &c); // read height
|
||||
if (*y == 0)
|
||||
return stbi__err("invalid width", "PPM image header had zero or overflowing width");
|
||||
if(t == '4') return 1; // Header ends here for PBM files
|
||||
stbi__pnm_skip_whitespace(s, &c);
|
||||
|
||||
maxv = stbi__pnm_getinteger(s, &c); // read max value
|
||||
|
@ -22,7 +22,7 @@ unzip $SRC/stbi/tga.zip -d $SRC/stb/tests
|
||||
|
||||
find $SRC/stb/tests -name "*.png" -o -name "*.jpg" -o -name "*.gif" \
|
||||
-o -name "*.bmp" -o -name "*.tga" -o -name "*.TGA" \
|
||||
-o -name "*.ppm" -o -name "*.pgm" \
|
||||
-o -name "*.ppm" -o -name "*.pgm" -o -name "*.pbm" \
|
||||
| xargs zip $OUT/stbi_read_fuzzer_seed_corpus.zip
|
||||
|
||||
echo "" >> $SRC/stbi/gif.dict
|
||||
|
BIN
tests/pbm/basi0g01.pbm
Normal file
BIN
tests/pbm/basi0g01.pbm
Normal file
Binary file not shown.
BIN
tests/pbm/basi0g01_31.pbm
Normal file
BIN
tests/pbm/basi0g01_31.pbm
Normal file
Binary file not shown.
BIN
tests/pbm/basi0g01_33.pbm
Normal file
BIN
tests/pbm/basi0g01_33.pbm
Normal file
Binary file not shown.
Loading…
x
Reference in New Issue
Block a user