1 /*
2 * Alias PIX image encoder
3 * Copyright (C) 2014 Vittorio Giovara <vittorio.giovara@gmail.com>
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
23
28
29 #define ALIAS_HEADER_SIZE 10
30
33 {
35 uint8_t *buf;
36
39
44 }
45
48 bits_pixel = 8;
49 break;
51 bits_pixel = 24;
52 break;
53 default:
55 }
56
60
62
63 /* Encode header. */
64 bytestream_put_be16(&buf,
width);
65 bytestream_put_be16(&buf,
height);
66 bytestream_put_be32(&buf, 0); /* X, Y offset */
67 bytestream_put_be16(&buf, bits_pixel);
68
69 for (
int j = 0, bytes_pixel = bits_pixel >> 3; j <
height; j++) {
70 const uint8_t *in_buf =
frame->data[0] +
frame->linesize[0] * j;
71 const uint8_t *
const line_end = in_buf + bytes_pixel *
width;
72 while (in_buf < line_end) {
73 int count = 0;
75
78 while (count < 255 && in_buf < line_end &&
pixel == *in_buf) {
79 count++;
80 in_buf++;
81 }
82 bytestream_put_byte(&buf, count);
83 bytestream_put_byte(&buf,
pixel);
84 } else { /* AV_PIX_FMT_BGR24 */
86 while (count < 255 && in_buf < line_end &&
88 count++;
89 in_buf += 3;
90 }
91 bytestream_put_byte(&buf, count);
92 bytestream_put_be24(&buf,
pixel);
93 }
94 }
95 }
96
97 /* Total length */
99 *got_packet = 1;
100
101 return 0;
102 }
103
112 },
113 };