⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 pixman-access.c

📁 嵌入式图形库
💻 C
📖 第 1 页 / 共 4 页
字号:
/* * * Copyright © 2000 Keith Packard, member of The XFree86 Project, Inc. *             2005 Lars Knoll & Zack Rusin, Trolltech * * Permission to use, copy, modify, distribute, and sell this software and its * documentation for any purpose is hereby granted without fee, provided that * the above copyright notice appear in all copies and that both that * copyright notice and this permission notice appear in supporting * documentation, and that the name of Keith Packard not be used in * advertising or publicity pertaining to distribution of the software without * specific, written prior permission.  Keith Packard makes no * representations about the suitability of this software for any purpose.  It * is provided "as is" without express or implied warranty. * * THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS * SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND * FITNESS, IN NO EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY * SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN * AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING * OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS * SOFTWARE. */#ifdef HAVE_CONFIG_H#include <config.h>#endif#include <string.h>#include "pixman-private.h"#ifdef PIXMAN_FB_ACCESSORS#define FETCH_PROC_FOR_PICTURE pixman_fetchProcForPicture_accessors#define FETCH_PIXEL_PROC_FOR_PICTURE pixman_fetchPixelProcForPicture_accessors#define STORE_PROC_FOR_PICTURE pixman_storeProcForPicture_accessors#else#define FETCH_PROC_FOR_PICTURE pixman_fetchProcForPicture#define FETCH_PIXEL_PROC_FOR_PICTURE pixman_fetchPixelProcForPicture#define STORE_PROC_FOR_PICTURE pixman_storeProcForPicture#endif/* * YV12 setup and access macros */#define YV12_SETUP(pict) \	uint32_t *bits = pict->bits; \	int stride = pict->rowstride; \	int offset0 = stride < 0 ? \		((-stride) >> 1) * ((pict->height - 1) >> 1) - stride : \		stride * pict->height; \	int offset1 = stride < 0 ? \		offset0 + ((-stride) >> 1) * ((pict->height) >> 1) : \		offset0 + (offset0 >> 2)/* Note n trailing semicolon on the above macro; if it's there, then * the typical usage of YV12_SETUP(pict); will have an extra trailing ; * that some compilers will interpret as a statement -- and then any further * variable declarations will cause an error. */#define YV12_Y(line)		\    ((uint8_t *) ((bits) + (stride) * (line)))#define YV12_U(line)	      \    ((uint8_t *) ((bits) + offset1 + \		((stride) >> 1) * ((line) >> 1)))#define YV12_V(line)	      \    ((uint8_t *) ((bits) + offset0 + \		((stride) >> 1) * ((line) >> 1)))/*********************************** Fetch ************************************/static FASTCALL voidfbFetch_a8r8g8b8 (bits_image_t *pict, int x, int y, int width, uint32_t *buffer){    const uint32_t *bits = pict->bits + y*pict->rowstride;    MEMCPY_WRAPPED(pict,                   buffer, (const uint32_t *)bits + x,		   width*sizeof(uint32_t));}static FASTCALL voidfbFetch_x8r8g8b8 (bits_image_t *pict, int x, int y, int width, uint32_t *buffer){    const uint32_t *bits = pict->bits + y*pict->rowstride;    const uint32_t *pixel = (const uint32_t *)bits + x;    const uint32_t *end = pixel + width;    while (pixel < end) {	*buffer++ = READ(pict, pixel++) | 0xff000000;    }}static FASTCALL voidfbFetch_a8b8g8r8 (bits_image_t *pict, int x, int y, int width, uint32_t *buffer){    const uint32_t *bits = pict->bits + y*pict->rowstride;    const uint32_t *pixel = (uint32_t *)bits + x;    const uint32_t *end = pixel + width;    while (pixel < end) {	uint32_t p = READ(pict, pixel++);	*buffer++ = (p & 0xff00ff00) |	            ((p >> 16) & 0xff) |	    ((p & 0xff) << 16);    }}static FASTCALL voidfbFetch_x8b8g8r8 (bits_image_t *pict, int x, int y, int width, uint32_t *buffer){    const uint32_t *bits = pict->bits + y*pict->rowstride;    const uint32_t *pixel = (uint32_t *)bits + x;    const uint32_t *end = pixel + width;    while (pixel < end) {	uint32_t p = READ(pict, pixel++);	*buffer++ = 0xff000000 |	    (p & 0x0000ff00) |	    ((p >> 16) & 0xff) |	    ((p & 0xff) << 16);    }}static FASTCALL voidfbFetch_r8g8b8 (bits_image_t *pict, int x, int y, int width, uint32_t *buffer){    const uint32_t *bits = pict->bits + y*pict->rowstride;    const uint8_t *pixel = (const uint8_t *)bits + 3*x;    const uint8_t *end = pixel + 3*width;    while (pixel < end) {	uint32_t b = Fetch24(pict, pixel) | 0xff000000;	pixel += 3;	*buffer++ = b;    }}static FASTCALL voidfbFetch_b8g8r8 (bits_image_t *pict, int x, int y, int width, uint32_t *buffer){    const uint32_t *bits = pict->bits + y*pict->rowstride;    const uint8_t *pixel = (const uint8_t *)bits + 3*x;    const uint8_t *end = pixel + 3*width;    while (pixel < end) {	uint32_t b = 0xff000000;#if IMAGE_BYTE_ORDER == MSBFirst	b |= (READ(pict, pixel++));	b |= (READ(pict, pixel++) << 8);	b |= (READ(pict, pixel++) << 16);#else	b |= (READ(pict, pixel++) << 16);	b |= (READ(pict, pixel++) << 8);	b |= (READ(pict, pixel++));#endif	*buffer++ = b;    }}static FASTCALL voidfbFetch_r5g6b5 (bits_image_t *pict, int x, int y, int width, uint32_t *buffer){    const uint32_t *bits = pict->bits + y*pict->rowstride;    const uint16_t *pixel = (const uint16_t *)bits + x;    const uint16_t *end = pixel + width;    while (pixel < end) {	uint32_t p = READ(pict, pixel++);	uint32_t r = (((p) << 3) & 0xf8) |	    (((p) << 5) & 0xfc00) |	    (((p) << 8) & 0xf80000);	r |= (r >> 5) & 0x70007;	r |= (r >> 6) & 0x300;	*buffer++ = 0xff000000 | r;    }}static FASTCALL voidfbFetch_b5g6r5 (bits_image_t *pict, int x, int y, int width, uint32_t *buffer){    uint32_t  r,g,b;    const uint32_t *bits = pict->bits + y*pict->rowstride;    const uint16_t *pixel = (const uint16_t *)bits + x;    const uint16_t *end = pixel + width;    while (pixel < end) {	uint32_t  p = READ(pict, pixel++);	b = ((p & 0xf800) | ((p & 0xe000) >> 5)) >> 8;	g = ((p & 0x07e0) | ((p & 0x0600) >> 6)) << 5;	r = ((p & 0x001c) | ((p & 0x001f) << 5)) << 14;	*buffer++ = 0xff000000 | r | g | b;    }}static FASTCALL voidfbFetch_a1r5g5b5 (bits_image_t *pict, int x, int y, int width, uint32_t *buffer){    uint32_t  r,g,b, a;    const uint32_t *bits = pict->bits + y*pict->rowstride;    const uint16_t *pixel = (const uint16_t *)bits + x;    const uint16_t *end = pixel + width;    while (pixel < end) {	uint32_t  p = READ(pict, pixel++);	a = (uint32_t) ((uint8_t) (0 - ((p & 0x8000) >> 15))) << 24;	r = ((p & 0x7c00) | ((p & 0x7000) >> 5)) << 9;	g = ((p & 0x03e0) | ((p & 0x0380) >> 5)) << 6;	b = ((p & 0x001c) | ((p & 0x001f) << 5)) >> 2;	*buffer++ = a | r | g | b;    }}static FASTCALL voidfbFetch_x1r5g5b5 (bits_image_t *pict, int x, int y, int width, uint32_t *buffer){    uint32_t  r,g,b;    const uint32_t *bits = pict->bits + y*pict->rowstride;    const uint16_t *pixel = (const uint16_t *)bits + x;    const uint16_t *end = pixel + width;    while (pixel < end) {	uint32_t  p = READ(pict, pixel++);	r = ((p & 0x7c00) | ((p & 0x7000) >> 5)) << 9;	g = ((p & 0x03e0) | ((p & 0x0380) >> 5)) << 6;	b = ((p & 0x001c) | ((p & 0x001f) << 5)) >> 2;	*buffer++ = 0xff000000 | r | g | b;    }}static FASTCALL voidfbFetch_a1b5g5r5 (bits_image_t *pict, int x, int y, int width, uint32_t *buffer){    uint32_t  r,g,b, a;    const uint32_t *bits = pict->bits + y*pict->rowstride;    const uint16_t *pixel = (const uint16_t *)bits + x;    const uint16_t *end = pixel + width;    while (pixel < end) {	uint32_t  p = READ(pict, pixel++);	a = (uint32_t) ((uint8_t) (0 - ((p & 0x8000) >> 15))) << 24;	b = ((p & 0x7c00) | ((p & 0x7000) >> 5)) >> 7;	g = ((p & 0x03e0) | ((p & 0x0380) >> 5)) << 6;	r = ((p & 0x001c) | ((p & 0x001f) << 5)) << 14;	*buffer++ = a | r | g | b;    }}static FASTCALL voidfbFetch_x1b5g5r5 (bits_image_t *pict, int x, int y, int width, uint32_t *buffer){    uint32_t  r,g,b;    const uint32_t *bits = pict->bits + y*pict->rowstride;    const uint16_t *pixel = (const uint16_t *)bits + x;    const uint16_t *end = pixel + width;    while (pixel < end) {	uint32_t  p = READ(pict, pixel++);	b = ((p & 0x7c00) | ((p & 0x7000) >> 5)) >> 7;	g = ((p & 0x03e0) | ((p & 0x0380) >> 5)) << 6;	r = ((p & 0x001c) | ((p & 0x001f) << 5)) << 14;	*buffer++ = 0xff000000 | r | g | b;    }}static FASTCALL voidfbFetch_a4r4g4b4 (bits_image_t *pict, int x, int y, int width, uint32_t *buffer){    uint32_t  r,g,b, a;    const uint32_t *bits = pict->bits + y*pict->rowstride;    const uint16_t *pixel = (const uint16_t *)bits + x;    const uint16_t *end = pixel + width;    while (pixel < end) {	uint32_t  p = READ(pict, pixel++);	a = ((p & 0xf000) | ((p & 0xf000) >> 4)) << 16;	r = ((p & 0x0f00) | ((p & 0x0f00) >> 4)) << 12;	g = ((p & 0x00f0) | ((p & 0x00f0) >> 4)) << 8;	b = ((p & 0x000f) | ((p & 0x000f) << 4));	*buffer++ = a | r | g | b;    }}static FASTCALL voidfbFetch_x4r4g4b4 (bits_image_t *pict, int x, int y, int width, uint32_t *buffer){    uint32_t  r,g,b;    const uint32_t *bits = pict->bits + y*pict->rowstride;    const uint16_t *pixel = (const uint16_t *)bits + x;    const uint16_t *end = pixel + width;    while (pixel < end) {	uint32_t  p = READ(pict, pixel++);	r = ((p & 0x0f00) | ((p & 0x0f00) >> 4)) << 12;	g = ((p & 0x00f0) | ((p & 0x00f0) >> 4)) << 8;	b = ((p & 0x000f) | ((p & 0x000f) << 4));	*buffer++ = 0xff000000 | r | g | b;    }}static FASTCALL voidfbFetch_a4b4g4r4 (bits_image_t *pict, int x, int y, int width, uint32_t *buffer){    uint32_t  r,g,b, a;    const uint32_t *bits = pict->bits + y*pict->rowstride;    const uint16_t *pixel = (const uint16_t *)bits + x;    const uint16_t *end = pixel + width;    while (pixel < end) {	uint32_t  p = READ(pict, pixel++);	a = ((p & 0xf000) | ((p & 0xf000) >> 4)) << 16;	b = ((p & 0x0f00) | ((p & 0x0f00) >> 4)) >> 4;	g = ((p & 0x00f0) | ((p & 0x00f0) >> 4)) << 8;	r = ((p & 0x000f) | ((p & 0x000f) << 4)) << 16;	*buffer++ = a | r | g | b;    }}static FASTCALL voidfbFetch_x4b4g4r4 (bits_image_t *pict, int x, int y, int width, uint32_t *buffer){    uint32_t  r,g,b;    const uint32_t *bits = pict->bits + y*pict->rowstride;    const uint16_t *pixel = (const uint16_t *)bits + x;    const uint16_t *end = pixel + width;    while (pixel < end) {	uint32_t  p = READ(pict, pixel++);	b = ((p & 0x0f00) | ((p & 0x0f00) >> 4)) >> 4;	g = ((p & 0x00f0) | ((p & 0x00f0) >> 4)) << 8;	r = ((p & 0x000f) | ((p & 0x000f) << 4)) << 16;	*buffer++ = 0xff000000 | r | g | b;    }}static FASTCALL voidfbFetch_a8 (bits_image_t *pict, int x, int y, int width, uint32_t *buffer){    const uint32_t *bits = pict->bits + y*pict->rowstride;    const uint8_t *pixel = (const uint8_t *)bits + x;    const uint8_t *end = pixel + width;    while (pixel < end) {	*buffer++ = READ(pict, pixel++) << 24;    }}static FASTCALL voidfbFetch_r3g3b2 (bits_image_t *pict, int x, int y, int width, uint32_t *buffer){    uint32_t  r,g,b;    const uint32_t *bits = pict->bits + y*pict->rowstride;    const uint8_t *pixel = (const uint8_t *)bits + x;    const uint8_t *end = pixel + width;    while (pixel < end) {	uint32_t  p = READ(pict, pixel++);	r = ((p & 0xe0) | ((p & 0xe0) >> 3) | ((p & 0xc0) >> 6)) << 16;	g = ((p & 0x1c) | ((p & 0x18) >> 3) | ((p & 0x1c) << 3)) << 8;	b = (((p & 0x03)     ) |	     ((p & 0x03) << 2) |	     ((p & 0x03) << 4) |	     ((p & 0x03) << 6));	*buffer++ = 0xff000000 | r | g | b;    }}static FASTCALL voidfbFetch_b2g3r3 (bits_image_t *pict, int x, int y, int width, uint32_t *buffer){    uint32_t  r,g,b;    const uint32_t *bits = pict->bits + y*pict->rowstride;    const uint8_t *pixel = (const uint8_t *)bits + x;    const uint8_t *end = pixel + width;    while (pixel < end) {	uint32_t  p = READ(pict, pixel++);	b = (((p & 0xc0)     ) |	     ((p & 0xc0) >> 2) |	     ((p & 0xc0) >> 4) |	     ((p & 0xc0) >> 6));	g = ((p & 0x38) | ((p & 0x38) >> 3) | ((p & 0x30) << 2)) << 8;	r = (((p & 0x07)     ) |	     ((p & 0x07) << 3) |	     ((p & 0x06) << 6)) << 16;	*buffer++ = 0xff000000 | r | g | b;    }}static FASTCALL voidfbFetch_a2r2g2b2 (bits_image_t *pict, int x, int y, int width, uint32_t *buffer){    uint32_t   a,r,g,b;    const uint32_t *bits = pict->bits + y*pict->rowstride;    const uint8_t *pixel = (const uint8_t *)bits + x;    const uint8_t *end = pixel + width;    while (pixel < end) {	uint32_t  p = READ(pict, pixel++);	a = ((p & 0xc0) * 0x55) << 18;	r = ((p & 0x30) * 0x55) << 12;	g = ((p & 0x0c) * 0x55) << 6;	b = ((p & 0x03) * 0x55);	*buffer++ = a|r|g|b;    }}static FASTCALL voidfbFetch_a2b2g2r2 (bits_image_t *pict, int x, int y, int width, uint32_t *buffer){    uint32_t   a,r,g,b;    const uint32_t *bits = pict->bits + y*pict->rowstride;    const uint8_t *pixel = (const uint8_t *)bits + x;    const uint8_t *end = pixel + width;    while (pixel < end) {	uint32_t  p = READ(pict, pixel++);	a = ((p & 0xc0) * 0x55) << 18;	b = ((p & 0x30) * 0x55) >> 6;	g = ((p & 0x0c) * 0x55) << 6;	r = ((p & 0x03) * 0x55) << 16;	*buffer++ = a|r|g|b;    }}static FASTCALL voidfbFetch_c8 (bits_image_t *pict, int x, int y, int width, uint32_t *buffer)

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -