Bug 452698. Ensure that YUV to RGB conversion puts bytes in the right order for big-endian machines (PPC). r+sr=roc
authorChris Double <chris.double@double.co.nz>
Fri, 30 Jan 2009 20:30:37 +1300
changeset 24451 1f87701751d79509164f416ef93d8283d1119f97
parent 24450 3509c34d4ffbf2a07781137c5ba609debb72f002
child 24452 fed00e0efe5c84c957d2563ab17056678c5e49d4
push idunknown
push userunknown
push dateunknown
bugs452698
milestone1.9.2a1pre
Bug 452698. Ensure that YUV to RGB conversion puts bytes in the right order for big-endian machines (PPC). r+sr=roc
content/media/video/src/nsOggDecoder.cpp
media/libfishsound/README_MOZILLA
media/libfishsound/endian.patch
media/libfishsound/include/fishsound/config.h
media/libfishsound/src/libfishsound/config.h
media/libfishsound/update.sh
media/liboggplay/README_MOZILLA
media/liboggplay/include/oggplay/oggplay_tools.h
media/liboggplay/src/liboggplay/config.h
media/liboggplay/src/liboggplay/oggplay_yuv2rgb.c
media/liboggplay/update.sh
media/liboggplay/yuv2argb.patch
media/liboggz/README_MOZILLA
media/liboggz/endian.patch
media/liboggz/include/oggz/config.h
media/liboggz/update.sh
--- a/content/media/video/src/nsOggDecoder.cpp
+++ b/content/media/video/src/nsOggDecoder.cpp
@@ -589,17 +589,21 @@ void nsOggDecodeStateMachine::HandleVide
   yuv.uv_height = uv_height;
   yuv.y_width = y_width;
   yuv.y_height = y_height;
       
   rgb.ptro = aFrame->mVideoData;
   rgb.rgb_width = aFrame->mVideoWidth;
   rgb.rgb_height = aFrame->mVideoHeight;
 
+#ifdef IS_BIG_ENDIAN
+  oggplay_yuv2argb(&yuv, &rgb);
+#else
   oggplay_yuv2bgr(&yuv, &rgb);
+#endif
 }
 
 void nsOggDecodeStateMachine::HandleAudioData(FrameData* aFrame, OggPlayAudioData* aAudioData, int aSize) {
   // 'aSize' is number of samples. Multiply by number of channels to
   // get the actual number of floats being sent.
   int size = aSize * mAudioChannels;
 
   aFrame->mAudioData.AppendElements(reinterpret_cast<float*>(aAudioData), size);
--- a/media/libfishsound/README_MOZILLA
+++ b/media/libfishsound/README_MOZILLA
@@ -1,7 +1,9 @@
 The source from this directory was copied from the libfishsound-0.9.1
 source distribution using the update.sh script. The only changes made
 were those applied by update.sh and the addition/upate of Makefile.in
 files for the Mozilla build system.
 
 Some files are renamed during the copy to prevent clashes with object
-file names with other Mozilla libraries.
\ No newline at end of file
+file names with other Mozilla libraries.
+
+endian.patch is applied to fix Bug 45269.
new file mode 100644
--- /dev/null
+++ b/media/libfishsound/endian.patch
@@ -0,0 +1,26 @@
+diff --git a/media/libfishsound/include/fishsound/config.h b/media/libfishsound/include/fishsound/config.h
+index 573822f..b7cae62 100644
+--- a/media/libfishsound/include/fishsound/config.h
++++ b/media/libfishsound/include/fishsound/config.h
+@@ -104,3 +104,8 @@
+ #undef HAVE_VORBISENC
+ #define HAVE_VORBISENC 0
+ #undef DEBUG
++
++#include "prcpucfg.h"
++#ifdef IS_BIG_ENDIAN
++#define WORDS_BIGENDIAN
++#endif
+diff --git a/media/libfishsound/src/libfishsound/config.h b/media/libfishsound/src/libfishsound/config.h
+index 573822f..b7cae62 100644
+--- a/media/libfishsound/src/libfishsound/config.h
++++ b/media/libfishsound/src/libfishsound/config.h
+@@ -104,3 +104,8 @@
+ #undef HAVE_VORBISENC
+ #define HAVE_VORBISENC 0
+ #undef DEBUG
++
++#include "prcpucfg.h"
++#ifdef IS_BIG_ENDIAN
++#define WORDS_BIGENDIAN
++#endif
--- a/media/libfishsound/include/fishsound/config.h
+++ b/media/libfishsound/include/fishsound/config.h
@@ -99,8 +99,13 @@
 #define HAVE_OGGZ 1
 #undef HAVE_SPEEX
 #define HAVE_SPEEX 0
 #undef HAVE_VORBIS
 #define HAVE_VORBIS 1
 #undef HAVE_VORBISENC
 #define HAVE_VORBISENC 0
 #undef DEBUG
+
+#include "prcpucfg.h"
+#ifdef IS_BIG_ENDIAN
+#define WORDS_BIGENDIAN
+#endif
--- a/media/libfishsound/src/libfishsound/config.h
+++ b/media/libfishsound/src/libfishsound/config.h
@@ -99,8 +99,13 @@
 #define HAVE_OGGZ 1
 #undef HAVE_SPEEX
 #define HAVE_SPEEX 0
 #undef HAVE_VORBIS
 #define HAVE_VORBIS 1
 #undef HAVE_VORBISENC
 #define HAVE_VORBISENC 0
 #undef DEBUG
+
+#include "prcpucfg.h"
+#ifdef IS_BIG_ENDIAN
+#define WORDS_BIGENDIAN
+#endif
--- a/media/libfishsound/update.sh
+++ b/media/libfishsound/update.sh
@@ -32,9 +32,10 @@ cp $1/src/libfishsound/flac.c ./src/libf
 cp $1/src/libfishsound/comments.c ./src/libfishsound/fishsound_comments.c
 cp $1/src/libfishsound/private.h ./src/libfishsound/private.h
 cp $1/src/libfishsound/fs_compat.h ./src/libfishsound/fs_compat.h
 cp $1/src/libfishsound/speex.c ./src/libfishsound/fishsound_speex.c
 cp $1/src/libfishsound/encode.c ./src/libfishsound/fishsound_encode.c
 cp $1/src/libfishsound/fs_vector.h ./src/libfishsound/fs_vector.h
 cp $1/src/libfishsound/fs_vector.c ./src/libfishsound/fs_vector.c
 cp $1/src/libfishsound/convert.h ./src/libfishsound/convert.h
-cp $1/AUTHORS ./AUTHORS
\ No newline at end of file
+cp $1/AUTHORS ./AUTHORS
+patch -p4 <endian.patch
--- a/media/liboggplay/README_MOZILLA
+++ b/media/liboggplay/README_MOZILLA
@@ -8,10 +8,13 @@ http://svn.annodex.net/liboggplay/trunk/
 The svn revision number used was r3774.
 
 The patch from Annodex trac ticket 421 is applied to fix bug 459938:
   http://trac.annodex.net/ticket/421
 
 The patch from Bug 468327 (yuv_disable_optimized.patch) is applied
 to disable optimized yuv to rgb routines.
 
+The patch from Bug 452698 (yuv2argb.patch) is applied to fix
+yuv to rgb conversion on PPC Mac OS X.
+
 The patch from Bug 464007 (bug464007.patch) is applied
 to fix oggplay issues.
--- a/media/liboggplay/include/oggplay/oggplay_tools.h
+++ b/media/liboggplay/include/oggplay/oggplay_tools.h
@@ -70,16 +70,19 @@ typedef struct _OggPlayRGBChannels {
     int             rgb_width;
     int             rgb_height;
 } OggPlayRGBChannels;
 
 void 
 oggplay_yuv2rgb(OggPlayYUVChannels* yuv, OggPlayRGBChannels * rgb);
 
 void 
+oggplay_yuv2argb(OggPlayYUVChannels* yuv, OggPlayRGBChannels * rgb);
+
+void
 oggplay_yuv2bgr(OggPlayYUVChannels* yuv, OggPlayRGBChannels * rgb);
 
 ogg_int64_t
 oggplay_sys_time_in_ms(void);
 
 void
 oggplay_millisleep(long ms);
 
--- a/media/liboggplay/src/liboggplay/config.h
+++ b/media/liboggplay/src/liboggplay/config.h
@@ -81,8 +81,13 @@
 /* #undef WORDS_BIGENDIAN */
 
 /* use MMX SSE2 compiler intrinsics */
 
 
 /* Define to empty if `const' does not conform to ANSI C. */
 /* #undef const */
 #undef HAVE_GLUT
+
+#include "prcpucfg.h"
+#ifdef IS_BIG_ENDIAN
+#define WORDS_BIGENDIAN
+#endif
--- a/media/liboggplay/src/liboggplay/oggplay_yuv2rgb.c
+++ b/media/liboggplay/src/liboggplay/oggplay_yuv2rgb.c
@@ -391,16 +391,67 @@ void oggplay_yuv2rgb(OggPlayYUVChannels 
     if (i & 1) {
       ptru += yuv->uv_width;
       ptrv += yuv->uv_width;
     }
     ptro += rgb->rgb_width * 4;
   }
 }
 
+/* Vanilla implementation if YUV->ARGB conversion */
+void oggplay_yuv2argb(OggPlayYUVChannels * yuv, OggPlayRGBChannels * rgb) {
+
+  unsigned char * ptry = yuv->ptry;
+  unsigned char * ptru = yuv->ptru;
+  unsigned char * ptrv = yuv->ptrv;
+  unsigned char * ptro = rgb->ptro;
+  unsigned char * ptro2;
+  int i, j;
+
+  for (i = 0; i < yuv->y_height; i++) {
+    ptro2 = ptro;
+    for (j = 0; j < yuv->y_width; j += 2) {
+
+      short pr, pg, pb, y;
+      short r, g, b;
+
+      pr = (-56992 + ptrv[j/2] * 409) >> 8;
+      pg = (34784 - ptru[j/2] * 100 - ptrv[j/2] * 208) >> 8;
+      pb = (-70688 + ptru[j/2] * 516) >> 8;
+
+      y = 298*ptry[j] >> 8;
+      r = y + pr;
+      g = y + pg;
+      b = y + pb;
+
+      *ptro2++ = 255;
+      *ptro2++ = CLAMP(r);
+      *ptro2++ = CLAMP(g);
+      *ptro2++ = CLAMP(b);
+
+      y = 298*ptry[j + 1] >> 8;
+      r = y + pr;
+      g = y + pg;
+      b = y + pb;
+
+      *ptro2++ = 255;
+      *ptro2++ = CLAMP(r);
+      *ptro2++ = CLAMP(g);
+      *ptro2++ = CLAMP(b);
+    }
+    ptry += yuv->y_width;
+    if (i & 1) {
+      ptru += yuv->uv_width;
+      ptrv += yuv->uv_width;
+    }
+    ptro += rgb->rgb_width * 4;
+  }
+}
+
+
 /* Vanilla implementation of YUV->BGR conversion*/
 void oggplay_yuv2bgr(OggPlayYUVChannels * yuv, OggPlayRGBChannels * rgb) {
 
   unsigned char * ptry = yuv->ptry;
   unsigned char * ptru = yuv->ptru;
   unsigned char * ptrv = yuv->ptrv;
   unsigned char * ptro = rgb->ptro;
   unsigned char * ptro2;
--- a/media/liboggplay/update.sh
+++ b/media/liboggplay/update.sh
@@ -33,9 +33,10 @@ cp $1/src/liboggplay/oggplay_query.c ./s
 sed s/\#include\ \"config_win32.h\"//g $1/src/liboggplay/oggplay_private.h >./src/liboggplay/oggplay_private.h1
 sed s/\#include\ \<config.h\>/\#ifdef\ WIN32\\n\#include\ \"config_win32.h\"\\n\#else\\n\#include\ \<config.h\>\\n\#endif/g ./src/liboggplay/oggplay_private.h1 >./src/liboggplay/oggplay_private.h
 rm ./src/liboggplay/oggplay_private.h1
 sed s/\#ifdef\ HAVE_INTTYPES_H/\#if\ HAVE_INTTYPES_H/g $1/src/liboggplay/oggplay_data.c >./src/liboggplay/oggplay_data.c
 cd ./src/liboggplay
 patch <../../yuv2rgb-vanilla-fix.patch
 patch <../../yuv_disable_optimized.patch
 cd ../..
+patch -p4 <yuv2argb.patch
 patch -p3 <bug464007.patch
new file mode 100644
--- /dev/null
+++ b/media/liboggplay/yuv2argb.patch
@@ -0,0 +1,89 @@
+diff --git a/media/liboggplay/include/oggplay/oggplay_tools.h b/media/liboggplay/include/oggplay/oggplay_tools.h
+index 30531a4..19fe709 100644
+--- a/media/liboggplay/include/oggplay/oggplay_tools.h
++++ b/media/liboggplay/include/oggplay/oggplay_tools.h
+@@ -75,6 +75,9 @@ void
+ oggplay_yuv2rgb(OggPlayYUVChannels* yuv, OggPlayRGBChannels * rgb);
+ 
+ void 
++oggplay_yuv2argb(OggPlayYUVChannels* yuv, OggPlayRGBChannels * rgb);
++
++void
+ oggplay_yuv2bgr(OggPlayYUVChannels* yuv, OggPlayRGBChannels * rgb);
+ 
+ ogg_int64_t
+diff --git a/media/liboggplay/src/liboggplay/config.h b/media/liboggplay/src/liboggplay/config.h
+index e1754e4..46faa8a 100644
+--- a/media/liboggplay/src/liboggplay/config.h
++++ b/media/liboggplay/src/liboggplay/config.h
+@@ -86,3 +86,8 @@
+ /* Define to empty if `const' does not conform to ANSI C. */
+ /* #undef const */
+ #undef HAVE_GLUT
++
++#include "prcpucfg.h"
++#ifdef IS_BIG_ENDIAN
++#define WORDS_BIGENDIAN
++#endif
+diff --git a/media/liboggplay/src/liboggplay/oggplay_yuv2rgb.c b/media/liboggplay/src/liboggplay/oggplay_yuv2rgb.c
+index 0e2cef0..e070dc7 100644
+--- a/media/liboggplay/src/liboggplay/oggplay_yuv2rgb.c
++++ b/media/liboggplay/src/liboggplay/oggplay_yuv2rgb.c
+@@ -396,6 +396,57 @@ void oggplay_yuv2rgb(OggPlayYUVChannels * yuv, OggPlayRGBChannels * rgb) {
+   }
+ }
+ 
++/* Vanilla implementation if YUV->ARGB conversion */
++void oggplay_yuv2argb(OggPlayYUVChannels * yuv, OggPlayRGBChannels * rgb) {
++
++  unsigned char * ptry = yuv->ptry;
++  unsigned char * ptru = yuv->ptru;
++  unsigned char * ptrv = yuv->ptrv;
++  unsigned char * ptro = rgb->ptro;
++  unsigned char * ptro2;
++  int i, j;
++
++  for (i = 0; i < yuv->y_height; i++) {
++    ptro2 = ptro;
++    for (j = 0; j < yuv->y_width; j += 2) {
++
++      short pr, pg, pb, y;
++      short r, g, b;
++
++      pr = (-56992 + ptrv[j/2] * 409) >> 8;
++      pg = (34784 - ptru[j/2] * 100 - ptrv[j/2] * 208) >> 8;
++      pb = (-70688 + ptru[j/2] * 516) >> 8;
++
++      y = 298*ptry[j] >> 8;
++      r = y + pr;
++      g = y + pg;
++      b = y + pb;
++
++      *ptro2++ = 255;
++      *ptro2++ = CLAMP(r);
++      *ptro2++ = CLAMP(g);
++      *ptro2++ = CLAMP(b);
++
++      y = 298*ptry[j + 1] >> 8;
++      r = y + pr;
++      g = y + pg;
++      b = y + pb;
++
++      *ptro2++ = 255;
++      *ptro2++ = CLAMP(r);
++      *ptro2++ = CLAMP(g);
++      *ptro2++ = CLAMP(b);
++    }
++    ptry += yuv->y_width;
++    if (i & 1) {
++      ptru += yuv->uv_width;
++      ptrv += yuv->uv_width;
++    }
++    ptro += rgb->rgb_width * 4;
++  }
++}
++
++
+ /* Vanilla implementation of YUV->BGR conversion*/
+ void oggplay_yuv2bgr(OggPlayYUVChannels * yuv, OggPlayRGBChannels * rgb) {
+ 
--- a/media/liboggz/README_MOZILLA
+++ b/media/liboggz/README_MOZILLA
@@ -12,8 +12,10 @@ The warning.patch addresses a printf in 
 in a DEBUG #ifdef. See Mozilla bug 450891 and Annodex ticket 431:
 
 http://trac.annodex.net/ticket/431
 
 The oggz_off_t.patch fixes a compile error on Solaris see bug 449754
 for details
 
 The wince.patch addresses the lack of posix file IO suppor on windows ce see bug 461844 for details.
+
+endian.patch is applied to fix bug 452698.
new file mode 100644
--- /dev/null
+++ b/media/liboggz/endian.patch
@@ -0,0 +1,13 @@
+diff --git a/media/liboggz/include/oggz/config.h b/media/liboggz/include/oggz/config.h
+index d645685..19d20f5 100644
+--- a/media/liboggz/include/oggz/config.h
++++ b/media/liboggz/include/oggz/config.h
+@@ -126,3 +126,8 @@
+ /* Define to `unsigned int' if <sys/types.h> does not define. */
+ /* #undef size_t */
+ #undef DEBUG
++
++#include "prcpucfg.h"
++#ifdef IS_BIG_ENDIAN
++#define WORDS_BIGENDIAN
++#endif
--- a/media/liboggz/include/oggz/config.h
+++ b/media/liboggz/include/oggz/config.h
@@ -121,8 +121,13 @@
 /* #undef off_t */
 
 /* Define to rpl_realloc if the replacement function should be used. */
 /* #undef realloc */
 
 /* Define to `unsigned int' if <sys/types.h> does not define. */
 /* #undef size_t */
 #undef DEBUG
+
+#include "prcpucfg.h"
+#ifdef IS_BIG_ENDIAN
+#define WORDS_BIGENDIAN
+#endif
--- a/media/liboggz/update.sh
+++ b/media/liboggz/update.sh
@@ -40,8 +40,9 @@ sed s/\#include\ \"config.h\"/\#ifdef\ W
 sed s/\#include\ \"config.h\"/\#ifdef\ WIN32\\n\#include\ \"config_win32.h\"\\n\#else\\n\#include\ \"config.h\"\\n\#endif/g $1/src/liboggz/oggz_seek.c >./src/liboggz/oggz_seek.c
 cp $1/src/liboggz/oggz_dlist.h ./src/liboggz/oggz_dlist.h
 sed s/\#include\ \"config.h\"/\#ifdef\ WIN32\\n\#include\ \"config_win32.h\"\\n\#else\\n\#include\ \"config.h\"\\n\#endif/g $1/src/liboggz/metric_internal.c >./src/liboggz/metric_internal.c
 cp $1/AUTHORS ./AUTHORS
 patch -p4 <seek.patch
 patch -p4 <warning.patch
 patch -p3 <oggz_off_t.patch
 patch -p3 <wince.patch
+patch -p4 <endian.patch