pixman-utils.c revision 27693ee9
1b4b94579Smrg/*
2b4b94579Smrg * Copyright © 2000 SuSE, Inc.
3b4b94579Smrg *
4b4b94579Smrg * Permission to use, copy, modify, distribute, and sell this software and its
5b4b94579Smrg * documentation for any purpose is hereby granted without fee, provided that
6b4b94579Smrg * the above copyright notice appear in all copies and that both that
7b4b94579Smrg * copyright notice and this permission notice appear in supporting
8b4b94579Smrg * documentation, and that the name of SuSE not be used in advertising or
9b4b94579Smrg * publicity pertaining to distribution of the software without specific,
10b4b94579Smrg * written prior permission.  SuSE makes no representations about the
11b4b94579Smrg * suitability of this software for any purpose.  It is provided "as is"
12b4b94579Smrg * without express or implied warranty.
13b4b94579Smrg *
14b4b94579Smrg * SuSE DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL
15b4b94579Smrg * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL SuSE
16b4b94579Smrg * BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
17b4b94579Smrg * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
18b4b94579Smrg * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
19b4b94579Smrg * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
20b4b94579Smrg *
21b4b94579Smrg * Author:  Keith Packard, SuSE, Inc.
22b4b94579Smrg */
23b4b94579Smrg
24b4b94579Smrg#ifdef HAVE_CONFIG_H
25b4b94579Smrg#include <config.h>
26b4b94579Smrg#endif
27b4b94579Smrg
28b4b94579Smrg#include <stdlib.h>
29b4b94579Smrg
30b4b94579Smrg#include "pixman-private.h"
31b4b94579Smrg#include "pixman-mmx.h"
32b4b94579Smrg
33b4b94579SmrgPIXMAN_EXPORT pixman_bool_t
34b4b94579Smrgpixman_transform_point_3d (pixman_transform_t *transform,
35b4b94579Smrg			   pixman_vector_t *vector)
36b4b94579Smrg{
37b4b94579Smrg    pixman_vector_t		result;
38b4b94579Smrg    int				i, j;
39b4b94579Smrg    pixman_fixed_32_32_t	partial;
40b4b94579Smrg    pixman_fixed_48_16_t	v;
41b4b94579Smrg
42b4b94579Smrg    for (j = 0; j < 3; j++)
43b4b94579Smrg    {
44b4b94579Smrg	v = 0;
45b4b94579Smrg	for (i = 0; i < 3; i++)
46b4b94579Smrg	{
47b4b94579Smrg	    partial = ((pixman_fixed_48_16_t) transform->matrix[j][i] *
48b4b94579Smrg		       (pixman_fixed_48_16_t) vector->vector[i]);
49b4b94579Smrg	    v += partial >> 16;
50b4b94579Smrg	}
51b4b94579Smrg
52b4b94579Smrg	if (v > pixman_max_fixed_48_16 || v < pixman_min_fixed_48_16)
53b4b94579Smrg	    return FALSE;
54b4b94579Smrg
55b4b94579Smrg	result.vector[j] = (pixman_fixed_48_16_t) v;
56b4b94579Smrg    }
57b4b94579Smrg
58b4b94579Smrg    if (!result.vector[2])
59b4b94579Smrg	return FALSE;
60b4b94579Smrg
61b4b94579Smrg    *vector = result;
62b4b94579Smrg    return TRUE;
63b4b94579Smrg}
64b4b94579Smrg
65b4b94579SmrgPIXMAN_EXPORT pixman_bool_t
66b4b94579Smrgpixman_blt (uint32_t *src_bits,
67b4b94579Smrg	    uint32_t *dst_bits,
68b4b94579Smrg	    int src_stride,
69b4b94579Smrg	    int dst_stride,
70b4b94579Smrg	    int src_bpp,
71b4b94579Smrg	    int dst_bpp,
72b4b94579Smrg	    int src_x, int src_y,
73b4b94579Smrg	    int dst_x, int dst_y,
74b4b94579Smrg	    int width, int height)
75b4b94579Smrg{
76b4b94579Smrg#ifdef USE_MMX
77b4b94579Smrg    if (pixman_have_mmx())
78b4b94579Smrg    {
79b4b94579Smrg	return pixman_blt_mmx (src_bits, dst_bits, src_stride, dst_stride, src_bpp, dst_bpp,
80b4b94579Smrg			       src_x, src_y, dst_x, dst_y, width, height);
81b4b94579Smrg    }
82b4b94579Smrg    else
83b4b94579Smrg#endif
84b4b94579Smrg	return FALSE;
85b4b94579Smrg}
86b4b94579Smrg
87b4b94579Smrgstatic void
88b4b94579Smrgpixman_fill8 (uint32_t  *bits,
89b4b94579Smrg	      int	stride,
90b4b94579Smrg	      int	x,
91b4b94579Smrg	      int	y,
92b4b94579Smrg	      int	width,
93b4b94579Smrg	      int	height,
94b4b94579Smrg	      uint32_t  xor)
95b4b94579Smrg{
96b4b94579Smrg    int byte_stride = stride * (int) sizeof (uint32_t);
97b4b94579Smrg    uint8_t *dst = (uint8_t *) bits;
98b4b94579Smrg    uint8_t v = xor & 0xff;
99b4b94579Smrg    int i;
100b4b94579Smrg
101b4b94579Smrg    dst = dst + y * byte_stride + x;
102b4b94579Smrg
103b4b94579Smrg    while (height--)
104b4b94579Smrg    {
105b4b94579Smrg	for (i = 0; i < width; ++i)
106b4b94579Smrg	    dst[i] = v;
107b4b94579Smrg
108b4b94579Smrg	dst += byte_stride;
109b4b94579Smrg    }
110b4b94579Smrg}
111b4b94579Smrg
112b4b94579Smrgstatic void
113b4b94579Smrgpixman_fill16 (uint32_t *bits,
114b4b94579Smrg	       int       stride,
115b4b94579Smrg	       int       x,
116b4b94579Smrg	       int       y,
117b4b94579Smrg	       int       width,
118b4b94579Smrg	       int       height,
119b4b94579Smrg	       uint32_t  xor)
120b4b94579Smrg{
121b4b94579Smrg    int short_stride = (stride * (int) sizeof (uint32_t)) / (int) sizeof (uint16_t);
122b4b94579Smrg    uint16_t *dst = (uint16_t *)bits;
123b4b94579Smrg    uint16_t v = xor & 0xffff;
124b4b94579Smrg    int i;
125b4b94579Smrg
126b4b94579Smrg    dst = dst + y * short_stride + x;
127b4b94579Smrg
128b4b94579Smrg    while (height--)
129b4b94579Smrg    {
130b4b94579Smrg	for (i = 0; i < width; ++i)
131b4b94579Smrg	    dst[i] = v;
132b4b94579Smrg
133b4b94579Smrg	dst += short_stride;
134b4b94579Smrg    }
135b4b94579Smrg}
136b4b94579Smrg
137b4b94579Smrgstatic void
138b4b94579Smrgpixman_fill32 (uint32_t *bits,
139b4b94579Smrg	       int       stride,
140b4b94579Smrg	       int       x,
141b4b94579Smrg	       int       y,
142b4b94579Smrg	       int       width,
143b4b94579Smrg	       int       height,
144b4b94579Smrg	       uint32_t  xor)
145b4b94579Smrg{
146b4b94579Smrg    int i;
147b4b94579Smrg
148b4b94579Smrg    bits = bits + y * stride + x;
149b4b94579Smrg
150b4b94579Smrg    while (height--)
151b4b94579Smrg    {
152b4b94579Smrg	for (i = 0; i < width; ++i)
153b4b94579Smrg	    bits[i] = xor;
154b4b94579Smrg
155b4b94579Smrg	bits += stride;
156b4b94579Smrg    }
157b4b94579Smrg}
158b4b94579Smrg
159b4b94579SmrgPIXMAN_EXPORT pixman_bool_t
160b4b94579Smrgpixman_fill (uint32_t *bits,
161b4b94579Smrg	     int stride,
162b4b94579Smrg	     int bpp,
163b4b94579Smrg	     int x,
164b4b94579Smrg	     int y,
165b4b94579Smrg	     int width,
166b4b94579Smrg	     int height,
167b4b94579Smrg	     uint32_t xor)
168b4b94579Smrg{
169b4b94579Smrg#if 0
170b4b94579Smrg    printf ("filling: %d %d %d %d (stride: %d, bpp: %d)   pixel: %x\n",
171b4b94579Smrg	    x, y, width, height, stride, bpp, xor);
172b4b94579Smrg#endif
173b4b94579Smrg
174b4b94579Smrg#ifdef USE_MMX
175b4b94579Smrg    if (!pixman_have_mmx() || !pixman_fill_mmx (bits, stride, bpp, x, y, width, height, xor))
176b4b94579Smrg#endif
177b4b94579Smrg    {
178b4b94579Smrg	switch (bpp)
179b4b94579Smrg	{
180b4b94579Smrg	case 8:
181b4b94579Smrg	    pixman_fill8 (bits, stride, x, y, width, height, xor);
182b4b94579Smrg	    break;
183b4b94579Smrg
184b4b94579Smrg	case 16:
185b4b94579Smrg	    pixman_fill16 (bits, stride, x, y, width, height, xor);
186b4b94579Smrg	    break;
187b4b94579Smrg
188b4b94579Smrg	case 32:
189b4b94579Smrg	    pixman_fill32 (bits, stride, x, y, width, height, xor);
190b4b94579Smrg	    break;
191b4b94579Smrg
192b4b94579Smrg	default:
193b4b94579Smrg	    return FALSE;
194b4b94579Smrg	    break;
195b4b94579Smrg	}
196b4b94579Smrg    }
197b4b94579Smrg
198b4b94579Smrg    return TRUE;
199b4b94579Smrg}
200b4b94579Smrg
201b4b94579Smrg
202b4b94579Smrg/*
203b4b94579Smrg * Compute the smallest value no less than y which is on a
204b4b94579Smrg * grid row
205b4b94579Smrg */
206b4b94579Smrg
207b4b94579SmrgPIXMAN_EXPORT pixman_fixed_t
208b4b94579Smrgpixman_sample_ceil_y (pixman_fixed_t y, int n)
209b4b94579Smrg{
210b4b94579Smrg    pixman_fixed_t   f = pixman_fixed_frac(y);
211b4b94579Smrg    pixman_fixed_t   i = pixman_fixed_floor(y);
212b4b94579Smrg
213b4b94579Smrg    f = ((f + Y_FRAC_FIRST(n)) / STEP_Y_SMALL(n)) * STEP_Y_SMALL(n) + Y_FRAC_FIRST(n);
214b4b94579Smrg    if (f > Y_FRAC_LAST(n))
215b4b94579Smrg    {
216b4b94579Smrg	f = Y_FRAC_FIRST(n);
217b4b94579Smrg	i += pixman_fixed_1;
218b4b94579Smrg    }
219b4b94579Smrg    return (i | f);
220b4b94579Smrg}
221b4b94579Smrg
222b4b94579Smrg#define _div(a,b)    ((a) >= 0 ? (a) / (b) : -((-(a) + (b) - 1) / (b)))
223b4b94579Smrg
224b4b94579Smrg/*
225b4b94579Smrg * Compute the largest value no greater than y which is on a
226b4b94579Smrg * grid row
227b4b94579Smrg */
228b4b94579SmrgPIXMAN_EXPORT pixman_fixed_t
229b4b94579Smrgpixman_sample_floor_y (pixman_fixed_t y, int n)
230b4b94579Smrg{
231b4b94579Smrg    pixman_fixed_t   f = pixman_fixed_frac(y);
232b4b94579Smrg    pixman_fixed_t   i = pixman_fixed_floor (y);
233b4b94579Smrg
234b4b94579Smrg    f = _div(f - Y_FRAC_FIRST(n), STEP_Y_SMALL(n)) * STEP_Y_SMALL(n) + Y_FRAC_FIRST(n);
235b4b94579Smrg    if (f < Y_FRAC_FIRST(n))
236b4b94579Smrg    {
237b4b94579Smrg	f = Y_FRAC_LAST(n);
238b4b94579Smrg	i -= pixman_fixed_1;
239b4b94579Smrg    }
240b4b94579Smrg    return (i | f);
241b4b94579Smrg}
242b4b94579Smrg
243b4b94579Smrg/*
244b4b94579Smrg * Step an edge by any amount (including negative values)
245b4b94579Smrg */
246b4b94579SmrgPIXMAN_EXPORT void
247b4b94579Smrgpixman_edge_step (pixman_edge_t *e, int n)
248b4b94579Smrg{
249b4b94579Smrg    pixman_fixed_48_16_t	ne;
250b4b94579Smrg
251b4b94579Smrg    e->x += n * e->stepx;
252b4b94579Smrg
253b4b94579Smrg    ne = e->e + n * (pixman_fixed_48_16_t) e->dx;
254b4b94579Smrg
255b4b94579Smrg    if (n >= 0)
256b4b94579Smrg    {
257b4b94579Smrg	if (ne > 0)
258b4b94579Smrg	{
259b4b94579Smrg	    int nx = (ne + e->dy - 1) / e->dy;
260b4b94579Smrg	    e->e = ne - nx * (pixman_fixed_48_16_t) e->dy;
261b4b94579Smrg	    e->x += nx * e->signdx;
262b4b94579Smrg	}
263b4b94579Smrg    }
264b4b94579Smrg    else
265b4b94579Smrg    {
266b4b94579Smrg	if (ne <= -e->dy)
267b4b94579Smrg	{
268b4b94579Smrg	    int nx = (-ne) / e->dy;
269b4b94579Smrg	    e->e = ne + nx * (pixman_fixed_48_16_t) e->dy;
270b4b94579Smrg	    e->x -= nx * e->signdx;
271b4b94579Smrg	}
272b4b94579Smrg    }
273b4b94579Smrg}
274b4b94579Smrg
275b4b94579Smrg/*
276b4b94579Smrg * A private routine to initialize the multi-step
277b4b94579Smrg * elements of an edge structure
278b4b94579Smrg */
279b4b94579Smrgstatic void
280b4b94579Smrg_pixman_edge_tMultiInit (pixman_edge_t *e, int n, pixman_fixed_t *stepx_p, pixman_fixed_t *dx_p)
281b4b94579Smrg{
282b4b94579Smrg    pixman_fixed_t	stepx;
283b4b94579Smrg    pixman_fixed_48_16_t	ne;
284b4b94579Smrg
285b4b94579Smrg    ne = n * (pixman_fixed_48_16_t) e->dx;
286b4b94579Smrg    stepx = n * e->stepx;
287b4b94579Smrg    if (ne > 0)
288b4b94579Smrg    {
289b4b94579Smrg	int nx = ne / e->dy;
290b4b94579Smrg	ne -= nx * e->dy;
291b4b94579Smrg	stepx += nx * e->signdx;
292b4b94579Smrg    }
293b4b94579Smrg    *dx_p = ne;
294b4b94579Smrg    *stepx_p = stepx;
295b4b94579Smrg}
296b4b94579Smrg
297b4b94579Smrg/*
298b4b94579Smrg * Initialize one edge structure given the line endpoints and a
299b4b94579Smrg * starting y value
300b4b94579Smrg */
301b4b94579SmrgPIXMAN_EXPORT void
302b4b94579Smrgpixman_edge_init (pixman_edge_t	*e,
303b4b94579Smrg		  int		n,
304b4b94579Smrg		  pixman_fixed_t		y_start,
305b4b94579Smrg		  pixman_fixed_t		x_top,
306b4b94579Smrg		  pixman_fixed_t		y_top,
307b4b94579Smrg		  pixman_fixed_t		x_bot,
308b4b94579Smrg		  pixman_fixed_t		y_bot)
309b4b94579Smrg{
310b4b94579Smrg    pixman_fixed_t	dx, dy;
311b4b94579Smrg
312b4b94579Smrg    e->x = x_top;
313b4b94579Smrg    e->e = 0;
314b4b94579Smrg    dx = x_bot - x_top;
315b4b94579Smrg    dy = y_bot - y_top;
316b4b94579Smrg    e->dy = dy;
317b4b94579Smrg    e->dx = 0;
318b4b94579Smrg    if (dy)
319b4b94579Smrg    {
320b4b94579Smrg	if (dx >= 0)
321b4b94579Smrg	{
322b4b94579Smrg	    e->signdx = 1;
323b4b94579Smrg	    e->stepx = dx / dy;
324b4b94579Smrg	    e->dx = dx % dy;
325b4b94579Smrg	    e->e = -dy;
326b4b94579Smrg	}
327b4b94579Smrg	else
328b4b94579Smrg	{
329b4b94579Smrg	    e->signdx = -1;
330b4b94579Smrg	    e->stepx = -(-dx / dy);
331b4b94579Smrg	    e->dx = -dx % dy;
332b4b94579Smrg	    e->e = 0;
333b4b94579Smrg	}
334b4b94579Smrg
335b4b94579Smrg	_pixman_edge_tMultiInit (e, STEP_Y_SMALL(n), &e->stepx_small, &e->dx_small);
336b4b94579Smrg	_pixman_edge_tMultiInit (e, STEP_Y_BIG(n), &e->stepx_big, &e->dx_big);
337b4b94579Smrg    }
338b4b94579Smrg    pixman_edge_step (e, y_start - y_top);
339b4b94579Smrg}
340b4b94579Smrg
341b4b94579Smrg/*
342b4b94579Smrg * Initialize one edge structure given a line, starting y value
343b4b94579Smrg * and a pixel offset for the line
344b4b94579Smrg */
345b4b94579SmrgPIXMAN_EXPORT void
346b4b94579Smrgpixman_line_fixed_edge_init (pixman_edge_t *e,
347b4b94579Smrg			     int	    n,
348b4b94579Smrg			     pixman_fixed_t	    y,
349b4b94579Smrg			     const pixman_line_fixed_t *line,
350b4b94579Smrg			     int	    x_off,
351b4b94579Smrg			     int	    y_off)
352b4b94579Smrg{
353b4b94579Smrg    pixman_fixed_t	x_off_fixed = pixman_int_to_fixed(x_off);
354b4b94579Smrg    pixman_fixed_t	y_off_fixed = pixman_int_to_fixed(y_off);
355b4b94579Smrg    const pixman_point_fixed_t *top, *bot;
356b4b94579Smrg
357b4b94579Smrg    if (line->p1.y <= line->p2.y)
358b4b94579Smrg    {
359b4b94579Smrg	top = &line->p1;
360b4b94579Smrg	bot = &line->p2;
361b4b94579Smrg    }
362b4b94579Smrg    else
363b4b94579Smrg    {
364b4b94579Smrg	top = &line->p2;
365b4b94579Smrg	bot = &line->p1;
366b4b94579Smrg    }
367b4b94579Smrg    pixman_edge_init (e, n, y,
368b4b94579Smrg		    top->x + x_off_fixed,
369b4b94579Smrg		    top->y + y_off_fixed,
370b4b94579Smrg		    bot->x + x_off_fixed,
371b4b94579Smrg		    bot->y + y_off_fixed);
372b4b94579Smrg}
373b4b94579Smrg
374b4b94579Smrgpixman_bool_t
375b4b94579Smrgpixman_multiply_overflows_int (unsigned int a,
376b4b94579Smrg		               unsigned int b)
377b4b94579Smrg{
378b4b94579Smrg    return a >= INT32_MAX / b;
379b4b94579Smrg}
380b4b94579Smrg
381b4b94579Smrgpixman_bool_t
382b4b94579Smrgpixman_addition_overflows_int (unsigned int a,
383b4b94579Smrg		               unsigned int b)
384b4b94579Smrg{
385b4b94579Smrg    return a > INT32_MAX - b;
386b4b94579Smrg}
387b4b94579Smrg
388b4b94579Smrgvoid *
389b4b94579Smrgpixman_malloc_ab(unsigned int a,
390b4b94579Smrg		 unsigned int b)
391b4b94579Smrg{
392b4b94579Smrg    if (a >= INT32_MAX / b)
393b4b94579Smrg	return NULL;
394b4b94579Smrg
395b4b94579Smrg    return malloc (a * b);
396b4b94579Smrg}
397b4b94579Smrg
398b4b94579Smrgvoid *
399b4b94579Smrgpixman_malloc_abc (unsigned int a,
400b4b94579Smrg		   unsigned int b,
401b4b94579Smrg		   unsigned int c)
402b4b94579Smrg{
403b4b94579Smrg    if (a >= INT32_MAX / b)
404b4b94579Smrg	return NULL;
405b4b94579Smrg    else if (a * b >= INT32_MAX / c)
406b4b94579Smrg	return NULL;
407b4b94579Smrg    else
408b4b94579Smrg	return malloc (a * b * c);
409b4b94579Smrg}
410b4b94579Smrg
411b4b94579Smrg
412b4b94579Smrg/**
413b4b94579Smrg * pixman_version:
414b4b94579Smrg *
415b4b94579Smrg * Returns the version of the pixman library encoded in a single
416b4b94579Smrg * integer as per %PIXMAN_VERSION_ENCODE. The encoding ensures that
417b4b94579Smrg * later versions compare greater than earlier versions.
418b4b94579Smrg *
419b4b94579Smrg * A run-time comparison to check that pixman's version is greater than
420b4b94579Smrg * or equal to version X.Y.Z could be performed as follows:
421b4b94579Smrg *
422b4b94579Smrg * <informalexample><programlisting>
423b4b94579Smrg * if (pixman_version() >= PIXMAN_VERSION_ENCODE(X,Y,Z)) {...}
424b4b94579Smrg * </programlisting></informalexample>
425b4b94579Smrg *
426b4b94579Smrg * See also pixman_version_string() as well as the compile-time
427b4b94579Smrg * equivalents %PIXMAN_VERSION and %PIXMAN_VERSION_STRING.
428b4b94579Smrg *
429b4b94579Smrg * Return value: the encoded version.
430b4b94579Smrg **/
431b4b94579SmrgPIXMAN_EXPORT int
432b4b94579Smrgpixman_version (void)
433b4b94579Smrg{
434b4b94579Smrg    return PIXMAN_VERSION;
435b4b94579Smrg}
436b4b94579Smrg
437b4b94579Smrg/**
438b4b94579Smrg * pixman_version_string:
439b4b94579Smrg *
440b4b94579Smrg * Returns the version of the pixman library as a human-readable string
441b4b94579Smrg * of the form "X.Y.Z".
442b4b94579Smrg *
443b4b94579Smrg * See also pixman_version() as well as the compile-time equivalents
444b4b94579Smrg * %PIXMAN_VERSION_STRING and %PIXMAN_VERSION.
445b4b94579Smrg *
446b4b94579Smrg * Return value: a string containing the version.
447b4b94579Smrg **/
448b4b94579SmrgPIXMAN_EXPORT const char*
449b4b94579Smrgpixman_version_string (void)
450b4b94579Smrg{
451b4b94579Smrg    return PIXMAN_VERSION_STRING;
452b4b94579Smrg}
453b4b94579Smrg
454b4b94579Smrg/**
455b4b94579Smrg * pixman_format_supported_destination:
456b4b94579Smrg * @format: A pixman_format_code_t format
457b4b94579Smrg *
458b4b94579Smrg * Return value: whether the provided format code is a supported
459b4b94579Smrg * format for a pixman surface used as a destination in
460b4b94579Smrg * rendering.
461b4b94579Smrg *
462b4b94579Smrg * Currently, all pixman_format_code_t values are supported
463b4b94579Smrg * except for the YUV formats.
464b4b94579Smrg **/
465b4b94579SmrgPIXMAN_EXPORT pixman_bool_t
466b4b94579Smrgpixman_format_supported_destination (pixman_format_code_t format)
467b4b94579Smrg{
468b4b94579Smrg    switch (format) {
469b4b94579Smrg    /* 32 bpp formats */
47027693ee9Sveego    case PIXMAN_a2b10g10r10:
47127693ee9Sveego    case PIXMAN_x2b10g10r10:
472b4b94579Smrg    case PIXMAN_a8r8g8b8:
473b4b94579Smrg    case PIXMAN_x8r8g8b8:
474b4b94579Smrg    case PIXMAN_a8b8g8r8:
475b4b94579Smrg    case PIXMAN_x8b8g8r8:
476b4b94579Smrg    case PIXMAN_r8g8b8:
477b4b94579Smrg    case PIXMAN_b8g8r8:
478b4b94579Smrg    case PIXMAN_r5g6b5:
479b4b94579Smrg    case PIXMAN_b5g6r5:
480b4b94579Smrg    /* 16 bpp formats */
481b4b94579Smrg    case PIXMAN_a1r5g5b5:
482b4b94579Smrg    case PIXMAN_x1r5g5b5:
483b4b94579Smrg    case PIXMAN_a1b5g5r5:
484b4b94579Smrg    case PIXMAN_x1b5g5r5:
485b4b94579Smrg    case PIXMAN_a4r4g4b4:
486b4b94579Smrg    case PIXMAN_x4r4g4b4:
487b4b94579Smrg    case PIXMAN_a4b4g4r4:
488b4b94579Smrg    case PIXMAN_x4b4g4r4:
489b4b94579Smrg    /* 8bpp formats */
490b4b94579Smrg    case PIXMAN_a8:
491b4b94579Smrg    case PIXMAN_r3g3b2:
492b4b94579Smrg    case PIXMAN_b2g3r3:
493b4b94579Smrg    case PIXMAN_a2r2g2b2:
494b4b94579Smrg    case PIXMAN_a2b2g2r2:
495b4b94579Smrg    case PIXMAN_c8:
496b4b94579Smrg    case PIXMAN_g8:
497b4b94579Smrg    case PIXMAN_x4a4:
498b4b94579Smrg    /* Collides with PIXMAN_c8
499b4b94579Smrg    case PIXMAN_x4c4:
500b4b94579Smrg    */
501b4b94579Smrg    /* Collides with PIXMAN_g8
502b4b94579Smrg    case PIXMAN_x4g4:
503b4b94579Smrg    */
504b4b94579Smrg    /* 4bpp formats */
505b4b94579Smrg    case PIXMAN_a4:
506b4b94579Smrg    case PIXMAN_r1g2b1:
507b4b94579Smrg    case PIXMAN_b1g2r1:
508b4b94579Smrg    case PIXMAN_a1r1g1b1:
509b4b94579Smrg    case PIXMAN_a1b1g1r1:
510b4b94579Smrg    case PIXMAN_c4:
511b4b94579Smrg    case PIXMAN_g4:
512b4b94579Smrg    /* 1bpp formats */
513b4b94579Smrg    case PIXMAN_a1:
514b4b94579Smrg    case PIXMAN_g1:
515b4b94579Smrg	return TRUE;
516b4b94579Smrg
517b4b94579Smrg    /* YUV formats */
518b4b94579Smrg    case PIXMAN_yuy2:
519b4b94579Smrg    case PIXMAN_yv12:
520b4b94579Smrg    default:
521b4b94579Smrg	return FALSE;
522b4b94579Smrg    }
523b4b94579Smrg}
524b4b94579Smrg
525b4b94579Smrg/**
526b4b94579Smrg * pixman_format_supported_source:
527b4b94579Smrg * @format: A pixman_format_code_t format
528b4b94579Smrg *
529b4b94579Smrg * Return value: whether the provided format code is a supported
530b4b94579Smrg * format for a pixman surface used as a source in
531b4b94579Smrg * rendering.
532b4b94579Smrg *
533b4b94579Smrg * Currently, all pixman_format_code_t values are supported.
534b4b94579Smrg **/
535b4b94579SmrgPIXMAN_EXPORT pixman_bool_t
536b4b94579Smrgpixman_format_supported_source (pixman_format_code_t format)
537b4b94579Smrg{
538b4b94579Smrg    switch (format) {
539b4b94579Smrg    /* 32 bpp formats */
54027693ee9Sveego    case PIXMAN_a2b10g10r10:
54127693ee9Sveego    case PIXMAN_x2b10g10r10:
542b4b94579Smrg    case PIXMAN_a8r8g8b8:
543b4b94579Smrg    case PIXMAN_x8r8g8b8:
544b4b94579Smrg    case PIXMAN_a8b8g8r8:
545b4b94579Smrg    case PIXMAN_x8b8g8r8:
546b4b94579Smrg    case PIXMAN_r8g8b8:
547b4b94579Smrg    case PIXMAN_b8g8r8:
548b4b94579Smrg    case PIXMAN_r5g6b5:
549b4b94579Smrg    case PIXMAN_b5g6r5:
550b4b94579Smrg    /* 16 bpp formats */
551b4b94579Smrg    case PIXMAN_a1r5g5b5:
552b4b94579Smrg    case PIXMAN_x1r5g5b5:
553b4b94579Smrg    case PIXMAN_a1b5g5r5:
554b4b94579Smrg    case PIXMAN_x1b5g5r5:
555b4b94579Smrg    case PIXMAN_a4r4g4b4:
556b4b94579Smrg    case PIXMAN_x4r4g4b4:
557b4b94579Smrg    case PIXMAN_a4b4g4r4:
558b4b94579Smrg    case PIXMAN_x4b4g4r4:
559b4b94579Smrg    /* 8bpp formats */
560b4b94579Smrg    case PIXMAN_a8:
561b4b94579Smrg    case PIXMAN_r3g3b2:
562b4b94579Smrg    case PIXMAN_b2g3r3:
563b4b94579Smrg    case PIXMAN_a2r2g2b2:
564b4b94579Smrg    case PIXMAN_a2b2g2r2:
565b4b94579Smrg    case PIXMAN_c8:
566b4b94579Smrg    case PIXMAN_g8:
567b4b94579Smrg    case PIXMAN_x4a4:
568b4b94579Smrg    /* Collides with PIXMAN_c8
569b4b94579Smrg    case PIXMAN_x4c4:
570b4b94579Smrg    */
571b4b94579Smrg    /* Collides with PIXMAN_g8
572b4b94579Smrg    case PIXMAN_x4g4:
573b4b94579Smrg    */
574b4b94579Smrg    /* 4bpp formats */
575b4b94579Smrg    case PIXMAN_a4:
576b4b94579Smrg    case PIXMAN_r1g2b1:
577b4b94579Smrg    case PIXMAN_b1g2r1:
578b4b94579Smrg    case PIXMAN_a1r1g1b1:
579b4b94579Smrg    case PIXMAN_a1b1g1r1:
580b4b94579Smrg    case PIXMAN_c4:
581b4b94579Smrg    case PIXMAN_g4:
582b4b94579Smrg    /* 1bpp formats */
583b4b94579Smrg    case PIXMAN_a1:
584b4b94579Smrg    case PIXMAN_g1:
585b4b94579Smrg    /* YUV formats */
586b4b94579Smrg    case PIXMAN_yuy2:
587b4b94579Smrg    case PIXMAN_yv12:
588b4b94579Smrg	return TRUE;
589b4b94579Smrg
590b4b94579Smrg    default:
591b4b94579Smrg	return FALSE;
592b4b94579Smrg    }
593b4b94579Smrg}
594