[FFmpeg-devel] remove palette8torgb15 and palette8torgb15, was: make swscale's palette functions public
Reinhard Tartler
siretart
Tue Jun 1 13:17:18 CEST 2010
On Di, Jun 01, 2010 at 10:42:21 (CEST), Stefano Sabatini wrote:
> On date Tuesday 2010-06-01 09:34:09 +0200, Reinhard Tartler encoded:
>>
>> okay, with the really deprecated functions now gone, I've reworked the
>> patch a bit, it is now much smaller:
>>
>> Index: libmpcodecs/vf_palette.c
>> ===================================================================
>> --- libmpcodecs/vf_palette.c (revision 31298)
>> +++ libmpcodecs/vf_palette.c (working copy)
>> @@ -29,6 +29,7 @@
>> #include "mp_image.h"
>> #include "vf.h"
>>
>> +#include "libswscale/swscale.h"
>> #include "libswscale/rgb2rgb.h"
>>
>> //===========================================================================//
>> @@ -122,15 +123,15 @@
>> break;
>> case 24:
>> if (IMGFMT_IS_BGR(dmpi->imgfmt))
>> - palette8topacked24(mpi->planes[0],dmpi->planes[0],mpi->h*mpi->w,mpi->planes[1]);
>> + sws_palette8topacked24(mpi->planes[0],dmpi->planes[0],mpi->h*mpi->w,mpi->planes[1]);
>
> What about
> sws_palette8ToPacked24(...)
> or
> sws_convertPalette8ToPacked24()?
>
> Since we're changing the name anyway we should strive to choose
> something which is more readable.
indeed, changed
> [...]
>> Index: libswscale/rgb2rgb.h
>> ===================================================================
>> --- libswscale/rgb2rgb.h (revision 31298)
>> +++ libswscale/rgb2rgb.h (working copy)
>> @@ -4,7 +4,7 @@
>> * Software YUV to YUV converter
>> * Software YUV to RGB converter
>> * Written by Nick Kurshev.
>> - * palette & YUV & runtime CPU stuff by Michael (michaelni at gmx.at)
>> + * YUV & runtime CPU stuff by Michael (michaelni at gmx.at)
>> *
>> * This file is part of FFmpeg.
>> *
>> @@ -28,6 +28,8 @@
>>
>> #include <inttypes.h>
>>
>> +#include "libavutil/avutil.h"
>> +
>> /* A full collection of RGB to RGB(BGR) converters */
>> extern void (*rgb24tobgr32)(const uint8_t *src, uint8_t *dst, long src_size);
>> extern void (*rgb24tobgr16)(const uint8_t *src, uint8_t *dst, long src_size);
>> @@ -66,11 +68,14 @@
>> void shuffle_bytes_3012(const uint8_t *src, uint8_t *dst, long src_size);
>> void shuffle_bytes_3210(const uint8_t *src, uint8_t *dst, long src_size);
>
>> -void palette8topacked32(const uint8_t *src, uint8_t *dst, long num_pixels, const uint8_t *palette);
>> -void palette8topacked24(const uint8_t *src, uint8_t *dst, long num_pixels, const uint8_t *palette);
>> -void palette8torgb16(const uint8_t *src, uint8_t *dst, long num_pixels, const uint8_t *palette);
>> -void palette8tobgr16(const uint8_t *src, uint8_t *dst, long num_pixels, const uint8_t *palette);
>> +/* deprecated, use the public versions in swscale.h */
>> +attribute_deprecated void palette8topacked32(const uint8_t *src, uint8_t *dst, long num_pixels, const uint8_t *palette);
>> +attribute_deprecated void palette8topacked24(const uint8_t *src, uint8_t *dst, long num_pixels, const uint8_t *palette);
>>
>> +/* totally deprecated, please fix code that use this */
>> +attribute_deprecated void palette8torgb16(const uint8_t *src, uint8_t *dst, long num_pixels, const uint8_t *palette);
>> +attribute_deprecated void palette8tobgr16(const uint8_t *src, uint8_t *dst, long num_pixels, const uint8_t *palette);
>
> Put these declarations under:
>
> #if LIBSWSCALE_VERSION_MAJOR < 1
> ...
> #endif
changed
> Also please don't forget to bump minor
changed
> and update APIchanges.
Thanks for the reminder, but this patch is against mplayer repo, so the
APIchanges change will be a seperate commit.
New patch follows:
Index: libmpcodecs/vf_palette.c
===================================================================
--- libmpcodecs/vf_palette.c (revision 31298)
+++ libmpcodecs/vf_palette.c (working copy)
@@ -29,6 +29,7 @@
#include "mp_image.h"
#include "vf.h"
+#include "libswscale/swscale.h"
#include "libswscale/rgb2rgb.h"
//===========================================================================//
@@ -122,15 +123,15 @@
break;
case 24:
if (IMGFMT_IS_BGR(dmpi->imgfmt))
- palette8topacked24(mpi->planes[0],dmpi->planes[0],mpi->h*mpi->w,mpi->planes[1]);
+ sws_convertPalette8ToPacked24(mpi->planes[0],dmpi->planes[0],mpi->h*mpi->w,mpi->planes[1]);
else
- palette8topacked24(mpi->planes[0],dmpi->planes[0],mpi->h*mpi->w,mpi->planes[1]);
+ sws_convertPalette8ToPacked24(mpi->planes[0],dmpi->planes[0],mpi->h*mpi->w,mpi->planes[1]);
break;
case 32:
if (IMGFMT_IS_BGR(dmpi->imgfmt))
- palette8topacked32(mpi->planes[0],dmpi->planes[0],mpi->h*mpi->w,mpi->planes[1]);
+ sws_convertPalette8ToPacked32(mpi->planes[0],dmpi->planes[0],mpi->h*mpi->w,mpi->planes[1]);
else
- palette8topacked32(mpi->planes[0],dmpi->planes[0],mpi->h*mpi->w,mpi->planes[1]);
+ sws_convertPalette8ToPacked32(mpi->planes[0],dmpi->planes[0],mpi->h*mpi->w,mpi->planes[1]);
break;
}
} else {
@@ -148,15 +149,15 @@
break;
case 24:
if (IMGFMT_IS_BGR(dmpi->imgfmt))
- palette8topacked24(src,dst,mpi->w,mpi->planes[1]);
+ sws_convertPalette8ToPacked24(src,dst,mpi->w,mpi->planes[1]);
else
- palette8topacked24(src,dst,mpi->w,mpi->planes[1]);
+ sws_convertPalette8ToPacked24(src,dst,mpi->w,mpi->planes[1]);
break;
case 32:
if (IMGFMT_IS_BGR(dmpi->imgfmt))
- palette8topacked32(src,dst,mpi->w,mpi->planes[1]);
+ sws_convertPalette8ToPacked32(src,dst,mpi->w,mpi->planes[1]);
else
- palette8topacked32(src,dst,mpi->w,mpi->planes[1]);
+ sws_convertPalette8ToPacked32(src,dst,mpi->w,mpi->planes[1]);
break;
}
}
Index: libswscale/swscale.c
===================================================================
--- libswscale/swscale.c (revision 31298)
+++ libswscale/swscale.c (working copy)
@@ -1419,12 +1419,12 @@
if (usePal(srcFormat)) {
switch (dstFormat) {
- case PIX_FMT_RGB32 : conv = palette8topacked32; break;
- case PIX_FMT_BGR32 : conv = palette8topacked32; break;
- case PIX_FMT_BGR32_1: conv = palette8topacked32; break;
- case PIX_FMT_RGB32_1: conv = palette8topacked32; break;
- case PIX_FMT_RGB24 : conv = palette8topacked24; break;
- case PIX_FMT_BGR24 : conv = palette8topacked24; break;
+ case PIX_FMT_RGB32 : conv = sws_convertPalette8ToPacked32; break;
+ case PIX_FMT_BGR32 : conv = sws_convertPalette8ToPacked32; break;
+ case PIX_FMT_BGR32_1: conv = sws_convertPalette8ToPacked32; break;
+ case PIX_FMT_RGB32_1: conv = sws_convertPalette8ToPacked32; break;
+ case PIX_FMT_RGB24 : conv = sws_convertPalette8ToPacked24; break;
+ case PIX_FMT_BGR24 : conv = sws_convertPalette8ToPacked24; break;
}
}
@@ -1957,3 +1957,26 @@
return sws_scale(c, src, srcStride, srcSliceY, srcSliceH, dst, dstStride);
}
#endif
+
+/* Convert the palette to the same packed 32-bit format as the palette */
+void sws_convertPalette8ToPacked32(const uint8_t *src, uint8_t *dst, long num_pixels, const uint8_t *palette)
+{
+ long i;
+
+ for (i=0; i<num_pixels; i++)
+ ((uint32_t *) dst)[i] = ((const uint32_t *) palette)[src[i]];
+}
+
+/* Palette format: ABCD -> dst format: ABC */
+void sws_convertPalette8ToPacked24(const uint8_t *src, uint8_t *dst, long num_pixels, const uint8_t *palette)
+{
+ long i;
+
+ for (i=0; i<num_pixels; i++) {
+ //FIXME slow?
+ dst[0]= palette[src[i]*4+0];
+ dst[1]= palette[src[i]*4+1];
+ dst[2]= palette[src[i]*4+2];
+ dst+= 3;
+ }
+}
Index: libswscale/swscale.h
===================================================================
--- libswscale/swscale.h (revision 31298)
+++ libswscale/swscale.h (working copy)
@@ -30,7 +30,7 @@
#include "libavutil/avutil.h"
#define LIBSWSCALE_VERSION_MAJOR 0
-#define LIBSWSCALE_VERSION_MINOR 10
+#define LIBSWSCALE_VERSION_MINOR 11
#define LIBSWSCALE_VERSION_MICRO 0
#define LIBSWSCALE_VERSION_INT AV_VERSION_INT(LIBSWSCALE_VERSION_MAJOR, \
@@ -303,4 +303,29 @@
int flags, SwsFilter *srcFilter,
SwsFilter *dstFilter, const double *param);
+/**
+ * Converts an 8bit paletted frame into a frame with a color depth of 32-bits.
+ *
+ * The output frame will have the same packed format as the palette.
+ *
+ * @param src source frame buffer
+ * @param dst destination frame buffer
+ * @param num_pixels number of pixels to convert
+ * @param palette array with [256] entries, which must match color arrangement (RGB or BGR) of src
+ */
+void sws_convertPalette8ToPacked32(const uint8_t *src, uint8_t *dst, long num_pixels, const uint8_t *palette);
+
+/**
+ * Converts an 8bit paletted frame into a frame with a color depth of 24 bits.
+ *
+ * With the palette format "ABCD", the destination frame ends up with the format "ABC".
+ *
+ * @param src source frame buffer
+ * @param dst destination frame buffer
+ * @param num_pixels number of pixels to convert
+ * @param palette array with [256] entries, which must match color arrangement (RGB or BGR) of src
+ */
+void sws_convertPalette8ToPacked24(const uint8_t *src, uint8_t *dst, long num_pixels, const uint8_t *palette);
+
+
#endif /* SWSCALE_SWSCALE_H */
Index: libswscale/rgb2rgb.c
===================================================================
--- libswscale/rgb2rgb.c (revision 31298)
+++ libswscale/rgb2rgb.c (working copy)
@@ -207,31 +207,15 @@
rgb2rgb_init_C();
}
-/**
- * Convert the palette to the same packet 32-bit format as the palette
- */
+#if LIBSWCALE_VERSION_MAJOR < 1
void palette8topacked32(const uint8_t *src, uint8_t *dst, long num_pixels, const uint8_t *palette)
{
- long i;
-
- for (i=0; i<num_pixels; i++)
- ((uint32_t *) dst)[i] = ((const uint32_t *) palette)[src[i]];
+ sws_convertPalette8ToPacked32(src, dst, num_pixels, palette);
}
-/**
- * Palette format: ABCD -> dst format: ABC
- */
void palette8topacked24(const uint8_t *src, uint8_t *dst, long num_pixels, const uint8_t *palette)
{
- long i;
-
- for (i=0; i<num_pixels; i++) {
- //FIXME slow?
- dst[0]= palette[src[i]*4+0];
- dst[1]= palette[src[i]*4+1];
- dst[2]= palette[src[i]*4+2];
- dst+= 3;
- }
+ sws_convertPalette8ToPacked24(src, dst, num_pixels, palette);
}
/**
@@ -249,6 +233,7 @@
for (i=0; i<num_pixels; i++)
((uint16_t *)dst)[i] = bswap_16(((const uint16_t *)palette)[src[i]]);
}
+#endif
void rgb32to24(const uint8_t *src, uint8_t *dst, long src_size)
{
Index: libswscale/rgb2rgb.h
===================================================================
--- libswscale/rgb2rgb.h (revision 31298)
+++ libswscale/rgb2rgb.h (working copy)
@@ -4,7 +4,7 @@
* Software YUV to YUV converter
* Software YUV to RGB converter
* Written by Nick Kurshev.
- * palette & YUV & runtime CPU stuff by Michael (michaelni at gmx.at)
+ * YUV & runtime CPU stuff by Michael (michaelni at gmx.at)
*
* This file is part of FFmpeg.
*
@@ -28,6 +28,8 @@
#include <inttypes.h>
+#include "libavutil/avutil.h"
+
/* A full collection of RGB to RGB(BGR) converters */
extern void (*rgb24tobgr32)(const uint8_t *src, uint8_t *dst, long src_size);
extern void (*rgb24tobgr16)(const uint8_t *src, uint8_t *dst, long src_size);
@@ -66,11 +68,16 @@
void shuffle_bytes_3012(const uint8_t *src, uint8_t *dst, long src_size);
void shuffle_bytes_3210(const uint8_t *src, uint8_t *dst, long src_size);
-void palette8topacked32(const uint8_t *src, uint8_t *dst, long num_pixels, const uint8_t *palette);
-void palette8topacked24(const uint8_t *src, uint8_t *dst, long num_pixels, const uint8_t *palette);
-void palette8torgb16(const uint8_t *src, uint8_t *dst, long num_pixels, const uint8_t *palette);
-void palette8tobgr16(const uint8_t *src, uint8_t *dst, long num_pixels, const uint8_t *palette);
+#if LIBSWCALE_VERSION_MAJOR < 1
+/* deprecated, use the public versions in swscale.h */
+attribute_deprecated void palette8topacked32(const uint8_t *src, uint8_t *dst, long num_pixels, const uint8_t *palette);
+attribute_deprecated void palette8topacked24(const uint8_t *src, uint8_t *dst, long num_pixels, const uint8_t *palette);
+/* totally deprecated, please fix code that use this */
+attribute_deprecated void palette8torgb16(const uint8_t *src, uint8_t *dst, long num_pixels, const uint8_t *palette);
+attribute_deprecated void palette8tobgr16(const uint8_t *src, uint8_t *dst, long num_pixels, const uint8_t *palette);
+#endif
+
/**
* Height should be a multiple of 2 and width should be a multiple of 16.
* (If this is a problem for anyone then tell me, and I will fix it.)
--
Gruesse/greetings,
Reinhard Tartler, KeyID 945348A4
More information about the ffmpeg-devel
mailing list