22#include "config_components.h"
39 for (
i=0;
i<n/2;
i++) {
48 const uint8_t *buf = avpkt->
data;
49 int buf_size = avpkt->
size;
51 int i, j, k, n, linesize,
h, upgrade = 0, is_mono = 0;
53 int components, sample_len, ret;
58 s->bytestream_end = buf + buf_size;
66 if (avctx->
width * avctx->
height / 8 >
s->bytestream_end -
s->bytestream)
80 if (
s->maxval < 65535)
87 if (
s->maxval < 65535)
110 n = avctx->
width * 2;
115 n = avctx->
width * 2;
118 if (
s->maxval < 65535)
122 n = avctx->
width * 4;
125 if (
s->maxval < 65535)
130 n = (avctx->
width + 7) >> 3;
136 linesize = p->linesize[0];
137 if (n * avctx->
height >
s->bytestream_end -
s->bytestream)
139 if(
s->type < 4 || (is_mono &&
s->type==7)){
143 for(j=0; j<avctx->
width * components; j++){
147 while(
s->bytestream <
s->bytestream_end && (*
s->bytestream <
'0' || *
s->bytestream >
'9' ))
149 if(
s->bytestream >=
s->bytestream_end)
153 v = (*
s->bytestream++)&1;
156 for (k = 0; k < 6 &&
c <= 9; k += 1) {
158 c = (*
s->bytestream++) -
'0';
165 if (sample_len == 16) {
166 ((uint16_t*)ptr)[j] = (((1<<sample_len)-1)*v + (
s->maxval>>1))/
s->maxval;
168 put_bits(&pb, sample_len, (((1<<sample_len)-1)*v + (
s->maxval>>1))/
s->maxval);
170 if (sample_len != 16)
175 for (
int i = 0;
i < avctx->
height;
i++) {
178 else if (upgrade == 1) {
179 unsigned int f = (255 * 128 +
s->maxval / 2) /
s->maxval;
180 for (
unsigned j = 0; j < n; j++)
181 ptr[j] = (
s->bytestream[j] *
f + 64) >> 7;
182 }
else if (upgrade == 2) {
183 unsigned int f = (65535 * 32768 +
s->maxval / 2) /
s->maxval;
184 for (
unsigned j = 0; j < n / 2; j++) {
185 unsigned v =
AV_RB16(
s->bytestream + 2*j);
186 ((uint16_t *)ptr)[j] = (v *
f + 16384) >> 15;
198 unsigned char *ptr1, *ptr2;
202 linesize = p->linesize[0];
203 if (
s->maxval >= 256)
205 if (n * avctx->
height * 3 / 2 >
s->bytestream_end -
s->bytestream)
216 for (
i = 0;
i <
h;
i++) {
221 ptr1 += p->linesize[1];
222 ptr2 += p->linesize[2];
228 uint16_t *ptr1, *ptr2;
229 const int f = (65535 * 32768 +
s->maxval / 2) /
s->maxval;
232 n = avctx->
width * 2;
234 linesize = p->linesize[0];
235 if (n * avctx->
height * 3 / 2 >
s->bytestream_end -
s->bytestream)
238 for (j = 0; j < n / 2; j++) {
240 ((uint16_t *)ptr)[j] = (v *
f + 16384) >> 15;
245 ptr1 = (uint16_t*)p->data[1];
246 ptr2 = (uint16_t*)p->data[2];
249 for (
i = 0;
i <
h;
i++) {
250 for (j = 0; j < n / 2; j++) {
252 ptr1[j] = (v *
f + 16384) >> 15;
256 for (j = 0; j < n / 2; j++) {
258 ptr2[j] = (v *
f + 16384) >> 15;
262 ptr1 += p->linesize[1] / 2;
263 ptr2 += p->linesize[2] / 2;
269 if (avctx->
width * avctx->
height * 12LL >
s->bytestream_end -
s->bytestream)
275 r = (
float *)p->data[2];
276 g = (
float *)p->data[0];
277 b = (
float *)p->data[1];
278 for (
int i = 0;
i < avctx->
height;
i++) {
279 for (
int j = 0; j < avctx->
width; j++) {
286 r += p->linesize[2] / 4;
287 g += p->linesize[0] / 4;
288 b += p->linesize[1] / 4;
293 r = (
float *)p->data[2];
294 g = (
float *)p->data[0];
295 b = (
float *)p->data[1];
296 for (
int i = 0;
i < avctx->
height;
i++) {
297 for (
int j = 0; j < avctx->
width; j++) {
304 r += p->linesize[2] / 4;
305 g += p->linesize[0] / 4;
306 b += p->linesize[1] / 4;
310 if (avctx->
width * avctx->
height * 6 >
s->bytestream_end -
s->bytestream)
316 r = (
float *)p->data[2];
317 g = (
float *)p->data[0];
318 b = (
float *)p->data[1];
319 for (
int i = 0;
i < avctx->
height;
i++) {
320 for (
int j = 0; j < avctx->
width; j++) {
327 r += p->linesize[2] / 4;
328 g += p->linesize[0] / 4;
329 b += p->linesize[1] / 4;
334 r = (
float *)p->data[2];
335 g = (
float *)p->data[0];
336 b = (
float *)p->data[1];
337 for (
int i = 0;
i < avctx->
height;
i++) {
338 for (
int j = 0; j < avctx->
width; j++) {
345 r += p->linesize[2] / 4;
346 g += p->linesize[0] / 4;
347 b += p->linesize[1] / 4;
352 p->data[0] += (avctx->
height - 1) * p->linesize[0];
353 p->data[1] += (avctx->
height - 1) * p->linesize[1];
354 p->data[2] += (avctx->
height - 1) * p->linesize[2];
355 p->linesize[0] = -p->linesize[0];
356 p->linesize[1] = -p->linesize[1];
357 p->linesize[2] = -p->linesize[2];
361 if (avctx->
width * avctx->
height * 4 >
s->bytestream_end -
s->bytestream)
365 float *
g = (
float *)p->data[0];
366 for (
int i = 0;
i < avctx->
height;
i++) {
367 for (
int j = 0; j < avctx->
width; j++) {
371 g += p->linesize[0] / 4;
374 float *
g = (
float *)p->data[0];
375 for (
int i = 0;
i < avctx->
height;
i++) {
376 for (
int j = 0; j < avctx->
width; j++) {
380 g += p->linesize[0] / 4;
384 if (avctx->
width * avctx->
height * 2 >
s->bytestream_end -
s->bytestream)
388 float *
g = (
float *)p->data[0];
389 for (
int i = 0;
i < avctx->
height;
i++) {
390 for (
int j = 0; j < avctx->
width; j++) {
394 g += p->linesize[0] / 4;
397 float *
g = (
float *)p->data[0];
398 for (
int i = 0;
i < avctx->
height;
i++) {
399 for (
int j = 0; j < avctx->
width; j++) {
403 g += p->linesize[0] / 4;
408 p->data[0] += (avctx->
height - 1) * p->linesize[0];
409 p->linesize[0] = -p->linesize[0];
414 return s->bytestream -
s->bytestream_start;
418#if CONFIG_PGM_DECODER
431#if CONFIG_PGMYUV_DECODER
444#if CONFIG_PPM_DECODER
457#if CONFIG_PBM_DECODER
470#if CONFIG_PAM_DECODER
483#if CONFIG_PFM_DECODER
496#if CONFIG_PHM_DECODER
513 .
init = phm_dec_init,
uint8_t ptrdiff_t const uint8_t ptrdiff_t int intptr_t intptr_t int int16_t * dst
const FFCodec ff_pgmyuv_decoder
const FFCodec ff_pgm_decoder
const FFCodec ff_ppm_decoder
const FFCodec ff_phm_decoder
const FFCodec ff_pbm_decoder
const FFCodec ff_pam_decoder
const FFCodec ff_pfm_decoder
Libavcodec external API header.
#define i(width, name, range_min, range_max)
#define FF_CODEC_CAP_SKIP_FRAME_FILL_PARAM
The decoder extracts and fills its parameters even if the frame is skipped due to the skip_frame sett...
#define FF_CODEC_DECODE_CB(func)
#define CODEC_LONG_NAME(str)
#define FFABS(a)
Absolute value, Note, INT_MIN / INT64_MIN result in undefined behavior as they are not representable ...
int ff_get_buffer(AVCodecContext *avctx, AVFrame *frame, int flags)
Get a buffer for a frame.
int(* init)(AVBSFContext *ctx)
#define AV_CODEC_CAP_DR1
Codec uses get_buffer() or get_encode_buffer() for allocating buffers and supports custom allocators.
@ AVDISCARD_ALL
discard all
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
static uint32_t half2float(uint16_t h, const Half2FloatTables *t)
static av_always_inline float av_int2float(uint32_t i)
Reinterpret a 32-bit integer as a float.
static void scale(int *out, const int *in, const int w, const int h, const int shift)
static void put_bits(Jpeg2000EncoderContext *s, int val, int n)
put n times val bit
void ff_init_half2float_tables(Half2FloatTables *t)
#define AV_PIX_FMT_YUV420P16
#define AV_PIX_FMT_GBRPF32
#define AV_PIX_FMT_YUV420P10
#define AV_PIX_FMT_RGBA64
#define AV_PIX_FMT_YUV420P9
#define AV_PIX_FMT_GRAYF32
@ AV_PIX_FMT_RGB24
packed RGB 8:8:8, 24bpp, RGBRGB...
@ AV_PIX_FMT_YUV420P
planar YUV 4:2:0, 12bpp, (1 Cr & Cb sample per 2x2 Y samples)
@ AV_PIX_FMT_MONOBLACK
Y , 1bpp, 0 is black, 1 is white, in each byte pixels are ordered from the msb to the lsb.
@ AV_PIX_FMT_GRAY8A
alias for AV_PIX_FMT_YA8
@ AV_PIX_FMT_GRAY8
Y , 8bpp.
@ AV_PIX_FMT_RGBA
packed RGBA 8:8:8:8, 32bpp, RGBARGBA...
@ AV_PIX_FMT_MONOWHITE
Y , 1bpp, 0 is white, 1 is black, in each byte pixels are ordered from the msb to the lsb.
#define AV_PIX_FMT_GRAY16
int ff_pnm_decode_header(AVCodecContext *avctx, PNMContext *const s)
static int pnm_decode_frame(AVCodecContext *avctx, AVFrame *p, int *got_frame, AVPacket *avpkt)
static void samplecpy(uint8_t *dst, const uint8_t *src, int n, int maxval)
static void init_put_bits(PutBitContext *s, uint8_t *buffer, int buffer_size)
Initialize the PutBitContext s.
static void flush_put_bits(PutBitContext *s)
Pad the end of the output stream with zeros.
main external API structure.
enum AVPixelFormat pix_fmt
Pixel format, see AV_PIX_FMT_xxx.
int width
picture width / height.
int bits_per_raw_sample
Bits per sample/pixel of internal libavcodec pixel/sample format.
enum AVDiscard skip_frame
Skip decoding for selected frames.
This structure describes decoded (raw) audio or video data.
This structure stores compressed data.