[vlc-commits] [Git][videolan/vlc][master] 2 commits: filter_picture: use a switch to process the r/g/b inidices
Steve Lhomme (@robUx4)
gitlab at videolan.org
Thu Sep 7 11:44:45 UTC 2023
Steve Lhomme pushed to branch master at VideoLAN / VLC
Commits:
4344a106 by Steve Lhomme at 2023-09-07T11:26:19+00:00
filter_picture: use a switch to process the r/g/b inidices
This will allow support for more RGB formats.
- - - - -
7c28374f by Steve Lhomme at 2023-09-07T11:26:19+00:00
filter_picture: get the alpha RGB index when there is one
Set -1 if there isn't one.
- - - - -
3 changed files:
- modules/video_filter/blend.cpp
- modules/video_filter/filter_picture.h
- modules/video_filter/sepia.c
Changes:
=====================================
modules/video_filter/blend.cpp
=====================================
@@ -262,29 +262,17 @@ private:
uint8_t *data;
};
-template <unsigned bytes, bool has_alpha>
+template <unsigned bytes>
class CPictureRGBX : public CPicture {
public:
CPictureRGBX(const CPicture &cfg) : CPicture(cfg)
{
- if (has_alpha) {
- if (fmt->i_chroma == VLC_CODEC_BGRA) {
- offset_r = 2;
- offset_g = 1;
- offset_b = 0;
- } else {
- offset_r = 0;
- offset_g = 1;
- offset_b = 2;
- }
- offset_a = 3;
- } else {
- if (GetPackedRgbIndexes(fmt, &offset_r, &offset_g, &offset_b) != VLC_SUCCESS) {
- /* at least init to something on error to silence compiler warnings */
- offset_r = 0;
- offset_g = 1;
- offset_b = 2;
- }
+ if (GetPackedRgbIndexes(fmt, &offset_r, &offset_g, &offset_b, &offset_a) != VLC_SUCCESS) {
+ /* at least init to something on error to silence compiler warnings */
+ offset_r = 0;
+ offset_g = 1;
+ offset_b = 2;
+ offset_a = -1;
}
data = CPicture::getLine<1>(0);
}
@@ -294,13 +282,13 @@ public:
px->i = src[offset_r];
px->j = src[offset_g];
px->k = src[offset_b];
- if (has_alpha)
+ if (offset_a != -1)
px->a = src[offset_a];
}
void merge(unsigned dx, const CPixel &spx, unsigned a, bool)
{
uint8_t *dst = getPointer(dx);
- if (has_alpha) {
+ if (offset_a != -1) {
// Handle different cases of existing alpha in the
// destination buffer. If the existing alpha is 0,
// the RGB components should be copied as is and
@@ -337,7 +325,7 @@ private:
int offset_r;
int offset_g;
int offset_b;
- unsigned offset_a;
+ int offset_a;
uint8_t *data;
};
@@ -410,10 +398,10 @@ typedef CPictureYUVPacked<1, 0, 2> CPictureUYVY;
typedef CPictureYUVPacked<0, 3, 1> CPictureYVYU;
typedef CPictureYUVPacked<1, 2, 0> CPictureVYUY;
-typedef CPictureRGBX<4, true> CPictureRGBA;
-typedef CPictureRGBX<4, true> CPictureBGRA;
-typedef CPictureRGBX<4, false> CPictureRGB32;
-typedef CPictureRGBX<3, false> CPictureRGB24;
+typedef CPictureRGBX<4> CPictureRGBA;
+typedef CPictureRGBX<4> CPictureBGRA;
+typedef CPictureRGBX<4> CPictureRGB32;
+typedef CPictureRGBX<3> CPictureRGB24;
struct convertNone {
convertNone(const video_format_t *, const video_format_t *) {}
=====================================
modules/video_filter/filter_picture.h
=====================================
@@ -49,7 +49,7 @@
#define CASE_PLANAR_YUV \
CASE_PLANAR_YUV_SQUARE \
- CASE_PLANAR_YUV_NONSQUARE
+ CASE_PLANAR_YUV_NONSQUARE
#define CASE_PACKED_YUV_422 \
case VLC_CODEC_UYVY: \
@@ -91,21 +91,81 @@ static inline int GetPackedYuvOffsets( vlc_fourcc_t i_chroma,
}
static inline int GetPackedRgbIndexes( const video_format_t *p_fmt, int *i_r_index,
- int *i_g_index, int *i_b_index )
+ int *i_g_index, int *i_b_index, int *i_a_index )
{
- if( p_fmt->i_chroma != VLC_CODEC_RGB24 && p_fmt->i_chroma != VLC_CODEC_RGB32 )
- return VLC_EGENERIC;
-
+ switch(p_fmt->i_chroma)
+ {
+ case VLC_CODEC_RGBA:
+#ifdef WORDS_BIGENDIAN
+ *i_r_index = 0;
+ *i_g_index = 1;
+ *i_b_index = 2;
+ *i_a_index = 3;
+#else
+ *i_r_index = 3;
+ *i_g_index = 2;
+ *i_b_index = 1;
+ *i_a_index = 0;
+#endif
+ break;
+ case VLC_CODEC_ARGB:
#ifdef WORDS_BIGENDIAN
- const int i_mask_bits = p_fmt->i_chroma == VLC_CODEC_RGB24 ? 16 : 24;
- *i_r_index = (i_mask_bits - vlc_ctz(p_fmt->i_rmask)) / 8;
- *i_g_index = (i_mask_bits - vlc_ctz(p_fmt->i_gmask)) / 8;
- *i_b_index = (i_mask_bits - vlc_ctz(p_fmt->i_bmask)) / 8;
+ *i_a_index = 0;
+ *i_r_index = 1;
+ *i_g_index = 2;
+ *i_b_index = 3;
#else
- *i_r_index = vlc_ctz(p_fmt->i_rmask) / 8;
- *i_g_index = vlc_ctz(p_fmt->i_gmask) / 8;
- *i_b_index = vlc_ctz(p_fmt->i_bmask) / 8;
+ *i_a_index = 3;
+ *i_r_index = 2;
+ *i_g_index = 1;
+ *i_b_index = 0;
#endif
+ break;
+ case VLC_CODEC_BGRA:
+#ifdef WORDS_BIGENDIAN
+ *i_b_index = 0;
+ *i_g_index = 1;
+ *i_r_index = 2;
+ *i_a_index = 3;
+#else
+ *i_b_index = 3;
+ *i_g_index = 2;
+ *i_r_index = 1;
+ *i_a_index = 0;
+#endif
+ break;
+ case VLC_CODEC_ABGR:
+#ifdef WORDS_BIGENDIAN
+ *i_a_index = 0;
+ *i_b_index = 1;
+ *i_g_index = 2;
+ *i_r_index = 3;
+#else
+ *i_a_index = 3;
+ *i_b_index = 2;
+ *i_g_index = 1;
+ *i_r_index = 0;
+#endif
+ break;
+ case VLC_CODEC_RGB32:
+ case VLC_CODEC_RGB24:
+#ifdef WORDS_BIGENDIAN
+ {
+ const int i_mask_bits = p_fmt->i_chroma == VLC_CODEC_RGB24 ? 16 : 24;
+ *i_r_index = (i_mask_bits - vlc_ctz(p_fmt->i_rmask)) / 8;
+ *i_g_index = (i_mask_bits - vlc_ctz(p_fmt->i_gmask)) / 8;
+ *i_b_index = (i_mask_bits - vlc_ctz(p_fmt->i_bmask)) / 8;
+ }
+#else
+ *i_r_index = vlc_ctz(p_fmt->i_rmask) / 8;
+ *i_g_index = vlc_ctz(p_fmt->i_gmask) / 8;
+ *i_b_index = vlc_ctz(p_fmt->i_bmask) / 8;
+#endif
+ *i_a_index = -1; // unused
+ break;
+ default:
+ return VLC_EGENERIC;
+ }
return VLC_SUCCESS;
}
=====================================
modules/video_filter/sepia.c
=====================================
@@ -399,9 +399,9 @@ static void RVSepia( picture_t *p_pic, picture_t *p_outpic, int i_intensity )
#define FIX(x) ((int) ((x) * (1<<SCALEBITS) + 0.5))
uint8_t *p_in, *p_in_end, *p_line_end, *p_out;
bool b_isRV32 = p_pic->format.i_chroma == VLC_CODEC_RGB32;
- int i_rindex = 0, i_gindex = 1, i_bindex = 2;
+ int i_rindex = 0, i_gindex = 1, i_bindex = 2, i_aindex = -1;
- GetPackedRgbIndexes( &p_outpic->format, &i_rindex, &i_gindex, &i_bindex );
+ GetPackedRgbIndexes( &p_outpic->format, &i_rindex, &i_gindex, &i_bindex, &i_aindex );
p_in = p_pic->p[0].p_pixels;
p_in_end = p_in + p_pic->p[0].i_visible_lines
View it on GitLab: https://code.videolan.org/videolan/vlc/-/compare/59a0f5adf96a938fc3c6db5d66f1d1972f9dfeff...7c28374fc4b1298709a0e96cfceec79ae7d248fa
--
View it on GitLab: https://code.videolan.org/videolan/vlc/-/compare/59a0f5adf96a938fc3c6db5d66f1d1972f9dfeff...7c28374fc4b1298709a0e96cfceec79ae7d248fa
You're receiving this email because of your account on code.videolan.org.
VideoLAN code repository instance
More information about the vlc-commits
mailing list