avcodec: av_log_ask_for_sample() ---> avpriv_request_sample()
[libav.git] / libavcodec / dxtory.c
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
28 static av_cold int decode_init(AVCodecContext *avctx)
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
52 pic->pict_type = AV_PICTURE_TYPE_I;
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
84 AVCodec ff_dxtory_decoder = {
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 };