File: image_format.c

package info (click to toggle)
zapping 0.10~cvs6-2
  • links: PTS
  • area: main
  • in suites: lenny
  • size: 9,856 kB
  • ctags: 11,841
  • sloc: ansic: 111,154; asm: 11,770; sh: 9,812; xml: 2,742; makefile: 1,283; perl: 488
file content (121 lines) | stat: -rw-r--r-- 2,603 bytes parent folder | download | duplicates (8)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
/*
 *  libzvbi
 *
 *  Copyright (C) 2003, 2004 Michael H. Schimek
 *
 *  This program is free software; you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License version 2 as
 *  published by the Free Software Foundation.
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with this program; if not, write to the Free Software
 *  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 */

/* $Id: image_format.c,v 1.2 2005/01/08 14:54:20 mschimek Exp $ */

#include "image_format.h"

/**
 * @param pixfmt Pixel format.
 *
 * Returns the name of a pixel format like VBI3_PIXFMT_YUYV ->
 * "YUYV". This is mainly intended for debugging.
 * 
 * @return
 * Static ASCII string, NULL if @a pixfmt is invalid.
 */
const char *
vbi3_pixfmt_name			(vbi3_pixfmt		pixfmt)
{
	switch (pixfmt) {

#undef CASE
#define CASE(fmt) case VBI3_PIXFMT_##fmt : return #fmt ;

	CASE (NONE)
	CASE (YUV444)
	CASE (YVU444)
	CASE (YUV422)
	CASE (YVU422)
	CASE (YUV411)
	CASE (YVU411)
	CASE (YUV420)
	CASE (YVU420)
	CASE (YUV410)
	CASE (YVU410)
	CASE (YUVA24_LE)
	CASE (YUVA24_BE)
	CASE (YVUA24_LE)
	CASE (YVUA24_BE)
	CASE (YUV24_LE)
	CASE (YUV24_BE)
	CASE (YVU24_LE)
	CASE (YVU24_BE)
	CASE (YUYV)
	CASE (YVYU)
	CASE (UYVY)
	CASE (VYUY)
	CASE (Y8)
	CASE (RGBA24_LE)
	CASE (RGBA24_BE)
	CASE (BGRA24_LE)
	CASE (BGRA24_BE)
	CASE (RGB24_LE)
	CASE (BGR24_LE)
	CASE (RGB16_LE)
	CASE (RGB16_BE)
	CASE (BGR16_LE)
	CASE (BGR16_BE)
	CASE (RGBA15_LE)
	CASE (RGBA15_BE)
	CASE (BGRA15_LE)
	CASE (BGRA15_BE)
	CASE (ARGB15_LE)
	CASE (ARGB15_BE)
	CASE (ABGR15_LE)
	CASE (ABGR15_BE)
	CASE (RGBA12_LE)
	CASE (RGBA12_BE)
	CASE (BGRA12_LE)
	CASE (BGRA12_BE)
	CASE (ARGB12_LE)
	CASE (ARGB12_BE)
	CASE (ABGR12_LE)
	CASE (ABGR12_BE)
	CASE (RGB8)
	CASE (BGR8)
	CASE (RGBA7)
	CASE (BGRA7)
	CASE (ARGB7)
	CASE (ABGR7)

	case VBI3_PIXFMT_RESERVED0:
	case VBI3_PIXFMT_RESERVED1:
	case VBI3_PIXFMT_RESERVED2:
	case VBI3_PIXFMT_RESERVED3:
		break;

		/* No default, gcc warns. */
	}

	return NULL;
}

unsigned int
_vbi3_pixfmt_bytes_per_pixel	(vbi3_pixfmt		pixfmt)
{
	vbi3_pixfmt_set set = VBI3_PIXFMT_SET (pixfmt);

	if (set & (_VBI3_PIXFMT_SET_4 | _VBI3_PIXFMT_SET_3))
		return (set & _VBI3_PIXFMT_SET_4) ? 4 : 3;
	else if (set & (_VBI3_PIXFMT_SET_2 | _VBI3_PIXFMT_SET_1))
		return (set & _VBI3_PIXFMT_SET_2) ? 2 : 1;

	return 0;
}