picture.h revision 4642e01f
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
2805b261ecSmrg#include <pixman.h>
2905b261ecSmrg
3005b261ecSmrgtypedef struct _DirectFormat	*DirectFormatPtr;
3105b261ecSmrgtypedef struct _PictFormat	*PictFormatPtr;
3205b261ecSmrgtypedef struct _Picture		*PicturePtr;
3305b261ecSmrg
3405b261ecSmrg/*
3505b261ecSmrg * While the protocol is generous in format support, the
3605b261ecSmrg * sample implementation allows only packed RGB and GBR
3705b261ecSmrg * representations for data to simplify software rendering,
3805b261ecSmrg */
3905b261ecSmrg#define PICT_FORMAT(bpp,type,a,r,g,b)	PIXMAN_FORMAT(bpp, type, a, r, g, b)
4005b261ecSmrg
4105b261ecSmrg/*
4205b261ecSmrg * gray/color formats use a visual index instead of argb
4305b261ecSmrg */
4405b261ecSmrg#define PICT_VISFORMAT(bpp,type,vi)	(((bpp) << 24) |  \
4505b261ecSmrg					 ((type) << 16) | \
4605b261ecSmrg					 ((vi)))
4705b261ecSmrg
4805b261ecSmrg#define PICT_FORMAT_BPP(f)	PIXMAN_FORMAT_BPP(f)
4905b261ecSmrg#define PICT_FORMAT_TYPE(f)	PIXMAN_FORMAT_TYPE(f)
5005b261ecSmrg#define PICT_FORMAT_A(f)	PIXMAN_FORMAT_A(f)
5105b261ecSmrg#define PICT_FORMAT_R(f)	PIXMAN_FORMAT_R(f)
5205b261ecSmrg#define PICT_FORMAT_G(f)	PIXMAN_FORMAT_G(f)
5305b261ecSmrg#define PICT_FORMAT_B(f)	PIXMAN_FORMAT_B(f)
5405b261ecSmrg#define PICT_FORMAT_RGB(f)	PIXMAN_FORMAT_RGB(f)
5505b261ecSmrg#define PICT_FORMAT_VIS(f)	PIXMAN_FORMAT_VIS(f)
5605b261ecSmrg
5705b261ecSmrg#define PICT_TYPE_OTHER		PIXMAN_TYPE_OTHER
5805b261ecSmrg#define PICT_TYPE_A		PIXMAN_TYPE_A
5905b261ecSmrg#define PICT_TYPE_ARGB		PIXMAN_TYPE_ARGB
6005b261ecSmrg#define PICT_TYPE_ABGR		PIXMAN_TYPE_ABGR
6105b261ecSmrg#define PICT_TYPE_COLOR		PIXMAN_TYPE_COLOR
6205b261ecSmrg#define PICT_TYPE_GRAY		PIXMAN_TYPE_GRAY
6305b261ecSmrg
6405b261ecSmrg#define PICT_FORMAT_COLOR(f)	PIXMAN_FORMAT_COLOR(f)
6505b261ecSmrg
6605b261ecSmrg/* 32bpp formats */
6705b261ecSmrgtypedef enum _PictFormatShort {
6805b261ecSmrg    PICT_a8r8g8b8 =	PIXMAN_a8r8g8b8,
6905b261ecSmrg    PICT_x8r8g8b8 =	PIXMAN_x8r8g8b8,
7005b261ecSmrg    PICT_a8b8g8r8 =	PIXMAN_a8b8g8r8,
7105b261ecSmrg    PICT_x8b8g8r8 =	PIXMAN_x8b8g8r8,
7205b261ecSmrg
7305b261ecSmrg/* 24bpp formats */
7405b261ecSmrg    PICT_r8g8b8 =	PIXMAN_r8g8b8,
7505b261ecSmrg    PICT_b8g8r8 =	PIXMAN_b8g8r8,
7605b261ecSmrg
7705b261ecSmrg/* 16bpp formats */
7805b261ecSmrg    PICT_r5g6b5 =	PIXMAN_r5g6b5,
7905b261ecSmrg    PICT_b5g6r5 =	PIXMAN_b5g6r5,
8005b261ecSmrg
8105b261ecSmrg    PICT_a1r5g5b5 =	PIXMAN_a1r5g5b5,
8205b261ecSmrg    PICT_x1r5g5b5 =	PIXMAN_x1r5g5b5,
8305b261ecSmrg    PICT_a1b5g5r5 =	PIXMAN_a1b5g5r5,
8405b261ecSmrg    PICT_x1b5g5r5 =	PIXMAN_x1b5g5r5,
8505b261ecSmrg    PICT_a4r4g4b4 =	PIXMAN_a4r4g4b4,
8605b261ecSmrg    PICT_x4r4g4b4 =	PIXMAN_x4r4g4b4,
8705b261ecSmrg    PICT_a4b4g4r4 =	PIXMAN_a4b4g4r4,
8805b261ecSmrg    PICT_x4b4g4r4 =	PIXMAN_x4b4g4r4,
8905b261ecSmrg
9005b261ecSmrg/* 8bpp formats */
9105b261ecSmrg    PICT_a8 =		PIXMAN_a8,
9205b261ecSmrg    PICT_r3g3b2 =	PIXMAN_r3g3b2,
9305b261ecSmrg    PICT_b2g3r3 =	PIXMAN_b2g3r3,
9405b261ecSmrg    PICT_a2r2g2b2 =	PIXMAN_a2r2g2b2,
9505b261ecSmrg    PICT_a2b2g2r2 =	PIXMAN_a2b2g2r2,
9605b261ecSmrg
9705b261ecSmrg    PICT_c8 =		PIXMAN_c8,
9805b261ecSmrg    PICT_g8 =		PIXMAN_g8,
9905b261ecSmrg
10005b261ecSmrg    PICT_x4a4 =		PIXMAN_x4a4,
10105b261ecSmrg
10205b261ecSmrg    PICT_x4c4 =		PIXMAN_x4c4,
10305b261ecSmrg    PICT_x4g4 =		PIXMAN_x4g4,
10405b261ecSmrg
10505b261ecSmrg/* 4bpp formats */
10605b261ecSmrg    PICT_a4 =		PIXMAN_a4,
10705b261ecSmrg    PICT_r1g2b1 =	PIXMAN_r1g2b1,
10805b261ecSmrg    PICT_b1g2r1 =	PIXMAN_b1g2r1,
10905b261ecSmrg    PICT_a1r1g1b1 =	PIXMAN_a1r1g1b1,
11005b261ecSmrg    PICT_a1b1g1r1 =	PIXMAN_a1b1g1r1,
11105b261ecSmrg
11205b261ecSmrg    PICT_c4 =		PIXMAN_c4,
11305b261ecSmrg    PICT_g4 =		PIXMAN_g4,
11405b261ecSmrg
11505b261ecSmrg/* 1bpp formats */
11605b261ecSmrg    PICT_a1 =		PIXMAN_a1,
11705b261ecSmrg
1184642e01fSmrg    PICT_g1 =		PIXMAN_g1
11905b261ecSmrg} PictFormatShort;
12005b261ecSmrg
12105b261ecSmrg/*
12205b261ecSmrg * For dynamic indexed visuals (GrayScale and PseudoColor), these control the
12305b261ecSmrg * selection of colors allocated for drawing to Pictures.  The default
12405b261ecSmrg * policy depends on the size of the colormap:
12505b261ecSmrg *
12605b261ecSmrg * Size		Default Policy
12705b261ecSmrg * ----------------------------
12805b261ecSmrg *  < 64	PolicyMono
12905b261ecSmrg *  < 256	PolicyGray
13005b261ecSmrg *  256		PolicyColor (only on PseudoColor)
13105b261ecSmrg *
13205b261ecSmrg * The actual allocation code lives in miindex.c, and so is
13305b261ecSmrg * austensibly server dependent, but that code does:
13405b261ecSmrg *
13505b261ecSmrg * PolicyMono	    Allocate no additional colors, use black and white
13605b261ecSmrg * PolicyGray	    Allocate 13 gray levels (11 cells used)
13705b261ecSmrg * PolicyColor	    Allocate a 4x4x4 cube and 13 gray levels (71 cells used)
13805b261ecSmrg * PolicyAll	    Allocate as big a cube as possible, fill with gray (all)
13905b261ecSmrg *
14005b261ecSmrg * Here's a picture to help understand how many colors are
14105b261ecSmrg * actually allocated (this is just the gray ramp):
14205b261ecSmrg *
14305b261ecSmrg *                 gray level
14405b261ecSmrg * all   0000 1555 2aaa 4000 5555 6aaa 8000 9555 aaaa bfff d555 eaaa ffff
14505b261ecSmrg * b/w   0000                                                        ffff
14605b261ecSmrg * 4x4x4                     5555                aaaa
14705b261ecSmrg * extra      1555 2aaa 4000      6aaa 8000 9555      bfff d555 eaaa
14805b261ecSmrg *
14905b261ecSmrg * The default colormap supplies two gray levels (black/white), the
15005b261ecSmrg * 4x4x4 cube allocates another two and nine more are allocated to fill
15105b261ecSmrg * in the 13 levels.  When the 4x4x4 cube is not allocated, a total of
15205b261ecSmrg * 11 cells are allocated.
15305b261ecSmrg */
15405b261ecSmrg
15505b261ecSmrg#define PictureCmapPolicyInvalid    -1
15605b261ecSmrg#define PictureCmapPolicyDefault    0
15705b261ecSmrg#define PictureCmapPolicyMono	    1
15805b261ecSmrg#define PictureCmapPolicyGray	    2
15905b261ecSmrg#define PictureCmapPolicyColor	    3
16005b261ecSmrg#define PictureCmapPolicyAll	    4
16105b261ecSmrg
16205b261ecSmrgextern int  PictureCmapPolicy;
16305b261ecSmrg
16405b261ecSmrgint	PictureParseCmapPolicy (const char *name);
16505b261ecSmrg
1664642e01fSmrgextern int RenderErrBase;
1674642e01fSmrgextern DevPrivateKey RenderClientPrivateKey;
16805b261ecSmrg
16905b261ecSmrg/* Fixed point updates from Carl Worth, USC, Information Sciences Institute */
17005b261ecSmrg
17105b261ecSmrgtypedef pixman_fixed_32_32_t	xFixed_32_32;
17205b261ecSmrg
17305b261ecSmrgtypedef pixman_fixed_48_16_t	xFixed_48_16;
17405b261ecSmrg
17505b261ecSmrg#define MAX_FIXED_48_16		pixman_max_fixed_48_16
17605b261ecSmrg#define MIN_FIXED_48_16		pixman_min_fixed_48_16
17705b261ecSmrg
17805b261ecSmrgtypedef pixman_fixed_1_31_t	xFixed_1_31;
17905b261ecSmrgtypedef pixman_fixed_1_16_t	xFixed_1_16;
18005b261ecSmrgtypedef pixman_fixed_16_16_t	xFixed_16_16;
18105b261ecSmrg
18205b261ecSmrg/*
18305b261ecSmrg * An unadorned "xFixed" is the same as xFixed_16_16,
18405b261ecSmrg * (since it's quite common in the code)
18505b261ecSmrg */
18605b261ecSmrgtypedef	pixman_fixed_t	xFixed;
18705b261ecSmrg#define XFIXED_BITS	16
18805b261ecSmrg
18905b261ecSmrg#define xFixedToInt(f)	pixman_fixed_to_int(f)
19005b261ecSmrg#define IntToxFixed(i)	pixman_int_to_fixed(i)
19105b261ecSmrg#define xFixedE		pixman_fixed_e
19205b261ecSmrg#define xFixed1		pixman_fixed_1
19305b261ecSmrg#define xFixed1MinusE	pixman_fixed_1_minus_e
19405b261ecSmrg#define xFixedFrac(f)	pixman_fixed_frac(f)
19505b261ecSmrg#define xFixedFloor(f)	pixman_fixed_floor(f)
19605b261ecSmrg#define xFixedCeil(f)	pixman_fixed_ceil(f)
19705b261ecSmrg
19805b261ecSmrg#define xFixedFraction(f)	pixman_fixed_fraction(f)
19905b261ecSmrg#define xFixedMod2(f)		pixman_fixed_mod2(f)
20005b261ecSmrg
20105b261ecSmrg/* whether 't' is a well defined not obviously empty trapezoid */
20205b261ecSmrg#define xTrapezoidValid(t)  ((t)->left.p1.y != (t)->left.p2.y && \
20305b261ecSmrg			     (t)->right.p1.y != (t)->right.p2.y && \
20405b261ecSmrg			     (int) ((t)->bottom - (t)->top) > 0)
20505b261ecSmrg
20605b261ecSmrg/*
20705b261ecSmrg * Standard NTSC luminance conversions:
20805b261ecSmrg *
20905b261ecSmrg *  y = r * 0.299 + g * 0.587 + b * 0.114
21005b261ecSmrg *
21105b261ecSmrg * Approximate this for a bit more speed:
21205b261ecSmrg *
21305b261ecSmrg *  y = (r * 153 + g * 301 + b * 58) / 512
21405b261ecSmrg *
21505b261ecSmrg * This gives 17 bits of luminance; to get 15 bits, lop the low two
21605b261ecSmrg */
21705b261ecSmrg
21805b261ecSmrg#define CvtR8G8B8toY15(s)	(((((s) >> 16) & 0xff) * 153 + \
21905b261ecSmrg				  (((s) >>  8) & 0xff) * 301 + \
22005b261ecSmrg				  (((s)      ) & 0xff) * 58) >> 2)
22105b261ecSmrg
22205b261ecSmrg#endif /* _PICTURE_H_ */
223