imported patch bug_545632_16bpp
authorDoug Turner <dougt@dougt.org>
Fri, 19 Mar 2010 00:05:29 -0700
changeset 46745 33517d1f7b441cb5ba4a3b1438f805bab5b94f03
parent 46744 e5f43afd81a93af804c7349952f5a214c70fe9e5
child 46746 e3a36a0d37aa0da05db3b98207cd8d28c6542b7a
push idunknown
push userunknown
push dateunknown
milestone1.9.3a4pre
imported patch bug_545632_16bpp
gfx/cairo/cairo/src/cairo-deprecated.h
gfx/cairo/cairo/src/cairo-image-surface.c
gfx/cairo/cairo/src/cairo.h
gfx/cairo/cairo/src/cairoint.h
gfx/thebes/public/gfxASurface.h
gfx/thebes/src/gfxASurface.cpp
gfx/thebes/src/gfxImageSurface.cpp
--- a/gfx/cairo/cairo/src/cairo-deprecated.h
+++ b/gfx/cairo/cairo/src/cairo-deprecated.h
@@ -43,17 +43,17 @@
  * backend can work fine with 16-bit visuals in the same way it works
  * with BGR visuals without any BGR formats in
  * #cairo_format_t).
  *
  * Additionally, the support for the RGB16_565 format was never
  * completely implemented. So while this format value is currently
  * deprecated, it may eventually acquire complete support in the future.
  */
-#define CAIRO_FORMAT_RGB16_565 4
+//#define CAIRO_FORMAT_RGB16_565 4
 
 #define CAIRO_FONT_TYPE_ATSUI CAIRO_FONT_TYPE_QUARTZ
 
 /* Obsolete functions. These definitions exist to coerce the compiler
  * into providing a little bit of guidance with its error
  * messages. The idea is to help users port their old code without
  * having to dig through lots of documentation.
  *
--- a/gfx/cairo/cairo/src/cairo-image-surface.c
+++ b/gfx/cairo/cairo/src/cairo-image-surface.c
@@ -44,18 +44,20 @@ static cairo_format_t
     case PIXMAN_a8r8g8b8:
 	return CAIRO_FORMAT_ARGB32;
     case PIXMAN_x8r8g8b8:
 	return CAIRO_FORMAT_RGB24;
     case PIXMAN_a8:
 	return CAIRO_FORMAT_A8;
     case PIXMAN_a1:
 	return CAIRO_FORMAT_A1;
+    case PIXMAN_r5g6b5:
+	return CAIRO_FORMAT_RGB16_565;
     case PIXMAN_a8b8g8r8: case PIXMAN_x8b8g8r8: case PIXMAN_r8g8b8:
-    case PIXMAN_b8g8r8:   case PIXMAN_r5g6b5:   case PIXMAN_b5g6r5:
+    case PIXMAN_b8g8r8:   case PIXMAN_b5g6r5:
     case PIXMAN_a1r5g5b5: case PIXMAN_x1r5g5b5: case PIXMAN_a1b5g5r5:
     case PIXMAN_x1b5g5r5: case PIXMAN_a4r4g4b4: case PIXMAN_x4r4g4b4:
     case PIXMAN_a4b4g4r4: case PIXMAN_x4b4g4r4: case PIXMAN_r3g3b2:
     case PIXMAN_b2g3r3:   case PIXMAN_a2r2g2b2: case PIXMAN_a2b2g2r2:
     case PIXMAN_c8:       case PIXMAN_g8:       case PIXMAN_x4a4:
     case PIXMAN_a4:       case PIXMAN_r1g2b1:   case PIXMAN_b1g2r1:
     case PIXMAN_a1r1g1b1: case PIXMAN_a1b1g1r1: case PIXMAN_c4:
     case PIXMAN_g4:       case PIXMAN_g1:
@@ -301,16 +303,19 @@ static pixman_format_code_t
 	ret = PIXMAN_a1;
 	break;
     case CAIRO_FORMAT_A8:
 	ret = PIXMAN_a8;
 	break;
     case CAIRO_FORMAT_RGB24:
 	ret = PIXMAN_x8r8g8b8;
 	break;
+    case CAIRO_FORMAT_RGB16_565:
+	ret = PIXMAN_r5g6b5;
+	break;
     case CAIRO_FORMAT_ARGB32:
     default:
 	ret = PIXMAN_a8r8g8b8;
 	break;
     }
     return ret;
 }
 
@@ -646,16 +651,18 @@ cairo_image_surface_get_stride (cairo_su
     return image_surface->stride;
 }
 slim_hidden_def (cairo_image_surface_get_stride);
 
 cairo_format_t
 _cairo_format_from_content (cairo_content_t content)
 {
     switch (content) {
+    case CAIRO_CONTENT_COLOR16:
+	return CAIRO_FORMAT_RGB16_565;
     case CAIRO_CONTENT_COLOR:
 	return CAIRO_FORMAT_RGB24;
     case CAIRO_CONTENT_ALPHA:
 	return CAIRO_FORMAT_A8;
     case CAIRO_CONTENT_COLOR_ALPHA:
 	return CAIRO_FORMAT_ARGB32;
     }
 
@@ -666,16 +673,18 @@ cairo_format_t
 cairo_content_t
 _cairo_content_from_format (cairo_format_t format)
 {
     switch (format) {
     case CAIRO_FORMAT_ARGB32:
 	return CAIRO_CONTENT_COLOR_ALPHA;
     case CAIRO_FORMAT_RGB24:
 	return CAIRO_CONTENT_COLOR;
+    case CAIRO_FORMAT_RGB16_565:
+	return CAIRO_CONTENT_COLOR16;
     case CAIRO_FORMAT_A8:
     case CAIRO_FORMAT_A1:
 	return CAIRO_CONTENT_ALPHA;
     }
 
     ASSERT_NOT_REACHED;
     return CAIRO_CONTENT_COLOR_ALPHA;
 }
@@ -683,16 +692,18 @@ cairo_content_t
 int
 _cairo_format_bits_per_pixel (cairo_format_t format)
 {
     switch (format) {
     case CAIRO_FORMAT_ARGB32:
 	return 32;
     case CAIRO_FORMAT_RGB24:
 	return 32;
+    case CAIRO_FORMAT_RGB16_565:
+	return 16;
     case CAIRO_FORMAT_A8:
 	return 8;
     case CAIRO_FORMAT_A1:
 	return 1;
     default:
 	ASSERT_NOT_REACHED;
 	return 0;
     }
--- a/gfx/cairo/cairo/src/cairo.h
+++ b/gfx/cairo/cairo/src/cairo.h
@@ -307,17 +307,18 @@ typedef enum _cairo_status {
  *
  * Note: The large values here are designed to keep #cairo_content_t
  * values distinct from #cairo_format_t values so that the
  * implementation can detect the error if users confuse the two types.
  **/
 typedef enum _cairo_content {
     CAIRO_CONTENT_COLOR		= 0x1000,
     CAIRO_CONTENT_ALPHA		= 0x2000,
-    CAIRO_CONTENT_COLOR_ALPHA	= 0x3000
+    CAIRO_CONTENT_COLOR_ALPHA	= 0x3000,
+    CAIRO_CONTENT_COLOR16	= 0x4000
 } cairo_content_t;
 
 /**
  * cairo_write_func_t:
  * @closure: the output closure
  * @data: the buffer containing the data to write
  * @length: the amount of data to write
  *
@@ -2061,21 +2062,18 @@ cairo_surface_has_show_text_glyphs (cair
  * image data.
  *
  * New entries may be added in future versions.
  **/
 typedef enum _cairo_format {
     CAIRO_FORMAT_ARGB32,
     CAIRO_FORMAT_RGB24,
     CAIRO_FORMAT_A8,
-    CAIRO_FORMAT_A1
-    /* The value of 4 is reserved by a deprecated enum value.
-     * The next format added must have an explicit value of 5.
-    CAIRO_FORMAT_RGB16_565 = 4,
-    */
+    CAIRO_FORMAT_A1,
+    CAIRO_FORMAT_RGB16_565
 } cairo_format_t;
 
 cairo_public cairo_surface_t *
 cairo_image_surface_create (cairo_format_t	format,
 			    int			width,
 			    int			height);
 
 cairo_public int
--- a/gfx/cairo/cairo/src/cairoint.h
+++ b/gfx/cairo/cairo/src/cairoint.h
@@ -2146,26 +2146,27 @@ cairo_private cairo_bool_t
  *
  * If we do decide to start fully supporting RGB16_565 as an external
  * format, then %CAIRO_FORMAT_VALID needs to be adjusted to include
  * it. But that should not happen before all necessary code is fixed
  * to support it (at least cairo_surface_write_to_png() and a few spots
  * in cairo-xlib-surface.c--again see -Wswitch-enum).
  */
 #define CAIRO_FORMAT_INVALID ((unsigned int) -1)
-#define CAIRO_FORMAT_VALID(format) ((format) <= CAIRO_FORMAT_A1)
+#define CAIRO_FORMAT_VALID(format) ((format) <= CAIRO_FORMAT_RGB16_565)
 
 /* pixman-required stride alignment in bytes. */
 #define CAIRO_STRIDE_ALIGNMENT (sizeof (uint32_t))
 #define CAIRO_STRIDE_FOR_WIDTH_BPP(w,bpp) \
    ((((bpp)*(w)+7)/8 + CAIRO_STRIDE_ALIGNMENT-1) & -CAIRO_STRIDE_ALIGNMENT)
 
 #define CAIRO_CONTENT_VALID(content) ((content) && 			         \
 				      (((content) & ~(CAIRO_CONTENT_COLOR |      \
 						      CAIRO_CONTENT_ALPHA |      \
+						      CAIRO_CONTENT_COLOR16 |    \
 						      CAIRO_CONTENT_COLOR_ALPHA))\
 				       == 0))
 
 cairo_private int
 _cairo_format_bits_per_pixel (cairo_format_t format) cairo_const;
 
 cairo_private cairo_format_t
 _cairo_format_from_content (cairo_content_t content) cairo_const;
--- a/gfx/thebes/public/gfxASurface.h
+++ b/gfx/thebes/public/gfxASurface.h
@@ -62,16 +62,17 @@ public:
      * The format for an image surface. For all formats with alpha data, 0
      * means transparent, 1 or 255 means fully opaque.
      */
     typedef enum {
         ImageFormatARGB32, ///< ARGB data in native endianness, using premultiplied alpha
         ImageFormatRGB24,  ///< xRGB data in native endianness
         ImageFormatA8,     ///< Only an alpha channel
         ImageFormatA1,     ///< Packed transparency information (one byte refers to 8 pixels)
+        ImageFormatRGB16,  ///< xRGB data in native endianness, using premultiplied alpha
         ImageFormatUnknown
     } gfxImageFormat;
 
     typedef enum {
         SurfaceTypeImage,
         SurfaceTypePDF,
         SurfaceTypePS,
         SurfaceTypeXlib,
@@ -88,17 +89,18 @@ public:
         SurfaceTypeScript,
         SurfaceTypeQPainter,
         SurfaceTypeDDraw
     } gfxSurfaceType;
 
     typedef enum {
         CONTENT_COLOR       = 0x1000,
         CONTENT_ALPHA       = 0x2000,
-        CONTENT_COLOR_ALPHA = 0x3000
+        CONTENT_COLOR_ALPHA = 0x3000,
+        CONTENT_COLOR16     = 0x4000
     } gfxContentType;
 
     /* Wrap the given cairo surface and return a gfxASurface for it */
     static already_AddRefed<gfxASurface> Wrap(cairo_surface_t *csurf);
 
     /*** this DOES NOT addref the surface */
     cairo_surface_t *CairoSurface() {
         NS_ASSERTION(mSurface != nsnull, "gfxASurface::CairoSurface called with mSurface == nsnull!");
--- a/gfx/thebes/src/gfxASurface.cpp
+++ b/gfx/thebes/src/gfxASurface.cpp
@@ -384,16 +384,18 @@ gfxASurface::EndPage()
 gfxASurface::gfxContentType
 gfxASurface::ContentFromFormat(gfxImageFormat format)
 {
     switch (format) {
         case ImageFormatARGB32:
             return CONTENT_COLOR_ALPHA;
         case ImageFormatRGB24:
             return CONTENT_COLOR;
+        case ImageFormatRGB16:
+            return CONTENT_COLOR16;
         case ImageFormatA8:
         case ImageFormatA1:
             return CONTENT_ALPHA;
 
         case ImageFormatUnknown:
         default:
             return CONTENT_COLOR;
     }
--- a/gfx/thebes/src/gfxImageSurface.cpp
+++ b/gfx/thebes/src/gfxImageSurface.cpp
@@ -117,16 +117,18 @@ long
 gfxImageSurface::ComputeStride() const
 {
     long stride;
 
     if (mFormat == ImageFormatARGB32)
         stride = mSize.width * 4;
     else if (mFormat == ImageFormatRGB24)
         stride = mSize.width * 4;
+    else if (mFormat == ImageFormatRGB16)
+        stride = mSize.width * 2;
     else if (mFormat == ImageFormatA8)
         stride = mSize.width;
     else if (mFormat == ImageFormatA1) {
         stride = (mSize.width + 7) / 8;
     } else {
         NS_WARNING("Unknown format specified to gfxImageSurface!");
         stride = mSize.width * 4;
     }