33 for (
i=0;
i<n/2;
i++) {
43 int buf_size = avpkt->
size;
46 int i, j, k, n, linesize,
h, upgrade = 0, is_mono = 0;
48 int components, sample_len, ret;
53 s->bytestream_end = (
uint8_t *)buf + buf_size;
71 if (
s->maxval < 65535)
78 if (
s->maxval < 65535)
101 n = avctx->
width * 2;
106 n = avctx->
width * 2;
109 if (
s->maxval < 65535)
113 n = avctx->
width * 4;
116 if (
s->maxval < 65535)
121 n = (avctx->
width + 7) >> 3;
128 if (n * avctx->
height >
s->bytestream_end -
s->bytestream)
130 if(
s->type < 4 || (is_mono &&
s->type==7)){
134 for(j=0; j<avctx->
width * components; j++){
138 while(
s->bytestream <
s->bytestream_end && (*
s->bytestream <
'0' || *
s->bytestream >
'9' ))
140 if(
s->bytestream >=
s->bytestream_end)
144 v = (*
s->bytestream++)&1;
147 for (k = 0; k < 6 &&
c <= 9; k += 1) {
149 c = (*
s->bytestream++) -
'0';
156 if (sample_len == 16) {
157 ((uint16_t*)ptr)[j] = (((1<<sample_len)-1)*v + (
s->maxval>>1))/
s->maxval;
159 put_bits(&pb, sample_len, (((1<<sample_len)-1)*v + (
s->maxval>>1))/
s->maxval);
161 if (sample_len != 16)
169 else if (upgrade == 1) {
170 unsigned int j,
f = (255 * 128 +
s->maxval / 2) /
s->maxval;
171 for (j = 0; j < n; j++)
172 ptr[j] = (
s->bytestream[j] *
f + 64) >> 7;
173 }
else if (upgrade == 2) {
174 unsigned int j, v,
f = (65535 * 32768 +
s->maxval / 2) /
s->maxval;
175 for (j = 0; j < n / 2; j++) {
177 ((uint16_t *)ptr)[j] = (v *
f + 16384) >> 15;
189 unsigned char *ptr1, *ptr2;
194 if (
s->maxval >= 256)
196 if (n * avctx->
height * 3 / 2 >
s->bytestream_end -
s->bytestream)
207 for (
i = 0;
i <
h;
i++) {
219 uint16_t *ptr1, *ptr2;
220 const int f = (65535 * 32768 +
s->maxval / 2) /
s->maxval;
223 n = avctx->
width * 2;
226 if (n * avctx->
height * 3 / 2 >
s->bytestream_end -
s->bytestream)
229 for (j = 0; j < n / 2; j++) {
231 ((uint16_t *)ptr)[j] = (v *
f + 16384) >> 15;
236 ptr1 = (uint16_t*)p->
data[1];
237 ptr2 = (uint16_t*)p->
data[2];
240 for (
i = 0;
i <
h;
i++) {
241 for (j = 0; j < n / 2; j++) {
243 ptr1[j] = (v *
f + 16384) >> 15;
247 for (j = 0; j < n / 2; j++) {
249 ptr2[j] = (v *
f + 16384) >> 15;
259 if (avctx->
width * avctx->
height * 12 >
s->bytestream_end -
s->bytestream)
261 scale = 1.f /
s->scale;
265 r = (
float *)p->
data[2];
266 g = (
float *)p->
data[0];
267 b = (
float *)p->
data[1];
269 for (
int j = 0; j < avctx->
width; j++) {
283 r = (
float *)p->
data[2];
284 g = (
float *)p->
data[0];
285 b = (
float *)p->
data[1];
287 for (
int j = 0; j < avctx->
width; j++) {
301 if (avctx->
width * avctx->
height * 4 >
s->bytestream_end -
s->bytestream)
303 scale = 1.f /
s->scale;
305 float *
g = (
float *)p->
data[0];
307 for (
int j = 0; j < avctx->
width; j++) {
314 float *
g = (
float *)p->
data[0];
316 for (
int j = 0; j < avctx->
width; j++) {
327 return s->bytestream -
s->bytestream_start;
331 #if CONFIG_PGM_DECODER
343 #if CONFIG_PGMYUV_DECODER
355 #if CONFIG_PPM_DECODER
367 #if CONFIG_PBM_DECODER
379 #if CONFIG_PAM_DECODER
391 #if CONFIG_PFM_DECODER
AVCodec ff_pgmyuv_decoder
Libavcodec external API header.
int ff_get_buffer(AVCodecContext *avctx, AVFrame *frame, int flags)
Get a buffer for a frame.
static void decode(AVCodecContext *dec_ctx, AVPacket *pkt, AVFrame *frame, FILE *outfile)
#define AV_CODEC_CAP_DR1
Codec uses get_buffer() or get_encode_buffer() for allocating buffers and supports custom allocators.
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
@ AV_PICTURE_TYPE_I
Intra.
static av_always_inline float av_int2float(uint32_t i)
Reinterpret a 32-bit integer as a float.
static void put_bits(Jpeg2000EncoderContext *s, int val, int n)
put n times val bit
common internal API header
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification.
#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, void *data, 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.
const char * name
Name of the codec implementation.
This structure describes decoded (raw) audio or video data.
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
int key_frame
1 -> keyframe, 0-> not
int linesize[AV_NUM_DATA_POINTERS]
For video, size in bytes of each picture line.
enum AVPictureType pict_type
Picture type of the frame.
This structure stores compressed data.