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
19f7df2e56Smrg * 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
32f7df2e56Smrgtypedef struct _DirectFormat *DirectFormatPtr;
33f7df2e56Smrgtypedef struct _PictFormat *PictFormatPtr;
34f7df2e56Smrgtypedef 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 {
71f7df2e56Smrg    PICT_a2r10g10b10 = PIXMAN_a2r10g10b10,
72f7df2e56Smrg    PICT_x2r10g10b10 = PIXMAN_x2r10g10b10,
73f7df2e56Smrg    PICT_a2b10g10r10 = PIXMAN_a2b10g10r10,
74f7df2e56Smrg    PICT_x2b10g10r10 = PIXMAN_x2b10g10r10,
75f7df2e56Smrg
76f7df2e56Smrg    PICT_a8r8g8b8 = PIXMAN_a8r8g8b8,
77f7df2e56Smrg    PICT_x8r8g8b8 = PIXMAN_x8r8g8b8,
78f7df2e56Smrg    PICT_a8b8g8r8 = PIXMAN_a8b8g8r8,
79f7df2e56Smrg    PICT_x8b8g8r8 = PIXMAN_x8b8g8r8,
80f7df2e56Smrg    PICT_b8g8r8a8 = PIXMAN_b8g8r8a8,
81f7df2e56Smrg    PICT_b8g8r8x8 = PIXMAN_b8g8r8x8,
8205b261ecSmrg
8305b261ecSmrg/* 24bpp formats */
84f7df2e56Smrg    PICT_r8g8b8 = PIXMAN_r8g8b8,
85f7df2e56Smrg    PICT_b8g8r8 = PIXMAN_b8g8r8,
8605b261ecSmrg
8705b261ecSmrg/* 16bpp formats */
88f7df2e56Smrg    PICT_r5g6b5 = PIXMAN_r5g6b5,
89f7df2e56Smrg    PICT_b5g6r5 = PIXMAN_b5g6r5,
90f7df2e56Smrg
91f7df2e56Smrg    PICT_a1r5g5b5 = PIXMAN_a1r5g5b5,
92f7df2e56Smrg    PICT_x1r5g5b5 = PIXMAN_x1r5g5b5,
93f7df2e56Smrg    PICT_a1b5g5r5 = PIXMAN_a1b5g5r5,
94f7df2e56Smrg    PICT_x1b5g5r5 = PIXMAN_x1b5g5r5,
95f7df2e56Smrg    PICT_a4r4g4b4 = PIXMAN_a4r4g4b4,
96f7df2e56Smrg    PICT_x4r4g4b4 = PIXMAN_x4r4g4b4,
97f7df2e56Smrg    PICT_a4b4g4r4 = PIXMAN_a4b4g4r4,
98f7df2e56Smrg    PICT_x4b4g4r4 = PIXMAN_x4b4g4r4,
9905b261ecSmrg
10005b261ecSmrg/* 8bpp formats */
101f7df2e56Smrg    PICT_a8 = PIXMAN_a8,
102f7df2e56Smrg    PICT_r3g3b2 = PIXMAN_r3g3b2,
103f7df2e56Smrg    PICT_b2g3r3 = PIXMAN_b2g3r3,
104f7df2e56Smrg    PICT_a2r2g2b2 = PIXMAN_a2r2g2b2,
105f7df2e56Smrg    PICT_a2b2g2r2 = PIXMAN_a2b2g2r2,
10605b261ecSmrg
107f7df2e56Smrg    PICT_c8 = PIXMAN_c8,
108f7df2e56Smrg    PICT_g8 = PIXMAN_g8,
10905b261ecSmrg
110f7df2e56Smrg    PICT_x4a4 = PIXMAN_x4a4,
111f7df2e56Smrg
112f7df2e56Smrg    PICT_x4c4 = PIXMAN_x4c4,
113f7df2e56Smrg    PICT_x4g4 = PIXMAN_x4g4,
11405b261ecSmrg
11505b261ecSmrg/* 4bpp formats */
116f7df2e56Smrg    PICT_a4 = PIXMAN_a4,
117f7df2e56Smrg    PICT_r1g2b1 = PIXMAN_r1g2b1,
118f7df2e56Smrg    PICT_b1g2r1 = PIXMAN_b1g2r1,
119f7df2e56Smrg    PICT_a1r1g1b1 = PIXMAN_a1r1g1b1,
120f7df2e56Smrg    PICT_a1b1g1r1 = PIXMAN_a1b1g1r1,
121f7df2e56Smrg
122f7df2e56Smrg    PICT_c4 = PIXMAN_c4,
123f7df2e56Smrg    PICT_g4 = PIXMAN_g4,
12405b261ecSmrg
12505b261ecSmrg/* 1bpp formats */
126f7df2e56Smrg    PICT_a1 = PIXMAN_a1,
12705b261ecSmrg
128f7df2e56Smrg    PICT_g1 = PIXMAN_g1
12905b261ecSmrg} PictFormatShort;
13005b261ecSmrg
13105b261ecSmrg/*
132f7df2e56Smrg * 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.
163f7df2e56Smrg */
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
172f7df2e56Smrgextern int PictureCmapPolicy;
17305b261ecSmrg
174f7df2e56Smrgextern int PictureParseCmapPolicy(const char *name);
17505b261ecSmrg
176f7df2e56Smrgextern int RenderErrBase;
17705b261ecSmrg
17805b261ecSmrg/* Fixed point updates from Carl Worth, USC, Information Sciences Institute */
17905b261ecSmrg
180f7df2e56Smrgtypedef pixman_fixed_32_32_t xFixed_32_32;
18105b261ecSmrg
182f7df2e56Smrgtypedef 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
187f7df2e56Smrgtypedef pixman_fixed_1_31_t xFixed_1_31;
188f7df2e56Smrgtypedef pixman_fixed_1_16_t xFixed_1_16;
189f7df2e56Smrgtypedef pixman_fixed_16_16_t xFixed_16_16;
19005b261ecSmrg
19105b261ecSmrg/*
192f7df2e56Smrg * An unadorned "xFixed" is the same as xFixed_16_16,
193f7df2e56Smrg * (since it's quite common in the code)
19405b261ecSmrg */
195f7df2e56Smrgtypedef pixman_fixed_t xFixed;
196f7df2e56Smrg
19705b261ecSmrg#define XFIXED_BITS	16
19805b261ecSmrg
19905b261ecSmrg#define xFixedToInt(f)	pixman_fixed_to_int(f)
20005b261ecSmrg#define IntToxFixed(i)	pixman_int_to_fixed(i)
20105b261ecSmrg#define xFixedE		pixman_fixed_e
20205b261ecSmrg#define xFixed1		pixman_fixed_1
20305b261ecSmrg#define xFixed1MinusE	pixman_fixed_1_minus_e
20405b261ecSmrg#define xFixedFrac(f)	pixman_fixed_frac(f)
20505b261ecSmrg#define xFixedFloor(f)	pixman_fixed_floor(f)
20605b261ecSmrg#define xFixedCeil(f)	pixman_fixed_ceil(f)
20705b261ecSmrg
20805b261ecSmrg#define xFixedFraction(f)	pixman_fixed_fraction(f)
20905b261ecSmrg#define xFixedMod2(f)		pixman_fixed_mod2(f)
21005b261ecSmrg
21105b261ecSmrg/* whether 't' is a well defined not obviously empty trapezoid */
21205b261ecSmrg#define xTrapezoidValid(t)  ((t)->left.p1.y != (t)->left.p2.y && \
21305b261ecSmrg			     (t)->right.p1.y != (t)->right.p2.y && \
21490fc26f8Smrg			     ((t)->bottom > (t)->top))
21505b261ecSmrg
21605b261ecSmrg/*
21705b261ecSmrg * Standard NTSC luminance conversions:
21805b261ecSmrg *
21905b261ecSmrg *  y = r * 0.299 + g * 0.587 + b * 0.114
22005b261ecSmrg *
22105b261ecSmrg * Approximate this for a bit more speed:
22205b261ecSmrg *
22305b261ecSmrg *  y = (r * 153 + g * 301 + b * 58) / 512
22405b261ecSmrg *
22505b261ecSmrg * This gives 17 bits of luminance; to get 15 bits, lop the low two
22605b261ecSmrg */
22705b261ecSmrg
22805b261ecSmrg#define CvtR8G8B8toY15(s)	(((((s) >> 16) & 0xff) * 153 + \
22905b261ecSmrg				  (((s) >>  8) & 0xff) * 301 + \
23005b261ecSmrg				  (((s)      ) & 0xff) * 58) >> 2)
23105b261ecSmrg
232f7df2e56Smrg#endif                          /* _PICTURE_H_ */
233