On Tue, Jan 10, 2012 at 06:49:57PM +0000, Paul B Mahol wrote:
> On 1/10/12, Maans Rullgaard <m...@mansr.com> wrote:
> > Paul B Mahol <one...@gmail.com> writes:
> >
> >> ---
> >>  libswscale/rgb2rgb.c          |   13 +++++++++++++
> >>  libswscale/rgb2rgb.h          |    1 +
> >>  libswscale/swscale_unscaled.c |    1 +
> >>  3 files changed, 15 insertions(+), 0 deletions(-)
> >>
> >> diff --git a/libswscale/rgb2rgb.c b/libswscale/rgb2rgb.c
> >> index 0f07e57..4d54ac5 100644
> >> --- a/libswscale/rgb2rgb.c
> >> +++ b/libswscale/rgb2rgb.c
> >> @@ -282,6 +282,19 @@ void rgb15tobgr15(const uint8_t *src, uint8_t *dst,
> >> int src_size)
> >>      }
> >>  }
> >>
> >> +void rgb12tobgr12(const uint8_t *src, uint8_t *dst, int src_size)
> >> +{
> >> +    int i;
> >> +    int num_pixels = src_size >> 1;
> >> +
> >> +    for (i = 0; i < num_pixels; i++) {
> >> +        unsigned br;
> >> +        unsigned rgb = ((const uint16_t *)src)[i];
> >> +        br = rgb & 0x0F0F;
> >> +        ((uint16_t *)dst)[i] = (br >> 8) | (rgb & 0x00F0) | (br << 8);
> >> +    }
> >> +}
> >
> > Why so complicated?
> >
> > I also don't like the look of those pointer casts.
> 
> I don't follow.

1) you can declare uint16_t* pointers at the beginning of the function and
then use them like *dst++ = FOO(src[i])
2) we try to go away from practice of having pointer aliasing, sometimes it
causes compilers to miscompile code and there may be a problem with alignment
too (i.e. (uint16_t*)0xXXXX01 on ARM/Alpha/PowerPC will often load incorrect
value, unlikely in this case though).

And maybe you should've used R,G,B components directly for clarity.
_______________________________________________
libav-devel mailing list
libav-devel@libav.org
https://lists.libav.org/mailman/listinfo/libav-devel

Reply via email to