FFmpeg
Loading...
Searching...
No Matches
wbmpenc.c
Go to the documentation of this file.
1/*
2 * WBMP (Wireless Application Protocol Bitmap) image
3 *
4 * This file is part of FFmpeg.
5 *
6 * FFmpeg is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
10 *
11 * FFmpeg is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
15 *
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with FFmpeg; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19 */
20
21#include "avcodec.h"
22#include "bytestream.h"
23#include "codec_internal.h"
24#include "encode.h"
25
26static void putv(uint8_t ** bufp, unsigned int v)
27{
28 unsigned int vv = 0;
29 int n = 0;
30
31 while (vv != v)
32 vv += v & (0x7F << 7 * n++);
33
34 while (--n > 0)
35 bytestream_put_byte(bufp, 0x80 | (v & (0x7F << 7 * n)) >> 7 * n);
36
37 bytestream_put_byte(bufp, v & 0x7F);
38}
39
40static void writebits(uint8_t ** bufp, const uint8_t * src, int width, int height, int linesize)
41{
42 int wpad = (width + 7) / 8;
43 for (int j = 0; j < height; j++) {
44 memcpy(*bufp, src, wpad);
45 *bufp += wpad;
46 src += linesize;
47 }
48}
49
51 const AVFrame *frame, int *got_packet)
52{
53 int64_t size = avctx->height * ((avctx->width + 7) / 8) + 32;
54 uint8_t *buf;
55 int ret;
56
57 if ((ret = ff_get_encode_buffer(avctx, pkt, size, 0)) < 0)
58 return ret;
59
60 buf = pkt->data;
61
62 putv(&buf, 0);
63 bytestream_put_byte(&buf, 0);
64 putv(&buf, avctx->width);
65 putv(&buf, avctx->height);
66
67 if (frame->linesize[0] == (avctx->width + 7) / 8)
68 bytestream_put_buffer(&buf, frame->data[0], avctx->height * ((avctx->width + 7) / 8));
69 else
70 writebits(&buf, frame->data[0], avctx->width, avctx->height, frame->linesize[0]);
71
72 av_shrink_packet(pkt, buf - pkt->data);
73
74 *got_packet = 1;
75 return 0;
76}
77
79 .p.name = "wbmp",
80 CODEC_LONG_NAME("WBMP (Wireless Application Protocol Bitmap) image"),
81 .p.type = AVMEDIA_TYPE_VIDEO,
82 .p.id = AV_CODEC_ID_WBMP,
87};
const FFCodec ff_wbmp_encoder
Definition wbmpenc.c:78
Libavcodec external API header.
static av_always_inline void bytestream_put_buffer(uint8_t **b, const uint8_t *src, unsigned int size)
Definition bytestream.h:372
#define CODEC_PIXFMTS(...)
#define FF_CODEC_ENCODE_CB(func)
#define CODEC_LONG_NAME(str)
long long int64_t
Definition coverity.c:34
static AVPacket * pkt
static AVFrame * frame
int ff_get_encode_buffer(AVCodecContext *avctx, AVPacket *avpkt, int64_t size, int flags)
Get a buffer for a packet.
Definition encode.c:106
#define AV_CODEC_CAP_ENCODER_REORDERED_OPAQUE
This encoder can reorder user opaque values from input AVFrames and return them with corresponding ou...
Definition codec.h:147
#define AV_CODEC_CAP_DR1
Codec uses get_buffer() or get_encode_buffer() for allocating buffers and supports custom allocators.
Definition codec.h:49
#define AV_CODEC_CAP_FRAME_THREADS
Codec supports frame-level multithreading.
Definition codec.h:98
@ AV_CODEC_ID_WBMP
Definition codec_id.h:312
void av_shrink_packet(AVPacket *pkt, int size)
Reduce packet size, correctly zeroing padding.
Definition packet.c:113
@ AVMEDIA_TYPE_VIDEO
Definition avutil.h:200
@ AV_PIX_FMT_MONOBLACK
Y , 1bpp, 0 is black, 1 is white, in each byte pixels are ordered from the msb to the lsb.
Definition pixfmt.h:83
main external API structure.
Definition avcodec.h:443
int width
picture width / height.
Definition avcodec.h:604
This structure describes decoded (raw) audio or video data.
Definition frame.h:472
This structure stores compressed data.
Definition packet.h:580
#define src
Definition vp8dsp.c:248
#define height
Definition dsp.h:89
#define width
Definition dsp.h:89
int size
static void putv(uint8_t **bufp, unsigned int v)
Definition wbmpenc.c:26
static int wbmp_encode_frame(AVCodecContext *avctx, AVPacket *pkt, const AVFrame *frame, int *got_packet)
Definition wbmpenc.c:50
static void writebits(uint8_t **bufp, const uint8_t *src, int width, int height, int linesize)
Definition wbmpenc.c:40