stb_image: support for 1-bit BMP
This commit is contained in:
parent
9d9f75eb68
commit
350173026a
55
stb_image.h
55
stb_image.h
@ -5007,7 +5007,6 @@ static void *stbi__bmp_parse_header(stbi__context *s, stbi__bmp_data *info)
|
|||||||
}
|
}
|
||||||
if (stbi__get16le(s) != 1) return stbi__errpuc("bad BMP", "bad BMP");
|
if (stbi__get16le(s) != 1) return stbi__errpuc("bad BMP", "bad BMP");
|
||||||
info->bpp = stbi__get16le(s);
|
info->bpp = stbi__get16le(s);
|
||||||
if (info->bpp == 1) return stbi__errpuc("monochrome", "BMP type not supported: 1-bit");
|
|
||||||
if (hsz != 12) {
|
if (hsz != 12) {
|
||||||
int compress = stbi__get32le(s);
|
int compress = stbi__get32le(s);
|
||||||
if (compress == 1 || compress == 2) return stbi__errpuc("BMP RLE", "BMP type not supported: RLE");
|
if (compress == 1 || compress == 2) return stbi__errpuc("BMP RLE", "BMP type not supported: RLE");
|
||||||
@ -5125,29 +5124,47 @@ static void *stbi__bmp_load(stbi__context *s, int *x, int *y, int *comp, int req
|
|||||||
pal[i][3] = 255;
|
pal[i][3] = 255;
|
||||||
}
|
}
|
||||||
stbi__skip(s, info.offset - 14 - info.hsz - psize * (info.hsz == 12 ? 3 : 4));
|
stbi__skip(s, info.offset - 14 - info.hsz - psize * (info.hsz == 12 ? 3 : 4));
|
||||||
if (info.bpp == 4) width = (s->img_x + 1) >> 1;
|
if (info.bpp == 1) width = (s->img_x + 7) >> 3;
|
||||||
|
else if (info.bpp == 4) width = (s->img_x + 1) >> 1;
|
||||||
else if (info.bpp == 8) width = s->img_x;
|
else if (info.bpp == 8) width = s->img_x;
|
||||||
else { STBI_FREE(out); return stbi__errpuc("bad bpp", "Corrupt BMP"); }
|
else { STBI_FREE(out); return stbi__errpuc("bad bpp", "Corrupt BMP"); }
|
||||||
pad = (-width)&3;
|
pad = (-width)&3;
|
||||||
for (j=0; j < (int) s->img_y; ++j) {
|
if (info.bpp == 1) {
|
||||||
for (i=0; i < (int) s->img_x; i += 2) {
|
for (j=0; j < (int) s->img_y; ++j) {
|
||||||
int v=stbi__get8(s),v2=0;
|
int bit_offset = 7, v = stbi__get8(s);
|
||||||
if (info.bpp == 4) {
|
for (i=0; i < (int) s->img_x; ++i) {
|
||||||
v2 = v & 15;
|
int color = (v>>bit_offset)&0x1;
|
||||||
v >>= 4;
|
out[z++] = pal[color][0];
|
||||||
|
out[z++] = pal[color][1];
|
||||||
|
out[z++] = pal[color][2];
|
||||||
|
if((--bit_offset) < 0) {
|
||||||
|
bit_offset = 7;
|
||||||
|
v = stbi__get8(s);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
out[z++] = pal[v][0];
|
stbi__skip(s, pad);
|
||||||
out[z++] = pal[v][1];
|
}
|
||||||
out[z++] = pal[v][2];
|
} else {
|
||||||
if (target == 4) out[z++] = 255;
|
for (j=0; j < (int) s->img_y; ++j) {
|
||||||
if (i+1 == (int) s->img_x) break;
|
for (i=0; i < (int) s->img_x; i += 2) {
|
||||||
v = (info.bpp == 8) ? stbi__get8(s) : v2;
|
int v=stbi__get8(s),v2=0;
|
||||||
out[z++] = pal[v][0];
|
if (info.bpp == 4) {
|
||||||
out[z++] = pal[v][1];
|
v2 = v & 15;
|
||||||
out[z++] = pal[v][2];
|
v >>= 4;
|
||||||
if (target == 4) out[z++] = 255;
|
}
|
||||||
|
out[z++] = pal[v][0];
|
||||||
|
out[z++] = pal[v][1];
|
||||||
|
out[z++] = pal[v][2];
|
||||||
|
if (target == 4) out[z++] = 255;
|
||||||
|
if (i+1 == (int) s->img_x) break;
|
||||||
|
v = (info.bpp == 8) ? stbi__get8(s) : v2;
|
||||||
|
out[z++] = pal[v][0];
|
||||||
|
out[z++] = pal[v][1];
|
||||||
|
out[z++] = pal[v][2];
|
||||||
|
if (target == 4) out[z++] = 255;
|
||||||
|
}
|
||||||
|
stbi__skip(s, pad);
|
||||||
}
|
}
|
||||||
stbi__skip(s, pad);
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
int rshift=0,gshift=0,bshift=0,ashift=0,rcount=0,gcount=0,bcount=0,acount=0;
|
int rshift=0,gshift=0,bshift=0,ashift=0,rcount=0,gcount=0,bcount=0,acount=0;
|
||||||
|
Loading…
Reference in New Issue
Block a user