FFmpeg
Loading...
Searching...
No Matches
pamenc.c
Go to the documentation of this file.
1/*
2 * PAM image format
3 * Copyright (c) 2002, 2003 Fabrice Bellard
4 *
5 * This file is part of FFmpeg.
6 *
7 * FFmpeg is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
11 *
12 * FFmpeg is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
16 *
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with FFmpeg; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20 */
21
22#include "libavutil/avassert.h"
23#include "avcodec.h"
24#include "codec_internal.h"
25#include "encode.h"
26
28 const AVFrame *p, int *got_packet)
29{
30 int i, h, w, n, linesize, depth, maxval, ret, header_size;
31 uint8_t *bytestream;
32 const uint8_t *ptr;
33 const char *tuple_type;
34 char header[100];
35
36 h = avctx->height;
37 w = avctx->width;
38 switch (avctx->pix_fmt) {
40 n = w;
41 depth = 1;
42 maxval = 1;
43 tuple_type = "BLACKANDWHITE";
44 break;
46 n = w;
47 depth = 1;
48 maxval = 255;
49 tuple_type = "GRAYSCALE";
50 break;
52 n = w * 2;
53 depth = 1;
54 maxval = 0xFFFF;
55 tuple_type = "GRAYSCALE";
56 break;
58 n = w * 2;
59 depth = 2;
60 maxval = 255;
61 tuple_type = "GRAYSCALE_ALPHA";
62 break;
64 n = w * 4;
65 depth = 2;
66 maxval = 0xFFFF;
67 tuple_type = "GRAYSCALE_ALPHA";
68 break;
70 n = w * 3;
71 depth = 3;
72 maxval = 255;
73 tuple_type = "RGB";
74 break;
75 case AV_PIX_FMT_RGBA:
76 n = w * 4;
77 depth = 4;
78 maxval = 255;
79 tuple_type = "RGB_ALPHA";
80 break;
82 n = w * 6;
83 depth = 3;
84 maxval = 0xFFFF;
85 tuple_type = "RGB";
86 break;
88 n = w * 8;
89 depth = 4;
90 maxval = 0xFFFF;
91 tuple_type = "RGB_ALPHA";
92 break;
93 default:
94 return -1;
95 }
96
97 header_size = snprintf(header, sizeof(header),
98 "P7\nWIDTH %d\nHEIGHT %d\nDEPTH %d\nMAXVAL %d\nTUPLTYPE %s\nENDHDR\n",
99 w, h, depth, maxval, tuple_type);
100 av_assert1(header_size < sizeof(header));
101
102 if ((ret = ff_get_encode_buffer(avctx, pkt, n*h + header_size, 0)) < 0)
103 return ret;
104
105 bytestream = pkt->data;
106 memcpy(bytestream, header, header_size);
107 bytestream += header_size;
108
109 ptr = p->data[0];
110 linesize = p->linesize[0];
111
112 if (avctx->pix_fmt == AV_PIX_FMT_MONOBLACK){
113 int j;
114 for (i = 0; i < h; i++) {
115 for (j = 0; j < w; j++)
116 *bytestream++ = ptr[j >> 3] >> (7 - j & 7) & 1;
117 ptr += linesize;
118 }
119 } else {
120 for (i = 0; i < h; i++) {
121 memcpy(bytestream, ptr, n);
122 bytestream += n;
123 ptr += linesize;
124 }
125 }
126
127 *got_packet = 1;
128 return 0;
129}
130
const FFCodec ff_pam_encoder
Definition pamenc.c:131
simple assert() macros that are a bit more flexible than ISO C assert().
#define av_assert1(cond)
assert() equivalent, that does not lie in speed critical code.
Definition avassert.h:58
Libavcodec external API header.
#define i(width, name, range_min, range_max)
Definition cbs_h264.c:63
#define CODEC_PIXFMTS(...)
#define FF_CODEC_ENCODE_CB(func)
#define CODEC_LONG_NAME(str)
static AVPacket * pkt
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
@ AV_CODEC_ID_PAM
Definition codec_id.h:116
@ AVMEDIA_TYPE_VIDEO
Definition avutil.h:200
uint8_t w
Definition llvidencdsp.c:39
static int pam_encode_frame(AVCodecContext *avctx, AVPacket *pkt, const AVFrame *p, int *got_packet)
Definition pamenc.c:27
@ AV_PIX_FMT_GRAY16BE
Y , 16bpp, big-endian.
Definition pixfmt.h:104
@ AV_PIX_FMT_RGB24
packed RGB 8:8:8, 24bpp, RGBRGB...
Definition pixfmt.h:75
@ AV_PIX_FMT_YA16BE
16 bits gray, 16 bits alpha (big-endian)
Definition pixfmt.h:209
@ 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
@ AV_PIX_FMT_GRAY8A
alias for AV_PIX_FMT_YA8
Definition pixfmt.h:143
@ AV_PIX_FMT_GRAY8
Y , 8bpp.
Definition pixfmt.h:81
@ AV_PIX_FMT_RGB48BE
packed RGB 16:16:16, 48bpp, 16R, 16G, 16B, the 2-byte value for each R/G/B component is stored as big...
Definition pixfmt.h:109
@ AV_PIX_FMT_RGBA64BE
packed RGBA 16:16:16:16, 64bpp, 16R, 16G, 16B, 16A, the 2-byte value for each R/G/B/A component is st...
Definition pixfmt.h:202
@ AV_PIX_FMT_RGBA
packed RGBA 8:8:8:8, 32bpp, RGBARGBA...
Definition pixfmt.h:100
static const uint8_t header[24]
Definition sdr2.c:68
#define snprintf
Definition snprintf.h:34
main external API structure.
Definition avcodec.h:443
enum AVPixelFormat pix_fmt
Pixel format, see AV_PIX_FMT_xxx.
Definition avcodec.h:643
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