CVS commit: src/sys/dev/stbi
Module Name:src Committed By: mrg Date: Sun Feb 4 09:18:44 UTC 2018 Modified Files: src/sys/dev/stbi: stb_image.c Log Message: a macro idiom used here triggers the GCC 6.4 ident checker. work around it. To generate a diff of this commit: cvs rdiff -u -r1.8 -r1.9 src/sys/dev/stbi/stb_image.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/sys/dev/stbi/stb_image.c diff -u src/sys/dev/stbi/stb_image.c:1.8 src/sys/dev/stbi/stb_image.c:1.9 --- src/sys/dev/stbi/stb_image.c:1.8 Thu Jan 21 17:17:53 2016 +++ src/sys/dev/stbi/stb_image.c Sun Feb 4 09:18:44 2018 @@ -430,7 +430,7 @@ extern int stbi_gif_info_from_file #endif #ifdef _KERNEL #include -__KERNEL_RCSID(0, "$NetBSD: stb_image.c,v 1.8 2016/01/21 17:17:53 christos Exp $"); +__KERNEL_RCSID(0, "$NetBSD: stb_image.c,v 1.9 2018/02/04 09:18:44 mrg Exp $"); #include #include #include @@ -1000,18 +1000,30 @@ static unsigned char *convert_format(uns // convert source image with img_n components to one with req_comp components; // avoid switch per pixel, so use switch per scanline and massive macros switch (COMBO(img_n, req_comp)) { - CASE(1,2) dest[0]=src[0], dest[1]=255; break; - CASE(1,3) dest[0]=dest[1]=dest[2]=src[0]; break; - CASE(1,4) dest[0]=dest[1]=dest[2]=src[0], dest[3]=255; break; - CASE(2,1) dest[0]=src[0]; break; - CASE(2,3) dest[0]=dest[1]=dest[2]=src[0]; break; - CASE(2,4) dest[0]=dest[1]=dest[2]=src[0], dest[3]=src[1]; break; - CASE(3,4) dest[0]=src[0],dest[1]=src[1],dest[2]=src[2],dest[3]=255; break; - CASE(3,1) dest[0]=compute_y(src[0],src[1],src[2]); break; - CASE(3,2) dest[0]=compute_y(src[0],src[1],src[2]), dest[1] = 255; break; - CASE(4,1) dest[0]=compute_y(src[0],src[1],src[2]); break; - CASE(4,2) dest[0]=compute_y(src[0],src[1],src[2]), dest[1] = src[3]; break; - CASE(4,3) dest[0]=src[0],dest[1]=src[1],dest[2]=src[2]; break; + CASE(1,2) dest[0]=src[0], dest[1]=255; + break; + CASE(1,3) dest[0]=dest[1]=dest[2]=src[0]; + break; + CASE(1,4) dest[0]=dest[1]=dest[2]=src[0], dest[3]=255; + break; + CASE(2,1) dest[0]=src[0]; + break; + CASE(2,3) dest[0]=dest[1]=dest[2]=src[0]; + break; + CASE(2,4) dest[0]=dest[1]=dest[2]=src[0], dest[3]=src[1]; + break; + CASE(3,4) dest[0]=src[0],dest[1]=src[1],dest[2]=src[2],dest[3]=255; + break; + CASE(3,1) dest[0]=compute_y(src[0],src[1],src[2]); + break; + CASE(3,2) dest[0]=compute_y(src[0],src[1],src[2]), dest[1] = 255; + break; + CASE(4,1) dest[0]=compute_y(src[0],src[1],src[2]); + break; + CASE(4,2) dest[0]=compute_y(src[0],src[1],src[2]), dest[1] = src[3]; + break; + CASE(4,3) dest[0]=src[0],dest[1]=src[1],dest[2]=src[2]; + break; default: assert(0); } #undef CASE @@ -1279,7 +1291,7 @@ __forceinline static int extend_receive( // predict well. I tried to table accelerate it but failed. // maybe it's compiling as a conditional move? if (k < m) - return (-1 << n) + k + 1; + return (UINT_MAX << n) + k + 1; else return k; } @@ -2696,13 +2708,20 @@ static int create_png_image_raw(png *a, for (i=x-1; i >= 1; --i, raw+=img_n,cur+=img_n,prior+=img_n) \ for (k=0; k < img_n; ++k) switch (filter) { -CASE(F_none) cur[k] = raw[k]; break; -CASE(F_sub) cur[k] = raw[k] + cur[k-img_n]; break; -CASE(F_up)cur[k] = raw[k] + prior[k]; break; -CASE(F_avg) cur[k] = raw[k] + ((prior[k] + cur[k-img_n])>>1); break; -CASE(F_paeth) cur[k] = (uint8) (raw[k] + paeth(cur[k-img_n],prior[k],prior[k-img_n])); break; -CASE(F_avg_first)cur[k] = raw[k] + (cur[k-img_n] >> 1); break; -CASE(F_paeth_first) cur[k] = (uint8) (raw[k] + paeth(cur[k-img_n],0,0)); break; +CASE(F_none) cur[k] = raw[k]; + break; +CASE(F_sub) cur[k] = raw[k] + cur[k-img_n]; + break; +CASE(F_up)cur[k] = raw[k] + prior[k]; + break; +CASE(F_avg) cur[k] = raw[k] + ((prior[k] + cur[k-img_n])>>1); + break; +CASE(F_paeth) cur[k] = (uint8) (raw[k] + paeth(cur[k-img_n],prior[k],prior[k-img_n])); + break; +CASE(F_avg_first)cur[k] = raw[k] + (cur[k-img_n] >> 1); + break; +CASE(F_paeth_first) cur[k] = (uint8) (raw[k] + paeth(cur[k-img_n],0,0)); + break; } #undef CASE } else { @@ -2712,13 +2731,20 @@ static int create_png_image_raw(png *a, for (i=x-1; i >= 1; --i, cur[img_n]=255,raw+=img_n,cur+=out_n,prior+=out_n) \ for (k=0; k < img_n; ++k) switch (filter) { -CASE(F_none) cur[k] = raw[k]; break; -CASE(F_sub) cur[k] = raw[k]
CVS commit: src/sys/dev/stbi
Module Name:src Committed By: christos Date: Thu Jan 21 17:16:48 UTC 2016 Modified Files: src/sys/dev/stbi: stb_image.c Log Message: remove malloc casts. To generate a diff of this commit: cvs rdiff -u -r1.6 -r1.7 src/sys/dev/stbi/stb_image.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/sys/dev/stbi/stb_image.c diff -u src/sys/dev/stbi/stb_image.c:1.6 src/sys/dev/stbi/stb_image.c:1.7 --- src/sys/dev/stbi/stb_image.c:1.6 Sun Sep 15 10:06:10 2013 +++ src/sys/dev/stbi/stb_image.c Thu Jan 21 12:16:48 2016 @@ -430,7 +430,7 @@ extern int stbi_gif_info_from_file #endif #ifdef _KERNEL #include -__KERNEL_RCSID(0, "$NetBSD: stb_image.c,v 1.6 2013/09/15 14:06:10 martin Exp $"); +__KERNEL_RCSID(0, "$NetBSD: stb_image.c,v 1.7 2016/01/21 17:16:48 christos Exp $"); #include #include #include @@ -985,7 +985,7 @@ static unsigned char *convert_format(uns if (req_comp == img_n) return data; assert(req_comp >= 1 && req_comp <= 4); - good = (unsigned char *) MALLOC(req_comp * x * y); + good = MALLOC(req_comp * x * y); if (good == NULL) { FREE(data); return epuc("outofmem", "Out of memory"); @@ -1025,7 +1025,7 @@ static unsigned char *convert_format(uns static float *ldr_to_hdr(stbi_uc *data, int x, int y, int comp) { int i,k,n; - float *output = (float *) MALLOC(x * y * comp * sizeof(float)); + float *output = MALLOC(x * y * comp * sizeof(float)); if (output == NULL) { FREE(data); return epf("outofmem", "Out of memory"); } // compute number of non-alpha components if (comp & 1) n = comp; else n = comp-1; @@ -1043,7 +1043,7 @@ static float *ldr_to_hdr(stbi_uc *data static stbi_uc *hdr_to_ldr(float *data, int x, int y, int comp) { int i,k,n; - stbi_uc *output = (stbi_uc *) MALLOC(x * y * comp); + stbi_uc *output = MALLOC(x * y * comp); if (output == NULL) { FREE(data); return epuc("outofmem", "Out of memory"); } // compute number of non-alpha components if (comp & 1) n = comp; else n = comp-1; @@ -1983,7 +1983,7 @@ static uint8 *load_jpeg_image(jpeg *z, i // allocate line buffer big enough for upsampling off the edges // with upsample factor of 4 - z->img_comp[k].linebuf = (uint8 *) MALLOC(z->s.img_x + 3); + z->img_comp[k].linebuf = MALLOC(z->s.img_x + 3); if (!z->img_comp[k].linebuf) { cleanup_jpeg(z); return epuc("outofmem", "Out of memory"); } r->hs = z->img_h_max / z->img_comp[k].h; @@ -2001,7 +2001,7 @@ static uint8 *load_jpeg_image(jpeg *z, i } // can't error after this so, this is safe - output = (uint8 *) MALLOC(n * z->s.img_x * z->s.img_y + 1); + output = MALLOC(n * z->s.img_x * z->s.img_y + 1); if (!output) { cleanup_jpeg(z); return epuc("outofmem", "Out of memory"); } // now go ahead and resample @@ -2074,7 +2074,7 @@ unsigned char *stbi_jpeg_load_from_memor { #ifdef STBI_SMALL_STACK unsigned char *result; - jpeg *j = (jpeg *) MALLOC(sizeof(*j)); + jpeg *j = MALLOC(sizeof(*j)); start_mem(>s, buffer, len); result = load_jpeg_image(j,x,y,comp,req_comp); FREE(j); @@ -2512,7 +2512,7 @@ static int do_zlib(zbuf *a, char *obuf, char *stbi_zlib_decode_malloc_guesssize(const char * buffer, int len, int initial_size, int *outlen) { zbuf a; - char *p = (char *) MALLOC(initial_size); + char *p = MALLOC(initial_size); if (p == NULL) return NULL; a.zbuffer = (uint8 const *) buffer; a.zbuffer_end = (uint8 const *) buffer + len; @@ -2533,7 +2533,7 @@ char *stbi_zlib_decode_malloc(char const char *stbi_zlib_decode_malloc_guesssize_headerflag(const char *buffer, int len, int initial_size, int *outlen, int parse_header) { zbuf a; - char *p = (char *) MALLOC(initial_size); + char *p = MALLOC(initial_size); if (p == NULL) return NULL; a.zbuffer = (uint8 const *) buffer; a.zbuffer_end = (uint8 const *) buffer + len; @@ -2560,7 +2560,7 @@ int stbi_zlib_decode_buffer(char *obuffe char *stbi_zlib_decode_noheader_malloc(char const *buffer, int len, int *outlen) { zbuf a; - char *p = (char *) MALLOC(16384); + char *p = MALLOC(16384); if (p == NULL) return NULL; a.zbuffer = (uint8 const *) buffer; a.zbuffer_end = (uint8 const *) buffer+len; @@ -2657,7 +2657,7 @@ static int create_png_image_raw(png *a, int img_n = s->img_n; // copy it into a local for later assert(out_n == s->img_n || out_n == s->img_n+1); if (stbi_png_partial) y = 1; - a->out = (uint8 *) MALLOC(x * y * out_n); + a->out = MALLOC(x * y * out_n); if (!a->out) return e("outofmem", "Out of memory"); if (!stbi_png_partial) { if (s->img_x == x && s->img_y == y) { @@ -2737,7 +2737,7 @@ static int create_png_image(png *a, uint stbi_png_partial = 0; // de-interlacing - final = (uint8 *) MALLOC(a->s.img_x * a->s.img_y * out_n); +
CVS commit: src/sys/dev/stbi
Module Name:src Committed By: christos Date: Thu Jan 21 17:17:53 UTC 2016 Modified Files: src/sys/dev/stbi: stb_image.c Log Message: PR/50686: David Binderman: fix memory leak To generate a diff of this commit: cvs rdiff -u -r1.7 -r1.8 src/sys/dev/stbi/stb_image.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/sys/dev/stbi/stb_image.c diff -u src/sys/dev/stbi/stb_image.c:1.7 src/sys/dev/stbi/stb_image.c:1.8 --- src/sys/dev/stbi/stb_image.c:1.7 Thu Jan 21 12:16:48 2016 +++ src/sys/dev/stbi/stb_image.c Thu Jan 21 12:17:53 2016 @@ -430,7 +430,7 @@ extern int stbi_gif_info_from_file #endif #ifdef _KERNEL #include -__KERNEL_RCSID(0, "$NetBSD: stb_image.c,v 1.7 2016/01/21 17:16:48 christos Exp $"); +__KERNEL_RCSID(0, "$NetBSD: stb_image.c,v 1.8 2016/01/21 17:17:53 christos Exp $"); #include #include #include @@ -3358,7 +3358,10 @@ static stbi_uc *bmp_load(stbi *s, int *x easy = 2; } if (!easy) { - if (!mr || !mg || !mb) return epuc("bad masks", "Corrupt BMP"); + if (!mr || !mg || !mb) { + FREE(out); + return epuc("bad masks", "Corrupt BMP"); + } // right shift amt to put high bit in position #7 rshift = high_bit(mr)-7; rcount = bitcount(mr); gshift = high_bit(mg)-7; gcount = bitcount(mr);
CVS commit: src/sys/dev/stbi
Module Name:src Committed By: martin Date: Sun Sep 15 14:06:10 UTC 2013 Modified Files: src/sys/dev/stbi: stb_image.c Log Message: Remove unused variables To generate a diff of this commit: cvs rdiff -u -r1.5 -r1.6 src/sys/dev/stbi/stb_image.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/sys/dev/stbi/stb_image.c diff -u src/sys/dev/stbi/stb_image.c:1.5 src/sys/dev/stbi/stb_image.c:1.6 --- src/sys/dev/stbi/stb_image.c:1.5 Sun Jan 27 14:47:37 2013 +++ src/sys/dev/stbi/stb_image.c Sun Sep 15 14:06:10 2013 @@ -430,7 +430,7 @@ extern int stbi_gif_info_from_file #endif #ifdef _KERNEL #include sys/cdefs.h -__KERNEL_RCSID(0, $NetBSD: stb_image.c,v 1.5 2013/01/27 14:47:37 mbalmer Exp $); +__KERNEL_RCSID(0, $NetBSD: stb_image.c,v 1.6 2013/09/15 14:06:10 martin Exp $); #include sys/param.h #include sys/systm.h #include sys/kernel.h @@ -3221,7 +3221,7 @@ static int shiftsigned(int v, int shift, static stbi_uc *bmp_load(stbi *s, int *x, int *y, int *comp, int req_comp) { uint8 *out; - unsigned int mr=0,mg=0,mb=0,ma=0, fake_a=0; + unsigned int mr=0,mg=0,mb=0,ma=0; stbi_uc pal[256][4]; int psize=0,i,j,compress=0,width; int bpp, flip_vertically, pad, target, offset, hsz; @@ -3270,7 +3270,6 @@ static stbi_uc *bmp_load(stbi *s, int *x mg = 0xffu 8; mb = 0xffu 0; ma = 0xffu 24; - fake_a = 1; // @TODO: check for cases like alpha value is all 0 and switch it to 255 } else { mr = 31u 10; mg = 31u 5;
CVS commit: src/sys/dev/stbi
Module Name:src Committed By: christos Date: Sat Jun 2 14:30:04 UTC 2012 Modified Files: src/sys/dev/stbi: stb_image.c Log Message: PR/46518: Nat Sloss: stbi splash: compressed PNG file causes panic Make the kernel FREE macro behave like the userland free(3), i.e. accept NULL To generate a diff of this commit: cvs rdiff -u -r1.2 -r1.3 src/sys/dev/stbi/stb_image.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/sys/dev/stbi/stb_image.c diff -u src/sys/dev/stbi/stb_image.c:1.2 src/sys/dev/stbi/stb_image.c:1.3 --- src/sys/dev/stbi/stb_image.c:1.2 Fri Jan 20 18:13:47 2012 +++ src/sys/dev/stbi/stb_image.c Sat Jun 2 10:30:04 2012 @@ -430,7 +430,7 @@ extern int stbi_gif_info_from_file #endif #ifdef _KERNEL #include sys/cdefs.h -__KERNEL_RCSID(0, $NetBSD: stb_image.c,v 1.2 2012/01/20 23:13:47 jmcneill Exp $); +__KERNEL_RCSID(0, $NetBSD: stb_image.c,v 1.3 2012/06/02 14:30:04 christos Exp $); #include sys/param.h #include sys/systm.h #include sys/kernel.h @@ -446,7 +446,8 @@ __KERNEL_RCSID(0, $NetBSD: stb_image.c, #ifdef _KERNEL #define MALLOC(size) malloc((size), M_TEMP, M_WAITOK) #define REALLOC(ptr, size) realloc((ptr), (size), M_TEMP, M_WAITOK) -#define FREE(ptr) free((ptr), M_TEMP) +#define FREE(ptr) \ +do { if (ptr) free((ptr), M_TEMP); } while (/*CONSTCOND*/0) #else #define MALLOC(size) malloc((size)) #define REALLOC(ptr, size) realloc((ptr), (size))
CVS commit: src/sys/dev/stbi
Module Name:src Committed By: christos Date: Sat Jun 2 14:37:38 UTC 2012 Modified Files: src/sys/dev/stbi: stb_image.c Log Message: p-out is always NULL here To generate a diff of this commit: cvs rdiff -u -r1.3 -r1.4 src/sys/dev/stbi/stb_image.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/sys/dev/stbi/stb_image.c diff -u src/sys/dev/stbi/stb_image.c:1.3 src/sys/dev/stbi/stb_image.c:1.4 --- src/sys/dev/stbi/stb_image.c:1.3 Sat Jun 2 10:30:04 2012 +++ src/sys/dev/stbi/stb_image.c Sat Jun 2 10:37:38 2012 @@ -430,7 +430,7 @@ extern int stbi_gif_info_from_file #endif #ifdef _KERNEL #include sys/cdefs.h -__KERNEL_RCSID(0, $NetBSD: stb_image.c,v 1.3 2012/06/02 14:30:04 christos Exp $); +__KERNEL_RCSID(0, $NetBSD: stb_image.c,v 1.4 2012/06/02 14:37:38 christos Exp $); #include sys/param.h #include sys/systm.h #include sys/kernel.h @@ -3051,7 +3051,6 @@ static unsigned char *do_png(png *p, int *y = p-s.img_y; if (n) *n = p-s.img_n; } - FREE(p-out); p-out = NULL; FREE(p-expanded); p-expanded = NULL; FREE(p-idata);p-idata= NULL;
CVS commit: src/sys/dev/stbi
Module Name:src Committed By: jmcneill Date: Fri Jan 20 23:13:47 UTC 2012 Modified Files: src/sys/dev/stbi: stb_image.c Log Message: reduce stack usage of stbi_gif_load_from_memory when STBI_SMALL_STACK is defined To generate a diff of this commit: cvs rdiff -u -r1.1 -r1.2 src/sys/dev/stbi/stb_image.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/sys/dev/stbi/stb_image.c diff -u src/sys/dev/stbi/stb_image.c:1.1 src/sys/dev/stbi/stb_image.c:1.2 --- src/sys/dev/stbi/stb_image.c:1.1 Sun Feb 6 23:13:04 2011 +++ src/sys/dev/stbi/stb_image.c Fri Jan 20 23:13:47 2012 @@ -430,7 +430,7 @@ extern int stbi_gif_info_from_file #endif #ifdef _KERNEL #include sys/cdefs.h -__KERNEL_RCSID(0, $NetBSD: stb_image.c,v 1.1 2011/02/06 23:13:04 jmcneill Exp $); +__KERNEL_RCSID(0, $NetBSD: stb_image.c,v 1.2 2012/01/20 23:13:47 jmcneill Exp $); #include sys/param.h #include sys/systm.h #include sys/kernel.h @@ -4601,16 +4601,30 @@ stbi_uc *stbi_gif_load_from_memory (stbi { uint8 *u = 0; stbi s; + stbi_gif *pg; + + #ifdef STBI_SMALL_STACK + pg = (stbi_gif *) MALLOC(sizeof(*pg)); + if (pg == NULL) + return NULL; + #else stbi_gif g; + pg = g; + #endif - memset(g, 0, sizeof(g)); + memset(pg, 0, sizeof(*pg)); start_mem(s, buffer, len); - u = stbi_gif_load_next(s, g, comp, req_comp); + u = stbi_gif_load_next(s, pg, comp, req_comp); if (u == (void *) 1) u = 0; // end of animated gif marker if (u) { - *x = g.w; - *y = g.h; + *x = pg-w; + *y = pg-h; } + + #ifdef STBI_SMALL_STACK + FREE(pg); + #endif + return u; }