]> rtime.felk.cvut.cz Git - frescor/ffmpeg.git/blobdiff - libavcodec/imgconvert.c
Remove redundant assignment in av_picture_copy() found by CSA.
[frescor/ffmpeg.git] / libavcodec / imgconvert.c
index f68105e54b702e2a75a3f5cd770cd4b2917633a5..08274c403456585cf1f9a14a539f416a1cc0618d 100644 (file)
@@ -192,8 +192,8 @@ static const PixFmtInfo pix_fmt_info[PIX_FMT_NB] = {
         .depth = 8,
         .x_chroma_shift = 0, .y_chroma_shift = 0,
     },
-    [PIX_FMT_RGB32] = {
-        .name = "rgb32",
+    [PIX_FMT_ARGB] = {
+        .name = "argb",
         .nb_channels = 4, .is_alpha = 1,
         .color_type = FF_COLOR_RGB,
         .pixel_type = FF_PIXEL_PACKED,
@@ -216,16 +216,32 @@ static const PixFmtInfo pix_fmt_info[PIX_FMT_NB] = {
         .depth = 16,
         .x_chroma_shift = 0, .y_chroma_shift = 0,
     },
-    [PIX_FMT_RGB565] = {
-        .name = "rgb565",
+    [PIX_FMT_RGB565BE] = {
+        .name = "rgb565be",
         .nb_channels = 3,
         .color_type = FF_COLOR_RGB,
         .pixel_type = FF_PIXEL_PACKED,
         .depth = 5,
         .x_chroma_shift = 0, .y_chroma_shift = 0,
     },
-    [PIX_FMT_RGB555] = {
-        .name = "rgb555",
+    [PIX_FMT_RGB565LE] = {
+        .name = "rgb565le",
+        .nb_channels = 3,
+        .color_type = FF_COLOR_RGB,
+        .pixel_type = FF_PIXEL_PACKED,
+        .depth = 5,
+        .x_chroma_shift = 0, .y_chroma_shift = 0,
+    },
+    [PIX_FMT_RGB555BE] = {
+        .name = "rgb555be",
+        .nb_channels = 3,
+        .color_type = FF_COLOR_RGB,
+        .pixel_type = FF_PIXEL_PACKED,
+        .depth = 5,
+        .x_chroma_shift = 0, .y_chroma_shift = 0,
+    },
+    [PIX_FMT_RGB555LE] = {
+        .name = "rgb555le",
         .nb_channels = 3,
         .color_type = FF_COLOR_RGB,
         .pixel_type = FF_PIXEL_PACKED,
@@ -319,24 +335,40 @@ static const PixFmtInfo pix_fmt_info[PIX_FMT_NB] = {
         .depth = 8,
         .x_chroma_shift = 2, .y_chroma_shift = 0,
     },
-    [PIX_FMT_BGR32] = {
-        .name = "bgr32",
+    [PIX_FMT_ABGR] = {
+        .name = "abgr",
         .nb_channels = 4, .is_alpha = 1,
         .color_type = FF_COLOR_RGB,
         .pixel_type = FF_PIXEL_PACKED,
         .depth = 8,
         .x_chroma_shift = 0, .y_chroma_shift = 0,
     },
-    [PIX_FMT_BGR565] = {
-        .name = "bgr565",
+    [PIX_FMT_BGR565BE] = {
+        .name = "bgr565be",
+        .nb_channels = 3,
+        .color_type = FF_COLOR_RGB,
+        .pixel_type = FF_PIXEL_PACKED,
+        .depth = 5,
+        .x_chroma_shift = 0, .y_chroma_shift = 0,
+    },
+    [PIX_FMT_BGR565LE] = {
+        .name = "bgr565le",
         .nb_channels = 3,
         .color_type = FF_COLOR_RGB,
         .pixel_type = FF_PIXEL_PACKED,
         .depth = 5,
         .x_chroma_shift = 0, .y_chroma_shift = 0,
     },
-    [PIX_FMT_BGR555] = {
-        .name = "bgr555",
+    [PIX_FMT_BGR555BE] = {
+        .name = "bgr555be",
+        .nb_channels = 3,
+        .color_type = FF_COLOR_RGB,
+        .pixel_type = FF_PIXEL_PACKED,
+        .depth = 5,
+        .x_chroma_shift = 0, .y_chroma_shift = 0,
+    },
+    [PIX_FMT_BGR555LE] = {
+        .name = "bgr555le",
         .nb_channels = 3,
         .color_type = FF_COLOR_RGB,
         .pixel_type = FF_PIXEL_PACKED,
@@ -408,16 +440,16 @@ static const PixFmtInfo pix_fmt_info[PIX_FMT_NB] = {
         .x_chroma_shift = 1, .y_chroma_shift = 1,
     },
 
-    [PIX_FMT_BGR32_1] = {
-        .name = "bgr32_1",
+    [PIX_FMT_BGRA] = {
+        .name = "bgra",
         .nb_channels = 4, .is_alpha = 1,
         .color_type = FF_COLOR_RGB,
         .pixel_type = FF_PIXEL_PACKED,
         .depth = 8,
         .x_chroma_shift = 0, .y_chroma_shift = 0,
     },
-    [PIX_FMT_RGB32_1] = {
-        .name = "rgb32_1",
+    [PIX_FMT_RGBA] = {
+        .name = "rgba",
         .nb_channels = 4, .is_alpha = 1,
         .color_type = FF_COLOR_RGB,
         .pixel_type = FF_PIXEL_PACKED,
@@ -443,13 +475,13 @@ static const PixFmtInfo pix_fmt_info[PIX_FMT_NB] = {
     },
 };
 
-void avcodec_get_chroma_sub_sample(int pix_fmt, int *h_shift, int *v_shift)
+void avcodec_get_chroma_sub_sample(enum PixelFormat pix_fmt, int *h_shift, int *v_shift)
 {
     *h_shift = pix_fmt_info[pix_fmt].x_chroma_shift;
     *v_shift = pix_fmt_info[pix_fmt].y_chroma_shift;
 }
 
-const char *avcodec_get_pix_fmt_name(int pix_fmt)
+const char *avcodec_get_pix_fmt_name(enum PixelFormat pix_fmt)
 {
     if (pix_fmt < 0 || pix_fmt >= PIX_FMT_NB)
         return NULL;
@@ -457,17 +489,41 @@ const char *avcodec_get_pix_fmt_name(int pix_fmt)
         return pix_fmt_info[pix_fmt].name;
 }
 
-enum PixelFormat avcodec_get_pix_fmt(const char* name)
+static enum PixelFormat avcodec_get_pix_fmt_internal(const char *name)
 {
     int i;
 
     for (i=0; i < PIX_FMT_NB; i++)
-         if (!strcmp(pix_fmt_info[i].name, name))
-             return i;
+        if (pix_fmt_info[i].name && !strcmp(pix_fmt_info[i].name, name))
+            return i;
     return PIX_FMT_NONE;
 }
 
-void avcodec_pix_fmt_string (char *buf, int buf_size, int pix_fmt)
+#ifdef WORDS_BIGENDIAN
+#   define X_NE(be, le) be
+#else
+#   define X_NE(be, le) le
+#endif
+
+enum PixelFormat avcodec_get_pix_fmt(const char *name)
+{
+    enum PixelFormat pix_fmt;
+
+    if (!strcmp(name, "rgb32"))
+        name = X_NE("argb", "bgra");
+    else if (!strcmp(name, "bgr32"))
+        name = X_NE("abgr", "rgba");
+
+    pix_fmt = avcodec_get_pix_fmt_internal(name);
+    if (pix_fmt == PIX_FMT_NONE) {
+        char name2[32];
+        snprintf(name2, sizeof(name2), "%s%s", name, X_NE("be", "le"));
+        pix_fmt = avcodec_get_pix_fmt_internal(name2);
+    }
+    return pix_fmt;
+}
+
+void avcodec_pix_fmt_string (char *buf, int buf_size, enum PixelFormat pix_fmt)
 {
     /* print header */
     if (pix_fmt < 0)
@@ -533,7 +589,7 @@ int ff_set_systematic_pal(uint32_t pal[256], enum PixelFormat pix_fmt){
     return 0;
 }
 
-int ff_fill_linesize(AVPicture *picture, int pix_fmt, int width)
+int ff_fill_linesize(AVPicture *picture, enum PixelFormat pix_fmt, int width)
 {
     int w2;
     const PixFmtInfo *pinfo;
@@ -574,10 +630,10 @@ int ff_fill_linesize(AVPicture *picture, int pix_fmt, int width)
     case PIX_FMT_BGR24:
         picture->linesize[0] = width * 3;
         break;
-    case PIX_FMT_RGB32:
-    case PIX_FMT_BGR32:
-    case PIX_FMT_RGB32_1:
-    case PIX_FMT_BGR32_1:
+    case PIX_FMT_ARGB:
+    case PIX_FMT_ABGR:
+    case PIX_FMT_RGBA:
+    case PIX_FMT_BGRA:
         picture->linesize[0] = width * 4;
         break;
     case PIX_FMT_RGB48BE:
@@ -621,7 +677,7 @@ int ff_fill_linesize(AVPicture *picture, int pix_fmt, int width)
     return 0;
 }
 
-int ff_fill_pointer(AVPicture *picture, uint8_t *ptr, int pix_fmt,
+int ff_fill_pointer(AVPicture *picture, uint8_t *ptr, enum PixelFormat pix_fmt,
                     int height)
 {
     int size, h2, size2;
@@ -666,10 +722,10 @@ int ff_fill_pointer(AVPicture *picture, uint8_t *ptr, int pix_fmt,
         return size + 2 * size2;
     case PIX_FMT_RGB24:
     case PIX_FMT_BGR24:
-    case PIX_FMT_RGB32:
-    case PIX_FMT_BGR32:
-    case PIX_FMT_RGB32_1:
-    case PIX_FMT_BGR32_1:
+    case PIX_FMT_ARGB:
+    case PIX_FMT_ABGR:
+    case PIX_FMT_RGBA:
+    case PIX_FMT_BGRA:
     case PIX_FMT_RGB48BE:
     case PIX_FMT_RGB48LE:
     case PIX_FMT_GRAY16BE:
@@ -712,7 +768,7 @@ int ff_fill_pointer(AVPicture *picture, uint8_t *ptr, int pix_fmt,
 }
 
 int avpicture_fill(AVPicture *picture, uint8_t *ptr,
-                   int pix_fmt, int width, int height)
+                   enum PixelFormat pix_fmt, int width, int height)
 {
 
     if(avcodec_check_dimensions(NULL, width, height))
@@ -724,7 +780,7 @@ int avpicture_fill(AVPicture *picture, uint8_t *ptr,
     return ff_fill_pointer(picture, ptr, pix_fmt, height);
 }
 
-int avpicture_layout(const AVPicture* src, int pix_fmt, int width, int height,
+int avpicture_layout(const AVPicture* src, enum PixelFormat pix_fmt, int width, int height,
                      unsigned char *dest, int dest_size)
 {
     const PixFmtInfo* pf = &pix_fmt_info[pix_fmt];
@@ -783,20 +839,30 @@ int avpicture_layout(const AVPicture* src, int pix_fmt, int width, int height,
     return size;
 }
 
-int avpicture_get_size(int pix_fmt, int width, int height)
+int avpicture_get_size(enum PixelFormat pix_fmt, int width, int height)
 {
     AVPicture dummy_pict;
+    if(avcodec_check_dimensions(NULL, width, height))
+        return -1;
+    switch (pix_fmt) {
+    case PIX_FMT_RGB8:
+    case PIX_FMT_BGR8:
+    case PIX_FMT_RGB4_BYTE:
+    case PIX_FMT_BGR4_BYTE:
+    case PIX_FMT_GRAY8:
+        // do not include palette for these pseudo-paletted formats
+        return width * height;
+    }
     return avpicture_fill(&dummy_pict, NULL, pix_fmt, width, height);
 }
 
-int avcodec_get_pix_fmt_loss(int dst_pix_fmt, int src_pix_fmt,
+int avcodec_get_pix_fmt_loss(enum PixelFormat dst_pix_fmt, enum PixelFormat src_pix_fmt,
                              int has_alpha)
 {
     const PixFmtInfo *pf, *ps;
     int loss;
 
     ps = &pix_fmt_info[src_pix_fmt];
-    pf = &pix_fmt_info[dst_pix_fmt];
 
     /* compute loss */
     loss = 0;
@@ -844,7 +910,7 @@ int avcodec_get_pix_fmt_loss(int dst_pix_fmt, int src_pix_fmt,
     return loss;
 }
 
-static int avg_bits_per_pixel(int pix_fmt)
+static int avg_bits_per_pixel(enum PixelFormat pix_fmt)
 {
     int bits;
     const PixFmtInfo *pf;
@@ -887,12 +953,13 @@ static int avg_bits_per_pixel(int pix_fmt)
     return bits;
 }
 
-static int avcodec_find_best_pix_fmt1(int64_t pix_fmt_mask,
-                                      int src_pix_fmt,
+static enum PixelFormat avcodec_find_best_pix_fmt1(int64_t pix_fmt_mask,
+                                      enum PixelFormat src_pix_fmt,
                                       int has_alpha,
                                       int loss_mask)
 {
-    int dist, i, loss, min_dist, dst_pix_fmt;
+    int dist, i, loss, min_dist;
+    enum PixelFormat dst_pix_fmt;
 
     /* find exact color match with smallest size */
     dst_pix_fmt = -1;
@@ -912,10 +979,11 @@ static int avcodec_find_best_pix_fmt1(int64_t pix_fmt_mask,
     return dst_pix_fmt;
 }
 
-int avcodec_find_best_pix_fmt(int64_t pix_fmt_mask, int src_pix_fmt,
+enum PixelFormat avcodec_find_best_pix_fmt(int64_t pix_fmt_mask, enum PixelFormat src_pix_fmt,
                               int has_alpha, int *loss_ptr)
 {
-    int dst_pix_fmt, loss_mask, i;
+    enum PixelFormat dst_pix_fmt;
+    int loss_mask, i;
     static const int loss_mask_order[] = {
         ~0, /* no loss first */
         ~FF_LOSS_ALPHA,
@@ -999,12 +1067,11 @@ int ff_get_plane_bytewidth(enum PixelFormat pix_fmt, int width, int plane)
 }
 
 void av_picture_copy(AVPicture *dst, const AVPicture *src,
-              int pix_fmt, int width, int height)
+                     enum PixelFormat pix_fmt, int width, int height)
 {
     int i;
     const PixFmtInfo *pf = &pix_fmt_info[pix_fmt];
 
-    pf = &pix_fmt_info[pix_fmt];
     switch(pf->pixel_type) {
     case FF_PIXEL_PACKED:
     case FF_PIXEL_PLANAR:
@@ -1120,12 +1187,12 @@ void ff_shrink88(uint8_t *dst, int dst_wrap,
 
 
 int avpicture_alloc(AVPicture *picture,
-                           int pix_fmt, int width, int height)
+                    enum PixelFormat pix_fmt, int width, int height)
 {
     int size;
     void *ptr;
 
-    size = avpicture_get_size(pix_fmt, width, height);
+    size = avpicture_fill(picture, NULL, pix_fmt, width, height);
     if(size<0)
         goto fail;
     ptr = av_malloc(size);
@@ -1177,7 +1244,7 @@ int av_picture_crop(AVPicture *dst, const AVPicture *src,
 }
 
 int av_picture_pad(AVPicture *dst, const AVPicture *src, int height, int width,
-            int pix_fmt, int padtop, int padbottom, int padleft, int padright,
+                   enum PixelFormat pix_fmt, int padtop, int padbottom, int padleft, int padright,
             int *color)
 {
     uint8_t *optr;
@@ -1263,7 +1330,7 @@ static int get_alpha_info_pal8(const AVPicture *src, int width, int height)
 }
 
 int img_get_alpha_info(const AVPicture *src,
-                       int pix_fmt, int width, int height)
+                       enum PixelFormat pix_fmt, int width, int height)
 {
     const PixFmtInfo *pf = &pix_fmt_info[pix_fmt];
     int ret;
@@ -1469,7 +1536,7 @@ static void deinterlace_bottom_field_inplace(uint8_t *src1, int src_wrap,
 }
 
 int avpicture_deinterlace(AVPicture *dst, const AVPicture *src,
-                          int pix_fmt, int width, int height)
+                          enum PixelFormat pix_fmt, int width, int height)
 {
     int i;