00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023 #include "avcodec.h"
00024 #include "internal.h"
00025
00026 static av_cold int xbm_encode_init(AVCodecContext *avctx)
00027 {
00028 avctx->coded_frame = avcodec_alloc_frame();
00029 if (!avctx->coded_frame)
00030 return AVERROR(ENOMEM);
00031 avctx->coded_frame->pict_type = AV_PICTURE_TYPE_I;
00032
00033 return 0;
00034 }
00035
00036 static int xbm_encode_frame(AVCodecContext *avctx, AVPacket *pkt,
00037 const AVFrame *p, int *got_packet)
00038 {
00039 int i, j, ret, size, linesize;
00040 uint8_t *ptr, *buf;
00041
00042 linesize = (avctx->width + 7) / 8;
00043 size = avctx->height * (linesize * 7 + 2) + 110;
00044 if ((ret = ff_alloc_packet2(avctx, pkt, size)) < 0)
00045 return ret;
00046
00047 buf = pkt->data;
00048 ptr = p->data[0];
00049
00050 buf += snprintf(buf, 32, "#define image_width %u\n", avctx->width);
00051 buf += snprintf(buf, 33, "#define image_height %u\n", avctx->height);
00052 buf += snprintf(buf, 40, "static unsigned char image_bits[] = {\n");
00053 for (i = 0; i < avctx->height; i++) {
00054 for (j = 0; j < linesize; j++)
00055 buf += snprintf(buf, 7, " 0x%02X,", av_reverse[*ptr++]);
00056 ptr += p->linesize[0] - linesize;
00057 buf += snprintf(buf, 2, "\n");
00058 }
00059 buf += snprintf(buf, 5, " };\n");
00060
00061 pkt->size = buf - pkt->data;
00062 pkt->flags |= AV_PKT_FLAG_KEY;
00063 *got_packet = 1;
00064 return 0;
00065 }
00066
00067 static av_cold int xbm_encode_close(AVCodecContext *avctx)
00068 {
00069 av_freep(&avctx->coded_frame);
00070
00071 return 0;
00072 }
00073
00074 AVCodec ff_xbm_encoder = {
00075 .name = "xbm",
00076 .type = AVMEDIA_TYPE_VIDEO,
00077 .id = CODEC_ID_XBM,
00078 .init = xbm_encode_init,
00079 .encode2 = xbm_encode_frame,
00080 .close = xbm_encode_close,
00081 .pix_fmts = (const enum PixelFormat[]) { PIX_FMT_MONOWHITE,
00082 PIX_FMT_NONE },
00083 .long_name = NULL_IF_CONFIG_SMALL("XBM (X BitMap) image"),
00084 };