diff imgconvert.c @ 1231:b88dfc4bbf8c libavcodec

* introducing new public interface in imgconvert.c + avcodec_get_pix_fmt converts textual representation of pixel format into the actual id. Complements avcodec_get_pix_fmt_name. + avpicture_layout serializes given picture into a flat array. Complements avpicture_fill. * adding a new option -pix_fmt to the ffmpeg, in order to control pixel format for the codecs that do support it, like rawvideo, for example. * reducing complexity of the rawvideo codec by splitting it in two and making it more reliable via hooking up to the avpicture_layout. Plus adding new FourCC as described here: http://www.fourcc.org * A tiny fix for avienc.c that makes avih and video strf consistent regarding codec FourCC.
author romansh
date Wed, 07 May 2003 19:01:45 +0000
parents 0aa744ab1c07
children 5d2376294fbf
line wrap: on
line diff
--- a/imgconvert.c	Wed May 07 12:28:36 2003 +0000
+++ b/imgconvert.c	Wed May 07 19:01:45 2003 +0000
@@ -224,6 +224,16 @@
         return pix_fmt_info[pix_fmt].name;
 }
 
+enum PixelFormat avcodec_get_pix_fmt(const char* name)
+{
+    int i; 
+    
+    for (i=0; i < PIX_FMT_NB; i++)
+         if (!strcmp(pix_fmt_info[i].name, name))
+	     break;
+    return i;
+}
+
 /* Picture field are filled with 'ptr' addresses. Also return size */
 int avpicture_fill(AVPicture *picture, uint8_t *ptr,
                    int pix_fmt, int width, int height)
@@ -303,6 +313,47 @@
     }
 }
 
+int avpicture_layout(AVPicture* src, int pix_fmt, int width, int height,
+                     unsigned char *dest, int dest_size)
+{
+    PixFmtInfo* pf = &pix_fmt_info[pix_fmt];
+    int i, j, w, h, data_planes;
+    unsigned char* s; 
+    int size = avpicture_get_size(pix_fmt, width, height);
+
+    if (size > dest_size)
+        return -1;
+
+    if (pf->pixel_type == FF_PIXEL_PACKED) {
+        if (pix_fmt == PIX_FMT_YUV422 || pix_fmt == PIX_FMT_RGB565 ||
+	    pix_fmt == PIX_FMT_RGB555)
+	  w = width * 2;
+	else
+	  w = width * (pf->depth * pf->nb_channels / 8);
+	data_planes = 1;
+	h = height;
+    } else {
+        data_planes = pf->nb_channels;
+	w = width;
+	h = height;
+    }
+    
+    for (i=0; i<data_planes; i++) {
+         if (i == 1) {
+	     w = width >> pf->x_chroma_shift;
+	     h = height >> pf->y_chroma_shift;
+	 }
+         s = src->data[i];
+	 for(j=0; j<h; j++) {
+	     memcpy(dest, s, w);
+	     dest += w;
+	     s += src->linesize[i];
+	 }
+    }
+
+    return size;
+}
+
 int avpicture_get_size(int pix_fmt, int width, int height)
 {
     AVPicture dummy_pict;