Mercurial > audlegacy-plugins
comparison src/ffmpeg/libavcodec/avs.c @ 808:e8776388b02a trunk
[svn] - add ffmpeg
| author | nenolod |
|---|---|
| date | Mon, 12 Mar 2007 11:18:54 -0700 |
| parents | |
| children |
comparison
equal
deleted
inserted
replaced
| 807:0f9c8d4d3ac4 | 808:e8776388b02a |
|---|---|
| 1 /* | |
| 2 * AVS video decoder. | |
| 3 * Copyright (c) 2006 Aurelien Jacobs <aurel@gnuage.org> | |
| 4 * | |
| 5 * This file is part of FFmpeg. | |
| 6 * | |
| 7 * FFmpeg is free software; you can redistribute it and/or | |
| 8 * modify it under the terms of the GNU Lesser General Public | |
| 9 * License as published by the Free Software Foundation; either | |
| 10 * version 2.1 of the License, or (at your option) any later version. | |
| 11 * | |
| 12 * FFmpeg is distributed in the hope that it will be useful, | |
| 13 * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
| 14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
| 15 * Lesser General Public License for more details. | |
| 16 * | |
| 17 * You should have received a copy of the GNU Lesser General Public | |
| 18 * License along with FFmpeg; if not, write to the Free Software | |
| 19 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | |
| 20 */ | |
| 21 | |
| 22 #include "avcodec.h" | |
| 23 #include "bitstream.h" | |
| 24 | |
| 25 | |
| 26 typedef struct { | |
| 27 AVFrame picture; | |
| 28 } avs_context_t; | |
| 29 | |
| 30 typedef enum { | |
| 31 AVS_VIDEO = 0x01, | |
| 32 AVS_AUDIO = 0x02, | |
| 33 AVS_PALETTE = 0x03, | |
| 34 AVS_GAME_DATA = 0x04, | |
| 35 } avs_block_type_t; | |
| 36 | |
| 37 typedef enum { | |
| 38 AVS_I_FRAME = 0x00, | |
| 39 AVS_P_FRAME_3X3 = 0x01, | |
| 40 AVS_P_FRAME_2X2 = 0x02, | |
| 41 AVS_P_FRAME_2X3 = 0x03, | |
| 42 } avs_video_sub_type_t; | |
| 43 | |
| 44 | |
| 45 static int | |
| 46 avs_decode_frame(AVCodecContext * avctx, | |
| 47 void *data, int *data_size, uint8_t * buf, int buf_size) | |
| 48 { | |
| 49 avs_context_t *const avs = avctx->priv_data; | |
| 50 AVFrame *picture = data; | |
| 51 AVFrame *const p = (AVFrame *) & avs->picture; | |
| 52 uint8_t *table, *vect, *out; | |
| 53 int i, j, x, y, stride, vect_w = 3, vect_h = 3; | |
| 54 int sub_type; | |
| 55 avs_block_type_t type; | |
| 56 GetBitContext change_map; | |
| 57 | |
| 58 if (avctx->reget_buffer(avctx, p)) { | |
| 59 av_log(avctx, AV_LOG_ERROR, "reget_buffer() failed\n"); | |
| 60 return -1; | |
| 61 } | |
| 62 p->reference = 1; | |
| 63 p->pict_type = FF_P_TYPE; | |
| 64 p->key_frame = 0; | |
| 65 | |
| 66 out = avs->picture.data[0]; | |
| 67 stride = avs->picture.linesize[0]; | |
| 68 | |
| 69 sub_type = buf[0]; | |
| 70 type = buf[1]; | |
| 71 buf += 4; | |
| 72 | |
| 73 if (type == AVS_PALETTE) { | |
| 74 int first, last; | |
| 75 uint32_t *pal = (uint32_t *) avs->picture.data[1]; | |
| 76 | |
| 77 first = LE_16(buf); | |
| 78 last = first + LE_16(buf + 2); | |
| 79 buf += 4; | |
| 80 for (i=first; i<last; i++, buf+=3) | |
| 81 pal[i] = (buf[0] << 18) | (buf[1] << 10) | (buf[2] << 2); | |
| 82 | |
| 83 sub_type = buf[0]; | |
| 84 type = buf[1]; | |
| 85 buf += 4; | |
| 86 } | |
| 87 | |
| 88 if (type != AVS_VIDEO) | |
| 89 return -1; | |
| 90 | |
| 91 switch (sub_type) { | |
| 92 case AVS_I_FRAME: | |
| 93 p->pict_type = FF_I_TYPE; | |
| 94 p->key_frame = 1; | |
| 95 case AVS_P_FRAME_3X3: | |
| 96 vect_w = 3; | |
| 97 vect_h = 3; | |
| 98 break; | |
| 99 | |
| 100 case AVS_P_FRAME_2X2: | |
| 101 vect_w = 2; | |
| 102 vect_h = 2; | |
| 103 break; | |
| 104 | |
| 105 case AVS_P_FRAME_2X3: | |
| 106 vect_w = 2; | |
| 107 vect_h = 3; | |
| 108 break; | |
| 109 | |
| 110 default: | |
| 111 return -1; | |
| 112 } | |
| 113 | |
| 114 table = buf + (256 * vect_w * vect_h); | |
| 115 if (sub_type != AVS_I_FRAME) { | |
| 116 int map_size = ((318 / vect_w + 7) / 8) * (198 / vect_h); | |
| 117 init_get_bits(&change_map, table, map_size); | |
| 118 table += map_size; | |
| 119 } | |
| 120 | |
| 121 for (y=0; y<198; y+=vect_h) { | |
| 122 for (x=0; x<318; x+=vect_w) { | |
| 123 if (sub_type == AVS_I_FRAME || get_bits1(&change_map)) { | |
| 124 vect = &buf[*table++ * (vect_w * vect_h)]; | |
| 125 for (j=0; j<vect_w; j++) { | |
| 126 out[(y + 0) * stride + x + j] = vect[(0 * vect_w) + j]; | |
| 127 out[(y + 1) * stride + x + j] = vect[(1 * vect_w) + j]; | |
| 128 if (vect_h == 3) | |
| 129 out[(y + 2) * stride + x + j] = | |
| 130 vect[(2 * vect_w) + j]; | |
| 131 } | |
| 132 } | |
| 133 } | |
| 134 if (sub_type != AVS_I_FRAME) | |
| 135 align_get_bits(&change_map); | |
| 136 } | |
| 137 | |
| 138 *picture = *(AVFrame *) & avs->picture; | |
| 139 *data_size = sizeof(AVPicture); | |
| 140 | |
| 141 return buf_size; | |
| 142 } | |
| 143 | |
| 144 static int avs_decode_init(AVCodecContext * avctx) | |
| 145 { | |
| 146 avctx->pix_fmt = PIX_FMT_PAL8; | |
| 147 return 0; | |
| 148 } | |
| 149 | |
| 150 AVCodec avs_decoder = { | |
| 151 "avs", | |
| 152 CODEC_TYPE_VIDEO, | |
| 153 CODEC_ID_AVS, | |
| 154 sizeof(avs_context_t), | |
| 155 avs_decode_init, | |
| 156 NULL, | |
| 157 NULL, | |
| 158 avs_decode_frame, | |
| 159 CODEC_CAP_DR1, | |
| 160 }; |
