FFmpeg
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 
26 static 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 
40 static 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,
83  .p.capabilities = AV_CODEC_CAP_DR1 | AV_CODEC_CAP_FRAME_THREADS |
86  .p.pix_fmts = (const enum AVPixelFormat[]){
89  },
90 };
AVPixelFormat
AVPixelFormat
Pixel format.
Definition: pixfmt.h:71
wbmp_encode_frame
static int wbmp_encode_frame(AVCodecContext *avctx, AVPacket *pkt, const AVFrame *frame, int *got_packet)
Definition: wbmpenc.c:50
int64_t
long long int64_t
Definition: coverity.c:34
AVFrame
This structure describes decoded (raw) audio or video data.
Definition: frame.h:389
AVPacket::data
uint8_t * data
Definition: packet.h:539
encode.h
FFCodec
Definition: codec_internal.h:127
FFCodec::p
AVCodec p
The public AVCodec.
Definition: codec_internal.h:131
av_shrink_packet
void av_shrink_packet(AVPacket *pkt, int size)
Reduce packet size, correctly zeroing padding.
Definition: packet.c:113
FF_CODEC_ENCODE_CB
#define FF_CODEC_ENCODE_CB(func)
Definition: codec_internal.h:320
pkt
AVPacket * pkt
Definition: movenc.c:60
AV_CODEC_CAP_ENCODER_REORDERED_OPAQUE
#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:159
CODEC_LONG_NAME
#define CODEC_LONG_NAME(str)
Definition: codec_internal.h:296
AV_CODEC_CAP_FRAME_THREADS
#define AV_CODEC_CAP_FRAME_THREADS
Codec supports frame-level multithreading.
Definition: codec.h:110
AV_PIX_FMT_MONOBLACK
@ 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
putv
static void putv(uint8_t **bufp, unsigned int v)
Definition: wbmpenc.c:26
AV_CODEC_CAP_DR1
#define AV_CODEC_CAP_DR1
Codec uses get_buffer() or get_encode_buffer() for allocating buffers and supports custom allocators.
Definition: codec.h:52
height
#define height
Definition: dsp.h:85
codec_internal.h
size
int size
Definition: twinvq_data.h:10344
bytestream_put_buffer
static av_always_inline void bytestream_put_buffer(uint8_t **b, const uint8_t *src, unsigned int size)
Definition: bytestream.h:372
AVCodec::name
const char * name
Name of the codec implementation.
Definition: codec.h:194
AVCodecContext::height
int height
Definition: avcodec.h:624
avcodec.h
ret
ret
Definition: filter_design.txt:187
frame
these buffered frames must be flushed immediately if a new input produces new the filter must not call request_frame to get more It must just process the frame or queue it The task of requesting more frames is left to the filter s request_frame method or the application If a filter has several the filter must be ready for frames arriving randomly on any input any filter with several inputs will most likely require some kind of queuing mechanism It is perfectly acceptable to have a limited queue and to drop frames when the inputs are too unbalanced request_frame For filters that do not use the this method is called when a frame is wanted on an output For a it should directly call filter_frame on the corresponding output For a if there are queued frames already one of these frames should be pushed If the filter should request a frame on one of its repeatedly until at least one frame has been pushed Return or at least make progress towards producing a frame
Definition: filter_design.txt:264
AVCodecContext
main external API structure.
Definition: avcodec.h:451
ff_get_encode_buffer
int ff_get_encode_buffer(AVCodecContext *avctx, AVPacket *avpkt, int64_t size, int flags)
Get a buffer for a packet.
Definition: encode.c:106
AV_PIX_FMT_NONE
@ AV_PIX_FMT_NONE
Definition: pixfmt.h:72
AV_CODEC_ID_WBMP
@ AV_CODEC_ID_WBMP
Definition: codec_id.h:321
AVMEDIA_TYPE_VIDEO
@ AVMEDIA_TYPE_VIDEO
Definition: avutil.h:201
AVPacket
This structure stores compressed data.
Definition: packet.h:516
ff_wbmp_encoder
const FFCodec ff_wbmp_encoder
Definition: wbmpenc.c:78
AVCodecContext::width
int width
picture width / height.
Definition: avcodec.h:624
bytestream.h
width
#define width
Definition: dsp.h:85
src
#define src
Definition: vp8dsp.c:248
writebits
static void writebits(uint8_t **bufp, const uint8_t *src, int width, int height, int linesize)
Definition: wbmpenc.c:40