📄 fbcompose.c
字号:
/* * $XdotOrg: xc/programs/Xserver/fb/fbcompose.c,v 1.5 2005/01/13 20:49:21 sandmann Exp $ * * 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 "pixman-xserver-compat.h"#include "fbpict.h"#ifdef RENDER#include "pixregionint.h"#ifdef _MSC_VER#define _USE_MATH_DEFINES#endif#include <math.h>#ifndef M_PI#define M_PI 3.14159265358979323846#endif/* #define PIXMAN_CONVOLUTION *//* #define PIXMAN_INDEXED_FORMATS */static BoolPictureTransformPoint3d (pixman_transform_t *transform, PictVector *vector){ PictVector result; int i, j; xFixed_32_32 partial; xFixed_48_16 v; for (j = 0; j < 3; j++) { v = 0; for (i = 0; i < 3; i++) { partial = ((xFixed_48_16) transform->matrix[j][i] * (xFixed_48_16) vector->vector[i]); v += partial >> 16; } if (v > MAX_FIXED_48_16 || v < MIN_FIXED_48_16) return FALSE; result.vector[j] = (xFixed) v; } if (!result.vector[2]) return FALSE; *vector = result; return TRUE;}static unsigned intSourcePictureClassify (PicturePtr pict, int x, int y, int width, int height){ if (pict->pSourcePict->type == SourcePictTypeSolidFill) { pict->pSourcePict->solidFill.class = SourcePictClassHorizontal; } else if (pict->pSourcePict->type == SourcePictTypeLinear) { PictVector v; xFixed_32_32 l; xFixed_48_16 dx, dy, a, b, off; xFixed_48_16 factors[4]; int i; dx = pict->pSourcePict->linear.p2.x - pict->pSourcePict->linear.p1.x; dy = pict->pSourcePict->linear.p2.y - pict->pSourcePict->linear.p1.y; l = dx * dx + dy * dy; if (l) { a = (dx << 32) / l; b = (dy << 32) / l; } else { a = b = 0; } off = (-a * pict->pSourcePict->linear.p1.x -b * pict->pSourcePict->linear.p1.y) >> 16; for (i = 0; i < 3; i++) { v.vector[0] = IntToxFixed ((i % 2) * (width - 1) + x); v.vector[1] = IntToxFixed ((i / 2) * (height - 1) + y); v.vector[2] = xFixed1; if (pict->transform) { if (!PictureTransformPoint3d (pict->transform, &v)) return SourcePictClassUnknown; } factors[i] = ((a * v.vector[0] + b * v.vector[1]) >> 16) + off; } if (factors[2] == factors[0]) pict->pSourcePict->linear.class = SourcePictClassHorizontal; else if (factors[1] == factors[0]) pict->pSourcePict->linear.class = SourcePictClassVertical; } return pict->pSourcePict->solidFill.class;}#define mod(a,b) ((b) == 1 ? 0 : (a) >= 0 ? (a) % (b) : (b) - (-a) % (b))#define SCANLINE_BUFFER_LENGTH 2048typedef FASTCALL void (*fetchProc)(const FbBits *bits, int x, int width, CARD32 *buffer, miIndexedPtr indexed);/* * All of the fetch functions */static FASTCALL voidfbFetch_a8r8g8b8 (const FbBits *bits, int x, int width, CARD32 *buffer, miIndexedPtr indexed){ memcpy(buffer, (const CARD32 *)bits + x, width*sizeof(CARD32));}static FASTCALL voidfbFetch_x8r8g8b8 (const FbBits *bits, int x, int width, CARD32 *buffer, miIndexedPtr indexed){ const CARD32 *pixel = (const CARD32 *)bits + x; const CARD32 *end = pixel + width; while (pixel < end) { *buffer++ = *pixel++ | 0xff000000; }}static FASTCALL voidfbFetch_a8b8g8r8 (const FbBits *bits, int x, int width, CARD32 *buffer, miIndexedPtr indexed){ const CARD32 *pixel = (CARD32 *)bits + x; const CARD32 *end = pixel + width; while (pixel < end) { *buffer++ = ((*pixel & 0xff00ff00) | ((*pixel >> 16) & 0xff) | ((*pixel & 0xff) << 16)); ++pixel; }}static FASTCALL voidfbFetch_x8b8g8r8 (const FbBits *bits, int x, int width, CARD32 *buffer, miIndexedPtr indexed){ const CARD32 *pixel = (CARD32 *)bits + x; const CARD32 *end = pixel + width; while (pixel < end) { *buffer++ = 0xff000000 | ((*pixel & 0x0000ff00) | ((*pixel >> 16) & 0xff) | ((*pixel & 0xff) << 16)); ++pixel; }}static FASTCALL voidfbFetch_r8g8b8 (const FbBits *bits, int x, int width, CARD32 *buffer, miIndexedPtr indexed){ const CARD8 *pixel = (const CARD8 *)bits + 3*x; const CARD8 *end = pixel + 3*width; while (pixel < end) { CARD32 b = Fetch24(pixel) | 0xff000000; pixel += 3; *buffer++ = b; }}static FASTCALL voidfbFetch_b8g8r8 (const FbBits *bits, int x, int width, CARD32 *buffer, miIndexedPtr indexed){ const CARD8 *pixel = (const CARD8 *)bits + 3*x; const CARD8 *end = pixel + 3*width; while (pixel < end) { CARD32 b = 0xff000000;#if IMAGE_BYTE_ORDER == MSBFirst b |= (*pixel++); b |= (*pixel++ << 8); b |= (*pixel++ << 16);#else b |= (*pixel++ << 16); b |= (*pixel++ << 8); b |= (*pixel++);#endif }}static FASTCALL voidfbFetch_r5g6b5 (const FbBits *bits, int x, int width, CARD32 *buffer, miIndexedPtr indexed){ const CARD16 *pixel = (const CARD16 *)bits + x; const CARD16 *end = pixel + width; while (pixel < end) { CARD32 p = *pixel++; CARD32 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 (const FbBits *bits, int x, int width, CARD32 *buffer, miIndexedPtr indexed){ const CARD16 *pixel = (const CARD16 *)bits + x; const CARD16 *end = pixel + width; while (pixel < end) { CARD32 p = *pixel++; CARD32 r,g,b; 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 (const FbBits *bits, int x, int width, CARD32 *buffer, miIndexedPtr indexed){ const CARD16 *pixel = (const CARD16 *)bits + x; const CARD16 *end = pixel + width; while (pixel < end) { CARD32 p = *pixel++; CARD32 r,g,b, a; a = (CARD32) ((CARD8) (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 (const FbBits *bits, int x, int width, CARD32 *buffer, miIndexedPtr indexed){ const CARD16 *pixel = (const CARD16 *)bits + x; const CARD16 *end = pixel + width; while (pixel < end) { CARD32 p = *pixel++; CARD32 r,g,b; 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 (const FbBits *bits, int x, int width, CARD32 *buffer, miIndexedPtr indexed){ const CARD16 *pixel = (const CARD16 *)bits + x; const CARD16 *end = pixel + width; while (pixel < end) { CARD32 p = *pixel++; CARD32 r,g,b, a; a = (CARD32) ((CARD8) (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 (const FbBits *bits, int x, int width, CARD32 *buffer, miIndexedPtr indexed){ const CARD16 *pixel = (const CARD16 *)bits + x; const CARD16 *end = pixel + width; while (pixel < end) { CARD32 p = *pixel++; CARD32 r,g,b; 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 (const FbBits *bits, int x, int width, CARD32 *buffer, miIndexedPtr indexed){ const CARD16 *pixel = (const CARD16 *)bits + x; const CARD16 *end = pixel + width; while (pixel < end) { CARD32 p = *pixel++; CARD32 r,g,b, a; 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 (const FbBits *bits, int x, int width, CARD32 *buffer, miIndexedPtr indexed){ const CARD16 *pixel = (const CARD16 *)bits + x; const CARD16 *end = pixel + width; while (pixel < end) { CARD32 p = *pixel++; CARD32 r,g,b; 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 (const FbBits *bits, int x, int width, CARD32 *buffer, miIndexedPtr indexed){ const CARD16 *pixel = (const CARD16 *)bits + x; const CARD16 *end = pixel + width; while (pixel < end) { CARD32 p = *pixel++; CARD32 r,g,b, a; a = ((p & 0xf000) | ((p & 0xf000) >> 4)) << 16; b = ((p & 0x0f00) | ((p & 0x0f00) >> 4)) << 12; g = ((p & 0x00f0) | ((p & 0x00f0) >> 4)) << 8; r = ((p & 0x000f) | ((p & 0x000f) << 4)); *buffer++ = (a | r | g | b); }}static FASTCALL voidfbFetch_x4b4g4r4 (const FbBits *bits, int x, int width, CARD32 *buffer, miIndexedPtr indexed){ const CARD16 *pixel = (const CARD16 *)bits + x; const CARD16 *end = pixel + width; while (pixel < end) { CARD32 p = *pixel++; CARD32 r,g,b; b = ((p & 0x0f00) | ((p & 0x0f00) >> 4)) << 12; g = ((p & 0x00f0) | ((p & 0x00f0) >> 4)) << 8; r = ((p & 0x000f) | ((p & 0x000f) << 4)); *buffer++ = (0xff000000 | r | g | b); }}static FASTCALL voidfbFetch_a8 (const FbBits *bits, int x, int width, CARD32 *buffer, miIndexedPtr indexed){ const CARD8 *pixel = (const CARD8 *)bits + x; const CARD8 *end = pixel + width; while (pixel < end) { *buffer++ = (*pixel++) << 24; }}static FASTCALL voidfbFetch_r3g3b2 (const FbBits *bits, int x, int width, CARD32 *buffer, miIndexedPtr indexed){ const CARD8 *pixel = (const CARD8 *)bits + x; const CARD8 *end = pixel + width; while (pixel < end) { CARD32 p = *pixel++; CARD32 r,g,b; 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 (const FbBits *bits, int x, int width, CARD32 *buffer, miIndexedPtr indexed){ const CARD8 *pixel = (const CARD8 *)bits + x; const CARD8 *end = pixel + width; while (pixel < end) { CARD32 p = *pixel++; CARD32 r,g,b; 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 (const FbBits *bits, int x, int width, CARD32 *buffer, miIndexedPtr indexed){ const CARD8 *pixel = (const CARD8 *)bits + x; const CARD8 *end = pixel + width; while (pixel < end) { CARD32 p = *pixel++; CARD32 a,r,g,b; 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 (const FbBits *bits, int x, int width, CARD32 *buffer, miIndexedPtr indexed){ const CARD8 *pixel = (const CARD8 *)bits + x; const CARD8 *end = pixel + width; while (pixel < end) { CARD32 p = *pixel++; CARD32 a,r,g,b; 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 (const FbBits *bits, int x, int width, CARD32 *buffer, miIndexedPtr indexed){ const CARD8 *pixel = (const CARD8 *)bits + x; const CARD8 *end = pixel + width; while (pixel < end) { CARD32 p = *pixel++; *buffer++ = indexed->rgba[p]; }}#define Fetch8(l,o) (((CARD8 *) (l))[(o) >> 2])#if IMAGE_BYTE_ORDER == MSBFirst#define Fetch4(l,o) ((o) & 2 ? Fetch8(l,o) & 0xf : Fetch8(l,o) >> 4)#else#define Fetch4(l,o) ((o) & 2 ? Fetch8(l,o) >> 4 : Fetch8(l,o) & 0xf)#endifstatic FASTCALL voidfbFetch_a4 (const FbBits *bits, int x, int width, CARD32 *buffer, miIndexedPtr indexed){
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -