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/common.h"
26 #include "libavutil/intreadwrite.h"
27 
29 {
30  avctx->pix_fmt = AV_PIX_FMT_YUV420P;
32  if (!avctx->coded_frame)
33  return AVERROR(ENOMEM);
34 
35  return 0;
36 }
37 
38 static int decode_frame(AVCodecContext *avctx, void *data, int *got_frame,
39  AVPacket *avpkt)
40 {
41  int h, w;
42  AVFrame *pic = avctx->coded_frame;
43  const uint8_t *src = avpkt->data;
44  uint8_t *Y1, *Y2, *U, *V;
45  int ret;
46 
47  if (pic->data[0])
48  avctx->release_buffer(avctx, pic);
49 
50  if (avpkt->size < avctx->width * avctx->height * 3 / 2 + 16) {
51  av_log(avctx, AV_LOG_ERROR, "packet too small\n");
52  return AVERROR_INVALIDDATA;
53  }
54 
55  pic->reference = 0;
56  if ((ret = ff_get_buffer(avctx, pic)) < 0)
57  return ret;
58 
60  pic->key_frame = 1;
61 
62  if (AV_RL32(src) != 0x01000002) {
63  av_log_ask_for_sample(avctx, "Unknown frame header %X\n", AV_RL32(src));
64  return AVERROR_PATCHWELCOME;
65  }
66  src += 16;
67 
68  Y1 = pic->data[0];
69  Y2 = pic->data[0] + pic->linesize[0];
70  U = pic->data[1];
71  V = pic->data[2];
72  for (h = 0; h < avctx->height; h += 2) {
73  for (w = 0; w < avctx->width; w += 2) {
74  AV_COPY16(Y1 + w, src);
75  AV_COPY16(Y2 + w, src + 2);
76  U[w >> 1] = src[4] + 0x80;
77  V[w >> 1] = src[5] + 0x80;
78  src += 6;
79  }
80  Y1 += pic->linesize[0] << 1;
81  Y2 += pic->linesize[0] << 1;
82  U += pic->linesize[1];
83  V += pic->linesize[2];
84  }
85 
86  *got_frame = 1;
87  *(AVFrame*)data = *pic;
88 
89  return avpkt->size;
90 }
91 
93 {
94  AVFrame *pic = avctx->coded_frame;
95  if (pic->data[0])
96  avctx->release_buffer(avctx, pic);
97  av_freep(&avctx->coded_frame);
98 
99  return 0;
100 }
101 
103  .name = "dxtory",
104  .long_name = NULL_IF_CONFIG_SMALL("Dxtory"),
105  .type = AVMEDIA_TYPE_VIDEO,
106  .id = AV_CODEC_ID_DXTORY,
107  .init = decode_init,
108  .close = decode_close,
109  .decode = decode_frame,
110  .capabilities = CODEC_CAP_DR1,
111 };
This structure describes decoded (raw) audio or video data.
Definition: avcodec.h:989
void(* release_buffer)(struct AVCodecContext *c, AVFrame *pic)
Called to release buffers which were allocated with get_buffer.
Definition: avcodec.h:2259
AVFrame * coded_frame
the picture in the bitstream
Definition: avcodec.h:2725
int size
Definition: avcodec.h:916
enum AVPixelFormat pix_fmt
Pixel format, see AV_PIX_FMT_xxx.
Definition: avcodec.h:1533
AVCodec.
Definition: avcodec.h:2960
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:151
uint8_t
const char data[16]
Definition: mxf.c:66
uint8_t * data
Definition: avcodec.h:915
void av_log_ask_for_sample(void *avc, const char *msg,...) av_printf_format(2
Log a generic warning message asking for a sample.
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:1132
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification. ...
Definition: internal.h:88
void av_log(void *avcl, int level, const char *fmt,...)
Definition: log.c:146
const char * name
Name of the codec implementation.
Definition: avcodec.h:2967
AVFrame * avcodec_alloc_frame(void)
Allocate an AVFrame and set its fields to default values.
Definition: utils.c:616
enum AVPictureType pict_type
Picture type of the frame, see ?_TYPE below.
Definition: avcodec.h:1065
#define AV_COPY16(d, s)
Definition: intreadwrite.h:502
int width
picture width / height.
Definition: avcodec.h:1508
int ff_get_buffer(AVCodecContext *avctx, AVFrame *frame)
Get a buffer for a frame.
Definition: utils.c:464
#define AV_RL32
Definition: intreadwrite.h:146
static av_cold int decode_init(AVCodecContext *avctx)
Definition: dxtory.c:28
AVCodec ff_dxtory_decoder
Definition: dxtory.c:102
external API header
int linesize[AV_NUM_DATA_POINTERS]
Size, in bytes, of the data for each picture/channel plane.
Definition: avcodec.h:1008
main external API structure.
Definition: avcodec.h:1339
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
Definition: avcodec.h:997
Definition: vf_drawbox.c:36
planar YUV 4:2:0, 12bpp, (1 Cr & Cb sample per 2x2 Y samples)
Definition: pixfmt.h:65
common internal api header.
common internal and external API header
static av_cold int decode_close(AVCodecContext *avctx)
Definition: dxtory.c:92
int key_frame
1 -> keyframe, 0-> not
Definition: avcodec.h:1058
This structure stores compressed data.
Definition: avcodec.h:898
static int decode_frame(AVCodecContext *avctx, void *data, int *got_frame, AVPacket *avpkt)
Definition: dxtory.c:38