FFmpeg: libavcodec/cri.c Source File
Go to the documentation of this file. 1 /*
2 * CRI image decoder
3 *
4 * Copyright (c) 2020 Paul B Mahol
5 *
6 * This file is part of FFmpeg.
7 *
8 * FFmpeg is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License as published by the Free Software Foundation; either
11 * version 2.1 of the License, or (at your option) any later version.
12 *
13 * FFmpeg is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Lesser General Public License for more details.
17 *
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with FFmpeg; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
21 */
22
23 /**
24 * @file
25 * Cintel RAW image decoder
26 */
27
28 #define BITSTREAM_READER_LE
29
37
42
49
51 {
55
59
63
65 if (!codec)
70 s->jpeg_avctx->flags = avctx->
flags;
71 s->jpeg_avctx->flags2 = avctx->
flags2;
72 s->jpeg_avctx->dct_algo = avctx->
dct_algo;
77
78 return 0;
79 }
80
83 {
86
87 while (count > 0) {
90 break;
91 a0 = bytestream2_get_le32(gb);
92 a1 = bytestream2_get_le32(gb);
93 a2 = bytestream2_get_le32(gb);
94 a3 = bytestream2_get_le32(gb);
95 dst[
pos] = (((
a0 >> 1) & 0xE00) | (
a0 & 0x1FF)) <<
shift;
98 if (count == 1)
99 break;
102 }
103 dst[
pos] = (((
a0 >> 13) & 0x3F) | ((
a0 >> 14) & 0xFC0)) <<
shift;
106 if (count == 2)
107 break;
110 }
111 dst[
pos] = (((
a0 >> 26) & 7) | ((
a1 & 0x1FF) << 3)) <<
shift;
114 if (count == 3)
115 break;
118 }
119 dst[
pos] = (((
a1 >> 10) & 0x1FF) | ((
a1 >> 11) & 0xE00)) <<
shift;
122 if (count == 4)
123 break;
126 }
127 dst[
pos] = (((
a1 >> 23) & 0x3F) | ((
a2 & 0x3F) << 6)) <<
shift;
130 if (count == 5)
131 break;
134 }
135 dst[
pos] = (((
a2 >> 7) & 0xFF8) | ((
a2 >> 6) & 7)) <<
shift;
138 if (count == 6)
139 break;
142 }
143 dst[
pos] = (((
a3 & 7) << 9) | ((
a2 >> 20) & 0x1FF)) <<
shift;
146 if (count == 7)
147 break;
150 }
151 dst[
pos] = (((
a3 >> 4) & 0xFC0) | ((
a3 >> 3) & 0x3F)) <<
shift;
154 if (count == 8)
155 break;
158 }
159 dst[
pos] = (((
a3 >> 16) & 7) | ((
a3 >> 17) & 0xFF8)) <<
shift;
162 if (count == 9)
163 break;
166 }
167
168 count -= 9;
169 }
170 }
171
174 {
178 int ret,
bps, hflip = 0, vflip = 0;
180 int compressed = 0;
182
185
187
189 char codec_name[1024];
190 uint32_t
key, length;
193
194 key = bytestream2_get_le32(gb);
195 length = bytestream2_get_le32(gb);
196
198 case 1:
199 if (length != 4)
201
202 if (bytestream2_get_le32(gb) !=
MKTAG(
'D',
'V',
'C',
'C'))
204 break;
205 case 100:
206 if (length < 16)
208 width = bytestream2_get_le32(gb);
209 height = bytestream2_get_le32(gb);
210 s->color_model = bytestream2_get_le32(gb);
211 if (bytestream2_get_le32(gb) != 1)
216 length -= 16;
217 goto skip;
218 case 101:
219 if (length != 4)
221
222 if (bytestream2_get_le32(gb) != 0)
224 break;
225 case 102:
227 length -=
FFMIN(length,
sizeof(codec_name) - 1);
228 if (strncmp(codec_name,
"cintel_craw",
FFMIN(length,
sizeof(codec_name) - 1)))
230 compressed = 1;
231 goto skip;
232 case 103:
236 s->data_size = length;
237 goto skip;
238 case 105:
239 hflip = bytestream2_get_byte(gb) != 0;
240 length--;
241 goto skip;
242 case 106:
243 vflip = bytestream2_get_byte(gb) != 0;
244 length--;
245 goto skip;
246 case 107:
247 if (length != 4)
252 break;
253 case 119:
254 if (length != 32)
256
257 for (
int i = 0;
i < 4;
i++)
258 s->tile_size[
i] = bytestream2_get_le64(gb);
259 break;
260 default:
262 skip:
264 }
265 }
266
267 switch (
s->color_model) {
268 case 76:
269 case 88:
271 break;
272 case 77:
273 case 89:
275 break;
276 case 78:
277 case 90:
279 break;
280 case 45:
281 case 79:
282 case 91:
284 break;
285 }
286
287 switch (
s->color_model) {
288 case 45:
290 break;
291 case 76:
292 case 77:
293 case 78:
294 case 79:
296 break;
297 case 88:
298 case 89:
299 case 90:
300 case 91:
302 break;
303 default:
305 }
306
307 if (compressed) {
308 for (
int i = 0;
i < 4;
i++) {
309 if (
s->tile_size[
i] >=
s->data_size)
311 }
312
313 if (
s->tile_size[0] +
s->tile_size[1] +
s->tile_size[2] +
s->tile_size[3] !=
316 }
317
318 if (!
s->data || !
s->data_size)
320
323
325
326 if (!compressed &&
s->color_model == 45) {
327 uint16_t *dst = (uint16_t *)p->
data[0];
329
332 } else if (!compressed) {
335
339
340 for (
int y = 0; y < avctx->
height; y++) {
341 uint16_t *dst = (uint16_t *)(p->
data[0] + y * p->
linesize[0]);
342
344 break;
345
346 for (
int x = 0; x < avctx->
width; x++)
348 }
349 } else {
351
352 for (int tile = 0; tile < 4; tile++) {
354 s->jpkt->data = (uint8_t *)
s->data +
offset;
355 s->jpkt->size =
s->tile_size[tile];
356
361 }
362
365 s->jpeg_avctx->width * 2 != avctx->
width ||
366 s->jpeg_avctx->height * 2 != avctx->
height) {
369 "JPEG decoding error (%d).\n",
ret);
370 } else {
372 "JPEG invalid format.\n");
374 }
375
376 /* Normally skip, if error explode */
379 else
380 return 0;
381 }
382
383 for (
int y = 0; y <
s->jpeg_avctx->height; y++) {
384 const int hw =
s->jpgframe->width / 2;
385 uint16_t *dst = (uint16_t *)(p->
data[0] + (y * 2) * p->
linesize[0] + tile * hw * 2);
386 const uint16_t *
src = (
const uint16_t *)(
s->jpgframe->data[0] + y *
s->jpgframe->linesize[0]);
387
388 memcpy(dst,
src, hw * 2);
391 memcpy(dst,
src, hw * 2);
392 }
393
396 }
397 }
398
399 if (hflip || vflip) {
402 if (rotation) {
405 }
406 }
407
410
411 *got_frame = 1;
412
413 return 0;
414 }
415
417 {
419
423
424 return 0;
425 }
426
438 };
void av_packet_unref(AVPacket *pkt)
Wipe the packet.
#define FF_CODEC_CAP_INIT_THREADSAFE
The codec does not modify any global variables in the init function, allowing to call the init functi...
static int get_bits_left(GetBitContext *gb)
Filter the word "frame" indicates either a video frame or a group of audio as stored in an AVFrame structure Format for each input and each output the list of supported formats For video that means pixel format For audio that means channel sample they are references to shared objects When the negotiation mechanism computes the intersection of the formats supported at each end of a all references to both lists are replaced with a reference to the intersection And when a single format is eventually chosen for a link amongst the remaining all references to the list are updated That means that if a filter requires that its input and output have the same format amongst a supported all it has to do is use a reference to the same list of formats query_formats can leave some formats unset and return AVERROR(EAGAIN) to cause the negotiation mechanism toagain later. That can be used by filters with complex requirements to use the format negotiated on one link to set the formats supported on another. Frame references ownership and permissions
const AVCodec ff_cri_decoder
AVFrameSideData * av_frame_new_side_data(AVFrame *frame, enum AVFrameSideDataType type, size_t size)
Add a new side data to a frame.
static void unpack_10bit(GetByteContext *gb, uint16_t *dst, int shift, int w, int h, ptrdiff_t stride)
int err_recognition
Error recognition; may misdetect some more or less valid parts as errors.
void av_frame_free(AVFrame **frame)
Free the frame and any dynamically allocated objects in it, e.g.
This structure describes decoded (raw) audio or video data.
void av_display_matrix_flip(int32_t matrix[9], int hflip, int vflip)
Flip the input matrix horizontally and/or vertically.
void av_display_rotation_set(int32_t matrix[9], double angle)
Initialize a transformation matrix describing a pure clockwise rotation by the specified angle (in de...
@ AV_FRAME_DATA_DISPLAYMATRIX
This side data contains a 3x3 transformation matrix describing an affine transformation that needs to...
#define AV_PIX_FMT_BAYER_GRBG16
void av_packet_free(AVPacket **pkt)
Free the packet, if the packet is reference counted, it will be unreferenced first.
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
static av_always_inline void bytestream2_skip(GetByteContext *g, unsigned int size)
static unsigned int get_bits(GetBitContext *s, int n)
Read 1-25 bits.
static av_always_inline float av_int2float(uint32_t i)
Reinterpret a 32-bit integer as a float.
the pkt_dts and pkt_pts fields in AVFrame will work as usual Restrictions on codec whose streams don t reset across will not work because their bitstreams cannot be decoded in parallel *The contents of buffers must not be read before as well as code calling up to before the decode process starts Call have so the codec calls ff_thread_report set FF_CODEC_CAP_ALLOCATE_PROGRESS in AVCodec caps_internal and use ff_thread_get_buffer() to allocate frames. The frames must then be freed with ff_thread_release_buffer(). Otherwise decode directly into the user-supplied frames. Call ff_thread_report_progress() after some part of the current picture has decoded. A good place to put this is where draw_horiz_band() is called - add this if it isn 't called anywhere
int key_frame
1 -> keyframe, 0-> not
int flags
AV_CODEC_FLAG_*.
int dct_algo
DCT algorithm, see FF_DCT_* below.
#define AV_PIX_FMT_GRAY16
AVFrame * av_frame_alloc(void)
Allocate an AVFrame and set its fields to default values.
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
static int init_get_bits8(GetBitContext *s, const uint8_t *buffer, int byte_size)
Initialize GetBitContext.
static void decode(AVCodecContext *dec_ctx, AVPacket *pkt, AVFrame *frame, FILE *outfile)
AVCodecContext * avcodec_alloc_context3(const AVCodec *codec)
Allocate an AVCodecContext and set its fields to default values.
int avcodec_receive_frame(AVCodecContext *avctx, AVFrame *frame)
Return decoded output data from a decoder.
static av_cold int cri_decode_init(AVCodecContext *avctx)
int bits_per_raw_sample
Bits per sample/pixel of internal libavcodec pixel/sample format.
#define AV_LOG_DEBUG
Stuff which is only useful for libav* developers.
#define AV_PIX_FMT_BAYER_BGGR16
AVCodecContext * jpeg_avctx
#define AV_CODEC_CAP_FRAME_THREADS
Codec supports frame-level multithreading.
void avcodec_free_context(AVCodecContext **avctx)
Free the codec context and everything associated with it and write NULL to the provided pointer.
@ AV_PICTURE_TYPE_I
Intra.
#define AV_PIX_FMT_BAYER_GBRG16
static av_always_inline unsigned int bytestream2_get_buffer(GetByteContext *g, uint8_t *dst, unsigned int size)
int attribute_align_arg avcodec_open2(AVCodecContext *avctx, const AVCodec *codec, AVDictionary **options)
Initialize the AVCodecContext to use the given AVCodec.
#define AV_EF_EXPLODE
abort decoding on minor error detection
static int cri_decode_frame(AVCodecContext *avctx, void *data, int *got_frame, AVPacket *avpkt)
static av_always_inline int bytestream2_get_bytes_left(GetByteContext *g)
const AVCodec * avcodec_find_decoder(enum AVCodecID id)
Find a registered decoder with a matching codec ID.
int flags2
AV_CODEC_FLAG2_*.
enum AVPictureType pict_type
Picture type of the frame.
#define AV_CODEC_CAP_DR1
Codec uses get_buffer() or get_encode_buffer() for allocating buffers and supports custom allocators.
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification.
it s the only field you need to keep assuming you have a context There is some magic you don t need to care about around this just let it vf offset
AVPacket * av_packet_alloc(void)
Allocate an AVPacket and set its fields to default values.
int avcodec_send_packet(AVCodecContext *avctx, const AVPacket *avpkt)
Supply raw packet data as input to a decoder.
#define i(width, name, range_min, range_max)
#define FF_CODEC_CAP_INIT_CLEANUP
The codec allows calling the close function for deallocation even if the init function returned a fai...
void av_frame_unref(AVFrame *frame)
Unreference all the buffers referenced by frame and reset the frame fields.
int idct_algo
IDCT algorithm, see FF_IDCT_* below.
const char * name
Name of the codec implementation.
enum AVPixelFormat pix_fmt
Pixel format, see AV_PIX_FMT_xxx.
these buffered frames must be flushed immediately if a new input produces new the filter must not call request_frame to get more It must just process the frame or queue it The task of requesting more frames is left to the filter s request_frame method or the application If a filter has several the filter must be ready for frames arriving randomly on any input any filter with several inputs will most likely require some kind of queuing mechanism It is perfectly acceptable to have a limited queue and to drop frames when the inputs are too unbalanced request_frame For filters that do not use the this method is called when a frame is wanted on an output For a it should directly call filter_frame on the corresponding output For a if there are queued frames already one of these frames should be pushed If the filter should request a frame on one of its repeatedly until at least one frame has been pushed Return or at least make progress towards producing a frame
main external API structure.
static int shift(int a, int b)
int ff_set_dimensions(AVCodecContext *s, int width, int height)
Check that the provided frame dimensions are valid and set them on the codec context.
Structure to hold side data for an AVFrame.
This structure stores compressed data.
int width
picture width / height.
static av_always_inline void bytestream2_init(GetByteContext *g, const uint8_t *buf, int buf_size)
#define AVERROR_BUG
Internal bug, also see AVERROR_BUG2.
int linesize[AV_NUM_DATA_POINTERS]
For video, a positive or negative value, which is typically indicating the size in bytes of each pict...
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
#define MKTAG(a, b, c, d)
#define AV_PIX_FMT_BAYER_RGGB16
static av_cold int cri_decode_close(AVCodecContext *avctx)
Generated on Wed Aug 24 2022 21:37:30 for FFmpeg by
doxygen
1.8.17