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;
31 
32  return 0;
33 }
34 
35 static int decode_frame(AVCodecContext *avctx, void *data, int *got_frame,
36  AVPacket *avpkt)
37 {
38  int h, w;
39  AVFrame *pic = data;
40  const uint8_t *src = avpkt->data;
41  uint8_t *Y1, *Y2, *U, *V;
42  int ret;
43 
44  if (avpkt->size < avctx->width * avctx->height * 3 / 2 + 16) {
45  av_log(avctx, AV_LOG_ERROR, "packet too small\n");
46  return AVERROR_INVALIDDATA;
47  }
48 
49  if ((ret = ff_get_buffer(avctx, pic, 0)) < 0)
50  return ret;
51 
53  pic->key_frame = 1;
54 
55  if (AV_RL32(src) != 0x01000002) {
56  avpriv_request_sample(avctx, "Frame header %X", AV_RL32(src));
57  return AVERROR_PATCHWELCOME;
58  }
59  src += 16;
60 
61  Y1 = pic->data[0];
62  Y2 = pic->data[0] + pic->linesize[0];
63  U = pic->data[1];
64  V = pic->data[2];
65  for (h = 0; h < avctx->height; h += 2) {
66  for (w = 0; w < avctx->width; w += 2) {
67  AV_COPY16(Y1 + w, src);
68  AV_COPY16(Y2 + w, src + 2);
69  U[w >> 1] = src[4] + 0x80;
70  V[w >> 1] = src[5] + 0x80;
71  src += 6;
72  }
73  Y1 += pic->linesize[0] << 1;
74  Y2 += pic->linesize[0] << 1;
75  U += pic->linesize[1];
76  V += pic->linesize[2];
77  }
78 
79  *got_frame = 1;
80 
81  return avpkt->size;
82 }
83 
85  .name = "dxtory",
86  .long_name = NULL_IF_CONFIG_SMALL("Dxtory"),
87  .type = AVMEDIA_TYPE_VIDEO,
88  .id = AV_CODEC_ID_DXTORY,
89  .init = decode_init,
90  .decode = decode_frame,
91  .capabilities = CODEC_CAP_DR1,
92 };
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
Definition: error.h:59
This structure describes decoded (raw) audio or video data.
Definition: frame.h:76
enum AVPixelFormat pix_fmt
Pixel format, see AV_PIX_FMT_xxx.
the sinusoids Y1
Definition: lab5.m:33
output residual component w
void void avpriv_request_sample(void *avc, const char *msg,...) av_printf_format(2
Log a generic warning message about a missing feature.
uint8_t
#define av_cold
Definition: attributes.h:78
#define CODEC_CAP_DR1
Codec uses get_buffer() for allocating buffers and supports custom allocators.
uint8_t * data
Y2
Definition: lab5.m:34
#define U(x)
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification. ...
Spectrum Plot time data
void av_log(void *avcl, int level, const char *fmt,...)
Definition: log.c:246
const char * name
Name of the codec implementation.
external API header
#define V
enum AVPictureType pict_type
Picture type of the frame.
Definition: frame.h:144
#define AV_COPY16(d, s)
Definition: intreadwrite.h:574
ret
Definition: avfilter.c:821
int width
picture width / height.
#define AV_RL32
static av_cold int decode_init(AVCodecContext *avctx)
Definition: dxtory.c:28
#define AVERROR_PATCHWELCOME
Not yet implemented in FFmpeg, patches welcome.
Definition: error.h:62
AVCodec ff_dxtory_decoder
Definition: dxtory.c:84
AVS_Value src
Definition: avisynth_c.h:523
int linesize[AV_NUM_DATA_POINTERS]
For video, size in bytes of each picture line.
Definition: frame.h:101
main external API structure.
int ff_get_buffer(AVCodecContext *avctx, AVFrame *frame, int flags)
Get a buffer for a frame.
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition: log.h:148
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
Definition: frame.h:87
planar YUV 4:2:0, 12bpp, (1 Cr & Cb sample per 2x2 Y samples)
Definition: pixfmt.h:68
common internal api header.
common internal and external API header
int key_frame
1 -> keyframe, 0-> not
Definition: frame.h:139
This structure stores compressed data.
static int decode_frame(AVCodecContext *avctx, void *data, int *got_frame, AVPacket *avpkt)
Definition: dxtory.c:35