Revision a32072d0

View differences:

Changelog
33 33
- VCD MPEG-PS mode. (Juanjo)
34 34
- PSNR stuff. (Juanjo)
35 35
- Simple stats output. (Juanjo)
36
- 16-bit and 15-bit rgb/bgr/gbr support (Bisqwit)
36 37

  
37 38
version 0.4.5:
38 39

  
libavcodec/avcodec.h
69 69
    PIX_FMT_RGBA32,
70 70
    PIX_FMT_BGRA32,
71 71
    PIX_FMT_YUV410P,
72
    PIX_FMT_YUV411P
72
    PIX_FMT_YUV411P,
73
    PIX_FMT_RGB565,
74
    PIX_FMT_RGB555,
75
//    PIX_FMT_RGB5551,
76
    PIX_FMT_BGR565,
77
    PIX_FMT_BGR555,
78
//    PIX_FMT_GBR565,
79
//    PIX_FMT_GBR555
73 80
};
74 81

  
75 82
/* currently unused, may be used if 24/32 bits samples ever supported */
libavcodec/imgconvert.c
184 184
    }
185 185
}
186 186

  
187
#define rgb565_to_yuv420p(lum,cb,cr,src,width,height) rgbmisc_to_yuv420p((lum),(cb),(cr),(src),(width),(height),0x0800,31, 0x0020,63,0x0001,31)
188
#define rgb555_to_yuv420p(lum,cb,cr,src,width,height) rgbmisc_to_yuv420p((lum),(cb),(cr),(src),(width),(height),0x0400,31, 0x0020,31,0x0001,31)
189
#define rgb5551_to_yuv420p(lum,cb,cr,src,width,height) rgbmisc_to_yuv420p((lum),(cb),(cr),(src),(width),(height),0x0800,31, 0x0040,31,0x0002,31)
190
#define bgr565_to_yuv420p(lum,cb,cr,src,width,height) rgbmisc_to_yuv420p((lum),(cb),(cr),(src),(width),(height),0x0001,31, 0x0020,63,0x0800,31)
191
#define bgr555_to_yuv420p(lum,cb,cr,src,width,height) rgbmisc_to_yuv420p((lum),(cb),(cr),(src),(width),(height),0x0001,31, 0x0020,31,0x0400,31)
192
#define gbr565_to_yuv420p(lum,cb,cr,src,width,height) rgbmisc_to_yuv420p((lum),(cb),(cr),(src),(width),(height),0x0001,31, 0x0800,31,0x0040,63)
193
#define gbr555_to_yuv420p(lum,cb,cr,src,width,height) rgbmisc_to_yuv420p((lum),(cb),(cr),(src),(width),(height),0x0001,31, 0x0400,31,0x0020,31)
194

  
195
static void rgbmisc_to_yuv420p
196
  (UINT8 *lum, UINT8 *cb, UINT8 *cr,
197
   UINT8 *src, int width, int height,
198
   
199
   UINT16 R_LOWMASK, UINT16 R_MAX,
200
   UINT16 G_LOWMASK, UINT16 G_MAX,
201
   UINT16 B_LOWMASK, UINT16 B_MAX
202
  )
203
{
204
    int wrap, wrap2, x, y;
205
    int r, g, b, r1, g1, b1;
206
    UINT8 *p;
207
    UINT16 pixel;
208

  
209
    wrap = width;
210
    wrap2 = width * 2;
211
    p = src;
212
    for(y=0;y<height;y+=2) {
213
        for(x=0;x<width;x+=2) {
214
            pixel = p[0] | (p[1]<<8);
215
            r = (((pixel/R_LOWMASK) & R_MAX) * (0x100 / (R_MAX+1)));
216
            g = (((pixel/G_LOWMASK) & G_MAX) * (0x100 / (G_MAX+1)));
217
            b = (((pixel/B_LOWMASK) & B_MAX) * (0x100 / (B_MAX+1)));
218
            r1 = r;
219
            g1 = g;
220
            b1 = b;
221
            lum[0] = (FIX(0.29900) * r + FIX(0.58700) * g + 
222
                      FIX(0.11400) * b + ONE_HALF) >> SCALEBITS;
223

  
224
            pixel = p[2] | (p[3]<<8);
225
            r = (((pixel/R_LOWMASK) & R_MAX) * (0x100 / (R_MAX+1)));
226
            g = (((pixel/G_LOWMASK) & G_MAX) * (0x100 / (G_MAX+1)));
227
            b = (((pixel/B_LOWMASK) & B_MAX) * (0x100 / (B_MAX+1)));
228
            r1 += r;
229
            g1 += g;
230
            b1 += b;
231
            lum[1] = (FIX(0.29900) * r + FIX(0.58700) * g + 
232
                      FIX(0.11400) * b + ONE_HALF) >> SCALEBITS;
233
            p += wrap2;
234
            lum += wrap;
235

  
236
            pixel = p[0] | (p[1]<<8);
237
            r = (((pixel/R_LOWMASK) & R_MAX) * (0x100 / (R_MAX+1)));
238
            g = (((pixel/G_LOWMASK) & G_MAX) * (0x100 / (G_MAX+1)));
239
            b = (((pixel/B_LOWMASK) & B_MAX) * (0x100 / (B_MAX+1)));
240
            r1 += r;
241
            g1 += g;
242
            b1 += b;
243
            lum[0] = (FIX(0.29900) * r + FIX(0.58700) * g + 
244
                      FIX(0.11400) * b + ONE_HALF) >> SCALEBITS;
245
            pixel = p[2] | (p[3]<<8);
246
            r = (((pixel/R_LOWMASK) & R_MAX) * (0x100 / (R_MAX+1)));
247
            g = (((pixel/G_LOWMASK) & G_MAX) * (0x100 / (G_MAX+1)));
248
            b = (((pixel/B_LOWMASK) & B_MAX) * (0x100 / (B_MAX+1)));
249
            r1 += r;
250
            g1 += g;
251
            b1 += b;
252
            lum[1] = (FIX(0.29900) * r + FIX(0.58700) * g + 
253
                      FIX(0.11400) * b + ONE_HALF) >> SCALEBITS;
254
            
255
            cb[0] = ((- FIX(0.16874) * r1 - FIX(0.33126) * g1 + 
256
                      FIX(0.50000) * b1 + 4 * ONE_HALF - 1) >> (SCALEBITS + 2)) + 128;
257
            cr[0] = ((FIX(0.50000) * r1 - FIX(0.41869) * g1 - 
258
                     FIX(0.08131) * b1 + 4 * ONE_HALF - 1) >> (SCALEBITS + 2)) + 128;
259

  
260
            cb++;
261
            cr++;
262
            p += -wrap2 + 2 * 2;
263
            lum += -wrap + 2;
264
        }
265
        p += wrap2;
266
        lum += wrap;
267
    }
268
}
269

  
270

  
187 271
static void bgr24_to_yuv420p(UINT8 *lum, UINT8 *cb, UINT8 *cr,
188 272
                              UINT8 *src, int width, int height)
189 273
{
......
730 814
            bgra32_to_yuv420p(dst->data[0], dst->data[1], dst->data[2], 
731 815
                             src->data[0], width, height);
732 816
            break;
817
        case PIX_FMT_RGB565:
818
            rgb565_to_yuv420p(dst->data[0], dst->data[1], dst->data[2], 
819
                             src->data[0], width, height);
820
            break;
821
        case PIX_FMT_RGB555:
822
            rgb555_to_yuv420p(dst->data[0], dst->data[1], dst->data[2], 
823
                             src->data[0], width, height);
824
            break;
825
/*        case PIX_FMT_RGB5551:
826
            rgb5551_to_yuv420p(dst->data[0], dst->data[1], dst->data[2], 
827
                             src->data[0], width, height);
828
            break;*/
829
        case PIX_FMT_BGR565:
830
            bgr565_to_yuv420p(dst->data[0], dst->data[1], dst->data[2], 
831
                             src->data[0], width, height);
832
            break;
833
        case PIX_FMT_BGR555:
834
            bgr555_to_yuv420p(dst->data[0], dst->data[1], dst->data[2], 
835
                             src->data[0], width, height);
836
            break;
837
/*        case PIX_FMT_GBR565:
838
            gbr565_to_yuv420p(dst->data[0], dst->data[1], dst->data[2], 
839
                             src->data[0], width, height);
840
            break;
841
        case PIX_FMT_GBR555:
842
            gbr555_to_yuv420p(dst->data[0], dst->data[1], dst->data[2],
843
                             src->data[0], width, height);
844
            break;*/
733 845
        default:
734 846
            return -1;
735 847
        }

Also available in: Unified diff