Commit a9bd29e1 authored by Michael Niedermayer's avatar Michael Niedermayer

Merge remote-tracking branch 'richardpl/sws'

* richardpl/sws:
  rgb2rgb: remove unused bgr8torgb8()
  rgb2rgb: rgb12tobgr12()
  rgb2rgb: allow conversion for <15 bpp
  bmpenc: support for PIX_FMT_RGB444
  bmpdec: support for rgb444 with bitfields compression
Merged-by: 's avatarMichael Niedermayer <michaelni@gmx.at>
parents f4a01d77 296a3382
......@@ -163,8 +163,18 @@ static int bmp_decode_frame(AVCodecContext *avctx,
case 16:
if(comp == BMP_RGB)
avctx->pix_fmt = PIX_FMT_RGB555;
if(comp == BMP_BITFIELDS)
avctx->pix_fmt = rgb[1] == 0x07E0 ? PIX_FMT_RGB565 : PIX_FMT_RGB555;
else if (comp == BMP_BITFIELDS) {
if (rgb[0] == 0xF800 && rgb[1] == 0x07E0 && rgb[2] == 0x001F)
avctx->pix_fmt = PIX_FMT_RGB565;
else if (rgb[0] == 0x7C00 && rgb[1] == 0x03E0 && rgb[2] == 0x001F)
avctx->pix_fmt = PIX_FMT_RGB555;
else if (rgb[0] == 0x0F00 && rgb[1] == 0x00F0 && rgb[2] == 0x000F)
avctx->pix_fmt = PIX_FMT_RGB444;
else {
av_log(avctx, AV_LOG_ERROR, "Unknown bitfields %0X %0X %0X\n", rgb[0], rgb[1], rgb[2]);
return AVERROR(EINVAL);
}
}
break;
case 8:
if(hsize - ihsize - 14 > 0)
......
......@@ -28,6 +28,7 @@
static const uint32_t monoblack_pal[] = { 0x000000, 0xFFFFFF };
static const uint32_t rgb565_masks[] = { 0xF800, 0x07E0, 0x001F };
static const uint32_t rgb444_masks[] = { 0x0F00, 0x00F0, 0x000F };
static av_cold int bmp_encode_init(AVCodecContext *avctx){
BMPContext *s = avctx->priv_data;
......@@ -40,9 +41,8 @@ static av_cold int bmp_encode_init(AVCodecContext *avctx){
avctx->bits_per_coded_sample = 24;
break;
case PIX_FMT_RGB555:
avctx->bits_per_coded_sample = 16;
break;
case PIX_FMT_RGB565:
case PIX_FMT_RGB444:
avctx->bits_per_coded_sample = 16;
break;
case PIX_FMT_RGB8:
......@@ -79,6 +79,11 @@ static int bmp_encode_frame(AVCodecContext *avctx, unsigned char *buf, int buf_s
p->pict_type= AV_PICTURE_TYPE_I;
p->key_frame= 1;
switch (avctx->pix_fmt) {
case PIX_FMT_RGB444:
compression = BMP_BITFIELDS;
pal = rgb444_masks; // abuse pal to hold color masks
pal_entries = 3;
break;
case PIX_FMT_RGB565:
compression = BMP_BITFIELDS;
pal = rgb565_masks; // abuse pal to hold color masks
......@@ -163,7 +168,7 @@ AVCodec ff_bmp_encoder = {
.encode = bmp_encode_frame,
.pix_fmts = (const enum PixelFormat[]){
PIX_FMT_BGR24,
PIX_FMT_RGB555, PIX_FMT_RGB565,
PIX_FMT_RGB555, PIX_FMT_RGB444, PIX_FMT_RGB565,
PIX_FMT_RGB8, PIX_FMT_BGR8, PIX_FMT_RGB4_BYTE, PIX_FMT_BGR4_BYTE, PIX_FMT_GRAY8, PIX_FMT_PAL8,
PIX_FMT_MONOBLACK,
PIX_FMT_NONE},
......
......@@ -282,18 +282,16 @@ void rgb15tobgr15(const uint8_t *src, uint8_t *dst, int src_size)
}
}
void bgr8torgb8(const uint8_t *src, uint8_t *dst, int src_size)
void rgb12tobgr12(const uint8_t *src, uint8_t *dst, int src_size)
{
int i;
int num_pixels = src_size;
for (i=0; i<num_pixels; i++) {
unsigned b,g,r;
register uint8_t rgb;
rgb = src[i];
r = (rgb&0x07);
g = (rgb&0x38)>>3;
b = (rgb&0xC0)>>6;
dst[i] = ((b<<1)&0x07) | ((g&0x07)<<3) | ((r&0x03)<<6);
int num_pixels = src_size >> 1;
for (i = 0; i < num_pixels; i++) {
unsigned br;
unsigned rgb = ((const uint16_t *)src)[i];
br = rgb & 0x0F0F;
((uint16_t *)dst)[i] = (br >> 8) | (rgb & 0x00F0) | (br << 8);
}
}
......
......@@ -62,7 +62,7 @@ void rgb15tobgr32(const uint8_t *src, uint8_t *dst, int src_size);
void rgb15to24(const uint8_t *src, uint8_t *dst, int src_size);
void rgb15tobgr16(const uint8_t *src, uint8_t *dst, int src_size);
void rgb15tobgr15(const uint8_t *src, uint8_t *dst, int src_size);
void bgr8torgb8(const uint8_t *src, uint8_t *dst, int src_size);
void rgb12tobgr12(const uint8_t *src, uint8_t *dst, int src_size);
void shuffle_bytes_0321(const uint8_t *src, uint8_t *dst, int src_size);
void shuffle_bytes_1230(const uint8_t *src, uint8_t *dst, int src_size);
......
......@@ -404,8 +404,8 @@ static int rgbToRgbWrapper(SwsContext *c, const uint8_t *src[], int srcStride[],
const enum PixelFormat dstFormat = c->dstFormat;
const int srcBpp = (c->srcFormatBpp + 7) >> 3;
const int dstBpp = (c->dstFormatBpp + 7) >> 3;
const int srcId = c->srcFormatBpp >> 2; /* 1:0, 4:1, 8:2, 15:3, 16:4, 24:6, 32:8 */
const int dstId = c->dstFormatBpp >> 2;
const int srcId = c->srcFormatBpp;
const int dstId = c->dstFormatBpp;
void (*conv)(const uint8_t *src, uint8_t *dst, int src_size) = NULL;
#define CONV_IS(src, dst) (srcFormat == PIX_FMT_##src && dstFormat == PIX_FMT_##dst)
......@@ -427,38 +427,39 @@ static int rgbToRgbWrapper(SwsContext *c, const uint8_t *src[], int srcStride[],
/* BGR -> BGR */
if ((isBGRinInt(srcFormat) && isBGRinInt(dstFormat)) ||
(isRGBinInt(srcFormat) && isRGBinInt(dstFormat))) {
switch (srcId | (dstId << 4)) {
case 0x34: conv = rgb16to15; break;
case 0x36: conv = rgb24to15; break;
case 0x38: conv = rgb32to15; break;
case 0x43: conv = rgb15to16; break;
case 0x46: conv = rgb24to16; break;
case 0x48: conv = rgb32to16; break;
case 0x63: conv = rgb15to24; break;
case 0x64: conv = rgb16to24; break;
case 0x68: conv = rgb32to24; break;
case 0x83: conv = rgb15to32; break;
case 0x84: conv = rgb16to32; break;
case 0x86: conv = rgb24to32; break;
switch (srcId | (dstId << 16)) {
case 0x000F0010: conv = rgb16to15; break;
case 0x000F0018: conv = rgb24to15; break;
case 0x000F0020: conv = rgb32to15; break;
case 0x0010000F: conv = rgb15to16; break;
case 0x00100018: conv = rgb24to16; break;
case 0x00100020: conv = rgb32to16; break;
case 0x0018000F: conv = rgb15to24; break;
case 0x00180010: conv = rgb16to24; break;
case 0x00180020: conv = rgb32to24; break;
case 0x0020000F: conv = rgb15to32; break;
case 0x00200010: conv = rgb16to32; break;
case 0x00200018: conv = rgb24to32; break;
}
} else if ((isBGRinInt(srcFormat) && isRGBinInt(dstFormat)) ||
(isRGBinInt(srcFormat) && isBGRinInt(dstFormat))) {
switch (srcId | (dstId << 4)) {
case 0x33: conv = rgb15tobgr15; break;
case 0x34: conv = rgb16tobgr15; break;
case 0x36: conv = rgb24tobgr15; break;
case 0x38: conv = rgb32tobgr15; break;
case 0x43: conv = rgb15tobgr16; break;
case 0x44: conv = rgb16tobgr16; break;
case 0x46: conv = rgb24tobgr16; break;
case 0x48: conv = rgb32tobgr16; break;
case 0x63: conv = rgb15tobgr24; break;
case 0x64: conv = rgb16tobgr24; break;
case 0x66: conv = rgb24tobgr24; break;
case 0x68: conv = rgb32tobgr24; break;
case 0x83: conv = rgb15tobgr32; break;
case 0x84: conv = rgb16tobgr32; break;
case 0x86: conv = rgb24tobgr32; break;
switch (srcId | (dstId << 16)) {
case 0x000C000C: conv = rgb12tobgr12; break;
case 0x000F000F: conv = rgb15tobgr15; break;
case 0x000F0010: conv = rgb16tobgr15; break;
case 0x000F0018: conv = rgb24tobgr15; break;
case 0x000F0020: conv = rgb32tobgr15; break;
case 0x0010000F: conv = rgb15tobgr16; break;
case 0x00100010: conv = rgb16tobgr16; break;
case 0x00100018: conv = rgb24tobgr16; break;
case 0x00100020: conv = rgb32tobgr16; break;
case 0x0018000F: conv = rgb15tobgr24; break;
case 0x00180010: conv = rgb16tobgr24; break;
case 0x00180018: conv = rgb24tobgr24; break;
case 0x00180020: conv = rgb32tobgr24; break;
case 0x0020000F: conv = rgb15tobgr32; break;
case 0x00200010: conv = rgb16tobgr32; break;
case 0x00200018: conv = rgb24tobgr32; break;
}
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment