Mercurial > libavcodec.hg
annotate ulti.c @ 10095:ef6e027092cc libavcodec
4xm: provide 16-byte alignment where required
author | mru |
---|---|
date | Wed, 26 Aug 2009 15:22:15 +0000 |
parents | 5da84f0d0a55 |
children | a16f74116015 |
rev | line source |
---|---|
2234
dff53892ff8a
IBM Ultimotion video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
1 /* |
2779 | 2 * IBM Ultimotion Video Decoder |
2234
dff53892ff8a
IBM Ultimotion video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
3 * Copyright (C) 2004 Konstantin Shishkov |
dff53892ff8a
IBM Ultimotion video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
4 * |
3947
c8c591fe26f8
Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents:
3036
diff
changeset
|
5 * This file is part of FFmpeg. |
c8c591fe26f8
Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents:
3036
diff
changeset
|
6 * |
c8c591fe26f8
Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents:
3036
diff
changeset
|
7 * FFmpeg is free software; you can redistribute it and/or |
2234
dff53892ff8a
IBM Ultimotion video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
8 * modify it under the terms of the GNU Lesser General Public |
dff53892ff8a
IBM Ultimotion video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
9 * License as published by the Free Software Foundation; either |
3947
c8c591fe26f8
Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents:
3036
diff
changeset
|
10 * version 2.1 of the License, or (at your option) any later version. |
2234
dff53892ff8a
IBM Ultimotion video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
11 * |
3947
c8c591fe26f8
Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents:
3036
diff
changeset
|
12 * FFmpeg is distributed in the hope that it will be useful, |
2234
dff53892ff8a
IBM Ultimotion video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
dff53892ff8a
IBM Ultimotion video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
dff53892ff8a
IBM Ultimotion video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
15 * Lesser General Public License for more details. |
dff53892ff8a
IBM Ultimotion video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
16 * |
dff53892ff8a
IBM Ultimotion video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
17 * You should have received a copy of the GNU Lesser General Public |
3947
c8c591fe26f8
Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents:
3036
diff
changeset
|
18 * License along with FFmpeg; if not, write to the Free Software |
3036
0b546eab515d
Update licensing information: The FSF changed postal address.
diego
parents:
2979
diff
changeset
|
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
2234
dff53892ff8a
IBM Ultimotion video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
20 */ |
dff53892ff8a
IBM Ultimotion video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
21 |
dff53892ff8a
IBM Ultimotion video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
22 /** |
8718
e9d9d946f213
Use full internal pathname in doxygen @file directives.
diego
parents:
7129
diff
changeset
|
23 * @file libavcodec/ulti.c |
2234
dff53892ff8a
IBM Ultimotion video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
24 * IBM Ultimotion Video Decoder. |
dff53892ff8a
IBM Ultimotion video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
25 */ |
2967 | 26 |
2234
dff53892ff8a
IBM Ultimotion video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
27 #include <stdio.h> |
dff53892ff8a
IBM Ultimotion video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
28 #include <stdlib.h> |
dff53892ff8a
IBM Ultimotion video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
29 #include <string.h> |
dff53892ff8a
IBM Ultimotion video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
30 |
dff53892ff8a
IBM Ultimotion video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
31 #include "avcodec.h" |
5089 | 32 #include "bytestream.h" |
2234
dff53892ff8a
IBM Ultimotion video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
33 |
dff53892ff8a
IBM Ultimotion video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
34 #include "ulti_cb.h" |
dff53892ff8a
IBM Ultimotion video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
35 |
dff53892ff8a
IBM Ultimotion video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
36 typedef struct UltimotionDecodeContext { |
dff53892ff8a
IBM Ultimotion video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
37 AVCodecContext *avctx; |
dff53892ff8a
IBM Ultimotion video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
38 int width, height, blocks; |
dff53892ff8a
IBM Ultimotion video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
39 AVFrame frame; |
2834 | 40 const uint8_t *ulti_codebook; |
2234
dff53892ff8a
IBM Ultimotion video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
41 } UltimotionDecodeContext; |
dff53892ff8a
IBM Ultimotion video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
42 |
6517
48759bfbd073
Apply 'cold' attribute to init/uninit functions in libavcodec
zuxy
parents:
6218
diff
changeset
|
43 static av_cold int ulti_decode_init(AVCodecContext *avctx) |
2234
dff53892ff8a
IBM Ultimotion video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
44 { |
dff53892ff8a
IBM Ultimotion video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
45 UltimotionDecodeContext *s = avctx->priv_data; |
dff53892ff8a
IBM Ultimotion video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
46 |
dff53892ff8a
IBM Ultimotion video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
47 s->avctx = avctx; |
dff53892ff8a
IBM Ultimotion video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
48 s->width = avctx->width; |
dff53892ff8a
IBM Ultimotion video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
49 s->height = avctx->height; |
dff53892ff8a
IBM Ultimotion video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
50 s->blocks = (s->width / 8) * (s->height / 8); |
dff53892ff8a
IBM Ultimotion video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
51 avctx->pix_fmt = PIX_FMT_YUV410P; |
dff53892ff8a
IBM Ultimotion video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
52 avctx->coded_frame = (AVFrame*) &s->frame; |
dff53892ff8a
IBM Ultimotion video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
53 s->ulti_codebook = ulti_codebook; |
dff53892ff8a
IBM Ultimotion video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
54 |
dff53892ff8a
IBM Ultimotion video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
55 return 0; |
dff53892ff8a
IBM Ultimotion video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
56 } |
dff53892ff8a
IBM Ultimotion video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
57 |
7129 | 58 static const int block_coords[8] = // 4x4 block coords in 8x8 superblock |
2234
dff53892ff8a
IBM Ultimotion video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
59 { 0, 0, 0, 4, 4, 4, 4, 0}; |
dff53892ff8a
IBM Ultimotion video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
60 |
7129 | 61 static const int angle_by_index[4] = { 0, 2, 6, 12}; |
2234
dff53892ff8a
IBM Ultimotion video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
62 |
dff53892ff8a
IBM Ultimotion video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
63 /* Lookup tables for luma and chroma - used by ulti_convert_yuv() */ |
7129 | 64 static const uint8_t ulti_lumas[64] = |
2234
dff53892ff8a
IBM Ultimotion video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
65 { 0x10, 0x13, 0x17, 0x1A, 0x1E, 0x21, 0x25, 0x28, |
dff53892ff8a
IBM Ultimotion video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
66 0x2C, 0x2F, 0x33, 0x36, 0x3A, 0x3D, 0x41, 0x44, |
dff53892ff8a
IBM Ultimotion video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
67 0x48, 0x4B, 0x4F, 0x52, 0x56, 0x59, 0x5C, 0x60, |
dff53892ff8a
IBM Ultimotion video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
68 0x63, 0x67, 0x6A, 0x6E, 0x71, 0x75, 0x78, 0x7C, |
dff53892ff8a
IBM Ultimotion video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
69 0x7F, 0x83, 0x86, 0x8A, 0x8D, 0x91, 0x94, 0x98, |
dff53892ff8a
IBM Ultimotion video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
70 0x9B, 0x9F, 0xA2, 0xA5, 0xA9, 0xAC, 0xB0, 0xB3, |
dff53892ff8a
IBM Ultimotion video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
71 0xB7, 0xBA, 0xBE, 0xC1, 0xC5, 0xC8, 0xCC, 0xCF, |
dff53892ff8a
IBM Ultimotion video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
72 0xD3, 0xD6, 0xDA, 0xDD, 0xE1, 0xE4, 0xE8, 0xEB}; |
2967 | 73 |
7129 | 74 static const uint8_t ulti_chromas[16] = |
2234
dff53892ff8a
IBM Ultimotion video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
75 { 0x60, 0x67, 0x6D, 0x73, 0x7A, 0x80, 0x86, 0x8D, |
dff53892ff8a
IBM Ultimotion video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
76 0x93, 0x99, 0xA0, 0xA6, 0xAC, 0xB3, 0xB9, 0xC0}; |
2967 | 77 |
2234
dff53892ff8a
IBM Ultimotion video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
78 /* convert Ultimotion YUV block (sixteen 6-bit Y samples and |
dff53892ff8a
IBM Ultimotion video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
79 two 4-bit chroma samples) into standard YUV and put it into frame */ |
dff53892ff8a
IBM Ultimotion video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
80 static void ulti_convert_yuv(AVFrame *frame, int x, int y, |
2979 | 81 uint8_t *luma,int chroma) |
2234
dff53892ff8a
IBM Ultimotion video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
82 { |
dff53892ff8a
IBM Ultimotion video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
83 uint8_t *y_plane, *cr_plane, *cb_plane; |
dff53892ff8a
IBM Ultimotion video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
84 int i; |
2967 | 85 |
2234
dff53892ff8a
IBM Ultimotion video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
86 y_plane = frame->data[0] + x + y * frame->linesize[0]; |
dff53892ff8a
IBM Ultimotion video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
87 cr_plane = frame->data[1] + (x / 4) + (y / 4) * frame->linesize[1]; |
dff53892ff8a
IBM Ultimotion video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
88 cb_plane = frame->data[2] + (x / 4) + (y / 4) * frame->linesize[2]; |
2967 | 89 |
2234
dff53892ff8a
IBM Ultimotion video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
90 cr_plane[0] = ulti_chromas[chroma >> 4]; |
2967 | 91 |
2234
dff53892ff8a
IBM Ultimotion video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
92 cb_plane[0] = ulti_chromas[chroma & 0xF]; |
dff53892ff8a
IBM Ultimotion video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
93 |
2967 | 94 |
2234
dff53892ff8a
IBM Ultimotion video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
95 for(i = 0; i < 16; i++){ |
2979 | 96 y_plane[i & 3] = ulti_lumas[luma[i]]; |
97 if((i & 3) == 3) { //next row | |
98 y_plane += frame->linesize[0]; | |
99 } | |
2234
dff53892ff8a
IBM Ultimotion video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
100 } |
dff53892ff8a
IBM Ultimotion video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
101 } |
dff53892ff8a
IBM Ultimotion video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
102 |
dff53892ff8a
IBM Ultimotion video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
103 /* generate block like in MS Video1 */ |
dff53892ff8a
IBM Ultimotion video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
104 static void ulti_pattern(AVFrame *frame, int x, int y, |
2979 | 105 int f0, int f1, int Y0, int Y1, int chroma) |
2234
dff53892ff8a
IBM Ultimotion video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
106 { |
dff53892ff8a
IBM Ultimotion video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
107 uint8_t Luma[16]; |
dff53892ff8a
IBM Ultimotion video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
108 int mask, i; |
dff53892ff8a
IBM Ultimotion video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
109 for(mask = 0x80, i = 0; mask; mask >>= 1, i++) { |
2979 | 110 if(f0 & mask) |
111 Luma[i] = Y1; | |
112 else | |
113 Luma[i] = Y0; | |
2234
dff53892ff8a
IBM Ultimotion video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
114 } |
2967 | 115 |
2234
dff53892ff8a
IBM Ultimotion video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
116 for(mask = 0x80, i = 8; mask; mask >>= 1, i++) { |
2979 | 117 if(f1 & mask) |
118 Luma[i] = Y1; | |
119 else | |
120 Luma[i] = Y0; | |
2234
dff53892ff8a
IBM Ultimotion video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
121 } |
2967 | 122 |
2234
dff53892ff8a
IBM Ultimotion video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
123 ulti_convert_yuv(frame, x, y, Luma, chroma); |
dff53892ff8a
IBM Ultimotion video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
124 } |
dff53892ff8a
IBM Ultimotion video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
125 |
dff53892ff8a
IBM Ultimotion video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
126 /* fill block with some gradient */ |
dff53892ff8a
IBM Ultimotion video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
127 static void ulti_grad(AVFrame *frame, int x, int y, uint8_t *Y, int chroma, int angle) |
dff53892ff8a
IBM Ultimotion video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
128 { |
dff53892ff8a
IBM Ultimotion video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
129 uint8_t Luma[16]; |
dff53892ff8a
IBM Ultimotion video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
130 if(angle & 8) { //reverse order |
2979 | 131 int t; |
132 angle &= 0x7; | |
133 t = Y[0]; | |
134 Y[0] = Y[3]; | |
135 Y[3] = t; | |
136 t = Y[1]; | |
137 Y[1] = Y[2]; | |
138 Y[2] = t; | |
2234
dff53892ff8a
IBM Ultimotion video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
139 } |
dff53892ff8a
IBM Ultimotion video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
140 switch(angle){ |
dff53892ff8a
IBM Ultimotion video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
141 case 0: |
2979 | 142 Luma[0] = Y[0]; Luma[1] = Y[1]; Luma[2] = Y[2]; Luma[3] = Y[3]; |
143 Luma[4] = Y[0]; Luma[5] = Y[1]; Luma[6] = Y[2]; Luma[7] = Y[3]; | |
144 Luma[8] = Y[0]; Luma[9] = Y[1]; Luma[10] = Y[2]; Luma[11] = Y[3]; | |
145 Luma[12] = Y[0]; Luma[13] = Y[1]; Luma[14] = Y[2]; Luma[15] = Y[3]; | |
146 break; | |
2234
dff53892ff8a
IBM Ultimotion video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
147 case 1: |
2979 | 148 Luma[0] = Y[1]; Luma[1] = Y[2]; Luma[2] = Y[3]; Luma[3] = Y[3]; |
149 Luma[4] = Y[0]; Luma[5] = Y[1]; Luma[6] = Y[2]; Luma[7] = Y[3]; | |
150 Luma[8] = Y[0]; Luma[9] = Y[1]; Luma[10] = Y[2]; Luma[11] = Y[3]; | |
151 Luma[12] = Y[0]; Luma[13] = Y[0]; Luma[14] = Y[1]; Luma[15] = Y[2]; | |
152 break; | |
2234
dff53892ff8a
IBM Ultimotion video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
153 case 2: |
2979 | 154 Luma[0] = Y[1]; Luma[1] = Y[2]; Luma[2] = Y[3]; Luma[3] = Y[3]; |
155 Luma[4] = Y[1]; Luma[5] = Y[2]; Luma[6] = Y[2]; Luma[7] = Y[3]; | |
156 Luma[8] = Y[0]; Luma[9] = Y[1]; Luma[10] = Y[1]; Luma[11] = Y[2]; | |
157 Luma[12] = Y[0]; Luma[13] = Y[0]; Luma[14] = Y[1]; Luma[15] = Y[2]; | |
158 break; | |
2234
dff53892ff8a
IBM Ultimotion video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
159 case 3: |
2979 | 160 Luma[0] = Y[2]; Luma[1] = Y[3]; Luma[2] = Y[3]; Luma[3] = Y[3]; |
161 Luma[4] = Y[1]; Luma[5] = Y[2]; Luma[6] = Y[2]; Luma[7] = Y[3]; | |
162 Luma[8] = Y[0]; Luma[9] = Y[1]; Luma[10] = Y[1]; Luma[11] = Y[2]; | |
163 Luma[12] = Y[0]; Luma[13] = Y[0]; Luma[14] = Y[0]; Luma[15] = Y[1]; | |
164 break; | |
2234
dff53892ff8a
IBM Ultimotion video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
165 case 4: |
2979 | 166 Luma[0] = Y[3]; Luma[1] = Y[3]; Luma[2] = Y[3]; Luma[3] = Y[3]; |
167 Luma[4] = Y[2]; Luma[5] = Y[2]; Luma[6] = Y[2]; Luma[7] = Y[2]; | |
168 Luma[8] = Y[1]; Luma[9] = Y[1]; Luma[10] = Y[1]; Luma[11] = Y[1]; | |
169 Luma[12] = Y[0]; Luma[13] = Y[0]; Luma[14] = Y[0]; Luma[15] = Y[0]; | |
170 break; | |
2234
dff53892ff8a
IBM Ultimotion video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
171 case 5: |
2979 | 172 Luma[0] = Y[3]; Luma[1] = Y[3]; Luma[2] = Y[3]; Luma[3] = Y[2]; |
173 Luma[4] = Y[3]; Luma[5] = Y[2]; Luma[6] = Y[2]; Luma[7] = Y[1]; | |
174 Luma[8] = Y[2]; Luma[9] = Y[1]; Luma[10] = Y[1]; Luma[11] = Y[0]; | |
175 Luma[12] = Y[1]; Luma[13] = Y[0]; Luma[14] = Y[0]; Luma[15] = Y[0]; | |
176 break; | |
2234
dff53892ff8a
IBM Ultimotion video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
177 case 6: |
2979 | 178 Luma[0] = Y[3]; Luma[1] = Y[3]; Luma[2] = Y[2]; Luma[3] = Y[2]; |
179 Luma[4] = Y[3]; Luma[5] = Y[2]; Luma[6] = Y[1]; Luma[7] = Y[1]; | |
180 Luma[8] = Y[2]; Luma[9] = Y[2]; Luma[10] = Y[1]; Luma[11] = Y[0]; | |
181 Luma[12] = Y[1]; Luma[13] = Y[1]; Luma[14] = Y[0]; Luma[15] = Y[0]; | |
182 break; | |
2234
dff53892ff8a
IBM Ultimotion video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
183 case 7: |
2979 | 184 Luma[0] = Y[3]; Luma[1] = Y[3]; Luma[2] = Y[2]; Luma[3] = Y[1]; |
185 Luma[4] = Y[3]; Luma[5] = Y[2]; Luma[6] = Y[1]; Luma[7] = Y[0]; | |
186 Luma[8] = Y[3]; Luma[9] = Y[2]; Luma[10] = Y[1]; Luma[11] = Y[0]; | |
187 Luma[12] = Y[2]; Luma[13] = Y[1]; Luma[14] = Y[0]; Luma[15] = Y[0]; | |
188 break; | |
2234
dff53892ff8a
IBM Ultimotion video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
189 default: |
2979 | 190 Luma[0] = Y[0]; Luma[1] = Y[0]; Luma[2] = Y[1]; Luma[3] = Y[1]; |
191 Luma[4] = Y[0]; Luma[5] = Y[0]; Luma[6] = Y[1]; Luma[7] = Y[1]; | |
192 Luma[8] = Y[2]; Luma[9] = Y[2]; Luma[10] = Y[3]; Luma[11] = Y[3]; | |
193 Luma[12] = Y[2]; Luma[13] = Y[2]; Luma[14] = Y[3]; Luma[15] = Y[3]; | |
194 break; | |
2234
dff53892ff8a
IBM Ultimotion video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
195 } |
2967 | 196 |
2234
dff53892ff8a
IBM Ultimotion video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
197 ulti_convert_yuv(frame, x, y, Luma, chroma); |
dff53892ff8a
IBM Ultimotion video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
198 } |
dff53892ff8a
IBM Ultimotion video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
199 |
2967 | 200 static int ulti_decode_frame(AVCodecContext *avctx, |
2234
dff53892ff8a
IBM Ultimotion video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
201 void *data, int *data_size, |
9355
54bc8a2727b0
Implement avcodec_decode_video2(), _audio3() and _subtitle2() which takes an
rbultje
parents:
8718
diff
changeset
|
202 AVPacket *avpkt) |
2234
dff53892ff8a
IBM Ultimotion video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
203 { |
9355
54bc8a2727b0
Implement avcodec_decode_video2(), _audio3() and _subtitle2() which takes an
rbultje
parents:
8718
diff
changeset
|
204 const uint8_t *buf = avpkt->data; |
54bc8a2727b0
Implement avcodec_decode_video2(), _audio3() and _subtitle2() which takes an
rbultje
parents:
8718
diff
changeset
|
205 int buf_size = avpkt->size; |
2234
dff53892ff8a
IBM Ultimotion video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
206 UltimotionDecodeContext *s=avctx->priv_data; |
dff53892ff8a
IBM Ultimotion video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
207 int modifier = 0; |
dff53892ff8a
IBM Ultimotion video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
208 int uniq = 0; |
dff53892ff8a
IBM Ultimotion video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
209 int mode = 0; |
dff53892ff8a
IBM Ultimotion video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
210 int blocks = 0; |
dff53892ff8a
IBM Ultimotion video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
211 int done = 0; |
dff53892ff8a
IBM Ultimotion video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
212 int x = 0, y = 0; |
dff53892ff8a
IBM Ultimotion video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
213 int i; |
dff53892ff8a
IBM Ultimotion video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
214 int skip; |
dff53892ff8a
IBM Ultimotion video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
215 int tmp; |
dff53892ff8a
IBM Ultimotion video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
216 |
dff53892ff8a
IBM Ultimotion video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
217 if(s->frame.data[0]) |
dff53892ff8a
IBM Ultimotion video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
218 avctx->release_buffer(avctx, &s->frame); |
dff53892ff8a
IBM Ultimotion video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
219 |
dff53892ff8a
IBM Ultimotion video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
220 s->frame.reference = 1; |
dff53892ff8a
IBM Ultimotion video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
221 s->frame.buffer_hints = FF_BUFFER_HINTS_VALID | FF_BUFFER_HINTS_PRESERVE | FF_BUFFER_HINTS_REUSABLE; |
dff53892ff8a
IBM Ultimotion video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
222 if(avctx->get_buffer(avctx, &s->frame) < 0) { |
dff53892ff8a
IBM Ultimotion video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
223 av_log(avctx, AV_LOG_ERROR, "get_buffer() failed\n"); |
dff53892ff8a
IBM Ultimotion video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
224 return -1; |
dff53892ff8a
IBM Ultimotion video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
225 } |
2967 | 226 |
2234
dff53892ff8a
IBM Ultimotion video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
227 while(!done) { |
2979 | 228 int idx; |
229 if(blocks >= s->blocks || y >= s->height) | |
230 break;//all blocks decoded | |
2967 | 231 |
2979 | 232 idx = *buf++; |
233 if((idx & 0xF8) == 0x70) { | |
234 switch(idx) { | |
235 case 0x70: //change modifier | |
236 modifier = *buf++; | |
237 if(modifier>1) | |
238 av_log(avctx, AV_LOG_INFO, "warning: modifier must be 0 or 1, got %i\n", modifier); | |
239 break; | |
240 case 0x71: // set uniq flag | |
241 uniq = 1; | |
242 break; | |
243 case 0x72: //toggle mode | |
244 mode = !mode; | |
245 break; | |
246 case 0x73: //end-of-frame | |
247 done = 1; | |
248 break; | |
249 case 0x74: //skip some blocks | |
250 skip = *buf++; | |
251 if ((blocks + skip) >= s->blocks) | |
252 break; | |
253 blocks += skip; | |
254 x += skip * 8; | |
255 while(x >= s->width) { | |
256 x -= s->width; | |
257 y += 8; | |
258 } | |
259 break; | |
260 default: | |
261 av_log(avctx, AV_LOG_INFO, "warning: unknown escape 0x%02X\n", idx); | |
262 } | |
263 } else { //handle one block | |
264 int code; | |
265 int cf; | |
266 int angle = 0; | |
267 uint8_t Y[4]; // luma samples of block | |
268 int tx = 0, ty = 0; //coords of subblock | |
269 int chroma = 0; | |
270 if (mode || uniq) { | |
271 uniq = 0; | |
272 cf = 1; | |
273 chroma = 0; | |
274 } else { | |
275 cf = 0; | |
276 if (idx) | |
277 chroma = *buf++; | |
278 } | |
279 for (i = 0; i < 4; i++) { // for every subblock | |
280 code = (idx >> (6 - i*2)) & 3; //extract 2 bits | |
281 if(!code) //skip subblock | |
282 continue; | |
283 if(cf) | |
284 chroma = *buf++; | |
285 tx = x + block_coords[i * 2]; | |
286 ty = y + block_coords[(i * 2) + 1]; | |
287 switch(code) { | |
288 case 1: | |
289 tmp = *buf++; | |
2967 | 290 |
2979 | 291 angle = angle_by_index[(tmp >> 6) & 0x3]; |
2967 | 292 |
2979 | 293 Y[0] = tmp & 0x3F; |
294 Y[1] = Y[0]; | |
2967 | 295 |
2979 | 296 if (angle) { |
297 Y[2] = Y[0]+1; | |
298 if (Y[2] > 0x3F) | |
299 Y[2] = 0x3F; | |
300 Y[3] = Y[2]; | |
301 } else { | |
302 Y[2] = Y[0]; | |
303 Y[3] = Y[0]; | |
304 } | |
305 break; | |
2967 | 306 |
2979 | 307 case 2: |
308 if (modifier) { // unpack four luma samples | |
5089 | 309 tmp = bytestream_get_be24(&buf); |
2967 | 310 |
2979 | 311 Y[0] = (tmp >> 18) & 0x3F; |
312 Y[1] = (tmp >> 12) & 0x3F; | |
313 Y[2] = (tmp >> 6) & 0x3F; | |
314 Y[3] = tmp & 0x3F; | |
315 angle = 16; | |
316 } else { // retrieve luma samples from codebook | |
5089 | 317 tmp = bytestream_get_be16(&buf); |
2967 | 318 |
2979 | 319 angle = (tmp >> 12) & 0xF; |
320 tmp &= 0xFFF; | |
321 tmp <<= 2; | |
322 Y[0] = s->ulti_codebook[tmp]; | |
323 Y[1] = s->ulti_codebook[tmp + 1]; | |
324 Y[2] = s->ulti_codebook[tmp + 2]; | |
325 Y[3] = s->ulti_codebook[tmp + 3]; | |
326 } | |
327 break; | |
2967 | 328 |
2979 | 329 case 3: |
330 if (modifier) { // all 16 luma samples | |
331 uint8_t Luma[16]; | |
2967 | 332 |
5089 | 333 tmp = bytestream_get_be24(&buf); |
2979 | 334 Luma[0] = (tmp >> 18) & 0x3F; |
335 Luma[1] = (tmp >> 12) & 0x3F; | |
336 Luma[2] = (tmp >> 6) & 0x3F; | |
337 Luma[3] = tmp & 0x3F; | |
2967 | 338 |
5089 | 339 tmp = bytestream_get_be24(&buf); |
2979 | 340 Luma[4] = (tmp >> 18) & 0x3F; |
341 Luma[5] = (tmp >> 12) & 0x3F; | |
342 Luma[6] = (tmp >> 6) & 0x3F; | |
343 Luma[7] = tmp & 0x3F; | |
2967 | 344 |
5089 | 345 tmp = bytestream_get_be24(&buf); |
2979 | 346 Luma[8] = (tmp >> 18) & 0x3F; |
347 Luma[9] = (tmp >> 12) & 0x3F; | |
348 Luma[10] = (tmp >> 6) & 0x3F; | |
349 Luma[11] = tmp & 0x3F; | |
2967 | 350 |
5089 | 351 tmp = bytestream_get_be24(&buf); |
2979 | 352 Luma[12] = (tmp >> 18) & 0x3F; |
353 Luma[13] = (tmp >> 12) & 0x3F; | |
354 Luma[14] = (tmp >> 6) & 0x3F; | |
355 Luma[15] = tmp & 0x3F; | |
2967 | 356 |
2979 | 357 ulti_convert_yuv(&s->frame, tx, ty, Luma, chroma); |
358 } else { | |
359 tmp = *buf++; | |
360 if(tmp & 0x80) { | |
361 angle = (tmp >> 4) & 0x7; | |
362 tmp = (tmp << 8) + *buf++; | |
363 Y[0] = (tmp >> 6) & 0x3F; | |
364 Y[1] = tmp & 0x3F; | |
365 Y[2] = (*buf++) & 0x3F; | |
366 Y[3] = (*buf++) & 0x3F; | |
367 ulti_grad(&s->frame, tx, ty, Y, chroma, angle); //draw block | |
368 } else { // some patterns | |
369 int f0, f1; | |
370 f0 = *buf++; | |
371 f1 = tmp; | |
372 Y[0] = (*buf++) & 0x3F; | |
373 Y[1] = (*buf++) & 0x3F; | |
374 ulti_pattern(&s->frame, tx, ty, f1, f0, Y[0], Y[1], chroma); | |
375 } | |
376 } | |
377 break; | |
378 } | |
379 if(code != 3) | |
380 ulti_grad(&s->frame, tx, ty, Y, chroma, angle); // draw block | |
381 } | |
382 blocks++; | |
383 x += 8; | |
384 if(x >= s->width) { | |
385 x = 0; | |
386 y += 8; | |
387 } | |
388 } | |
2234
dff53892ff8a
IBM Ultimotion video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
389 } |
2967 | 390 |
2234
dff53892ff8a
IBM Ultimotion video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
391 *data_size=sizeof(AVFrame); |
dff53892ff8a
IBM Ultimotion video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
392 *(AVFrame*)data= s->frame; |
dff53892ff8a
IBM Ultimotion video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
393 |
dff53892ff8a
IBM Ultimotion video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
394 return buf_size; |
dff53892ff8a
IBM Ultimotion video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
395 } |
dff53892ff8a
IBM Ultimotion video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
396 |
6517
48759bfbd073
Apply 'cold' attribute to init/uninit functions in libavcodec
zuxy
parents:
6218
diff
changeset
|
397 static av_cold int ulti_decode_end(AVCodecContext *avctx) |
2234
dff53892ff8a
IBM Ultimotion video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
398 { |
dff53892ff8a
IBM Ultimotion video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
399 /* UltimotionDecodeContext *s = avctx->priv_data;*/ |
dff53892ff8a
IBM Ultimotion video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
400 |
dff53892ff8a
IBM Ultimotion video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
401 return 0; |
dff53892ff8a
IBM Ultimotion video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
402 } |
dff53892ff8a
IBM Ultimotion video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
403 |
dff53892ff8a
IBM Ultimotion video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
404 AVCodec ulti_decoder = { |
dff53892ff8a
IBM Ultimotion video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
405 "ultimotion", |
dff53892ff8a
IBM Ultimotion video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
406 CODEC_TYPE_VIDEO, |
dff53892ff8a
IBM Ultimotion video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
407 CODEC_ID_ULTI, |
dff53892ff8a
IBM Ultimotion video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
408 sizeof(UltimotionDecodeContext), |
dff53892ff8a
IBM Ultimotion video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
409 ulti_decode_init, |
dff53892ff8a
IBM Ultimotion video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
410 NULL, |
dff53892ff8a
IBM Ultimotion video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
411 ulti_decode_end, |
dff53892ff8a
IBM Ultimotion video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
412 ulti_decode_frame, |
dff53892ff8a
IBM Ultimotion video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
413 CODEC_CAP_DR1, |
6712 | 414 NULL, |
7040
e943e1409077
Make AVCodec long_names definition conditional depending on CONFIG_SMALL.
stefano
parents:
6712
diff
changeset
|
415 .long_name = NULL_IF_CONFIG_SMALL("IBM UltiMotion"), |
2234
dff53892ff8a
IBM Ultimotion video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
416 }; |
dff53892ff8a
IBM Ultimotion video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
417 |