dxtory.c
Go to the documentation of this file.
1 /*
2  * Dxtory decoder
3  *
4  * Copyright (c) 2011 Konstantin Shishkov
5  *
6  * This file is part of Libav.
7  *
8  * Libav 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  * Libav 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 Libav; if not, write to the Free Software
20  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
21  */
22 
23 #include "avcodec.h"
24 #include "internal.h"
25 #include "libavutil/intreadwrite.h"
26 
28 {
29  avctx->pix_fmt = PIX_FMT_YUV420P;
31  if (!avctx->coded_frame)
32  return AVERROR(ENOMEM);
33 
34  return 0;
35 }
36 
37 static int decode_frame(AVCodecContext *avctx, void *data, int *data_size,
38  AVPacket *avpkt)
39 {
40  int h, w;
41  AVFrame *pic = avctx->coded_frame;
42  const uint8_t *src = avpkt->data;
43  uint8_t *Y1, *Y2, *U, *V;
44  int ret;
45 
46  if (pic->data[0])
47  avctx->release_buffer(avctx, pic);
48 
49  if (avpkt->size < avctx->width * avctx->height * 3 / 2 + 16) {
50  av_log(avctx, AV_LOG_ERROR, "packet too small\n");
51  return AVERROR_INVALIDDATA;
52  }
53 
54  pic->reference = 0;
55  if ((ret = ff_get_buffer(avctx, pic)) < 0)
56  return ret;
57 
59  pic->key_frame = 1;
60 
61  if (AV_RL32(src) != 0x01000002) {
62  av_log_ask_for_sample(avctx, "Unknown frame header %X\n", AV_RL32(src));
63  return AVERROR_PATCHWELCOME;
64  }
65  src += 16;
66 
67  Y1 = pic->data[0];
68  Y2 = pic->data[0] + pic->linesize[0];
69  U = pic->data[1];
70  V = pic->data[2];
71  for (h = 0; h < avctx->height; h += 2) {
72  for (w = 0; w < avctx->width; w += 2) {
73  AV_WN16A(Y1 + w, AV_RN16A(src));
74  AV_WN16A(Y2 + w, AV_RN16A(src + 2));
75  U[w >> 1] = src[4] + 0x80;
76  V[w >> 1] = src[5] + 0x80;
77  src += 6;
78  }
79  Y1 += pic->linesize[0] << 1;
80  Y2 += pic->linesize[0] << 1;
81  U += pic->linesize[1];
82  V += pic->linesize[2];
83  }
84 
85  *data_size = sizeof(AVFrame);
86  *(AVFrame*)data = *pic;
87 
88  return avpkt->size;
89 }
90 
92 {
93  AVFrame *pic = avctx->coded_frame;
94  if (pic->data[0])
95  avctx->release_buffer(avctx, pic);
96  av_freep(&avctx->coded_frame);
97 
98  return 0;
99 }
100 
102  .name = "dxtory",
103  .long_name = NULL_IF_CONFIG_SMALL("Dxtory"),
104  .type = AVMEDIA_TYPE_VIDEO,
105  .id = CODEC_ID_DXTORY,
106  .init = decode_init,
107  .close = decode_close,
108  .decode = decode_frame,
109  .capabilities = CODEC_CAP_DR1,
110 };
enum PixelFormat pix_fmt
Pixel format, see PIX_FMT_xxx.
Definition: avcodec.h:1426
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
Definition: error.h:54
Audio Video Frame.
Definition: avcodec.h:985
void(* release_buffer)(struct AVCodecContext *c, AVFrame *pic)
Called to release buffers which were allocated with get_buffer.
Definition: avcodec.h:1737
AVFrame * coded_frame
the picture in the bitstream
Definition: avcodec.h:2000
int size
Definition: avcodec.h:909
AVCodec.
Definition: avcodec.h:3189
void av_freep(void *arg)
Free a memory block which has been allocated with av_malloc(z)() or av_realloc() and set the pointer ...
Definition: mem.c:147
planar YUV 4:2:0, 12bpp, (1 Cr & Cb sample per 2x2 Y samples)
Definition: pixfmt.h:64
#define av_cold
Definition: attributes.h:71
const char data[16]
Definition: mxf.c:60
uint8_t * data
Definition: avcodec.h:908
#define V
Definition: options.c:69
#define CODEC_CAP_DR1
Codec uses get_buffer() for allocating buffers and supports custom allocators.
Definition: avcodec.h:719
int reference
is this picture used as reference The values for this are the same as the MpegEncContext.picture_structure variable, that is 1->top field, 2->bottom field, 3->frame/both fields.
Definition: avcodec.h:1074
#define AVERROR(e)
Definition: error.h:43
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification. ...
Definition: internal.h:191
AV_RL32
Definition: bytestream.h:89
void av_log(void *avcl, int level, const char *fmt,...)
Definition: log.c:140
const char * name
Name of the codec implementation.
Definition: avcodec.h:3196
AVFrame * avcodec_alloc_frame(void)
Allocate an AVFrame and set its fields to default values.
Definition: utils.c:618
enum AVPictureType pict_type
Picture type of the frame, see ?_TYPE below.
Definition: avcodec.h:1029
int width
picture width / height.
Definition: avcodec.h:1408
struct AVFrame AVFrame
Audio Video Frame.
int ff_get_buffer(AVCodecContext *avctx, AVFrame *frame)
Definition: utils.c:1867
static av_cold int decode_init(AVCodecContext *avctx)
Definition: dxtory.c:27
#define AV_WN16A(p, v)
Definition: intreadwrite.h:454
#define AVERROR_PATCHWELCOME
Not yet implemented in Libav, patches welcome.
Definition: error.h:57
AVCodec ff_dxtory_decoder
Definition: dxtory.c:101
external API header
int linesize[AV_NUM_DATA_POINTERS]
Size, in bytes, of the data for each picture/channel plane.
Definition: avcodec.h:1008
void av_log_ask_for_sample(void *avc, const char *msg,...) av_printf_format(2
Log a generic warning message asking for a sample.
main external API structure.
Definition: avcodec.h:1329
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition: log.h:111
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
Definition: avcodec.h:997
common internal api header.
static int decode_frame(AVCodecContext *avctx, void *data, int *data_size, AVPacket *avpkt)
Definition: dxtory.c:37
static av_cold int decode_close(AVCodecContext *avctx)
Definition: dxtory.c:91
int key_frame
1 -> keyframe, 0-> not
Definition: avcodec.h:1022
#define AV_RN16A(p)
Definition: intreadwrite.h:442
Definition: vf_drawbox.c:32