]> git.sesse.net Git - ffmpeg/blobdiff - libavcodec/imgconvert_template.h
Enable proper output from the LFE channel, based on patch from Mathias Rauen dear...
[ffmpeg] / libavcodec / imgconvert_template.h
index b2573b262342a582f017cacefe206f1a1103b220..2d23be87b9aab8a13b0a9a7a63dc85f629dfc2c4 100644 (file)
@@ -1,32 +1,39 @@
 /*
- * Templates for image convertion routines
+ * templates for image conversion routines
  * Copyright (c) 2001, 2002, 2003 Fabrice Bellard.
  *
- * This library is free software; you can redistribute it and/or
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Lesser General Public
  * License as published by the Free Software Foundation; either
- * version 2 of the License, or (at your option) any later version.
+ * version 2.1 of the License, or (at your option) any later version.
  *
- * This library is distributed in the hope that it will be useful,
+ * FFmpeg is distributed in the hope that it will be useful,
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  * Lesser General Public License for more details.
  *
  * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ * License along with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  */
 
+/* This header intentionally has no multiple inclusion guards. It is meant to
+ * be included multiple times and generates different code depending on the
+ * value of certain #defines. */
+
 #ifndef RGB_OUT
 #define RGB_OUT(d, r, g, b) RGBA_OUT(d, r, g, b, 0xff)
 #endif
 
-static void glue(yuv420p_to_, RGB_NAME)(AVPicture *dst, AVPicture *src,
+static void glue(yuv420p_to_, RGB_NAME)(AVPicture *dst, const AVPicture *src,
                                         int width, int height)
 {
-    uint8_t *y1_ptr, *y2_ptr, *cb_ptr, *cr_ptr, *d, *d1, *d2;
+    const uint8_t *y1_ptr, *y2_ptr, *cb_ptr, *cr_ptr;
+    uint8_t *d, *d1, *d2;
     int w, y, cb, cr, r_add, g_add, b_add, width2;
-    uint8_t *cm = cropTbl + MAX_NEG_CROP;
+    uint8_t *cm = ff_cropTbl + MAX_NEG_CROP;
     unsigned int r, g, b;
 
     d = dst->data[0];
@@ -114,12 +121,13 @@ static void glue(yuv420p_to_, RGB_NAME)(AVPicture *dst, AVPicture *src,
     }
 }
 
-static void glue(yuvj420p_to_, RGB_NAME)(AVPicture *dst, AVPicture *src,
+static void glue(yuvj420p_to_, RGB_NAME)(AVPicture *dst, const AVPicture *src,
                                          int width, int height)
 {
-    uint8_t *y1_ptr, *y2_ptr, *cb_ptr, *cr_ptr, *d, *d1, *d2;
+    const uint8_t *y1_ptr, *y2_ptr, *cb_ptr, *cr_ptr;
+    uint8_t *d, *d1, *d2;
     int w, y, cb, cr, r_add, g_add, b_add, width2;
-    uint8_t *cm = cropTbl + MAX_NEG_CROP;
+    uint8_t *cm = ff_cropTbl + MAX_NEG_CROP;
     unsigned int r, g, b;
 
     d = dst->data[0];
@@ -207,7 +215,7 @@ static void glue(yuvj420p_to_, RGB_NAME)(AVPicture *dst, AVPicture *src,
     }
 }
 
-static void glue(RGB_NAME, _to_yuv420p)(AVPicture *dst, AVPicture *src,
+static void glue(RGB_NAME, _to_yuv420p)(AVPicture *dst, const AVPicture *src,
                                         int width, int height)
 {
     int wrap, wrap3, width2;
@@ -314,7 +322,7 @@ static void glue(RGB_NAME, _to_yuv420p)(AVPicture *dst, AVPicture *src,
     }
 }
 
-static void glue(RGB_NAME, _to_gray)(AVPicture *dst, AVPicture *src,
+static void glue(RGB_NAME, _to_gray)(AVPicture *dst, const AVPicture *src,
                                      int width, int height)
 {
     const unsigned char *p;
@@ -340,7 +348,7 @@ static void glue(RGB_NAME, _to_gray)(AVPicture *dst, AVPicture *src,
     }
 }
 
-static void glue(gray_to_, RGB_NAME)(AVPicture *dst, AVPicture *src,
+static void glue(gray_to_, RGB_NAME)(AVPicture *dst, const AVPicture *src,
                                      int width, int height)
 {
     const unsigned char *p;
@@ -366,7 +374,7 @@ static void glue(gray_to_, RGB_NAME)(AVPicture *dst, AVPicture *src,
     }
 }
 
-static void glue(pal8_to_, RGB_NAME)(AVPicture *dst, AVPicture *src,
+static void glue(pal8_to_, RGB_NAME)(AVPicture *dst, const AVPicture *src,
                                      int width, int height)
 {
     const unsigned char *p;
@@ -406,16 +414,20 @@ static void glue(pal8_to_, RGB_NAME)(AVPicture *dst, AVPicture *src,
     }
 }
 
-#if !defined(FMT_RGBA32) && defined(RGBA_OUT)
+// RGB24 has optimized routines
+#if !defined(FMT_RGB32) && !defined(FMT_RGB24)
 /* alpha support */
 
-static void glue(rgba32_to_, RGB_NAME)(AVPicture *dst, AVPicture *src,
+static void glue(rgb32_to_, RGB_NAME)(AVPicture *dst, const AVPicture *src,
                                       int width, int height)
 {
     const uint8_t *s;
     uint8_t *d;
     int src_wrap, dst_wrap, j, y;
-    unsigned int v, r, g, b, a;
+    unsigned int v, r, g, b;
+#ifdef RGBA_OUT
+    unsigned int a;
+#endif
 
     s = src->data[0];
     src_wrap = src->linesize[0] - width * 4;
@@ -426,11 +438,15 @@ static void glue(rgba32_to_, RGB_NAME)(AVPicture *dst, AVPicture *src,
     for(y=0;y<height;y++) {
         for(j = 0;j < width; j++) {
             v = ((const uint32_t *)(s))[0];
-            a = (v >> 24) & 0xff;
             r = (v >> 16) & 0xff;
             g = (v >> 8) & 0xff;
             b = v & 0xff;
+#ifdef RGBA_OUT
+            a = (v >> 24) & 0xff;
             RGBA_OUT(d, r, g, b, a);
+#else
+            RGB_OUT(d, r, g, b);
+#endif
             s += 4;
             d += BPP;
         }
@@ -439,13 +455,16 @@ static void glue(rgba32_to_, RGB_NAME)(AVPicture *dst, AVPicture *src,
     }
 }
 
-static void glue(RGB_NAME, _to_rgba32)(AVPicture *dst, AVPicture *src,
+static void glue(RGB_NAME, _to_rgb32)(AVPicture *dst, const AVPicture *src,
                                        int width, int height)
 {
     const uint8_t *s;
     uint8_t *d;
     int src_wrap, dst_wrap, j, y;
-    unsigned int r, g, b, a;
+    unsigned int r, g, b;
+#ifdef RGBA_IN
+    unsigned int a;
+#endif
 
     s = src->data[0];
     src_wrap = src->linesize[0] - width * BPP;
@@ -455,8 +474,13 @@ static void glue(RGB_NAME, _to_rgba32)(AVPicture *dst, AVPicture *src,
 
     for(y=0;y<height;y++) {
         for(j = 0;j < width; j++) {
+#ifdef RGBA_IN
             RGBA_IN(r, g, b, a, s);
             ((uint32_t *)(d))[0] = (a << 24) | (r << 16) | (g << 8) | b;
+#else
+            RGB_IN(r, g, b, s);
+            ((uint32_t *)(d))[0] = (0xff << 24) | (r << 16) | (g << 8) | b;
+#endif
             d += 4;
             s += BPP;
         }
@@ -465,11 +489,11 @@ static void glue(RGB_NAME, _to_rgba32)(AVPicture *dst, AVPicture *src,
     }
 }
 
-#endif /* !defined(FMT_RGBA32) && defined(RGBA_IN) */
+#endif /* !defined(FMT_RGB32) */
 
 #ifndef FMT_RGB24
 
-static void glue(rgb24_to_, RGB_NAME)(AVPicture *dst, AVPicture *src,
+static void glue(rgb24_to_, RGB_NAME)(AVPicture *dst, const AVPicture *src,
                                       int width, int height)
 {
     const uint8_t *s;
@@ -497,7 +521,7 @@ static void glue(rgb24_to_, RGB_NAME)(AVPicture *dst, AVPicture *src,
     }
 }
 
-static void glue(RGB_NAME, _to_rgb24)(AVPicture *dst, AVPicture *src,
+static void glue(RGB_NAME, _to_rgb24)(AVPicture *dst, const AVPicture *src,
                                       int width, int height)
 {
     const uint8_t *s;
@@ -529,12 +553,13 @@ static void glue(RGB_NAME, _to_rgb24)(AVPicture *dst, AVPicture *src,
 
 #ifdef FMT_RGB24
 
-static void yuv444p_to_rgb24(AVPicture *dst, AVPicture *src,
+static void yuv444p_to_rgb24(AVPicture *dst, const AVPicture *src,
                              int width, int height)
 {
-    uint8_t *y1_ptr, *cb_ptr, *cr_ptr, *d, *d1;
+    const uint8_t *y1_ptr, *cb_ptr, *cr_ptr;
+    uint8_t *d, *d1;
     int w, y, cb, cr, r_add, g_add, b_add;
-    uint8_t *cm = cropTbl + MAX_NEG_CROP;
+    uint8_t *cm = ff_cropTbl + MAX_NEG_CROP;
     unsigned int r, g, b;
 
     d = dst->data[0];
@@ -561,12 +586,13 @@ static void yuv444p_to_rgb24(AVPicture *dst, AVPicture *src,
     }
 }
 
-static void yuvj444p_to_rgb24(AVPicture *dst, AVPicture *src,
+static void yuvj444p_to_rgb24(AVPicture *dst, const AVPicture *src,
                               int width, int height)
 {
-    uint8_t *y1_ptr, *cb_ptr, *cr_ptr, *d, *d1;
+    const uint8_t *y1_ptr, *cb_ptr, *cr_ptr;
+    uint8_t *d, *d1;
     int w, y, cb, cr, r_add, g_add, b_add;
-    uint8_t *cm = cropTbl + MAX_NEG_CROP;
+    uint8_t *cm = ff_cropTbl + MAX_NEG_CROP;
     unsigned int r, g, b;
 
     d = dst->data[0];
@@ -593,7 +619,7 @@ static void yuvj444p_to_rgb24(AVPicture *dst, AVPicture *src,
     }
 }
 
-static void rgb24_to_yuv444p(AVPicture *dst, AVPicture *src,
+static void rgb24_to_yuv444p(AVPicture *dst, const AVPicture *src,
                              int width, int height)
 {
     int src_wrap, x, y;
@@ -625,7 +651,7 @@ static void rgb24_to_yuv444p(AVPicture *dst, AVPicture *src,
     }
 }
 
-static void rgb24_to_yuvj420p(AVPicture *dst, AVPicture *src,
+static void rgb24_to_yuvj420p(AVPicture *dst, const AVPicture *src,
                               int width, int height)
 {
     int wrap, wrap3, width2;
@@ -732,7 +758,7 @@ static void rgb24_to_yuvj420p(AVPicture *dst, AVPicture *src,
     }
 }
 
-static void rgb24_to_yuvj444p(AVPicture *dst, AVPicture *src,
+static void rgb24_to_yuvj444p(AVPicture *dst, const AVPicture *src,
                               int width, int height)
 {
     int src_wrap, x, y;
@@ -766,9 +792,9 @@ static void rgb24_to_yuvj444p(AVPicture *dst, AVPicture *src,
 
 #endif /* FMT_RGB24 */
 
-#if defined(FMT_RGB24) || defined(FMT_RGBA32)
+#if defined(FMT_RGB24) || defined(FMT_RGB32)
 
-static void glue(RGB_NAME, _to_pal8)(AVPicture *dst, AVPicture *src,
+static void glue(RGB_NAME, _to_pal8)(AVPicture *dst, const AVPicture *src,
                                      int width, int height)
 {
     const unsigned char *p;
@@ -783,7 +809,7 @@ static void glue(RGB_NAME, _to_pal8)(AVPicture *dst, AVPicture *src,
     q = dst->data[0];
     dst_wrap = dst->linesize[0] - width;
     has_alpha = 0;
-    
+
     for(y=0;y<height;y++) {
         for(x=0;x<width;x++) {
 #ifdef RGBA_IN
@@ -812,8 +838,37 @@ static void glue(RGB_NAME, _to_pal8)(AVPicture *dst, AVPicture *src,
     build_rgb_palette(dst->data[1], has_alpha);
 }
 
-#endif /* defined(FMT_RGB24) || defined(FMT_RGBA32) */
-        
+#endif /* defined(FMT_RGB24) || defined(FMT_RGB32) */
+
+#ifdef RGBA_IN
+
+static int glue(get_alpha_info_, RGB_NAME)(const AVPicture *src,
+                                           int width, int height)
+{
+    const unsigned char *p;
+    int src_wrap, ret, x, y;
+    unsigned int r, g, b, a;
+
+    p = src->data[0];
+    src_wrap = src->linesize[0] - BPP * width;
+    ret = 0;
+    for(y=0;y<height;y++) {
+        for(x=0;x<width;x++) {
+            RGBA_IN(r, g, b, a, p);
+            if (a == 0x00) {
+                ret |= FF_ALPHA_TRANSP;
+            } else if (a != 0xff) {
+                ret |= FF_ALPHA_SEMI_TRANSP;
+            }
+            p += BPP;
+        }
+        p += src_wrap;
+    }
+    return ret;
+}
+
+#endif /* RGBA_IN */
+
 #undef RGB_IN
 #undef RGBA_IN
 #undef RGB_OUT
@@ -821,4 +876,4 @@ static void glue(RGB_NAME, _to_pal8)(AVPicture *dst, AVPicture *src,
 #undef BPP
 #undef RGB_NAME
 #undef FMT_RGB24
-#undef FMT_RGBA32
+#undef FMT_RGB32