You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

551 lines
19KB

  1. /*
  2. * Copyright 2011 Stefano Sabatini <stefano.sabatini-lala poste it>
  3. * Copyright 2012 Nicolas George <nicolas.george normalesup org>
  4. *
  5. * This file is part of FFmpeg.
  6. *
  7. * FFmpeg is free software; you can redistribute it and/or
  8. * modify it under the terms of the GNU Lesser General Public
  9. * License as published by the Free Software Foundation; either
  10. * version 2.1 of the License, or (at your option) any later version.
  11. *
  12. * FFmpeg is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  15. * Lesser General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU Lesser General Public
  18. * License along with FFmpeg; if not, write to the Free Software
  19. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  20. */
  21. #include "libavutil/avutil.h"
  22. #include "libavutil/colorspace.h"
  23. #include "libavutil/pixdesc.h"
  24. #include "drawutils.h"
  25. #include "formats.h"
  26. enum { RED = 0, GREEN, BLUE, ALPHA };
  27. int ff_fill_rgba_map(uint8_t *rgba_map, enum PixelFormat pix_fmt)
  28. {
  29. switch (pix_fmt) {
  30. case PIX_FMT_0RGB:
  31. case PIX_FMT_ARGB: rgba_map[ALPHA] = 0; rgba_map[RED ] = 1; rgba_map[GREEN] = 2; rgba_map[BLUE ] = 3; break;
  32. case PIX_FMT_0BGR:
  33. case PIX_FMT_ABGR: rgba_map[ALPHA] = 0; rgba_map[BLUE ] = 1; rgba_map[GREEN] = 2; rgba_map[RED ] = 3; break;
  34. case PIX_FMT_RGB0:
  35. case PIX_FMT_RGBA:
  36. case PIX_FMT_RGB24: rgba_map[RED ] = 0; rgba_map[GREEN] = 1; rgba_map[BLUE ] = 2; rgba_map[ALPHA] = 3; break;
  37. case PIX_FMT_BGRA:
  38. case PIX_FMT_BGR0:
  39. case PIX_FMT_BGR24: rgba_map[BLUE ] = 0; rgba_map[GREEN] = 1; rgba_map[RED ] = 2; rgba_map[ALPHA] = 3; break;
  40. default: /* unsupported */
  41. return AVERROR(EINVAL);
  42. }
  43. return 0;
  44. }
  45. int ff_fill_line_with_color(uint8_t *line[4], int pixel_step[4], int w, uint8_t dst_color[4],
  46. enum PixelFormat pix_fmt, uint8_t rgba_color[4],
  47. int *is_packed_rgba, uint8_t rgba_map_ptr[4])
  48. {
  49. uint8_t rgba_map[4] = {0};
  50. int i;
  51. const AVPixFmtDescriptor *pix_desc = &av_pix_fmt_descriptors[pix_fmt];
  52. int hsub = pix_desc->log2_chroma_w;
  53. *is_packed_rgba = ff_fill_rgba_map(rgba_map, pix_fmt) >= 0;
  54. if (*is_packed_rgba) {
  55. pixel_step[0] = (av_get_bits_per_pixel(pix_desc))>>3;
  56. for (i = 0; i < 4; i++)
  57. dst_color[rgba_map[i]] = rgba_color[i];
  58. line[0] = av_malloc(w * pixel_step[0]);
  59. for (i = 0; i < w; i++)
  60. memcpy(line[0] + i * pixel_step[0], dst_color, pixel_step[0]);
  61. if (rgba_map_ptr)
  62. memcpy(rgba_map_ptr, rgba_map, sizeof(rgba_map[0]) * 4);
  63. } else {
  64. int plane;
  65. dst_color[0] = RGB_TO_Y_CCIR(rgba_color[0], rgba_color[1], rgba_color[2]);
  66. dst_color[1] = RGB_TO_U_CCIR(rgba_color[0], rgba_color[1], rgba_color[2], 0);
  67. dst_color[2] = RGB_TO_V_CCIR(rgba_color[0], rgba_color[1], rgba_color[2], 0);
  68. dst_color[3] = rgba_color[3];
  69. for (plane = 0; plane < 4; plane++) {
  70. int line_size;
  71. int hsub1 = (plane == 1 || plane == 2) ? hsub : 0;
  72. pixel_step[plane] = 1;
  73. line_size = (w >> hsub1) * pixel_step[plane];
  74. line[plane] = av_malloc(line_size);
  75. memset(line[plane], dst_color[plane], line_size);
  76. }
  77. }
  78. return 0;
  79. }
  80. void ff_draw_rectangle(uint8_t *dst[4], int dst_linesize[4],
  81. uint8_t *src[4], int pixelstep[4],
  82. int hsub, int vsub, int x, int y, int w, int h)
  83. {
  84. int i, plane;
  85. uint8_t *p;
  86. for (plane = 0; plane < 4 && dst[plane]; plane++) {
  87. int hsub1 = plane == 1 || plane == 2 ? hsub : 0;
  88. int vsub1 = plane == 1 || plane == 2 ? vsub : 0;
  89. p = dst[plane] + (y >> vsub1) * dst_linesize[plane];
  90. for (i = 0; i < (h >> vsub1); i++) {
  91. memcpy(p + (x >> hsub1) * pixelstep[plane],
  92. src[plane], (w >> hsub1) * pixelstep[plane]);
  93. p += dst_linesize[plane];
  94. }
  95. }
  96. }
  97. void ff_copy_rectangle(uint8_t *dst[4], int dst_linesize[4],
  98. uint8_t *src[4], int src_linesize[4], int pixelstep[4],
  99. int hsub, int vsub, int x, int y, int y2, int w, int h)
  100. {
  101. int i, plane;
  102. uint8_t *p;
  103. for (plane = 0; plane < 4 && dst[plane]; plane++) {
  104. int hsub1 = plane == 1 || plane == 2 ? hsub : 0;
  105. int vsub1 = plane == 1 || plane == 2 ? vsub : 0;
  106. p = dst[plane] + (y >> vsub1) * dst_linesize[plane];
  107. for (i = 0; i < (h >> vsub1); i++) {
  108. memcpy(p + (x >> hsub1) * pixelstep[plane],
  109. src[plane] + src_linesize[plane]*(i+(y2>>vsub1)), (w >> hsub1) * pixelstep[plane]);
  110. p += dst_linesize[plane];
  111. }
  112. }
  113. }
  114. int ff_draw_init(FFDrawContext *draw, enum PixelFormat format, unsigned flags)
  115. {
  116. const AVPixFmtDescriptor *desc = &av_pix_fmt_descriptors[format];
  117. const AVComponentDescriptor *c;
  118. unsigned i, nb_planes = 0;
  119. int pixelstep[MAX_PLANES] = { 0 };
  120. if (!desc->name)
  121. return AVERROR(EINVAL);
  122. if (desc->flags & ~(PIX_FMT_PLANAR | PIX_FMT_RGB | PIX_FMT_PSEUDOPAL))
  123. return AVERROR(ENOSYS);
  124. for (i = 0; i < desc->nb_components; i++) {
  125. c = &desc->comp[i];
  126. /* for now, only 8-bits formats */
  127. if (c->depth_minus1 != 8 - 1)
  128. return AVERROR(ENOSYS);
  129. if (c->plane >= MAX_PLANES)
  130. return AVERROR(ENOSYS);
  131. /* strange interleaving */
  132. if (pixelstep[c->plane] != 0 &&
  133. pixelstep[c->plane] != c->step_minus1 + 1)
  134. return AVERROR(ENOSYS);
  135. pixelstep[c->plane] = c->step_minus1 + 1;
  136. if (pixelstep[c->plane] >= 8)
  137. return AVERROR(ENOSYS);
  138. nb_planes = FFMAX(nb_planes, c->plane + 1);
  139. }
  140. if ((desc->log2_chroma_w || desc->log2_chroma_h) && nb_planes < 3)
  141. return AVERROR(ENOSYS); /* exclude NV12 and NV21 */
  142. memset(draw, 0, sizeof(*draw));
  143. draw->desc = desc;
  144. draw->format = format;
  145. draw->nb_planes = nb_planes;
  146. memcpy(draw->pixelstep, pixelstep, sizeof(draw->pixelstep));
  147. if (nb_planes >= 3 && !(desc->flags & PIX_FMT_RGB)) {
  148. draw->hsub[1] = draw->hsub[2] = draw->hsub_max = desc->log2_chroma_w;
  149. draw->vsub[1] = draw->vsub[2] = draw->vsub_max = desc->log2_chroma_h;
  150. }
  151. for (i = 0; i < ((desc->nb_components - 1) | 1); i++)
  152. draw->comp_mask[desc->comp[i].plane] |=
  153. 1 << (desc->comp[i].offset_plus1 - 1);
  154. return 0;
  155. }
  156. void ff_draw_color(FFDrawContext *draw, FFDrawColor *color, uint8_t rgba[4])
  157. {
  158. unsigned i;
  159. uint8_t rgba_map[4];
  160. if (rgba != color->rgba)
  161. memcpy(color->rgba, rgba, sizeof(color->rgba));
  162. if ((draw->desc->flags & PIX_FMT_RGB) && draw->nb_planes == 1 &&
  163. ff_fill_rgba_map(rgba_map, draw->format) >= 0) {
  164. for (i = 0; i < 4; i++)
  165. color->comp[0].u8[rgba_map[i]] = rgba[i];
  166. } else if (draw->nb_planes == 3 || draw->nb_planes == 4) {
  167. /* assume YUV */
  168. color->comp[0].u8[0] = RGB_TO_Y_CCIR(rgba[0], rgba[1], rgba[2]);
  169. color->comp[1].u8[0] = RGB_TO_U_CCIR(rgba[0], rgba[1], rgba[2], 0);
  170. color->comp[2].u8[0] = RGB_TO_V_CCIR(rgba[0], rgba[1], rgba[2], 0);
  171. color->comp[3].u8[0] = rgba[3];
  172. } else if (draw->format == PIX_FMT_GRAY8 || draw->format == PIX_FMT_GRAY8A) {
  173. color->comp[0].u8[0] = RGB_TO_Y_CCIR(rgba[0], rgba[1], rgba[2]);
  174. color->comp[1].u8[0] = rgba[3];
  175. } else {
  176. av_log(NULL, AV_LOG_WARNING,
  177. "Color conversion not implemented for %s\n", draw->desc->name);
  178. memset(color, 128, sizeof(*color));
  179. }
  180. }
  181. static uint8_t *pointer_at(FFDrawContext *draw, uint8_t *data[], int linesize[],
  182. int plane, int x, int y)
  183. {
  184. return data[plane] +
  185. (y >> draw->vsub[plane]) * linesize[plane] +
  186. (x >> draw->hsub[plane]) * draw->pixelstep[plane];
  187. }
  188. void ff_copy_rectangle2(FFDrawContext *draw,
  189. uint8_t *dst[], int dst_linesize[],
  190. uint8_t *src[], int src_linesize[],
  191. int dst_x, int dst_y, int src_x, int src_y,
  192. int w, int h)
  193. {
  194. int plane, y, wp, hp;
  195. uint8_t *p, *q;
  196. for (plane = 0; plane < draw->nb_planes; plane++) {
  197. p = pointer_at(draw, src, src_linesize, plane, src_x, src_y);
  198. q = pointer_at(draw, dst, dst_linesize, plane, dst_x, dst_y);
  199. wp = (w >> draw->hsub[plane]) * draw->pixelstep[plane];
  200. hp = (h >> draw->vsub[plane]);
  201. for (y = 0; y < hp; y++) {
  202. memcpy(q, p, wp);
  203. p += src_linesize[plane];
  204. q += dst_linesize[plane];
  205. }
  206. }
  207. }
  208. void ff_fill_rectangle(FFDrawContext *draw, FFDrawColor *color,
  209. uint8_t *dst[], int dst_linesize[],
  210. int dst_x, int dst_y, int w, int h)
  211. {
  212. int plane, x, y, wp, hp;
  213. uint8_t *p0, *p;
  214. for (plane = 0; plane < draw->nb_planes; plane++) {
  215. p0 = pointer_at(draw, dst, dst_linesize, plane, dst_x, dst_y);
  216. wp = (w >> draw->hsub[plane]);
  217. hp = (h >> draw->vsub[plane]);
  218. if (!hp)
  219. return;
  220. p = p0;
  221. /* copy first line from color */
  222. for (x = 0; x < wp; x++) {
  223. memcpy(p, color->comp[plane].u8, draw->pixelstep[plane]);
  224. p += draw->pixelstep[plane];
  225. }
  226. wp *= draw->pixelstep[plane];
  227. /* copy next lines from first line */
  228. p = p0 + dst_linesize[plane];
  229. for (y = 1; y < hp; y++) {
  230. memcpy(p, p0, wp);
  231. p += dst_linesize[plane];
  232. }
  233. }
  234. }
  235. /**
  236. * Clip interval [x; x+w[ within [0; wmax[.
  237. * The resulting w may be negative if the final interval is empty.
  238. * dx, if not null, return the difference between in and out value of x.
  239. */
  240. static void clip_interval(int wmax, int *x, int *w, int *dx)
  241. {
  242. if (dx)
  243. *dx = 0;
  244. if (*x < 0) {
  245. if (dx)
  246. *dx = -*x;
  247. *w += *x;
  248. *x = 0;
  249. }
  250. if (*x + *w > wmax)
  251. *w = wmax - *x;
  252. }
  253. /**
  254. * Decompose w pixels starting at x
  255. * into start + (w starting at x) + end
  256. * with x and w aligned on multiples of 1<<sub.
  257. */
  258. static void subsampling_bounds(int sub, int *x, int *w, int *start, int *end)
  259. {
  260. int mask = (1 << sub) - 1;
  261. *start = (-*x) & mask;
  262. *x += *start;
  263. *start = FFMIN(*start, *w);
  264. *w -= *start;
  265. *end = *w & mask;
  266. *w >>= sub;
  267. }
  268. static int component_used(FFDrawContext *draw, int plane, int comp)
  269. {
  270. return (draw->comp_mask[plane] >> comp) & 1;
  271. }
  272. /* If alpha is in the [ 0 ; 0x1010101 ] range,
  273. then alpha * value is in the [ 0 ; 0xFFFFFFFF ] range,
  274. and >> 24 gives a correct rounding. */
  275. static void blend_line(uint8_t *dst, unsigned src, unsigned alpha,
  276. int dx, int w, unsigned hsub, int left, int right)
  277. {
  278. unsigned asrc = alpha * src;
  279. unsigned tau = 0x1010101 - alpha;
  280. int x;
  281. src *= alpha;
  282. if (left) {
  283. unsigned suba = (left * alpha) >> hsub;
  284. *dst = (*dst * (0x1010101 - suba) + src * suba) >> 24;
  285. dst += dx;
  286. }
  287. for (x = 0; x < w; x++) {
  288. *dst = (*dst * tau + asrc) >> 24;
  289. dst += dx;
  290. }
  291. if (right) {
  292. unsigned suba = (right * alpha) >> hsub;
  293. *dst = (*dst * (0x1010101 - suba) + src * suba) >> 24;
  294. }
  295. }
  296. void ff_blend_rectangle(FFDrawContext *draw, FFDrawColor *color,
  297. uint8_t *dst[], int dst_linesize[],
  298. int dst_w, int dst_h,
  299. int x0, int y0, int w, int h)
  300. {
  301. unsigned alpha, nb_planes, nb_comp, plane, comp;
  302. int w_sub, h_sub, x_sub, y_sub, left, right, top, bottom, y;
  303. uint8_t *p0, *p;
  304. /* TODO optimize if alpha = 0xFF */
  305. clip_interval(dst_w, &x0, &w, NULL);
  306. clip_interval(dst_h, &y0, &h, NULL);
  307. if (w <= 0 || h <= 0 || !color->rgba[3])
  308. return;
  309. /* 0x10203 * alpha + 2 is in the [ 2 ; 0x1010101 - 2 ] range */
  310. alpha = 0x10203 * color->rgba[3] + 0x2;
  311. nb_planes = (draw->nb_planes - 1) | 1; /* eliminate alpha */
  312. for (plane = 0; plane < nb_planes; plane++) {
  313. nb_comp = draw->pixelstep[plane];
  314. p0 = pointer_at(draw, dst, dst_linesize, plane, x0, y0);
  315. w_sub = w;
  316. h_sub = h;
  317. x_sub = x0;
  318. y_sub = y0;
  319. subsampling_bounds(draw->hsub[plane], &x_sub, &w_sub, &left, &right);
  320. subsampling_bounds(draw->vsub[plane], &y_sub, &h_sub, &top, &bottom);
  321. for (comp = 0; comp < nb_comp; comp++) {
  322. if (!component_used(draw, plane, comp))
  323. continue;
  324. p = p0 + comp;
  325. if (top) {
  326. blend_line(p, color->comp[plane].u8[comp], alpha >> 1,
  327. draw->pixelstep[plane], w_sub,
  328. draw->hsub[plane], left, right);
  329. p += dst_linesize[plane];
  330. }
  331. for (y = 0; y < h_sub; y++) {
  332. blend_line(p, color->comp[plane].u8[comp], alpha,
  333. draw->pixelstep[plane], w_sub,
  334. draw->hsub[plane], left, right);
  335. p += dst_linesize[plane];
  336. }
  337. if (bottom)
  338. blend_line(p, color->comp[plane].u8[comp], alpha >> 1,
  339. draw->pixelstep[plane], w_sub,
  340. draw->hsub[plane], left, right);
  341. }
  342. }
  343. }
  344. static void blend_pixel(uint8_t *dst, unsigned src, unsigned alpha,
  345. uint8_t *mask, int mask_linesize, int l2depth,
  346. unsigned w, unsigned h, unsigned shift, unsigned xm0)
  347. {
  348. unsigned xm, x, y, t = 0;
  349. unsigned xmshf = 3 - l2depth;
  350. unsigned xmmod = 7 >> l2depth;
  351. unsigned mbits = (1 << (1 << l2depth)) - 1;
  352. unsigned mmult = 255 / mbits;
  353. for (y = 0; y < h; y++) {
  354. xm = xm0;
  355. for (x = 0; x < w; x++) {
  356. t += ((mask[xm >> xmshf] >> ((~xm & xmmod) << l2depth)) & mbits)
  357. * mmult;
  358. xm++;
  359. }
  360. mask += mask_linesize;
  361. }
  362. alpha = (t >> shift) * alpha;
  363. *dst = ((0x1010101 - alpha) * *dst + alpha * src) >> 24;
  364. }
  365. static void blend_line_hv(uint8_t *dst, int dst_delta,
  366. unsigned src, unsigned alpha,
  367. uint8_t *mask, int mask_linesize, int l2depth, int w,
  368. unsigned hsub, unsigned vsub,
  369. int xm, int left, int right, int hband)
  370. {
  371. int x;
  372. if (left) {
  373. blend_pixel(dst, src, alpha, mask, mask_linesize, l2depth,
  374. left, hband, hsub + vsub, xm);
  375. dst += dst_delta;
  376. xm += left;
  377. }
  378. for (x = 0; x < w; x++) {
  379. blend_pixel(dst, src, alpha, mask, mask_linesize, l2depth,
  380. 1 << hsub, hband, hsub + vsub, xm);
  381. dst += dst_delta;
  382. xm += 1 << hsub;
  383. }
  384. if (right)
  385. blend_pixel(dst, src, alpha, mask, mask_linesize, l2depth,
  386. right, hband, hsub + vsub, xm);
  387. }
  388. void ff_blend_mask(FFDrawContext *draw, FFDrawColor *color,
  389. uint8_t *dst[], int dst_linesize[], int dst_w, int dst_h,
  390. uint8_t *mask, int mask_linesize, int mask_w, int mask_h,
  391. int l2depth, unsigned endianness, int x0, int y0)
  392. {
  393. unsigned alpha, nb_planes, nb_comp, plane, comp;
  394. int xm0, ym0, w_sub, h_sub, x_sub, y_sub, left, right, top, bottom, y;
  395. uint8_t *p0, *p, *m;
  396. clip_interval(dst_w, &x0, &mask_w, &xm0);
  397. clip_interval(dst_h, &y0, &mask_h, &ym0);
  398. mask += ym0 * mask_linesize;
  399. if (mask_w <= 0 || mask_h <= 0 || !color->rgba[3])
  400. return;
  401. /* alpha is in the [ 0 ; 0x10203 ] range,
  402. alpha * mask is in the [ 0 ; 0x1010101 - 4 ] range */
  403. alpha = (0x10307 * color->rgba[3] + 0x3) >> 8;
  404. nb_planes = (draw->nb_planes - 1) | 1; /* eliminate alpha */
  405. for (plane = 0; plane < nb_planes; plane++) {
  406. nb_comp = draw->pixelstep[plane];
  407. p0 = pointer_at(draw, dst, dst_linesize, plane, x0, y0);
  408. w_sub = mask_w;
  409. h_sub = mask_h;
  410. x_sub = x0;
  411. y_sub = y0;
  412. subsampling_bounds(draw->hsub[plane], &x_sub, &w_sub, &left, &right);
  413. subsampling_bounds(draw->vsub[plane], &y_sub, &h_sub, &top, &bottom);
  414. for (comp = 0; comp < nb_comp; comp++) {
  415. if (!component_used(draw, plane, comp))
  416. continue;
  417. p = p0 + comp;
  418. m = mask;
  419. if (top) {
  420. blend_line_hv(p, draw->pixelstep[plane],
  421. color->comp[plane].u8[comp], alpha,
  422. m, mask_linesize, l2depth, w_sub,
  423. draw->hsub[plane], draw->vsub[plane],
  424. xm0, left, right, top);
  425. p += dst_linesize[plane];
  426. m += top * mask_linesize;
  427. }
  428. for (y = 0; y < h_sub; y++) {
  429. blend_line_hv(p, draw->pixelstep[plane],
  430. color->comp[plane].u8[comp], alpha,
  431. m, mask_linesize, l2depth, w_sub,
  432. draw->hsub[plane], draw->vsub[plane],
  433. xm0, left, right, 1 << draw->vsub[plane]);
  434. p += dst_linesize[plane];
  435. m += mask_linesize << draw->vsub[plane];
  436. }
  437. if (bottom)
  438. blend_line_hv(p, draw->pixelstep[plane],
  439. color->comp[plane].u8[comp], alpha,
  440. m, mask_linesize, l2depth, w_sub,
  441. draw->hsub[plane], draw->vsub[plane],
  442. xm0, left, right, bottom);
  443. }
  444. }
  445. }
  446. int ff_draw_round_to_sub(FFDrawContext *draw, int sub_dir, int round_dir,
  447. int value)
  448. {
  449. unsigned shift = sub_dir ? draw->vsub_max : draw->hsub_max;
  450. if (!shift)
  451. return value;
  452. if (round_dir >= 0)
  453. value += round_dir ? (1 << shift) - 1 : 1 << (shift - 1);
  454. return (value >> shift) << shift;
  455. }
  456. AVFilterFormats *ff_draw_supported_pixel_formats(unsigned flags)
  457. {
  458. enum PixelFormat i, pix_fmts[PIX_FMT_NB + 1];
  459. unsigned n = 0;
  460. FFDrawContext draw;
  461. for (i = 0; i < PIX_FMT_NB; i++)
  462. if (ff_draw_init(&draw, i, flags) >= 0)
  463. pix_fmts[n++] = i;
  464. pix_fmts[n++] = PIX_FMT_NONE;
  465. return ff_make_format_list(pix_fmts);
  466. }
  467. #ifdef TEST
  468. #undef printf
  469. int main(void)
  470. {
  471. enum PixelFormat f;
  472. const AVPixFmtDescriptor *desc;
  473. FFDrawContext draw;
  474. FFDrawColor color;
  475. int r, i;
  476. for (f = 0; f < PIX_FMT_NB; f++) {
  477. desc = &av_pix_fmt_descriptors[f];
  478. if (!desc->name)
  479. continue;
  480. printf("Testing %s...%*s", desc->name,
  481. (int)(16 - strlen(desc->name)), "");
  482. r = ff_draw_init(&draw, f, 0);
  483. if (r < 0) {
  484. char buf[128];
  485. av_strerror(r, buf, sizeof(buf));
  486. printf("no: %s\n", buf);
  487. continue;
  488. }
  489. ff_draw_color(&draw, &color, (uint8_t[]) { 1, 0, 0, 1 });
  490. for (i = 0; i < sizeof(color); i++)
  491. if (((uint8_t *)&color)[i] != 128)
  492. break;
  493. if (i == sizeof(color)) {
  494. printf("fallback color\n");
  495. continue;
  496. }
  497. printf("ok\n");
  498. }
  499. return 0;
  500. }
  501. #endif