History

libavcodec/pgxdec: Add PGX decoder

This patch adds a pgx decoder.

Gautam Ramakrishnan committed 6 years ago

Commit cfe2cf01 parent 76a3ee98 files · +183 −2Browse files

Unified · Split

8 files
  1. Changelog +1 −0
  2. doc/general.texi +2 −0
  3. libavcodec/Makefile +1 −0
  4. libavcodec/allcodecs.c +1 −0
  5. libavcodec/codec_desc.c +7 −0
  6. libavcodec/codec_id.h +1 −0
  7. libavcodec/pgxdec.c +168 −0
  8. libavcodec/version.h +2 −2
Changelog+1−0
@@ -4,6 +4,7 @@ releases are sorted from youngest to oldest. · 3 unmodified lines
4version <next>:4version <next>:
5- AudioToolbox output device5- AudioToolbox output device
6- MacCaption demuxer6- MacCaption demuxer
7- PGX decoder
7 8
8 9
9version 4.3:10version 4.3:
doc/general.texi+2−0
@@ -751,6 +751,8 @@ following image formats are supported: · 750 unmodified lines
751 @tab Portable GrayMap image751 @tab Portable GrayMap image
752@item PGMYUV @tab X @tab X752@item PGMYUV @tab X @tab X
753 @tab PGM with U and V components in YUV 4:2:0753 @tab PGM with U and V components in YUV 4:2:0
754@item PGX @tab @tab X
755 @tab PGX file decoder
754@item PIC @tab @tab X756@item PIC @tab @tab X
755 @tab Pictor/PC Paint757 @tab Pictor/PC Paint
756@item PNG @tab X @tab X758@item PNG @tab X @tab X
libavcodec/Makefile+1−0
@@ -536,6 +536,7 @@ OBJS-$(CONFIG_PGM_ENCODER) += pnmenc.o · 535 unmodified lines
536OBJS-$(CONFIG_PGMYUV_DECODER) += pnmdec.o pnm.o536OBJS-$(CONFIG_PGMYUV_DECODER) += pnmdec.o pnm.o
537OBJS-$(CONFIG_PGMYUV_ENCODER) += pnmenc.o537OBJS-$(CONFIG_PGMYUV_ENCODER) += pnmenc.o
538OBJS-$(CONFIG_PGSSUB_DECODER) += pgssubdec.o538OBJS-$(CONFIG_PGSSUB_DECODER) += pgssubdec.o
539OBJS-$(CONFIG_PGX_DECODER) += pgxdec.o
539OBJS-$(CONFIG_PICTOR_DECODER) += pictordec.o cga_data.o540OBJS-$(CONFIG_PICTOR_DECODER) += pictordec.o cga_data.o
540OBJS-$(CONFIG_PIXLET_DECODER) += pixlet.o541OBJS-$(CONFIG_PIXLET_DECODER) += pixlet.o
541OBJS-$(CONFIG_PJS_DECODER) += textdec.o ass.o542OBJS-$(CONFIG_PJS_DECODER) += textdec.o ass.o
libavcodec/allcodecs.c+1−0
@@ -238,6 +238,7 @@ extern AVCodec ff_pgm_encoder; · 237 unmodified lines
238extern AVCodec ff_pgm_decoder;238extern AVCodec ff_pgm_decoder;
239extern AVCodec ff_pgmyuv_encoder;239extern AVCodec ff_pgmyuv_encoder;
240extern AVCodec ff_pgmyuv_decoder;240extern AVCodec ff_pgmyuv_decoder;
241extern AVCodec ff_pgx_decoder;
241extern AVCodec ff_pictor_decoder;242extern AVCodec ff_pictor_decoder;
242extern AVCodec ff_pixlet_decoder;243extern AVCodec ff_pixlet_decoder;
243extern AVCodec ff_png_encoder;244extern AVCodec ff_png_encoder;
libavcodec/codec_desc.c+7−0
@@ -1405,6 +1405,13 @@ static const AVCodecDescriptor codec_descriptors[] = { · 1404 unmodified lines
1405 .long_name = NULL_IF_CONFIG_SMALL("AVS2-P2/IEEE1857.4"),1405 .long_name = NULL_IF_CONFIG_SMALL("AVS2-P2/IEEE1857.4"),
1406 .props = AV_CODEC_PROP_LOSSY,1406 .props = AV_CODEC_PROP_LOSSY,
1407 },1407 },
1408 {
1409 .id = AV_CODEC_ID_PGX,
1410 .type = AVMEDIA_TYPE_VIDEO,
1411 .name = "pgx",
1412 .long_name = NULL_IF_CONFIG_SMALL("PGX (JPEG2000 Test Format)"),
1413 .props = AV_CODEC_PROP_INTRA_ONLY | AV_CODEC_PROP_LOSSLESS,
1414 },
1408 {1415 {
1409 .id = AV_CODEC_ID_Y41P,1416 .id = AV_CODEC_ID_Y41P,
1410 .type = AVMEDIA_TYPE_VIDEO,1417 .type = AVMEDIA_TYPE_VIDEO,
libavcodec/codec_id.h+1−0
@@ -241,6 +241,7 @@ enum AVCodecID { · 240 unmodified lines
241 AV_CODEC_ID_SCREENPRESSO,241 AV_CODEC_ID_SCREENPRESSO,
242 AV_CODEC_ID_RSCC,242 AV_CODEC_ID_RSCC,
243 AV_CODEC_ID_AVS2,243 AV_CODEC_ID_AVS2,
244 AV_CODEC_ID_PGX,
244 245
245 AV_CODEC_ID_Y41P = 0x8000,246 AV_CODEC_ID_Y41P = 0x8000,
246 AV_CODEC_ID_AVRP,247 AV_CODEC_ID_AVRP,
libavcodec/pgxdec.c+168−0
@@ -0,0 +1,168 @@
1/*
2 * PGX image format
3 * Copyright (c) 2020 Gautam Ramakrishnan
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 "avcodec.h"
23#include "internal.h"
24#include "bytestream.h"
25#include "libavutil/imgutils.h"
26
27static int pgx_get_number(AVCodecContext *avctx, GetByteContext *g, int *number) {
28 int ret = AVERROR_INVALIDDATA;
29 char digit;
30
31 *number = 0;
32 while (1) {
33 uint64_t temp;
34 if (!bytestream2_get_bytes_left(g))
35 return AVERROR_INVALIDDATA;
36 digit = bytestream2_get_byte(g);
37 if (digit == ' ' || digit == 0xA || digit == 0xD)
38 break;
39 else if (digit < '0' || digit > '9')
40 return AVERROR_INVALIDDATA;
41
42 temp = (uint64_t)10 * (*number) + (digit - '0');
43 if (temp > INT_MAX)
44 return AVERROR_INVALIDDATA;
45 *number = temp;
46 ret = 0;
47 }
48
49 return ret;
50}
51
52static int pgx_decode_header(AVCodecContext *avctx, GetByteContext *g,
53 int *depth, int *width, int *height,
54 int *sign)
55{
56 int byte;
57
58 if (bytestream2_get_bytes_left(g) < 6) {
59 return AVERROR_INVALIDDATA;
60 }
61
62 bytestream2_skip(g, 6);
63
64 // Is the component signed?
65 byte = bytestream2_peek_byte(g);
66 if (byte == '+') {
67 *sign = 0;
68 bytestream2_skip(g, 1);
69 } else if (byte == '-') {
70 *sign = 1;
71 bytestream2_skip(g, 1);
72 } else if (byte == 0)
73 goto error;
74
75 byte = bytestream2_peek_byte(g);
76 if (byte == ' ')
77 bytestream2_skip(g, 1);
78 else if (byte == 0)
79 goto error;
80
81 if (pgx_get_number(avctx, g, depth))
82 goto error;
83 if (pgx_get_number(avctx, g, width))
84 goto error;
85 if (pgx_get_number(avctx, g, height))
86 goto error;
87
88 if (bytestream2_peek_byte(g) == 0xA)
89 bytestream2_skip(g, 1);
90 return 0;
91
92error:
93 av_log(avctx, AV_LOG_ERROR, "Error in decoding header.\n");
94 return AVERROR_INVALIDDATA;
95}
96
97#define WRITE_FRAME(D, PIXEL, suffix) \
98 static inline void write_frame_ ##D(AVPacket *avpkt, AVFrame *frame, GetByteContext *g, \
99 int width, int height, int sign, int depth) \
100 { \
101 int i, j; \
102 for (i = 0; i < height; i++) { \
103 PIXEL *line = (PIXEL*)frame->data[0] + i*frame->linesize[0]/sizeof(PIXEL); \
104 for (j = 0; j < width; j++) { \
105 int val; \
106 if (sign) \
107 val = (PIXEL)bytestream2_get_ ##suffix(g) + (1 << (depth - 1)); \
108 else \
109 val = bytestream2_get_ ##suffix(g); \
110 val <<= (D - depth); \
111 *(line + j) = val; \
112 } \
113 } \
114 } \
115
116WRITE_FRAME(8, int8_t, byte)
117WRITE_FRAME(16, int16_t, be16)
118
119static int pgx_decode_frame(AVCodecContext *avctx, void *data,
120 int *got_frame, AVPacket *avpkt)
121{
122 AVFrame *p = data;
123 int ret;
124 int bpp;
125 int width, height, depth;
126 int sign = 0;
127 GetByteContext g;
128 bytestream2_init(&g, avpkt->data, avpkt->size);
129
130 if ((ret = pgx_decode_header(avctx, &g, &depth, &width, &height, &sign)) < 0)
131 return ret;
132
133 if ((ret = ff_set_dimensions(avctx, width, height)) < 0)
134 return ret;
135
136 if (depth <= 8) {
137 avctx->pix_fmt = AV_PIX_FMT_GRAY8;
138 bpp = 8;
139 } else if (depth <= 16) {
140 avctx->pix_fmt = AV_PIX_FMT_GRAY16BE;
141 bpp = 16;
142 } else {
143 av_log(avctx, AV_LOG_ERROR, "Maximum depth of 16 bits supported.\n");
144 return AVERROR_PATCHWELCOME;
145 }
146 if (bytestream2_get_bytes_left(&g) < width * height * (bpp >> 3))
147 return AVERROR_INVALIDDATA;
148 if ((ret = ff_get_buffer(avctx, p, 0)) < 0)
149 return ret;
150 p->pict_type = AV_PICTURE_TYPE_I;
151 p->key_frame = 1;
152 avctx->bits_per_raw_sample = depth;
153 if (bpp == 8)
154 write_frame_8(avpkt, p, &g, width, height, sign, depth);
155 else if (bpp == 16)
156 write_frame_16(avpkt, p, &g, width, height, sign, depth);
157 *got_frame = 1;
158 return 0;
159}
160
161AVCodec ff_pgx_decoder = {
162 .name = "pgx",
163 .long_name = NULL_IF_CONFIG_SMALL("PGX (JPEG2000 Test Format)"),
164 .type = AVMEDIA_TYPE_VIDEO,
165 .id = AV_CODEC_ID_PGX,
166 .decode = pgx_decode_frame,
167 .capabilities = AV_CODEC_CAP_DR1,
168};
libavcodec/version.h+2−2
@@ -28,8 +28,8 @@ · 27 unmodified lines
28#include "libavutil/version.h"28#include "libavutil/version.h"
29 29
30#define LIBAVCODEC_VERSION_MAJOR 5830#define LIBAVCODEC_VERSION_MAJOR 58
31#define LIBAVCODEC_VERSION_MINOR 9331#define LIBAVCODEC_VERSION_MINOR 94
32#define LIBAVCODEC_VERSION_MICRO 10432#define LIBAVCODEC_VERSION_MICRO 100
33 33
34#define LIBAVCODEC_VERSION_INT AV_VERSION_INT(LIBAVCODEC_VERSION_MAJOR, \34#define LIBAVCODEC_VERSION_INT AV_VERSION_INT(LIBAVCODEC_VERSION_MAJOR, \
35 LIBAVCODEC_VERSION_MINOR, \35 LIBAVCODEC_VERSION_MINOR, \

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t