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