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:64
wbmp_encode_frame
static int wbmp_encode_frame(AVCodecContext *avctx, AVPacket *pkt, const AVFrame *frame, int *got_packet)
Definition: wbmpenc.c:50
AVFrame
This structure describes decoded (raw) audio or video data.
Definition: frame.h:340
AVPacket::data
uint8_t * data
Definition: packet.h:491
encode.h
FFCodec
Definition: codec_internal.h:127
AVFrame::data
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
Definition: frame.h:361
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: avpacket.c:113
FF_CODEC_ENCODE_CB
#define FF_CODEC_ENCODE_CB(func)
Definition: codec_internal.h:315
pkt
AVPacket * pkt
Definition: movenc.c:59
width
#define width
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:272
frame
static AVFrame * frame
Definition: demux_decode.c:54
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:76
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
codec_internal.h
size
int size
Definition: twinvq_data.h:10344
height
#define height
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:621
avcodec.h
ret
ret
Definition: filter_design.txt:187
AVCodecContext
main external API structure.
Definition: avcodec.h:441
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:105
AV_PIX_FMT_NONE
@ AV_PIX_FMT_NONE
Definition: pixfmt.h:65
AV_CODEC_ID_WBMP
@ AV_CODEC_ID_WBMP
Definition: codec_id.h:320
AVMEDIA_TYPE_VIDEO
@ AVMEDIA_TYPE_VIDEO
Definition: avutil.h:201
AVPacket
This structure stores compressed data.
Definition: packet.h:468
ff_wbmp_encoder
const FFCodec ff_wbmp_encoder
Definition: wbmpenc.c:78
src
INIT_CLIP pixel * src
Definition: h264pred_template.c:418
AVCodecContext::width
int width
picture width / height.
Definition: avcodec.h:621
bytestream.h
AVFrame::linesize
int linesize[AV_NUM_DATA_POINTERS]
For video, a positive or negative value, which is typically indicating the size in bytes of each pict...
Definition: frame.h:385
writebits
static void writebits(uint8_t **bufp, const uint8_t *src, int width, int height, int linesize)
Definition: wbmpenc.c:40