Skip to content
Myr

merge https://github.com/nothings/stb/pull/427 but I messed up the merge

Before adoption: this commit came in with the history the project adopted, so no landing records it.

so you don't get the automatic info you normally do

authored by Sean Barrett · committed by Sean Barrett · parent 6d60610 · Browse files · 1 file+51 added−6 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

1 file+51 added−6 removed

  • other:+51 added−6 removed

1 file+51 added−6 removed

modified:stb_image.h+51 added-6 removed
2626 unmodified lines
2627{2628 j->code_bits = 0;2629 j->code_buffer = 0;2630 j->nomore = 0;2631 j->img_comp[0].dc_pred = j->img_comp[1].dc_pred = j->img_comp[2].dc_pred = 0;2631 j->img_comp[0].dc_pred = j->img_comp[1].dc_pred = j->img_comp[2].dc_pred = j->img_comp[3].dc_pred = 0;2632 j->marker = STBI__MARKER_none;2633 j->todo = j->restart_interval ? j->restart_interval : 0x7fffffff;2634 j->eob_run = 0;2635 // no more than 1<<31 MCUs if no restart_interal? that's plenty safe,
322 unmodified lines
2958 p = stbi__get8(s); if (p != 8) return stbi__err("only 8-bit","JPEG format not supported: 8-bit only"); // JPEG baseline2959 s->img_y = stbi__get16be(s); if (s->img_y == 0) return stbi__err("no header height", "JPEG format not supported: delayed height"); // Legal, but we don't handle it--but neither does IJG2960 s->img_x = stbi__get16be(s); if (s->img_x == 0) return stbi__err("0 width","Corrupt JPEG"); // JPEG requires2961 c = stbi__get8(s);2962 if (c != 3 && c != 1) return stbi__err("bad component count","Corrupt JPEG"); // JFIF requires2962 if (c != 3 && c != 1 && c != 4) return stbi__err("bad component count","Corrupt JPEG");2963 s->img_n = c;2964 for (i=0; i < c; ++i) {2965 z->img_comp[i].data = NULL;2966 z->img_comp[i].linebuf = NULL;
4 unmodified lines
2971 z->rgb = 0;2972 for (i=0; i < s->img_n; ++i) {2973 static unsigned char rgb[3] = { 'R', 'G', 'B' };2974 z->img_comp[i].id = stbi__get8(s);2975 if (z->img_comp[i].id == rgb[i])2975 if (s->img_n == 3 && z->img_comp[i].id == rgb[i])2976 ++z->rgb;2977 q = stbi__get8(s);2978 z->img_comp[i].h = (q >> 4); if (!z->img_comp[i].h || z->img_comp[i].h > 4) return stbi__err("bad H","Corrupt JPEG");2979 z->img_comp[i].v = q & 15; if (!z->img_comp[i].v || z->img_comp[i].v > 4) return stbi__err("bad V","Corrupt JPEG");
535 unmodified lines
3515 int ystep; // how far through vertical expansion we are3516 int ypos; // which pre-expansion row we're on3517} stbi__resample;35183519// fast 0..255 * 0..255 => 0..255 rounded multiplication3520static stbi_uc stbi__blinn_8x8(stbi_uc x, stbi_uc y)3521{3522 unsigned int t = x*y + 128;3523 return (stbi_uc) ((t + (t >>8)) >> 8);3524}35253526static stbi_uc *load_jpeg_image(stbi__jpeg *z, int *out_x, int *out_y, int *comp, int req_comp)3527{3528 int n, decode_n, is_rgb;3529 z->s->img_n = 0; // make stbi__cleanup_jpeg safe
4 unmodified lines
3534 // load a jpeg image from whichever source, but leave in YCbCr format3535 if (!stbi__decode_jpeg_image(z)) { stbi__cleanup_jpeg(z); return NULL; }35363537 // determine actual number of components to generate3531 n = req_comp ? req_comp : z->s->img_n;3538 n = req_comp ? req_comp : z->s->img_n >= 3 ? 3 : 1;35393540 is_rgb = z->s->img_n == 3 && (z->rgb == 3 || (z->app14_color_transform == 0 && !z->jfif));35413542 if (z->s->img_n == 3 && n < 3 && !is_rgb)
66 unmodified lines
3609 }3610 } else {3611 z->YCbCr_to_RGB_kernel(out, y, coutput[1], coutput[2], z->s->img_x, n);3612 }3613 } else if (z->s->img_n == 4) {3614 if (z->app14_color_transform == 0) { // CMYK3615 for (i=0; i < z->s->img_x; ++i) {3616 stbi_uc k = coutput[3][i];3617 out[0] = stbi__blinn_8x8(coutput[0][i], k);3618 out[1] = stbi__blinn_8x8(coutput[1][i], k);3619 out[2] = stbi__blinn_8x8(coutput[2][i], k);3620 out[3] = 255;3621 out += n;3622 }3623 } else if (z->app14_color_transform == 2) { // YCCK3624 z->YCbCr_to_RGB_kernel(out, y, coutput[1], coutput[2], z->s->img_x, n);3625 for (i=0; i < z->s->img_x; ++i) {3626 stbi_uc k = coutput[3][i];3627 out[0] = stbi__blinn_8x8(255 - out[0], k);3628 out[1] = stbi__blinn_8x8(255 - out[1], k);3629 out[2] = stbi__blinn_8x8(255 - out[2], k);3630 out += n;3631 }3632 } else { // YCbCr + alpha? Ignore the fourth channel for now3633 z->YCbCr_to_RGB_kernel(out, y, coutput[1], coutput[2], z->s->img_x, n);3634 }3635 } else3636 for (i=0; i < z->s->img_x; ++i) {3637 out[0] = out[1] = out[2] = y[i];3638 out[3] = 255; // not used if n==3
9 unmodified lines
3648 out[0] = stbi__compute_y(coutput[0][i], coutput[1][i], coutput[2][i]);3649 out[1] = 255;3650 }3651 }3652 } else if (z->s->img_n == 4 && z->app14_color_transform == 0) {3653 for (i=0; i < z->s->img_x; ++i) {3654 stbi_uc k = coutput[3][i];3655 stbi_uc r = stbi__blinn_8x8(coutput[0][i], k);3656 stbi_uc g = stbi__blinn_8x8(coutput[1][i], k);3657 stbi_uc b = stbi__blinn_8x8(coutput[2][i], k);3658 out[0] = stbi__compute_y(r, g, b);3659 out[1] = 255;3660 out += n;3661 }3662 } else if (z->s->img_n == 4 && z->app14_color_transform == 2) {3663 for (i=0; i < z->s->img_x; ++i) {3664 out[0] = stbi__blinn_8x8(255 - coutput[0][i], coutput[3][i]);3665 out[1] = 255;3666 out += n;3667 }3668 } else {3669 stbi_uc *y = coutput[0];3670 if (n == 1)3671 for (i=0; i < z->s->img_x; ++i) out[i] = y[i];
4 unmodified lines
3676 }3677 stbi__cleanup_jpeg(z);3678 *out_x = z->s->img_x;3679 *out_y = z->s->img_y;3635 if (comp) *comp = z->s->img_n; // report original components, not output3680 if (comp) *comp = z->s->img_n >= 3 ? 3 : 1; // report original components, not output3681 return output;3682 }3683}3684
28 unmodified lines
3713 return 0;3714 }3715 if (x) *x = j->s->img_x;3716 if (y) *y = j->s->img_y;3672 if (comp) *comp = j->s->img_n;3717 if (comp) *comp = j->s->img_n >= 3 ? 3 : 1;3718 return 1;3719}37203721static int stbi__jpeg_info(stbi__context *s, int *x, int *y, int *comp)
3420 unmodified lines