From patchwork Fri Mar 18 17:38:54 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: alexandros.frantzis@linaro.org X-Patchwork-Id: 669 Return-Path: Delivered-To: unknown Received: from imap.gmail.com (74.125.159.109) by localhost6.localdomain6 with IMAP4-SSL; 08 Jun 2011 14:44:35 -0000 Delivered-To: patches@linaro.org Received: by 10.220.28.198 with SMTP id n6cs31164vcc; Fri, 18 Mar 2011 10:39:05 -0700 (PDT) Received: by 10.14.10.81 with SMTP id 57mr107479eeu.26.1300469944553; Fri, 18 Mar 2011 10:39:04 -0700 (PDT) Received: from mail-ew0-f50.google.com (mail-ew0-f50.google.com [209.85.215.50]) by mx.google.com with ESMTPS id s8si294917eeh.88.2011.03.18.10.39.03 (version=TLSv1/SSLv3 cipher=OTHER); Fri, 18 Mar 2011 10:39:03 -0700 (PDT) Received-SPF: neutral (google.com: 209.85.215.50 is neither permitted nor denied by best guess record for domain of alexandros.frantzis@linaro.org) client-ip=209.85.215.50; Authentication-Results: mx.google.com; spf=neutral (google.com: 209.85.215.50 is neither permitted nor denied by best guess record for domain of alexandros.frantzis@linaro.org) smtp.mail=alexandros.frantzis@linaro.org Received: by ewy10 with SMTP id 10so1157803ewy.37 for ; Fri, 18 Mar 2011 10:39:03 -0700 (PDT) Received: by 10.213.96.79 with SMTP id g15mr637609ebn.72.1300469942835; Fri, 18 Mar 2011 10:39:02 -0700 (PDT) Received: from localhost (77.49.212.182.dsl.dyn.forthnet.gr [77.49.212.182]) by mx.google.com with ESMTPS id x54sm92945eeh.19.2011.03.18.10.39.01 (version=TLSv1/SSLv3 cipher=OTHER); Fri, 18 Mar 2011 10:39:02 -0700 (PDT) From: alexandros.frantzis@linaro.org To: pixman@lists.freedesktop.org Subject: [PATCH 1/2] Add simple support for the r8g8b8a8 and r8g8b8x8 formats. Date: Fri, 18 Mar 2011 19:38:54 +0200 Message-Id: <1300469935-28431-2-git-send-email-alexandros.frantzis@linaro.org> X-Mailer: git-send-email 1.7.4.1 In-Reply-To: <1300469935-28431-1-git-send-email-alexandros.frantzis@linaro.org> References: <1300469935-28431-1-git-send-email-alexandros.frantzis@linaro.org> From: Alexandros Frantzis This format is particularly useful on big-endian architectures, where RGBA in memory/file order corresponds to r8g8b8a8 as an uint32_t. This is important because RGBA is in some cases the only available choice (for example as a pixel format in OpenGL ES 2.0). --- pixman/pixman-access.c | 97 ++++++++++++++++++++++++++++++++++++++++++++++++ pixman/pixman.c | 6 +++ pixman/pixman.h | 6 ++- 3 files changed, 108 insertions(+), 1 deletions(-) diff --git a/pixman/pixman-access.c b/pixman/pixman-access.c index f1ce0ba..32c4d8b 100644 --- a/pixman/pixman-access.c +++ b/pixman/pixman-access.c @@ -211,6 +211,46 @@ fetch_scanline_b8g8r8x8 (pixman_image_t *image, } static void +fetch_scanline_r8g8b8a8 (pixman_image_t *image, + int x, + int y, + int width, + uint32_t * buffer, + const uint32_t *mask) +{ + const uint32_t *bits = image->bits.bits + y * image->bits.rowstride; + const uint32_t *pixel = (uint32_t *)bits + x; + const uint32_t *end = pixel + width; + + while (pixel < end) + { + uint32_t p = READ (image, pixel++); + + *buffer++ = (((p & 0x000000ff) << 24) | (p >> 8)); + } +} + +static void +fetch_scanline_r8g8b8x8 (pixman_image_t *image, + int x, + int y, + int width, + uint32_t * buffer, + const uint32_t *mask) +{ + const uint32_t *bits = image->bits.bits + y * image->bits.rowstride; + const uint32_t *pixel = (uint32_t *)bits + x; + const uint32_t *end = pixel + width; + + while (pixel < end) + { + uint32_t p = READ (image, pixel++); + + *buffer++ = (0xff000000 | (p >> 8)); + } +} + +static void fetch_scanline_x14r6g6b6 (pixman_image_t *image, int x, int y, @@ -1292,6 +1332,28 @@ fetch_pixel_b8g8r8x8 (bits_image_t *image, } static uint32_t +fetch_pixel_r8g8b8a8 (bits_image_t *image, + int offset, + int line) +{ + uint32_t *bits = image->bits + line * image->rowstride; + uint32_t pixel = READ (image, (uint32_t *)bits + offset); + + return (((pixel & 0x000000ff) << 24) | (pixel >> 8)); +} + +static uint32_t +fetch_pixel_r8g8b8x8 (bits_image_t *image, + int offset, + int line) +{ + uint32_t *bits = image->bits + line * image->rowstride; + uint32_t pixel = READ (image, (uint32_t *)bits + offset); + + return (0xff000000 | (pixel >> 8)); +} + +static uint32_t fetch_pixel_x14r6g6b6 (bits_image_t *image, int offset, int line) @@ -2028,6 +2090,39 @@ store_scanline_b8g8r8x8 (bits_image_t * image, } static void +store_scanline_r8g8b8a8 (bits_image_t * image, + int x, + int y, + int width, + const uint32_t *values) +{ + uint32_t *bits = image->bits + image->rowstride * y; + uint32_t *pixel = (uint32_t *)bits + x; + int i; + + for (i = 0; i < width; ++i) + { + WRITE (image, pixel++, + ((values[i] >> 24) & 0x000000ff) | (values[i] << 8)); + } +} + +static void +store_scanline_r8g8b8x8 (bits_image_t * image, + int x, + int y, + int width, + const uint32_t *values) +{ + uint32_t *bits = image->bits + image->rowstride * y; + uint32_t *pixel = (uint32_t *)bits + x; + int i; + + for (i = 0; i < width; ++i) + WRITE (image, pixel++, (values[i] << 8)); +} + +static void store_scanline_x14r6g6b6 (bits_image_t * image, int x, int y, @@ -2845,6 +2940,8 @@ static const format_info_t accessors[] = FORMAT_INFO (x8b8g8r8), FORMAT_INFO (b8g8r8a8), FORMAT_INFO (b8g8r8x8), + FORMAT_INFO (r8g8b8a8), + FORMAT_INFO (r8g8b8x8), FORMAT_INFO (x14r6g6b6), /* 24bpp formats */ diff --git a/pixman/pixman.c b/pixman/pixman.c index ec565f9..f21af2f 100644 --- a/pixman/pixman.c +++ b/pixman/pixman.c @@ -873,6 +873,8 @@ color_to_pixel (pixman_color_t * color, format == PIXMAN_x8b8g8r8 || format == PIXMAN_b8g8r8a8 || format == PIXMAN_b8g8r8x8 || + format == PIXMAN_r8g8b8a8 || + format == PIXMAN_r8g8b8x8 || format == PIXMAN_r5g6b5 || format == PIXMAN_b5g6r5 || format == PIXMAN_a8 || @@ -895,6 +897,8 @@ color_to_pixel (pixman_color_t * color, ((c & 0x0000ff00) << 8) | ((c & 0x000000ff) << 24); } + if (PIXMAN_FORMAT_TYPE (format) == PIXMAN_TYPE_RGBA) + c = ((c & 0xff000000) >> 24) | (c << 8); if (format == PIXMAN_a1) c = c >> 31; @@ -1105,6 +1109,8 @@ pixman_format_supported_source (pixman_format_code_t format) case PIXMAN_x8b8g8r8: case PIXMAN_b8g8r8a8: case PIXMAN_b8g8r8x8: + case PIXMAN_r8g8b8a8: + case PIXMAN_r8g8b8x8: case PIXMAN_r8g8b8: case PIXMAN_b8g8r8: case PIXMAN_r5g6b5: diff --git a/pixman/pixman.h b/pixman/pixman.h index 1305bc1..59d0760 100644 --- a/pixman/pixman.h +++ b/pixman/pixman.h @@ -650,11 +650,13 @@ struct pixman_indexed #define PIXMAN_TYPE_YUY2 6 #define PIXMAN_TYPE_YV12 7 #define PIXMAN_TYPE_BGRA 8 +#define PIXMAN_TYPE_RGBA 9 #define PIXMAN_FORMAT_COLOR(f) \ (PIXMAN_FORMAT_TYPE(f) == PIXMAN_TYPE_ARGB || \ PIXMAN_FORMAT_TYPE(f) == PIXMAN_TYPE_ABGR || \ - PIXMAN_FORMAT_TYPE(f) == PIXMAN_TYPE_BGRA) + PIXMAN_FORMAT_TYPE(f) == PIXMAN_TYPE_BGRA || \ + PIXMAN_FORMAT_TYPE(f) == PIXMAN_TYPE_RGBA) /* 32bpp formats */ typedef enum { @@ -664,6 +666,8 @@ typedef enum { PIXMAN_x8b8g8r8 = PIXMAN_FORMAT(32,PIXMAN_TYPE_ABGR,0,8,8,8), PIXMAN_b8g8r8a8 = PIXMAN_FORMAT(32,PIXMAN_TYPE_BGRA,8,8,8,8), PIXMAN_b8g8r8x8 = PIXMAN_FORMAT(32,PIXMAN_TYPE_BGRA,0,8,8,8), + PIXMAN_r8g8b8a8 = PIXMAN_FORMAT(32,PIXMAN_TYPE_RGBA,8,8,8,8), + PIXMAN_r8g8b8x8 = PIXMAN_FORMAT(32,PIXMAN_TYPE_RGBA,0,8,8,8), PIXMAN_x14r6g6b6 = PIXMAN_FORMAT(32,PIXMAN_TYPE_ARGB,0,6,6,6), PIXMAN_x2r10g10b10 = PIXMAN_FORMAT(32,PIXMAN_TYPE_ARGB,0,10,10,10), PIXMAN_a2r10g10b10 = PIXMAN_FORMAT(32,PIXMAN_TYPE_ARGB,2,10,10,10),