picture.h revision 6747b715
105b261ecSmrg/*
205b261ecSmrg *
305b261ecSmrg * Copyright © 2000 SuSE, Inc.
405b261ecSmrg *
505b261ecSmrg * Permission to use, copy, modify, distribute, and sell this software and its
605b261ecSmrg * documentation for any purpose is hereby granted without fee, provided that
705b261ecSmrg * the above copyright notice appear in all copies and that both that
805b261ecSmrg * copyright notice and this permission notice appear in supporting
905b261ecSmrg * documentation, and that the name of SuSE not be used in advertising or
1005b261ecSmrg * publicity pertaining to distribution of the software without specific,
1105b261ecSmrg * written prior permission.  SuSE makes no representations about the
1205b261ecSmrg * suitability of this software for any purpose.  It is provided "as is"
1305b261ecSmrg * without express or implied warranty.
1405b261ecSmrg *
1505b261ecSmrg * SuSE DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL
1605b261ecSmrg * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL SuSE
1705b261ecSmrg * BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
1805b261ecSmrg * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
1905b261ecSmrg * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
2005b261ecSmrg * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
2105b261ecSmrg *
2205b261ecSmrg * Author:  Keith Packard, SuSE, Inc.
2305b261ecSmrg */
2405b261ecSmrg
2505b261ecSmrg#ifndef _PICTURE_H_
2605b261ecSmrg#define _PICTURE_H_
2705b261ecSmrg
286747b715Smrg#include "privates.h"
296747b715Smrg
3005b261ecSmrg#include <pixman.h>
3105b261ecSmrg
3205b261ecSmrgtypedef struct _DirectFormat	*DirectFormatPtr;
3305b261ecSmrgtypedef struct _PictFormat	*PictFormatPtr;
3405b261ecSmrgtypedef struct _Picture		*PicturePtr;
3505b261ecSmrg
3605b261ecSmrg/*
3705b261ecSmrg * While the protocol is generous in format support, the
3805b261ecSmrg * sample implementation allows only packed RGB and GBR
3905b261ecSmrg * representations for data to simplify software rendering,
4005b261ecSmrg */
4105b261ecSmrg#define PICT_FORMAT(bpp,type,a,r,g,b)	PIXMAN_FORMAT(bpp, type, a, r, g, b)
4205b261ecSmrg
4305b261ecSmrg/*
4405b261ecSmrg * gray/color formats use a visual index instead of argb
4505b261ecSmrg */
4605b261ecSmrg#define PICT_VISFORMAT(bpp,type,vi)	(((bpp) << 24) |  \
4705b261ecSmrg					 ((type) << 16) | \
4805b261ecSmrg					 ((vi)))
4905b261ecSmrg
5005b261ecSmrg#define PICT_FORMAT_BPP(f)	PIXMAN_FORMAT_BPP(f)
5105b261ecSmrg#define PICT_FORMAT_TYPE(f)	PIXMAN_FORMAT_TYPE(f)
5205b261ecSmrg#define PICT_FORMAT_A(f)	PIXMAN_FORMAT_A(f)
5305b261ecSmrg#define PICT_FORMAT_R(f)	PIXMAN_FORMAT_R(f)
5405b261ecSmrg#define PICT_FORMAT_G(f)	PIXMAN_FORMAT_G(f)
5505b261ecSmrg#define PICT_FORMAT_B(f)	PIXMAN_FORMAT_B(f)
5605b261ecSmrg#define PICT_FORMAT_RGB(f)	PIXMAN_FORMAT_RGB(f)
5705b261ecSmrg#define PICT_FORMAT_VIS(f)	PIXMAN_FORMAT_VIS(f)
5805b261ecSmrg
5905b261ecSmrg#define PICT_TYPE_OTHER		PIXMAN_TYPE_OTHER
6005b261ecSmrg#define PICT_TYPE_A		PIXMAN_TYPE_A
6105b261ecSmrg#define PICT_TYPE_ARGB		PIXMAN_TYPE_ARGB
6205b261ecSmrg#define PICT_TYPE_ABGR		PIXMAN_TYPE_ABGR
6305b261ecSmrg#define PICT_TYPE_COLOR		PIXMAN_TYPE_COLOR
6405b261ecSmrg#define PICT_TYPE_GRAY		PIXMAN_TYPE_GRAY
656747b715Smrg#define PICT_TYPE_BGRA		PIXMAN_TYPE_BGRA
6605b261ecSmrg
6705b261ecSmrg#define PICT_FORMAT_COLOR(f)	PIXMAN_FORMAT_COLOR(f)
6805b261ecSmrg
6905b261ecSmrg/* 32bpp formats */
7005b261ecSmrgtypedef enum _PictFormatShort {
716747b715Smrg    PICT_a2r10g10b10 =	PIXMAN_a2r10g10b10,
726747b715Smrg    PICT_x2r10g10b10 =	PIXMAN_x2r10g10b10,
736747b715Smrg    PICT_a2b10g10r10 =	PIXMAN_a2b10g10r10,
746747b715Smrg    PICT_x2b10g10r10 =	PIXMAN_x2b10g10r10,
756747b715Smrg
7605b261ecSmrg    PICT_a8r8g8b8 =	PIXMAN_a8r8g8b8,
7705b261ecSmrg    PICT_x8r8g8b8 =	PIXMAN_x8r8g8b8,
7805b261ecSmrg    PICT_a8b8g8r8 =	PIXMAN_a8b8g8r8,
7905b261ecSmrg    PICT_x8b8g8r8 =	PIXMAN_x8b8g8r8,
806747b715Smrg    PICT_b8g8r8a8 =	PIXMAN_b8g8r8a8,
816747b715Smrg    PICT_b8g8r8x8 =	PIXMAN_b8g8r8x8,
8205b261ecSmrg
8305b261ecSmrg/* 24bpp formats */
8405b261ecSmrg    PICT_r8g8b8 =	PIXMAN_r8g8b8,
8505b261ecSmrg    PICT_b8g8r8 =	PIXMAN_b8g8r8,
8605b261ecSmrg
8705b261ecSmrg/* 16bpp formats */
8805b261ecSmrg    PICT_r5g6b5 =	PIXMAN_r5g6b5,
8905b261ecSmrg    PICT_b5g6r5 =	PIXMAN_b5g6r5,
9005b261ecSmrg
9105b261ecSmrg    PICT_a1r5g5b5 =	PIXMAN_a1r5g5b5,
9205b261ecSmrg    PICT_x1r5g5b5 =	PIXMAN_x1r5g5b5,
9305b261ecSmrg    PICT_a1b5g5r5 =	PIXMAN_a1b5g5r5,
9405b261ecSmrg    PICT_x1b5g5r5 =	PIXMAN_x1b5g5r5,
9505b261ecSmrg    PICT_a4r4g4b4 =	PIXMAN_a4r4g4b4,
9605b261ecSmrg    PICT_x4r4g4b4 =	PIXMAN_x4r4g4b4,
9705b261ecSmrg    PICT_a4b4g4r4 =	PIXMAN_a4b4g4r4,
9805b261ecSmrg    PICT_x4b4g4r4 =	PIXMAN_x4b4g4r4,
9905b261ecSmrg
10005b261ecSmrg/* 8bpp formats */
10105b261ecSmrg    PICT_a8 =		PIXMAN_a8,
10205b261ecSmrg    PICT_r3g3b2 =	PIXMAN_r3g3b2,
10305b261ecSmrg    PICT_b2g3r3 =	PIXMAN_b2g3r3,
10405b261ecSmrg    PICT_a2r2g2b2 =	PIXMAN_a2r2g2b2,
10505b261ecSmrg    PICT_a2b2g2r2 =	PIXMAN_a2b2g2r2,
10605b261ecSmrg
10705b261ecSmrg    PICT_c8 =		PIXMAN_c8,
10805b261ecSmrg    PICT_g8 =		PIXMAN_g8,
10905b261ecSmrg
11005b261ecSmrg    PICT_x4a4 =		PIXMAN_x4a4,
11105b261ecSmrg
11205b261ecSmrg    PICT_x4c4 =		PIXMAN_x4c4,
11305b261ecSmrg    PICT_x4g4 =		PIXMAN_x4g4,
11405b261ecSmrg
11505b261ecSmrg/* 4bpp formats */
11605b261ecSmrg    PICT_a4 =		PIXMAN_a4,
11705b261ecSmrg    PICT_r1g2b1 =	PIXMAN_r1g2b1,
11805b261ecSmrg    PICT_b1g2r1 =	PIXMAN_b1g2r1,
11905b261ecSmrg    PICT_a1r1g1b1 =	PIXMAN_a1r1g1b1,
12005b261ecSmrg    PICT_a1b1g1r1 =	PIXMAN_a1b1g1r1,
12105b261ecSmrg
12205b261ecSmrg    PICT_c4 =		PIXMAN_c4,
12305b261ecSmrg    PICT_g4 =		PIXMAN_g4,
12405b261ecSmrg
12505b261ecSmrg/* 1bpp formats */
12605b261ecSmrg    PICT_a1 =		PIXMAN_a1,
12705b261ecSmrg
1284642e01fSmrg    PICT_g1 =		PIXMAN_g1
12905b261ecSmrg} PictFormatShort;
13005b261ecSmrg
13105b261ecSmrg/*
13205b261ecSmrg * For dynamic indexed visuals (GrayScale and PseudoColor), these control the
13305b261ecSmrg * selection of colors allocated for drawing to Pictures.  The default
13405b261ecSmrg * policy depends on the size of the colormap:
13505b261ecSmrg *
13605b261ecSmrg * Size		Default Policy
13705b261ecSmrg * ----------------------------
13805b261ecSmrg *  < 64	PolicyMono
13905b261ecSmrg *  < 256	PolicyGray
14005b261ecSmrg *  256		PolicyColor (only on PseudoColor)
14105b261ecSmrg *
14205b261ecSmrg * The actual allocation code lives in miindex.c, and so is
14305b261ecSmrg * austensibly server dependent, but that code does:
14405b261ecSmrg *
14505b261ecSmrg * PolicyMono	    Allocate no additional colors, use black and white
14605b261ecSmrg * PolicyGray	    Allocate 13 gray levels (11 cells used)
14705b261ecSmrg * PolicyColor	    Allocate a 4x4x4 cube and 13 gray levels (71 cells used)
14805b261ecSmrg * PolicyAll	    Allocate as big a cube as possible, fill with gray (all)
14905b261ecSmrg *
15005b261ecSmrg * Here's a picture to help understand how many colors are
15105b261ecSmrg * actually allocated (this is just the gray ramp):
15205b261ecSmrg *
15305b261ecSmrg *                 gray level
15405b261ecSmrg * all   0000 1555 2aaa 4000 5555 6aaa 8000 9555 aaaa bfff d555 eaaa ffff
15505b261ecSmrg * b/w   0000                                                        ffff
15605b261ecSmrg * 4x4x4                     5555                aaaa
15705b261ecSmrg * extra      1555 2aaa 4000      6aaa 8000 9555      bfff d555 eaaa
15805b261ecSmrg *
15905b261ecSmrg * The default colormap supplies two gray levels (black/white), the
16005b261ecSmrg * 4x4x4 cube allocates another two and nine more are allocated to fill
16105b261ecSmrg * in the 13 levels.  When the 4x4x4 cube is not allocated, a total of
16205b261ecSmrg * 11 cells are allocated.
16305b261ecSmrg */
16405b261ecSmrg
16505b261ecSmrg#define PictureCmapPolicyInvalid    -1
16605b261ecSmrg#define PictureCmapPolicyDefault    0
16705b261ecSmrg#define PictureCmapPolicyMono	    1
16805b261ecSmrg#define PictureCmapPolicyGray	    2
16905b261ecSmrg#define PictureCmapPolicyColor	    3
17005b261ecSmrg#define PictureCmapPolicyAll	    4
17105b261ecSmrg
1726747b715Smrgextern _X_EXPORT int PictureCmapPolicy;
17305b261ecSmrg
1746747b715Smrgextern _X_EXPORT int PictureParseCmapPolicy (const char *name);
17505b261ecSmrg
1766747b715Smrgextern _X_EXPORT int RenderErrBase;
17705b261ecSmrg
17805b261ecSmrg/* Fixed point updates from Carl Worth, USC, Information Sciences Institute */
17905b261ecSmrg
18005b261ecSmrgtypedef pixman_fixed_32_32_t	xFixed_32_32;
18105b261ecSmrg
18205b261ecSmrgtypedef pixman_fixed_48_16_t	xFixed_48_16;
18305b261ecSmrg
18405b261ecSmrg#define MAX_FIXED_48_16		pixman_max_fixed_48_16
18505b261ecSmrg#define MIN_FIXED_48_16		pixman_min_fixed_48_16
18605b261ecSmrg
18705b261ecSmrgtypedef pixman_fixed_1_31_t	xFixed_1_31;
18805b261ecSmrgtypedef pixman_fixed_1_16_t	xFixed_1_16;
18905b261ecSmrgtypedef pixman_fixed_16_16_t	xFixed_16_16;
19005b261ecSmrg
19105b261ecSmrg/*
19205b261ecSmrg * An unadorned "xFixed" is the same as xFixed_16_16,
19305b261ecSmrg * (since it's quite common in the code)
19405b261ecSmrg */
19505b261ecSmrgtypedef	pixman_fixed_t	xFixed;
19605b261ecSmrg#define XFIXED_BITS	16
19705b261ecSmrg
19805b261ecSmrg#define xFixedToInt(f)	pixman_fixed_to_int(f)
19905b261ecSmrg#define IntToxFixed(i)	pixman_int_to_fixed(i)
20005b261ecSmrg#define xFixedE		pixman_fixed_e
20105b261ecSmrg#define xFixed1		pixman_fixed_1
20205b261ecSmrg#define xFixed1MinusE	pixman_fixed_1_minus_e
20305b261ecSmrg#define xFixedFrac(f)	pixman_fixed_frac(f)
20405b261ecSmrg#define xFixedFloor(f)	pixman_fixed_floor(f)
20505b261ecSmrg#define xFixedCeil(f)	pixman_fixed_ceil(f)
20605b261ecSmrg
20705b261ecSmrg#define xFixedFraction(f)	pixman_fixed_fraction(f)
20805b261ecSmrg#define xFixedMod2(f)		pixman_fixed_mod2(f)
20905b261ecSmrg
21005b261ecSmrg/* whether 't' is a well defined not obviously empty trapezoid */
21105b261ecSmrg#define xTrapezoidValid(t)  ((t)->left.p1.y != (t)->left.p2.y && \
21205b261ecSmrg			     (t)->right.p1.y != (t)->right.p2.y && \
21305b261ecSmrg			     (int) ((t)->bottom - (t)->top) > 0)
21405b261ecSmrg
21505b261ecSmrg/*
21605b261ecSmrg * Standard NTSC luminance conversions:
21705b261ecSmrg *
21805b261ecSmrg *  y = r * 0.299 + g * 0.587 + b * 0.114
21905b261ecSmrg *
22005b261ecSmrg * Approximate this for a bit more speed:
22105b261ecSmrg *
22205b261ecSmrg *  y = (r * 153 + g * 301 + b * 58) / 512
22305b261ecSmrg *
22405b261ecSmrg * This gives 17 bits of luminance; to get 15 bits, lop the low two
22505b261ecSmrg */
22605b261ecSmrg
22705b261ecSmrg#define CvtR8G8B8toY15(s)	(((((s) >> 16) & 0xff) * 153 + \
22805b261ecSmrg				  (((s) >>  8) & 0xff) * 301 + \
22905b261ecSmrg				  (((s)      ) & 0xff) * 58) >> 2)
23005b261ecSmrg
23105b261ecSmrg#endif /* _PICTURE_H_ */
232