32#define CACHED_BITSTREAM_READER !ARCH_X86_32
79 int start =
s->streampos +
img_info[2].start;
80 uint8_t *ptr, *ptr1, *ptr2;
84 ptr = picture->
data[0];
85 ptr1 = picture->
data[1];
86 ptr2 = picture->
data[2];
90 for (
int y = 0; y <
height; y += 2) {
92 for (
int x = 0; x <
width - 1; x++) {
93 fill = bytestream2_get_byte(gb);
95 *(
dst++) = (fill + bytestream2_peek_byte(gb) + 1) >> 1;
97 fill = bytestream2_get_byte(gb);
104 for (
int x = 0; x <
width - 1; x++) {
105 fill = bytestream2_get_byte(gb);
107 *(
dst++) = (fill + bytestream2_peek_byte(gb) + 1) >> 1;
109 fill = bytestream2_get_byte(gb);
116 for (
int x = 0; x < (
width >> 1) - 1; x++) {
117 fill = bytestream2_get_byte(gb);
119 *(
dst++) = (fill + bytestream2_peek_byte(gb) + 1) >> 1;
121 fill = bytestream2_get_byte(gb);
128 for (
int x = 0; x < (
width >> 1) - 1; x++) {
129 fill = bytestream2_get_byte(gb);
131 *(
dst++) = (fill + bytestream2_peek_byte(gb) + 1) >> 1;
133 fill = bytestream2_get_byte(gb);
150 for (
int y = 0; y <
height - 2; y += 2) {
151 const uint8_t *
src1 = ptr;
152 uint8_t *
dst = ptr + linesize;
153 const uint8_t *
src2 =
dst + linesize;
154 for (x = 0; x <
width - 2; x += 2) {
160 ptr += linesize << 1;
164 dst = ptr + linesize;
165 for (x = 0; x <
width - 2; x += 2) {
175 for (
int y =
height - 2; y >= 0; y -= 2) {
176 const uint8_t *
src = ptr + (y >> 1) * linesize;
177 uint8_t *
dst = ptr + y * linesize;
180 for (
int x =
width - 4; x >= 0; x -= 2) {
182 dst[x + 1] = (
src[x >> 1] +
src[(x >> 1) + 1] + 1) >> 1;
191 int start =
s->streampos;
196 count = bytestream2_get_byte(gb) + 1;
200 for (
int j = 0; j < count; j++) {
201 const int bit = bytestream2_get_byteu(gb) + 1;
202 const int code = bytestream2_get_be16u(gb);
203 const int sym = bytestream2_get_byteu(gb);
215 s->bits,
sizeof(*
s->bits),
sizeof(*
s->bits),
216 s->codes,
sizeof(*
s->codes),
sizeof(*
s->codes),
217 s->syms,
sizeof(*
s->syms),
sizeof(*
s->syms), 0);
225 int target_res,
int curr_res)
231 int start =
s->streampos;
233 const int scaling = target_res - curr_res;
234 const uint8_t type2idx[] = { 0, 0xff, 1, 2 };
254 while (shiftreg != 0xfffffe) {
269 idx = type2idx[
type];
273 x2 = avctx->
width >> (scaling + !!idx);
274 for (
int x = 0; x < x2; x++) {
279 m =
get_vlc2(&
g,
s->vlc[idx].table,
s->vlc[idx].bits, 2);
288 s->streampos = (
s->streampos + 0x6000 + 2047) & ~0x7ff;
297 const uint8_t *buf = avpkt->
data;
299 uint8_t *ptr, *ptr1, *ptr2;
305 if (!memcmp(
"PCD_OPA", buf, 7)) {
308 "reading first thumbnail only\n");
309 }
else if (avpkt->
size < 786432) {
311 }
else if (memcmp(
"PCD_IPI", buf + 0x800, 7)) {
315 s->orientation =
s->thumbnails ? buf[12] & 3 : buf[0x48] & 3;
319 else if (avpkt->
size <= 788480)
322 s->resolution =
av_clip(4 -
s->lowres, 0, 4);
336 if (
s->resolution < 3) {
346 for (
int y = 0; y < avctx->
height; y += 2) {
348 ptr += p->linesize[0];
351 ptr += p->linesize[0];
354 ptr1 += p->linesize[1];
357 ptr2 += p->linesize[2];
370 if (
s->resolution == 4) {
379 s->streampos = 0xc2000;
380 for (
int n = 0; n < 3; n++) {
384 s->streampos = (
s->streampos + 2047) & ~0x3ff;
388 if (
s->resolution == 4) {
392 for (
int n = 0; n < 3; n++) {
396 s->streampos = (
s->streampos + 2047) & ~0x3ff;
406 for (
int y = 0; y < avctx->
height >> 1; y++) {
407 for (
int x = 0; x < avctx->
width >> 1; x++) {
412 ptr1 += p->linesize[1];
413 ptr2 += p->linesize[2];
437 for (
int i = 0;
i < 3;
i++)
443#define OFFSET(x) offsetof(PhotoCDContext, x)
444#define VD AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_DECODING_PARAM
447 {
"lowres",
"Lower the decoding resolution by a power of two",
453 .class_name =
"photocd",
uint8_t ptrdiff_t const uint8_t ptrdiff_t int intptr_t intptr_t int int16_t * dst
const FFCodec ff_photocd_decoder
Libavcodec external API header.
static av_always_inline unsigned int bytestream2_get_buffer(GetByteContext *g, uint8_t *dst, unsigned int size)
static av_always_inline int bytestream2_get_bytes_left(const GetByteContext *g)
static av_always_inline void bytestream2_init(GetByteContext *g, const uint8_t *buf, int buf_size)
static av_always_inline int bytestream2_seek(GetByteContext *g, int offset, int whence)
static av_always_inline int bytestream2_tell(const GetByteContext *g)
#define i(width, name, range_min, range_max)
#define bit(string, value)
#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)
int ff_set_dimensions(AVCodecContext *s, int width, int height)
bitstream reader API header.
static av_always_inline int get_vlc2(GetBitContext *s, const VLCElem *table, int bits, int max_depth)
Parse a vlc code.
static int get_bits_left(GetBitContext *gb)
static void skip_bits(GetBitContext *s, int n)
static int init_get_bits8(GetBitContext *s, const uint8_t *buffer, int byte_size)
Initialize GetBitContext.
static int get_bits_count(const GetBitContext *s)
static unsigned int get_bits(GetBitContext *s, int n)
Read 1-25 bits.
static unsigned int show_bits(GetBitContext *s, int n)
Show 1-25 bits.
@ AV_OPT_TYPE_INT
Underlying C type is int.
#define AV_CODEC_CAP_DR1
Codec uses get_buffer() or get_encode_buffer() for allocating buffers and supports custom allocators.
#define AV_CODEC_CAP_FRAME_THREADS
Codec supports frame-level multithreading.
@ AVDISCARD_ALL
discard all
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
#define AV_LOG_WARNING
Something somehow does not look correct.
const char * av_default_item_name(void *ptr)
Return the context name.
#define LIBAVUTIL_VERSION_INT
Multithreading API for decoders.
static av_const int sign_extend(int val, unsigned bits)
static av_noinline int decode_huff(AVCodecContext *avctx, AVFrame *frame, int target_res, int curr_res)
static av_noinline int read_hufftable(AVCodecContext *avctx, VLC *vlc)
static av_cold int photocd_decode_close(AVCodecContext *avctx)
static av_noinline void interp_lines(uint8_t *ptr, int linesize, int width, int height)
static int photocd_decode_frame(AVCodecContext *avctx, AVFrame *p, int *got_frame, AVPacket *avpkt)
static const AVClass photocd_class
static const ImageInfo img_info[6]
static av_noinline void interp_lowres(PhotoCDContext *s, AVFrame *picture, int width, int height)
static av_cold int photocd_decode_init(AVCodecContext *avctx)
static av_noinline void interp_pixels(uint8_t *ptr, int linesize, int width, int height)
@ AVCOL_RANGE_JPEG
Full range content.
@ AV_PIX_FMT_YUV420P
planar YUV 4:2:0, 12bpp, (1 Cr & Cb sample per 2x2 Y samples)
@ AVCOL_PRI_BT709
also ITU-R BT1361 / IEC 61966-2-4 / SMPTE RP 177 Annex B
@ AVCOL_TRC_IEC61966_2_1
IEC 61966-2-1 (sRGB or sYCC)
@ AVCOL_SPC_BT709
also ITU-R BT1361 / IEC 61966-2-4 xvYCC709 / derived in SMPTE RP 177 Annex B
int ff_thread_get_buffer(AVCodecContext *avctx, AVFrame *f, int flags)
Wrapper around get_buffer() for frame-multithreaded codecs.
Describe the class of an AVClass context structure.
main external API structure.
enum AVPixelFormat pix_fmt
Pixel format, see AV_PIX_FMT_xxx.
int width
picture width / height.
enum AVColorRange color_range
MPEG vs JPEG YUV range.
enum AVColorPrimaries color_primaries
Chromaticity coordinates of the source primaries.
enum AVColorSpace colorspace
YUV colorspace type.
enum AVColorTransferCharacteristic color_trc
Color Transfer Characteristic.
enum AVDiscard skip_frame
Skip decoding for selected frames.
This structure describes decoded (raw) audio or video data.
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
int linesize[AV_NUM_DATA_POINTERS]
For video, a positive or negative value, which is typically indicating the size in bytes of each pict...
This structure stores compressed data.
int ff_vlc_init_sparse(VLC *vlc, int nb_bits, int nb_codes, const void *bits, int bits_wrap, int bits_size, const void *codes, int codes_wrap, int codes_size, const void *symbols, int symbols_wrap, int symbols_size, int flags)
Build VLC decoding tables suitable for use with get_vlc2().
void ff_vlc_free(VLC *vlc)