(RBMP/RJPEG) Cleanups + optimizations
This commit is contained in:
parent
1027762db5
commit
b582f1c7c6
|
@ -35,7 +35,7 @@
|
||||||
#include <formats/rbmp.h>
|
#include <formats/rbmp.h>
|
||||||
|
|
||||||
/* truncate int to byte without warnings */
|
/* truncate int to byte without warnings */
|
||||||
#define RBMP__BYTECAST(x) ((unsigned char) ((x) & 255))
|
#define RBMP_BYTECAST(x) ((unsigned char) ((x) & 255))
|
||||||
|
|
||||||
#define RBMP_COMPUTE_Y(r, g, b) ((unsigned char) ((((r) * 77) + ((g) * 150) + (29 * (b))) >> 8))
|
#define RBMP_COMPUTE_Y(r, g, b) ((unsigned char) ((((r) * 77) + ((g) * 150) + (29 * (b))) >> 8))
|
||||||
|
|
||||||
|
@ -52,7 +52,7 @@ typedef struct
|
||||||
unsigned char *img_buffer;
|
unsigned char *img_buffer;
|
||||||
unsigned char *img_buffer_end;
|
unsigned char *img_buffer_end;
|
||||||
unsigned char *img_buffer_original;
|
unsigned char *img_buffer_original;
|
||||||
} rbmp__context;
|
} rbmp_context;
|
||||||
|
|
||||||
struct rbmp
|
struct rbmp
|
||||||
{
|
{
|
||||||
|
@ -60,7 +60,7 @@ struct rbmp
|
||||||
uint32_t *output_image;
|
uint32_t *output_image;
|
||||||
};
|
};
|
||||||
|
|
||||||
static INLINE unsigned char rbmp__get8(rbmp__context *s)
|
static INLINE unsigned char rbmp_get8(rbmp_context *s)
|
||||||
{
|
{
|
||||||
if (s->img_buffer < s->img_buffer_end)
|
if (s->img_buffer < s->img_buffer_end)
|
||||||
return *s->img_buffer++;
|
return *s->img_buffer++;
|
||||||
|
@ -68,7 +68,7 @@ static INLINE unsigned char rbmp__get8(rbmp__context *s)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void rbmp__skip(rbmp__context *s, int n)
|
static void rbmp_skip(rbmp_context *s, int n)
|
||||||
{
|
{
|
||||||
if (n < 0)
|
if (n < 0)
|
||||||
{
|
{
|
||||||
|
@ -79,19 +79,17 @@ static void rbmp__skip(rbmp__context *s, int n)
|
||||||
s->img_buffer += n;
|
s->img_buffer += n;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int rbmp__get16le(rbmp__context *s)
|
static int rbmp_get16le(rbmp_context *s)
|
||||||
{
|
{
|
||||||
int z = rbmp__get8(s);
|
return rbmp_get8(s) + (rbmp_get8(s) << 8);
|
||||||
return z + (rbmp__get8(s) << 8);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static uint32_t rbmp__get32le(rbmp__context *s)
|
static uint32_t rbmp_get32le(rbmp_context *s)
|
||||||
{
|
{
|
||||||
uint32_t z = rbmp__get16le(s);
|
return rbmp_get16le(s) + (rbmp_get16le(s) << 16);
|
||||||
return z + (rbmp__get16le(s) << 16);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static unsigned char *rbmp__convert_format(
|
static unsigned char *rbmp_convert_format(
|
||||||
unsigned char *data,
|
unsigned char *data,
|
||||||
int img_n,
|
int img_n,
|
||||||
int req_comp,
|
int req_comp,
|
||||||
|
@ -112,40 +110,40 @@ static unsigned char *rbmp__convert_format(
|
||||||
switch (((img_n)*8+(req_comp)))
|
switch (((img_n)*8+(req_comp)))
|
||||||
{
|
{
|
||||||
case ((1)*8+(2)):
|
case ((1)*8+(2)):
|
||||||
for(i=x-1; i >= 0; --i, src += 1, dest += 2)
|
for(i = x-1; i >= 0; --i, src += 1, dest += 2)
|
||||||
{
|
{
|
||||||
dest[0]=src[0];
|
dest[0]=src[0];
|
||||||
dest[1]=255;
|
dest[1]=255;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case ((1)*8+(3)):
|
case ((1)*8+(3)):
|
||||||
for(i=x-1; i >= 0; --i, src += 1, dest += 3)
|
for(i = x-1; i >= 0; --i, src += 1, dest += 3)
|
||||||
dest[0]=dest[1]=dest[2]=src[0];
|
dest[0]=dest[1]=dest[2]=src[0];
|
||||||
break;
|
break;
|
||||||
case ((1)*8+(4)):
|
case ((1)*8+(4)):
|
||||||
for(i=x-1; i >= 0; --i, src += 1, dest += 4)
|
for(i = x-1; i >= 0; --i, src += 1, dest += 4)
|
||||||
{
|
{
|
||||||
dest[0]=dest[1]=dest[2]=src[0];
|
dest[0]=dest[1]=dest[2]=src[0];
|
||||||
dest[3]=255;
|
dest[3]=255;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case ((2)*8+(1)):
|
case ((2)*8+(1)):
|
||||||
for(i=x-1; i >= 0; --i, src += 2, dest += 1)
|
for(i = x-1; i >= 0; --i, src += 2, dest += 1)
|
||||||
dest[0]=src[0];
|
dest[0]=src[0];
|
||||||
break;
|
break;
|
||||||
case ((2)*8+(3)):
|
case ((2)*8+(3)):
|
||||||
for(i=x-1; i >= 0; --i, src += 2, dest += 3)
|
for(i = x-1; i >= 0; --i, src += 2, dest += 3)
|
||||||
dest[0]=dest[1]=dest[2]=src[0];
|
dest[0]=dest[1]=dest[2]=src[0];
|
||||||
break;
|
break;
|
||||||
case ((2)*8+(4)):
|
case ((2)*8+(4)):
|
||||||
for(i=x-1; i >= 0; --i, src += 2, dest += 4)
|
for(i = x-1; i >= 0; --i, src += 2, dest += 4)
|
||||||
{
|
{
|
||||||
dest[0]=dest[1]=dest[2]=src[0];
|
dest[0]=dest[1]=dest[2]=src[0];
|
||||||
dest[3]=src[1];
|
dest[3]=src[1];
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case ((3)*8+(4)):
|
case ((3)*8+(4)):
|
||||||
for(i=x-1; i >= 0; --i, src += 3, dest += 4)
|
for(i = x-1; i >= 0; --i, src += 3, dest += 4)
|
||||||
{
|
{
|
||||||
dest[0]=src[0];
|
dest[0]=src[0];
|
||||||
dest[1]=src[1];
|
dest[1]=src[1];
|
||||||
|
@ -154,29 +152,29 @@ static unsigned char *rbmp__convert_format(
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case ((3)*8+(1)):
|
case ((3)*8+(1)):
|
||||||
for(i=x-1; i >= 0; --i, src += 3, dest += 1)
|
for(i = x-1; i >= 0; --i, src += 3, dest += 1)
|
||||||
dest[0] = RBMP_COMPUTE_Y(src[0],src[1],src[2]);
|
dest[0] = RBMP_COMPUTE_Y(src[0],src[1],src[2]);
|
||||||
break;
|
break;
|
||||||
case ((3)*8+(2)):
|
case ((3)*8+(2)):
|
||||||
for(i=x-1; i >= 0; --i, src += 3, dest += 2)
|
for(i = x-1; i >= 0; --i, src += 3, dest += 2)
|
||||||
{
|
{
|
||||||
dest[0] = RBMP_COMPUTE_Y(src[0],src[1],src[2]);
|
dest[0] = RBMP_COMPUTE_Y(src[0],src[1],src[2]);
|
||||||
dest[1] = 255;
|
dest[1] = 255;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case ((4)*8+(1)):
|
case ((4)*8+(1)):
|
||||||
for(i=x-1; i >= 0; --i, src += 4, dest += 1)
|
for(i = x-1; i >= 0; --i, src += 4, dest += 1)
|
||||||
dest[0] = RBMP_COMPUTE_Y(src[0],src[1],src[2]);
|
dest[0] = RBMP_COMPUTE_Y(src[0],src[1],src[2]);
|
||||||
break;
|
break;
|
||||||
case ((4)*8+(2)):
|
case ((4)*8+(2)):
|
||||||
for(i=x-1; i >= 0; --i, src += 4, dest += 2)
|
for(i = x-1; i >= 0; --i, src += 4, dest += 2)
|
||||||
{
|
{
|
||||||
dest[0] = RBMP_COMPUTE_Y(src[0],src[1],src[2]);
|
dest[0] = RBMP_COMPUTE_Y(src[0],src[1],src[2]);
|
||||||
dest[1] = src[3];
|
dest[1] = src[3];
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case ((4)*8+(3)):
|
case ((4)*8+(3)):
|
||||||
for(i=x-1; i >= 0; --i, src += 4, dest += 3)
|
for(i = x-1; i >= 0; --i, src += 4, dest += 3)
|
||||||
{
|
{
|
||||||
dest[0]=src[0];
|
dest[0]=src[0];
|
||||||
dest[1]=src[1];
|
dest[1]=src[1];
|
||||||
|
@ -195,29 +193,30 @@ static unsigned char *rbmp__convert_format(
|
||||||
/* Microsoft/Windows BMP image */
|
/* Microsoft/Windows BMP image */
|
||||||
|
|
||||||
/* returns 0..31 for the highest set bit */
|
/* returns 0..31 for the highest set bit */
|
||||||
static int rbmp__high_bit(unsigned int z)
|
static int rbmp_high_bit(unsigned int z)
|
||||||
{
|
{
|
||||||
int n=0;
|
int n=0;
|
||||||
if (z == 0)
|
if (z == 0)
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
if (z >= 0x10000)
|
if (z >= 0x10000)
|
||||||
{
|
{
|
||||||
n += 16;
|
n += 16;
|
||||||
z >>= 16;
|
z >>= 16;
|
||||||
}
|
}
|
||||||
if (z >= 0x00100)
|
if (z >= 0x00100)
|
||||||
{
|
{
|
||||||
n += 8;
|
n += 8;
|
||||||
z >>= 8;
|
z >>= 8;
|
||||||
}
|
}
|
||||||
if (z >= 0x00010)
|
if (z >= 0x00010)
|
||||||
{
|
{
|
||||||
n += 4;
|
n += 4;
|
||||||
z >>= 4;
|
z >>= 4;
|
||||||
}
|
}
|
||||||
if (z >= 0x00004)
|
if (z >= 0x00004)
|
||||||
{
|
{
|
||||||
n += 2;
|
n += 2;
|
||||||
z >>= 2;
|
z >>= 2;
|
||||||
}
|
}
|
||||||
if (z >= 0x00002)
|
if (z >= 0x00002)
|
||||||
|
@ -225,7 +224,7 @@ static int rbmp__high_bit(unsigned int z)
|
||||||
return n;
|
return n;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int rbmp__bitcount(unsigned int a)
|
static int rbmp_bitcount(unsigned int a)
|
||||||
{
|
{
|
||||||
a = (a & 0x55555555) + ((a >> 1) & 0x55555555); /* max 2 */
|
a = (a & 0x55555555) + ((a >> 1) & 0x55555555); /* max 2 */
|
||||||
a = (a & 0x33333333) + ((a >> 2) & 0x33333333); /* max 4 */
|
a = (a & 0x33333333) + ((a >> 2) & 0x33333333); /* max 4 */
|
||||||
|
@ -235,10 +234,10 @@ static int rbmp__bitcount(unsigned int a)
|
||||||
return a & 0xff;
|
return a & 0xff;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int rbmp__shiftsigned(int v, int shift, int bits)
|
static int rbmp_shiftsigned(int v, int shift, int bits)
|
||||||
{
|
{
|
||||||
int result;
|
int result;
|
||||||
int z=0;
|
int z = bits;
|
||||||
|
|
||||||
if (shift < 0)
|
if (shift < 0)
|
||||||
v <<= -shift;
|
v <<= -shift;
|
||||||
|
@ -246,17 +245,16 @@ static int rbmp__shiftsigned(int v, int shift, int bits)
|
||||||
v >>= shift;
|
v >>= shift;
|
||||||
|
|
||||||
result = v;
|
result = v;
|
||||||
z = bits;
|
|
||||||
|
|
||||||
while (z < 8)
|
while (z < 8)
|
||||||
{
|
{
|
||||||
result += v >> z;
|
result += v >> z;
|
||||||
z += bits;
|
z += bits;
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
static unsigned char *rbmp__bmp_load(rbmp__context *s, unsigned *x, unsigned *y,
|
static unsigned char *rbmp_bmp_load(rbmp_context *s, unsigned *x, unsigned *y,
|
||||||
int *comp, int req_comp)
|
int *comp, int req_comp)
|
||||||
{
|
{
|
||||||
unsigned char *out;
|
unsigned char *out;
|
||||||
|
@ -265,14 +263,14 @@ static unsigned char *rbmp__bmp_load(rbmp__context *s, unsigned *x, unsigned *y,
|
||||||
unsigned int mr=0,mg=0,mb=0,ma=0;
|
unsigned int mr=0,mg=0,mb=0,ma=0;
|
||||||
|
|
||||||
/* Corrupt BMP? */
|
/* Corrupt BMP? */
|
||||||
if (rbmp__get8(s) != 'B' || rbmp__get8(s) != 'M')
|
if (rbmp_get8(s) != 'B' || rbmp_get8(s) != 'M')
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
rbmp__get32le(s); /* discard filesize */
|
rbmp_get32le(s); /* discard filesize */
|
||||||
rbmp__get16le(s); /* discard reserved */
|
rbmp_get16le(s); /* discard reserved */
|
||||||
rbmp__get16le(s); /* discard reserved */
|
rbmp_get16le(s); /* discard reserved */
|
||||||
offset = rbmp__get32le(s);
|
offset = rbmp_get32le(s);
|
||||||
hsz = rbmp__get32le(s);
|
hsz = rbmp_get32le(s);
|
||||||
|
|
||||||
/* BMP type not supported? */
|
/* BMP type not supported? */
|
||||||
if (hsz != 12 && hsz != 40 && hsz != 56 && hsz != 108 && hsz != 124)
|
if (hsz != 12 && hsz != 40 && hsz != 56 && hsz != 108 && hsz != 124)
|
||||||
|
@ -280,20 +278,20 @@ static unsigned char *rbmp__bmp_load(rbmp__context *s, unsigned *x, unsigned *y,
|
||||||
|
|
||||||
if (hsz == 12)
|
if (hsz == 12)
|
||||||
{
|
{
|
||||||
s->img_x = rbmp__get16le(s);
|
s->img_x = rbmp_get16le(s);
|
||||||
s->img_y = rbmp__get16le(s);
|
s->img_y = rbmp_get16le(s);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
s->img_x = rbmp__get32le(s);
|
s->img_x = rbmp_get32le(s);
|
||||||
s->img_y = rbmp__get32le(s);
|
s->img_y = rbmp_get32le(s);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Bad BMP? */
|
/* Bad BMP? */
|
||||||
if (rbmp__get16le(s) != 1)
|
if (rbmp_get16le(s) != 1)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
bpp = rbmp__get16le(s);
|
bpp = rbmp_get16le(s);
|
||||||
|
|
||||||
/* BMP 1-bit type not supported? */
|
/* BMP 1-bit type not supported? */
|
||||||
if (bpp == 1)
|
if (bpp == 1)
|
||||||
|
@ -309,26 +307,26 @@ static unsigned char *rbmp__bmp_load(rbmp__context *s, unsigned *x, unsigned *y,
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
int compress = rbmp__get32le(s);
|
int compress = rbmp_get32le(s);
|
||||||
|
|
||||||
/* BMP RLE type not supported? */
|
/* BMP RLE type not supported? */
|
||||||
if (compress == 1 || compress == 2)
|
if (compress == 1 || compress == 2)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
rbmp__get32le(s); /* discard sizeof */
|
rbmp_get32le(s); /* discard sizeof */
|
||||||
rbmp__get32le(s); /* discard hres */
|
rbmp_get32le(s); /* discard hres */
|
||||||
rbmp__get32le(s); /* discard vres */
|
rbmp_get32le(s); /* discard vres */
|
||||||
rbmp__get32le(s); /* discard colors used */
|
rbmp_get32le(s); /* discard colors used */
|
||||||
rbmp__get32le(s); /* discard max important */
|
rbmp_get32le(s); /* discard max important */
|
||||||
|
|
||||||
if (hsz == 40 || hsz == 56)
|
if (hsz == 40 || hsz == 56)
|
||||||
{
|
{
|
||||||
if (hsz == 56)
|
if (hsz == 56)
|
||||||
{
|
{
|
||||||
rbmp__get32le(s);
|
rbmp_get32le(s);
|
||||||
rbmp__get32le(s);
|
rbmp_get32le(s);
|
||||||
rbmp__get32le(s);
|
rbmp_get32le(s);
|
||||||
rbmp__get32le(s);
|
rbmp_get32le(s);
|
||||||
}
|
}
|
||||||
if (bpp == 16 || bpp == 32)
|
if (bpp == 16 || bpp == 32)
|
||||||
{
|
{
|
||||||
|
@ -352,9 +350,9 @@ static unsigned char *rbmp__bmp_load(rbmp__context *s, unsigned *x, unsigned *y,
|
||||||
#endif
|
#endif
|
||||||
break;
|
break;
|
||||||
case 3:
|
case 3:
|
||||||
mr = rbmp__get32le(s);
|
mr = rbmp_get32le(s);
|
||||||
mg = rbmp__get32le(s);
|
mg = rbmp_get32le(s);
|
||||||
mb = rbmp__get32le(s);
|
mb = rbmp_get32le(s);
|
||||||
/* not documented, but generated by
|
/* not documented, but generated by
|
||||||
* Photoshop and handled by MS Paint */
|
* Photoshop and handled by MS Paint */
|
||||||
/* Bad BMP ?*/
|
/* Bad BMP ?*/
|
||||||
|
@ -374,19 +372,19 @@ static unsigned char *rbmp__bmp_load(rbmp__context *s, unsigned *x, unsigned *y,
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
mr = rbmp__get32le(s);
|
mr = rbmp_get32le(s);
|
||||||
mg = rbmp__get32le(s);
|
mg = rbmp_get32le(s);
|
||||||
mb = rbmp__get32le(s);
|
mb = rbmp_get32le(s);
|
||||||
ma = rbmp__get32le(s);
|
ma = rbmp_get32le(s);
|
||||||
rbmp__get32le(s); /* Discard color space */
|
rbmp_get32le(s); /* Discard color space */
|
||||||
for (i=0; i < 12; ++i)
|
for (i = 0; i < 12; ++i)
|
||||||
rbmp__get32le(s); /* Discard color space parameters */
|
rbmp_get32le(s); /* Discard color space parameters */
|
||||||
if (hsz == 124)
|
if (hsz == 124)
|
||||||
{
|
{
|
||||||
rbmp__get32le(s); /* Discard rendering intent */
|
rbmp_get32le(s); /* Discard rendering intent */
|
||||||
rbmp__get32le(s); /* Discard offset of profile data */
|
rbmp_get32le(s); /* Discard offset of profile data */
|
||||||
rbmp__get32le(s); /* Discard size of profile data */
|
rbmp_get32le(s); /* Discard size of profile data */
|
||||||
rbmp__get32le(s); /* Discard reserved */
|
rbmp_get32le(s); /* Discard reserved */
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (bpp < 16)
|
if (bpp < 16)
|
||||||
|
@ -415,16 +413,17 @@ static unsigned char *rbmp__bmp_load(rbmp__context *s, unsigned *x, unsigned *y,
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (i=0; i < psize; ++i)
|
for (i = 0; i < psize; ++i)
|
||||||
{
|
{
|
||||||
pal[i][2] = rbmp__get8(s);
|
pal[i][2] = rbmp_get8(s);
|
||||||
pal[i][1] = rbmp__get8(s);
|
pal[i][1] = rbmp_get8(s);
|
||||||
pal[i][0] = rbmp__get8(s);
|
pal[i][0] = rbmp_get8(s);
|
||||||
if (hsz != 12) rbmp__get8(s);
|
if (hsz != 12)
|
||||||
|
rbmp_get8(s);
|
||||||
pal[i][3] = 255;
|
pal[i][3] = 255;
|
||||||
}
|
}
|
||||||
|
|
||||||
rbmp__skip(s, offset - 14 - hsz - psize * (hsz == 12 ? 3 : 4));
|
rbmp_skip(s, offset - 14 - hsz - psize * (hsz == 12 ? 3 : 4));
|
||||||
if (bpp == 4)
|
if (bpp == 4)
|
||||||
width = (s->img_x + 1) >> 1;
|
width = (s->img_x + 1) >> 1;
|
||||||
else if (bpp == 8)
|
else if (bpp == 8)
|
||||||
|
@ -439,13 +438,13 @@ static unsigned char *rbmp__bmp_load(rbmp__context *s, unsigned *x, unsigned *y,
|
||||||
pad = (-width)&3;
|
pad = (-width)&3;
|
||||||
for (j=0; j < (int) s->img_y; ++j)
|
for (j=0; j < (int) s->img_y; ++j)
|
||||||
{
|
{
|
||||||
for (i=0; i < (int) s->img_x; i += 2)
|
for (i = 0; i < (int) s->img_x; i += 2)
|
||||||
{
|
{
|
||||||
int v=rbmp__get8(s);
|
int v = rbmp_get8(s);
|
||||||
int v2=0;
|
int v2 = 0;
|
||||||
if (bpp == 4)
|
if (bpp == 4)
|
||||||
{
|
{
|
||||||
v2 = v & 15;
|
v2 = v & 15;
|
||||||
v >>= 4;
|
v >>= 4;
|
||||||
}
|
}
|
||||||
out[z++] = pal[v][0];
|
out[z++] = pal[v][0];
|
||||||
|
@ -457,7 +456,7 @@ static unsigned char *rbmp__bmp_load(rbmp__context *s, unsigned *x, unsigned *y,
|
||||||
if (i+1 == (int)s->img_x)
|
if (i+1 == (int)s->img_x)
|
||||||
break;
|
break;
|
||||||
|
|
||||||
v = (bpp == 8) ? rbmp__get8(s) : v2;
|
v = (bpp == 8) ? rbmp_get8(s) : v2;
|
||||||
out[z++] = pal[v][0];
|
out[z++] = pal[v][0];
|
||||||
out[z++] = pal[v][1];
|
out[z++] = pal[v][1];
|
||||||
out[z++] = pal[v][2];
|
out[z++] = pal[v][2];
|
||||||
|
@ -465,23 +464,23 @@ static unsigned char *rbmp__bmp_load(rbmp__context *s, unsigned *x, unsigned *y,
|
||||||
if (target == 4)
|
if (target == 4)
|
||||||
out[z++] = 255;
|
out[z++] = 255;
|
||||||
}
|
}
|
||||||
rbmp__skip(s, pad);
|
rbmp_skip(s, pad);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
int rshift=0;
|
int rshift = 0;
|
||||||
int gshift=0;
|
int gshift = 0;
|
||||||
int bshift=0;
|
int bshift = 0;
|
||||||
int ashift=0;
|
int ashift = 0;
|
||||||
int rcount=0;
|
int rcount = 0;
|
||||||
int gcount=0;
|
int gcount = 0;
|
||||||
int bcount=0;
|
int bcount = 0;
|
||||||
int acount=0;
|
int acount = 0;
|
||||||
int z = 0;
|
int z = 0;
|
||||||
int easy=0;
|
int easy = 0;
|
||||||
|
|
||||||
rbmp__skip(s, offset - 14 - hsz);
|
rbmp_skip(s, offset - 14 - hsz);
|
||||||
|
|
||||||
if (bpp == 24)
|
if (bpp == 24)
|
||||||
width = 3 * s->img_x;
|
width = 3 * s->img_x;
|
||||||
|
@ -515,46 +514,110 @@ static unsigned char *rbmp__bmp_load(rbmp__context *s, unsigned *x, unsigned *y,
|
||||||
}
|
}
|
||||||
|
|
||||||
/* right shift amt to put high bit in position #7 */
|
/* right shift amt to put high bit in position #7 */
|
||||||
rshift = rbmp__high_bit(mr)-7;
|
rshift = rbmp_high_bit(mr)-7;
|
||||||
rcount = rbmp__bitcount(mr);
|
rcount = rbmp_bitcount(mr);
|
||||||
gshift = rbmp__high_bit(mg)-7;
|
gshift = rbmp_high_bit(mg)-7;
|
||||||
gcount = rbmp__bitcount(mg);
|
gcount = rbmp_bitcount(mg);
|
||||||
bshift = rbmp__high_bit(mb)-7;
|
bshift = rbmp_high_bit(mb)-7;
|
||||||
bcount = rbmp__bitcount(mb);
|
bcount = rbmp_bitcount(mb);
|
||||||
ashift = rbmp__high_bit(ma)-7;
|
ashift = rbmp_high_bit(ma)-7;
|
||||||
acount = rbmp__bitcount(ma);
|
acount = rbmp_bitcount(ma);
|
||||||
}
|
}
|
||||||
|
|
||||||
for (j=0; j < (int) s->img_y; ++j)
|
for (j=0; j < (int) s->img_y; ++j)
|
||||||
{
|
{
|
||||||
if (easy)
|
if (easy)
|
||||||
{
|
{
|
||||||
for (i=0; i < (int) s->img_x; ++i)
|
if (target == 4)
|
||||||
{
|
{
|
||||||
unsigned char a;
|
/* Need to apply alpha channel as well */
|
||||||
out[z+2] = rbmp__get8(s);
|
if (easy == 2)
|
||||||
out[z+1] = rbmp__get8(s);
|
{
|
||||||
out[z+0] = rbmp__get8(s);
|
for (i = 0; i < (int) s->img_x; ++i)
|
||||||
z += 3;
|
{
|
||||||
a = (easy == 2 ? rbmp__get8(s) : 255);
|
out[z+2] = rbmp_get8(s);
|
||||||
if (target == 4)
|
out[z+1] = rbmp_get8(s);
|
||||||
out[z++] = a;
|
out[z+0] = rbmp_get8(s);
|
||||||
|
z += 3;
|
||||||
|
out[z++] = rbmp_get8(s);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
for (i = 0; i < (int) s->img_x; ++i)
|
||||||
|
{
|
||||||
|
out[z+2] = rbmp_get8(s);
|
||||||
|
out[z+1] = rbmp_get8(s);
|
||||||
|
out[z+0] = rbmp_get8(s);
|
||||||
|
z += 3;
|
||||||
|
out[z++] = 255;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
for (i = 0; i < (int) s->img_x; ++i)
|
||||||
|
{
|
||||||
|
out[z+2] = rbmp_get8(s);
|
||||||
|
out[z+1] = rbmp_get8(s);
|
||||||
|
out[z+0] = rbmp_get8(s);
|
||||||
|
z += 3;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
for (i=0; i < (int) s->img_x; ++i)
|
if (target == 4)
|
||||||
{
|
{
|
||||||
uint32_t v = (bpp == 16 ? (uint32_t) rbmp__get16le(s) : rbmp__get32le(s));
|
/* Need to apply alpha channel as well */
|
||||||
int a;
|
if (ma)
|
||||||
out[z++] = RBMP__BYTECAST(rbmp__shiftsigned(v & mr, rshift, rcount));
|
{
|
||||||
out[z++] = RBMP__BYTECAST(rbmp__shiftsigned(v & mg, gshift, gcount));
|
for (i = 0; i < (int) s->img_x; ++i)
|
||||||
out[z++] = RBMP__BYTECAST(rbmp__shiftsigned(v & mb, bshift, bcount));
|
{
|
||||||
a = (ma ? rbmp__shiftsigned(v & ma, ashift, acount) : 255);
|
uint32_t v = (bpp == 16 ? (uint32_t) rbmp_get16le(s) : rbmp_get32le(s));
|
||||||
if (target == 4)
|
out[z++] = RBMP_BYTECAST(rbmp_shiftsigned(v & mr, rshift, rcount));
|
||||||
out[z++] = RBMP__BYTECAST(a);
|
out[z++] = RBMP_BYTECAST(rbmp_shiftsigned(v & mg, gshift, gcount));
|
||||||
|
out[z++] = RBMP_BYTECAST(rbmp_shiftsigned(v & mb, bshift, bcount));
|
||||||
|
out[z++] = RBMP_BYTECAST(rbmp_shiftsigned(v & ma, ashift, acount));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
for (i = 0; i < (int) s->img_x; ++i)
|
||||||
|
{
|
||||||
|
uint32_t v = (bpp == 16 ? (uint32_t) rbmp_get16le(s) : rbmp_get32le(s));
|
||||||
|
out[z++] = RBMP_BYTECAST(rbmp_shiftsigned(v & mr, rshift, rcount));
|
||||||
|
out[z++] = RBMP_BYTECAST(rbmp_shiftsigned(v & mg, gshift, gcount));
|
||||||
|
out[z++] = RBMP_BYTECAST(rbmp_shiftsigned(v & mb, bshift, bcount));
|
||||||
|
out[z++] = RBMP_BYTECAST(255);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if (bpp == 16)
|
||||||
|
{
|
||||||
|
for (i = 0; i < (int) s->img_x; ++i)
|
||||||
|
{
|
||||||
|
uint32_t v = (uint32_t)rbmp_get16le(s);
|
||||||
|
out[z++] = RBMP_BYTECAST(rbmp_shiftsigned(v & mr, rshift, rcount));
|
||||||
|
out[z++] = RBMP_BYTECAST(rbmp_shiftsigned(v & mg, gshift, gcount));
|
||||||
|
out[z++] = RBMP_BYTECAST(rbmp_shiftsigned(v & mb, bshift, bcount));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
for (i = 0; i < (int) s->img_x; ++i)
|
||||||
|
{
|
||||||
|
uint32_t v = rbmp_get32le(s);
|
||||||
|
out[z++] = RBMP_BYTECAST(rbmp_shiftsigned(v & mr, rshift, rcount));
|
||||||
|
out[z++] = RBMP_BYTECAST(rbmp_shiftsigned(v & mg, gshift, gcount));
|
||||||
|
out[z++] = RBMP_BYTECAST(rbmp_shiftsigned(v & mb, bshift, bcount));
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
rbmp__skip(s, pad);
|
rbmp_skip(s, pad);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -565,7 +628,7 @@ static unsigned char *rbmp__bmp_load(rbmp__context *s, unsigned *x, unsigned *y,
|
||||||
{
|
{
|
||||||
unsigned char *p1 = out + j *s->img_x*target;
|
unsigned char *p1 = out + j *s->img_x*target;
|
||||||
unsigned char *p2 = out + (s->img_y-1-j)*s->img_x*target;
|
unsigned char *p2 = out + (s->img_y-1-j)*s->img_x*target;
|
||||||
for (i=0; i < (int) s->img_x*target; ++i)
|
for (i = 0; i < (int) s->img_x*target; ++i)
|
||||||
{
|
{
|
||||||
t = p1[i];
|
t = p1[i];
|
||||||
p1[i] = p2[i];
|
p1[i] = p2[i];
|
||||||
|
@ -579,7 +642,7 @@ static unsigned char *rbmp__bmp_load(rbmp__context *s, unsigned *x, unsigned *y,
|
||||||
&& (req_comp >= 1 && req_comp <= 4)
|
&& (req_comp >= 1 && req_comp <= 4)
|
||||||
&& (req_comp != target))
|
&& (req_comp != target))
|
||||||
{
|
{
|
||||||
unsigned char *tmp = rbmp__convert_format(out, target, req_comp, s->img_x, s->img_y);
|
unsigned char *tmp = rbmp_convert_format(out, target, req_comp, s->img_x, s->img_y);
|
||||||
|
|
||||||
free(out);
|
free(out);
|
||||||
out = NULL;
|
out = NULL;
|
||||||
|
@ -602,13 +665,13 @@ static unsigned char *rbmp__bmp_load(rbmp__context *s, unsigned *x, unsigned *y,
|
||||||
static unsigned char *rbmp_load_from_memory(unsigned char const *buffer, int len,
|
static unsigned char *rbmp_load_from_memory(unsigned char const *buffer, int len,
|
||||||
unsigned *x, unsigned *y, int *comp, int req_comp)
|
unsigned *x, unsigned *y, int *comp, int req_comp)
|
||||||
{
|
{
|
||||||
rbmp__context s;
|
rbmp_context s;
|
||||||
|
|
||||||
s.img_buffer = (unsigned char*)buffer;
|
s.img_buffer = (unsigned char*)buffer;
|
||||||
s.img_buffer_original = (unsigned char*)buffer;
|
s.img_buffer_original = (unsigned char*)buffer;
|
||||||
s.img_buffer_end = (unsigned char*)buffer+len;
|
s.img_buffer_end = (unsigned char*)buffer+len;
|
||||||
|
|
||||||
return rbmp__bmp_load(&s,x,y,comp,req_comp);
|
return rbmp_bmp_load(&s,x,y,comp,req_comp);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void rbmp_convert_frame(uint32_t *frame, unsigned width, unsigned height)
|
static void rbmp_convert_frame(uint32_t *frame, unsigned width, unsigned height)
|
||||||
|
|
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue