Move/add COSTABLE/SINTABLE macros to dsputil to add extern definitions
[FFMpeg-mirror/lagarith.git] / libavcodec / frwu.c
blob28ed612df00262e6468c61b935ac29c7ad11825e
1 /*
2 * Forward Uncompressed
4 * Copyright (c) 2009 Reimar Döffinger <Reimar.Doeffinger@gmx.de>
6 * This file is part of FFmpeg.
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.
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.
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
23 #include "avcodec.h"
24 #include "bytestream.h"
25 #include "libavutil/intreadwrite.h"
27 static av_cold int decode_init(AVCodecContext *avctx)
29 if (avctx->width & 1) {
30 av_log(avctx, AV_LOG_ERROR, "FRWU needs even width\n");
31 return -1;
33 avctx->pix_fmt = PIX_FMT_UYVY422;
35 avctx->coded_frame = avcodec_alloc_frame();
37 return 0;
40 static int decode_frame(AVCodecContext *avctx, void *data, int *data_size,
41 AVPacket *avpkt)
43 int field;
44 AVFrame *pic = avctx->coded_frame;
45 const uint8_t *buf = avpkt->data;
46 const uint8_t *buf_end = buf + avpkt->size;
48 if (pic->data[0])
49 avctx->release_buffer(avctx, pic);
51 if (avpkt->size < avctx->width * 2 * avctx->height + 4 + 2*8) {
52 av_log(avctx, AV_LOG_ERROR, "Packet is too small.\n");
53 return -1;
55 if (bytestream_get_le32(&buf) != AV_RL32("FRW1")) {
56 av_log(avctx, AV_LOG_ERROR, "incorrect marker\n");
57 return -1;
60 pic->reference = 0;
61 if (avctx->get_buffer(avctx, pic) < 0)
62 return -1;
64 pic->pict_type = FF_I_TYPE;
65 pic->key_frame = 1;
66 pic->interlaced_frame = 1;
67 pic->top_field_first = 1;
69 for (field = 0; field < 2; field++) {
70 int i;
71 int field_h = (avctx->height + !field) >> 1;
72 int field_size, min_field_size = avctx->width * 2 * field_h;
73 uint8_t *dst = pic->data[0];
74 if (buf_end - buf < 8)
75 return -1;
76 buf += 4; // flags? 0x80 == bottom field maybe?
77 field_size = bytestream_get_le32(&buf);
78 if (field_size < min_field_size) {
79 av_log(avctx, AV_LOG_ERROR, "Field size %i is too small (required %i)\n", field_size, min_field_size);
80 return -1;
82 if (buf_end - buf < field_size) {
83 av_log(avctx, AV_LOG_ERROR, "Packet is too small, need %i, have %i\n", field_size, (int)(buf_end - buf));
84 return -1;
86 if (field)
87 dst += pic->linesize[0];
88 for (i = 0; i < field_h; i++) {
89 memcpy(dst, buf, avctx->width * 2);
90 buf += avctx->width * 2;
91 dst += pic->linesize[0] << 1;
93 buf += field_size - min_field_size;
96 *data_size = sizeof(AVFrame);
97 *(AVFrame*)data = *pic;
99 return avpkt->size;
102 static av_cold int decode_close(AVCodecContext *avctx)
104 AVFrame *pic = avctx->coded_frame;
105 if (pic->data[0])
106 avctx->release_buffer(avctx, pic);
107 av_freep(&avctx->coded_frame);
109 return 0;
112 AVCodec frwu_decoder = {
113 "FRWU",
114 CODEC_TYPE_VIDEO,
115 CODEC_ID_FRWU,
117 decode_init,
118 NULL,
119 decode_close,
120 decode_frame,
121 CODEC_CAP_DR1,
122 .long_name = NULL_IF_CONFIG_SMALL("Forward Uncompressed"),