yading@10
|
1 /*
|
yading@10
|
2 * XBM image format
|
yading@10
|
3 *
|
yading@10
|
4 * Copyright (c) 2012 Paul B Mahol
|
yading@10
|
5 *
|
yading@10
|
6 * This file is part of FFmpeg.
|
yading@10
|
7 *
|
yading@10
|
8 * FFmpeg is free software; you can redistribute it and/or
|
yading@10
|
9 * modify it under the terms of the GNU Lesser General Public
|
yading@10
|
10 * License as published by the Free Software Foundation; either
|
yading@10
|
11 * version 2.1 of the License, or (at your option) any later version.
|
yading@10
|
12 *
|
yading@10
|
13 * FFmpeg is distributed in the hope that it will be useful,
|
yading@10
|
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
yading@10
|
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
yading@10
|
16 * Lesser General Public License for more details.
|
yading@10
|
17 *
|
yading@10
|
18 * You should have received a copy of the GNU Lesser General Public
|
yading@10
|
19 * License along with FFmpeg; if not, write to the Free Software
|
yading@10
|
20 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
yading@10
|
21 */
|
yading@10
|
22
|
yading@10
|
23 #include "avcodec.h"
|
yading@10
|
24 #include "internal.h"
|
yading@10
|
25 #include "mathops.h"
|
yading@10
|
26
|
yading@10
|
27 static int xbm_encode_frame(AVCodecContext *avctx, AVPacket *pkt,
|
yading@10
|
28 const AVFrame *p, int *got_packet)
|
yading@10
|
29 {
|
yading@10
|
30 int i, j, ret, size, linesize;
|
yading@10
|
31 uint8_t *ptr, *buf;
|
yading@10
|
32
|
yading@10
|
33 linesize = (avctx->width + 7) / 8;
|
yading@10
|
34 size = avctx->height * (linesize * 7 + 2) + 110;
|
yading@10
|
35 if ((ret = ff_alloc_packet2(avctx, pkt, size)) < 0)
|
yading@10
|
36 return ret;
|
yading@10
|
37
|
yading@10
|
38 buf = pkt->data;
|
yading@10
|
39 ptr = p->data[0];
|
yading@10
|
40
|
yading@10
|
41 buf += snprintf(buf, 32, "#define image_width %u\n", avctx->width);
|
yading@10
|
42 buf += snprintf(buf, 33, "#define image_height %u\n", avctx->height);
|
yading@10
|
43 buf += snprintf(buf, 40, "static unsigned char image_bits[] = {\n");
|
yading@10
|
44 for (i = 0; i < avctx->height; i++) {
|
yading@10
|
45 for (j = 0; j < linesize; j++)
|
yading@10
|
46 buf += snprintf(buf, 7, " 0x%02X,", ff_reverse[*ptr++]);
|
yading@10
|
47 ptr += p->linesize[0] - linesize;
|
yading@10
|
48 buf += snprintf(buf, 2, "\n");
|
yading@10
|
49 }
|
yading@10
|
50 buf += snprintf(buf, 5, " };\n");
|
yading@10
|
51
|
yading@10
|
52 pkt->size = buf - pkt->data;
|
yading@10
|
53 pkt->flags |= AV_PKT_FLAG_KEY;
|
yading@10
|
54 *got_packet = 1;
|
yading@10
|
55 return 0;
|
yading@10
|
56 }
|
yading@10
|
57
|
yading@10
|
58 AVCodec ff_xbm_encoder = {
|
yading@10
|
59 .name = "xbm",
|
yading@10
|
60 .type = AVMEDIA_TYPE_VIDEO,
|
yading@10
|
61 .id = AV_CODEC_ID_XBM,
|
yading@10
|
62 .encode2 = xbm_encode_frame,
|
yading@10
|
63 .pix_fmts = (const enum AVPixelFormat[]) { AV_PIX_FMT_MONOWHITE,
|
yading@10
|
64 AV_PIX_FMT_NONE },
|
yading@10
|
65 .long_name = NULL_IF_CONFIG_SMALL("XBM (X BitMap) image"),
|
yading@10
|
66 };
|