29 typedef struct XPMContext {
47 {
"AliceBlue", 0xFFF0F8FF },
48 {
"AntiqueWhite", 0xFFFAEBD7 },
49 {
"Aqua", 0xFF00FFFF },
50 {
"Aquamarine", 0xFF7FFFD4 },
51 {
"Azure", 0xFFF0FFFF },
52 {
"Beige", 0xFFF5F5DC },
53 {
"Bisque", 0xFFFFE4C4 },
54 {
"Black", 0xFF000000 },
55 {
"BlanchedAlmond", 0xFFFFEBCD },
56 {
"Blue", 0xFF0000FF },
57 {
"BlueViolet", 0xFF8A2BE2 },
58 {
"Brown", 0xFFA52A2A },
59 {
"BurlyWood", 0xFFDEB887 },
60 {
"CadetBlue", 0xFF5F9EA0 },
61 {
"Chartreuse", 0xFF7FFF00 },
62 {
"Chocolate", 0xFFD2691E },
63 {
"Coral", 0xFFFF7F50 },
64 {
"CornflowerBlue", 0xFF6495ED },
65 {
"Cornsilk", 0xFFFFF8DC },
66 {
"Crimson", 0xFFDC143C },
67 {
"Cyan", 0xFF00FFFF },
68 {
"DarkBlue", 0xFF00008B },
69 {
"DarkCyan", 0xFF008B8B },
70 {
"DarkGoldenRod", 0xFFB8860B },
71 {
"DarkGray", 0xFFA9A9A9 },
72 {
"DarkGreen", 0xFF006400 },
73 {
"DarkKhaki", 0xFFBDB76B },
74 {
"DarkMagenta", 0xFF8B008B },
75 {
"DarkOliveGreen", 0xFF556B2F },
76 {
"Darkorange", 0xFFFF8C00 },
77 {
"DarkOrchid", 0xFF9932CC },
78 {
"DarkRed", 0xFF8B0000 },
79 {
"DarkSalmon", 0xFFE9967A },
80 {
"DarkSeaGreen", 0xFF8FBC8F },
81 {
"DarkSlateBlue", 0xFF483D8B },
82 {
"DarkSlateGray", 0xFF2F4F4F },
83 {
"DarkTurquoise", 0xFF00CED1 },
84 {
"DarkViolet", 0xFF9400D3 },
85 {
"DeepPink", 0xFFFF1493 },
86 {
"DeepSkyBlue", 0xFF00BFFF },
87 {
"DimGray", 0xFF696969 },
88 {
"DodgerBlue", 0xFF1E90FF },
89 {
"FireBrick", 0xFFB22222 },
90 {
"FloralWhite", 0xFFFFFAF0 },
91 {
"ForestGreen", 0xFF228B22 },
92 {
"Fuchsia", 0xFFFF00FF },
93 {
"Gainsboro", 0xFFDCDCDC },
94 {
"GhostWhite", 0xFFF8F8FF },
95 {
"Gold", 0xFFFFD700 },
96 {
"GoldenRod", 0xFFDAA520 },
97 {
"Gray", 0xFFBEBEBE },
98 {
"Green", 0xFF00FF00 },
99 {
"GreenYellow", 0xFFADFF2F },
100 {
"HoneyDew", 0xFFF0FFF0 },
101 {
"HotPink", 0xFFFF69B4 },
102 {
"IndianRed", 0xFFCD5C5C },
103 {
"Indigo", 0xFF4B0082 },
104 {
"Ivory", 0xFFFFFFF0 },
105 {
"Khaki", 0xFFF0E68C },
106 {
"Lavender", 0xFFE6E6FA },
107 {
"LavenderBlush", 0xFFFFF0F5 },
108 {
"LawnGreen", 0xFF7CFC00 },
109 {
"LemonChiffon", 0xFFFFFACD },
110 {
"LightBlue", 0xFFADD8E6 },
111 {
"LightCoral", 0xFFF08080 },
112 {
"LightCyan", 0xFFE0FFFF },
113 {
"LightGoldenRodYellow", 0xFFFAFAD2 },
114 {
"LightGreen", 0xFF90EE90 },
115 {
"LightGrey", 0xFFD3D3D3 },
116 {
"LightPink", 0xFFFFB6C1 },
117 {
"LightSalmon", 0xFFFFA07A },
118 {
"LightSeaGreen", 0xFF20B2AA },
119 {
"LightSkyBlue", 0xFF87CEFA },
120 {
"LightSlateGray", 0xFF778899 },
121 {
"LightSteelBlue", 0xFFB0C4DE },
122 {
"LightYellow", 0xFFFFFFE0 },
123 {
"Lime", 0xFF00FF00 },
124 {
"LimeGreen", 0xFF32CD32 },
125 {
"Linen", 0xFFFAF0E6 },
126 {
"Magenta", 0xFFFF00FF },
127 {
"Maroon", 0xFFB03060 },
128 {
"MediumAquaMarine", 0xFF66CDAA },
129 {
"MediumBlue", 0xFF0000CD },
130 {
"MediumOrchid", 0xFFBA55D3 },
131 {
"MediumPurple", 0xFF9370D8 },
132 {
"MediumSeaGreen", 0xFF3CB371 },
133 {
"MediumSlateBlue", 0xFF7B68EE },
134 {
"MediumSpringGreen", 0xFF00FA9A },
135 {
"MediumTurquoise", 0xFF48D1CC },
136 {
"MediumVioletRed", 0xFFC71585 },
137 {
"MidnightBlue", 0xFF191970 },
138 {
"MintCream", 0xFFF5FFFA },
139 {
"MistyRose", 0xFFFFE4E1 },
140 {
"Moccasin", 0xFFFFE4B5 },
141 {
"NavajoWhite", 0xFFFFDEAD },
142 {
"Navy", 0xFF000080 },
143 {
"None", 0x00000000 },
144 {
"OldLace", 0xFFFDF5E6 },
145 {
"Olive", 0xFF808000 },
146 {
"OliveDrab", 0xFF6B8E23 },
147 {
"Orange", 0xFFFFA500 },
148 {
"OrangeRed", 0xFFFF4500 },
149 {
"Orchid", 0xFFDA70D6 },
150 {
"PaleGoldenRod", 0xFFEEE8AA },
151 {
"PaleGreen", 0xFF98FB98 },
152 {
"PaleTurquoise", 0xFFAFEEEE },
153 {
"PaleVioletRed", 0xFFD87093 },
154 {
"PapayaWhip", 0xFFFFEFD5 },
155 {
"PeachPuff", 0xFFFFDAB9 },
156 {
"Peru", 0xFFCD853F },
157 {
"Pink", 0xFFFFC0CB },
158 {
"Plum", 0xFFDDA0DD },
159 {
"PowderBlue", 0xFFB0E0E6 },
160 {
"Purple", 0xFFA020F0 },
161 {
"Red", 0xFFFF0000 },
162 {
"RosyBrown", 0xFFBC8F8F },
163 {
"RoyalBlue", 0xFF4169E1 },
164 {
"SaddleBrown", 0xFF8B4513 },
165 {
"Salmon", 0xFFFA8072 },
166 {
"SandyBrown", 0xFFF4A460 },
167 {
"SeaGreen", 0xFF2E8B57 },
168 {
"SeaShell", 0xFFFFF5EE },
169 {
"Sienna", 0xFFA0522D },
170 {
"Silver", 0xFFC0C0C0 },
171 {
"SkyBlue", 0xFF87CEEB },
172 {
"SlateBlue", 0xFF6A5ACD },
173 {
"SlateGray", 0xFF708090 },
174 {
"Snow", 0xFFFFFAFA },
175 {
"SpringGreen", 0xFF00FF7F },
176 {
"SteelBlue", 0xFF4682B4 },
177 {
"Tan", 0xFFD2B48C },
178 {
"Teal", 0xFF008080 },
179 {
"Thistle", 0xFFD8BFD8 },
180 {
"Tomato", 0xFFFF6347 },
181 {
"Turquoise", 0xFF40E0D0 },
182 {
"Violet", 0xFFEE82EE },
183 {
"Wheat", 0xFFF5DEB3 },
184 {
"White", 0xFFFFFFFF },
185 {
"WhiteSmoke", 0xFFF5F5F5 },
186 {
"Yellow", 0xFFFFFF00 },
187 {
"YellowGreen", 0xFF9ACD32 }
192 if (x >=
'a' && x <=
'f')
194 else if (x >=
'A' && x <=
'F')
196 else if (x >=
'0' && x <=
'9')
210 for (i = 0;
string &&
string[i]; i++) {
211 if (
string[i] ==
'/' &&
string[i+1] ==
'*') {
213 while (
string &&
string[i] && (
string[i] !=
'*' ||
string[i+1] !=
'/') )
216 }
else if (
string[i] ==
'/' &&
string[i+1] ==
'/') {
218 while (
string &&
string[i] &&
string[i] !=
'\n' )
221 for (j = 0; reject && reject[j]; j++) {
222 if (
string[i] == reject[j])
225 if (reject && reject[j])
234 uint32_t ret = 0xFF000000;
236 char color_name[100];
238 len =
FFMIN(
FFMAX(len, 0),
sizeof(color_name) - 1);
247 }
else if (len == 4) {
252 }
else if (len == 6) {
259 }
else if (len == 8) {
270 strncpy(color_name, p, len);
271 color_name[
len] =
'\0';
273 entry = bsearch(color_name,
292 for (i = 0; i < cpp; i++) {
293 if (*p < ' ' || *p >
'~')
295 n += (*p++ -
' ') * m;
307 int ncolors, cpp, ret, i, j;
321 while (end - ptr > 9 && memcmp(ptr,
"/* XPM */", 9))
324 if (end - ptr <= 9) {
330 if (sscanf(ptr,
"\"%u %u %u %u\",",
331 &avctx->
width, &avctx->
height, &ncolors, &cpp) != 4) {
342 if (cpp <= 0 || cpp >= 5) {
343 av_log(avctx,
AV_LOG_ERROR,
"unsupported/invalid number of chars per pixel: %d\n", cpp);
348 for (i = 0; i < cpp; i++)
351 if (ncolors <= 0 || ncolors > size) {
366 for (i = 0; i < ncolors; i++) {
376 ptr = strstr(ptr,
"c ");
383 len = strcspn(ptr,
"\" ");
394 for (i = 0; i < avctx->
height; i++) {
402 for (j = 0; j < avctx->
width; j++) {
static int xpm_decode_frame(AVCodecContext *avctx, void *data, int *got_frame, AVPacket *avpkt)
static int color_table_compare(const void *lhs, const void *rhs)
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
This structure describes decoded (raw) audio or video data.
int ff_set_dimensions(AVCodecContext *s, int width, int height)
Check that the provided frame dimensions are valid and set them on the codec context.
const char * name
a string representing the name of the color
enum AVPixelFormat pix_fmt
Pixel format, see AV_PIX_FMT_xxx.
void av_fast_padded_malloc(void *ptr, unsigned int *size, size_t min_size)
Same behaviour av_fast_malloc but the buffer has additional AV_INPUT_BUFFER_PADDING_SIZE at the end w...
static void decode(AVCodecContext *dec_ctx, AVPacket *pkt, AVFrame *frame, FILE *outfile)
static uint32_t color_string_to_rgba(const char *p, int len)
static av_cold int end(AVCodecContext *avctx)
uint32_t rgb_color
RGB values for the color.
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
static av_cold int xpm_decode_close(AVCodecContext *avctx)
static const ColorEntry color_table[]
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification. ...
packed BGRA 8:8:8:8, 32bpp, BGRABGRA...
const char * name
Name of the codec implementation.
enum AVPictureType pict_type
Picture type of the frame.
int av_strcasecmp(const char *a, const char *b)
Locale-independent case-insensitive compare.
int width
picture width / height.
#define FF_ARRAY_ELEMS(a)
Libavcodec external API header.
int linesize[AV_NUM_DATA_POINTERS]
For video, size in bytes of each picture line.
main external API structure.
int ff_get_buffer(AVCodecContext *avctx, AVFrame *frame, int flags)
Get a buffer for a frame.
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
static size_t mod_strcspn(const char *string, const char *reject)
common internal api header.
int key_frame
1 -> keyframe, 0-> not
static int ascii2index(const uint8_t *cpixel, int cpp)
This structure stores compressed data.
#define AV_CODEC_CAP_DR1
Codec uses get_buffer() for allocating buffers and supports custom allocators.
static unsigned hex_char_to_number(uint8_t x)