[FFmpeg-cvslog] huffyuvenc: store alpha for bgr32
Michael Niedermayer
git at videolan.org
Mon Nov 28 04:30:01 CET 2011
ffmpeg | branch: master | Michael Niedermayer <michaelni at gmx.at> | Mon Nov 28 03:44:20 2011 +0100| [0af7d7082fb3472496ee355e16d697f19c1ddd26] | committer: Michael Niedermayer
huffyuvenc: store alpha for bgr32
Signed-off-by: Michael Niedermayer <michaelni at gmx.at>
> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=0af7d7082fb3472496ee355e16d697f19c1ddd26
---
libavcodec/huffyuv.c | 39 ++++++++++++++++++++++++---------------
1 files changed, 24 insertions(+), 15 deletions(-)
diff --git a/libavcodec/huffyuv.c b/libavcodec/huffyuv.c
index b7a79a8..18e8c78 100644
--- a/libavcodec/huffyuv.c
+++ b/libavcodec/huffyuv.c
@@ -152,27 +152,32 @@ static inline int sub_left_prediction(HYuvContext *s, uint8_t *dst, uint8_t *src
}
}
-static inline void sub_left_prediction_bgr32(HYuvContext *s, uint8_t *dst, uint8_t *src, int w, int *red, int *green, int *blue){
+static inline void sub_left_prediction_bgr32(HYuvContext *s, uint8_t *dst, uint8_t *src, int w, int *red, int *green, int *blue, int *alpha){
int i;
- int r,g,b;
+ int r,g,b,a;
r= *red;
g= *green;
b= *blue;
+ a= *alpha;
for(i=0; i<FFMIN(w,4); i++){
const int rt= src[i*4+R];
const int gt= src[i*4+G];
const int bt= src[i*4+B];
+ const int at= src[i*4+A];
dst[i*4+R]= rt - r;
dst[i*4+G]= gt - g;
dst[i*4+B]= bt - b;
+ dst[i*4+A]= at - a;
r = rt;
g = gt;
b = bt;
+ a = at;
}
s->dsp.diff_bytes(dst+16, src+16, src+12, w*4-16);
*red= src[(w-1)*4+R];
*green= src[(w-1)*4+G];
*blue= src[(w-1)*4+B];
+ *alpha= src[(w-1)*4+A];
}
static int read_len_table(uint8_t *dst, GetBitContext *gb){
@@ -593,7 +598,7 @@ static av_cold int encode_init(AVCodecContext *avctx)
s->bitstream_bpp= 16;
break;
case PIX_FMT_RGB32:
- s->bitstream_bpp= 24;
+ s->bitstream_bpp= 32;
break;
default:
av_log(avctx, AV_LOG_ERROR, "format not supported\n");
@@ -879,10 +884,10 @@ static void decode_bgr_bitstream(HYuvContext *s, int count){
}
}
-static int encode_bgr_bitstream(HYuvContext *s, int count){
+static int encode_bgr_bitstream(HYuvContext *s, int count, int alpha){
int i;
- if(s->pb.buf_end - s->pb.buf - (put_bits_count(&s->pb)>>3) < 3*4*count){
+ if(s->pb.buf_end - s->pb.buf - (put_bits_count(&s->pb)>>3) < 4*(3+alpha)*count){
av_log(s->avctx, AV_LOG_ERROR, "encoded frame too large\n");
return -1;
}
@@ -890,15 +895,18 @@ static int encode_bgr_bitstream(HYuvContext *s, int count){
#define LOAD3\
int g= s->temp[0][4*i+G];\
int b= (s->temp[0][4*i+B] - g) & 0xff;\
- int r= (s->temp[0][4*i+R] - g) & 0xff;
+ int r= (s->temp[0][4*i+R] - g) & 0xff;\
+ int a= s->temp[0][4*i+A];
#define STAT3\
s->stats[0][b]++;\
s->stats[1][g]++;\
- s->stats[2][r]++;
+ s->stats[2][r]++;\
+ if(alpha) s->stats[2][a]++;
#define WRITE3\
put_bits(&s->pb, s->len[1][g], s->bits[1][g]);\
put_bits(&s->pb, s->len[0][b], s->bits[0][b]);\
- put_bits(&s->pb, s->len[2][r], s->bits[2][r]);
+ put_bits(&s->pb, s->len[2][r], s->bits[2][r]);\
+ if(alpha) put_bits(&s->pb, s->len[2][a], s->bits[2][a]);
if((s->flags&CODEC_FLAG_PASS1) && (s->avctx->flags2&CODEC_FLAG2_NO_OUTPUT)){
for(i=0; i<count; i++){
@@ -1366,25 +1374,26 @@ static int encode_frame(AVCodecContext *avctx, unsigned char *buf, int buf_size,
const int stride = -p->linesize[0];
const int fake_stride = -fake_ystride;
int y;
- int leftr, leftg, leftb;
+ int leftr, leftg, leftb, lefta;
+ if(s->bitstream_bpp == 32) put_bits(&s->pb, 8, lefta= data[A]);
put_bits(&s->pb, 8, leftr= data[R]);
put_bits(&s->pb, 8, leftg= data[G]);
put_bits(&s->pb, 8, leftb= data[B]);
- put_bits(&s->pb, 8, 0);
+ if(s->bitstream_bpp == 24) put_bits(&s->pb, 8, 0);
- sub_left_prediction_bgr32(s, s->temp[0], data+4, width-1, &leftr, &leftg, &leftb);
- encode_bgr_bitstream(s, width-1);
+ sub_left_prediction_bgr32(s, s->temp[0], data+4, width-1, &leftr, &leftg, &leftb, &lefta);
+ encode_bgr_bitstream(s, width-1, s->bitstream_bpp == 32);
for(y=1; y<s->height; y++){
uint8_t *dst = data + y*stride;
if(s->predictor == PLANE && s->interlaced < y){
s->dsp.diff_bytes(s->temp[1], dst, dst - fake_stride, width*4);
- sub_left_prediction_bgr32(s, s->temp[0], s->temp[1], width, &leftr, &leftg, &leftb);
+ sub_left_prediction_bgr32(s, s->temp[0], s->temp[1], width, &leftr, &leftg, &leftb, &lefta);
}else{
- sub_left_prediction_bgr32(s, s->temp[0], dst, width, &leftr, &leftg, &leftb);
+ sub_left_prediction_bgr32(s, s->temp[0], dst, width, &leftr, &leftg, &leftb, &lefta);
}
- encode_bgr_bitstream(s, width);
+ encode_bgr_bitstream(s, width, s->bitstream_bpp == 32);
}
}else{
av_log(avctx, AV_LOG_ERROR, "Format not supported!\n");
More information about the ffmpeg-cvslog
mailing list