annotate libmpcodecs/vd_huffyuv.c @ 5625:5fee21c3720c

mga_vid driver in form of a patch against linux-2.4.18 applicable using for example cd linux && patch -p1 < ~/mgavid.patch
author eyck
date Mon, 15 Apr 2002 00:08:22 +0000
parents 9e80ac615570
children e2fe4801a98e
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
5235
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
1 /*
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
2 *
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
3 * HuffYUV Decoder for Mplayer
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
4 * (c) 2002 Roberto Togni
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
5 *
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
6 * Fourcc: HFYU
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
7 *
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
8 * Original Win32 codec copyright:
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
9 *
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
10 *** Huffyuv v2.1.1, by Ben Rudiak-Gould.
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
11 *** http://www.math.berkeley.edu/~benrg/huffyuv.html
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
12 ***
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
13 *** This file is copyright 2000 Ben Rudiak-Gould, and distributed under
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
14 *** the terms of the GNU General Public License, v2 or later. See
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
15 *** http://www.gnu.org/copyleft/gpl.html.
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
16 *
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
17 */
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
18
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
19 #include <stdio.h>
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
20 #include <stdlib.h>
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
21
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
22 #include "config.h"
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
23 #include "mp_msg.h"
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
24
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
25 #include "vd_internal.h"
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
26
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
27
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
28 static vd_info_t info = {
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
29 "HuffYUV Video decoder",
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
30 "huffyuv",
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
31 VFM_HUFFYUV,
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
32 "Roberto Togni",
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
33 "Roberto Togni",
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
34 "native codec, original win32 by Ben Rudiak-Gould http://www.math.berkeley.edu/~benrg/huffyuv.html"
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
35 };
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
36
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
37 LIBVD_EXTERN(huffyuv)
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
38
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
39
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
40 /*
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
41 * Bitmap types
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
42 */
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
43 #define BMPTYPE_YUV -1
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
44 #define BMPTYPE_RGB -2
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
45 #define BMPTYPE_RGBA -3
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
46
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
47 /*
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
48 * Compression methods
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
49 */
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
50 #define METHOD_LEFT 0
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
51 #define METHOD_GRAD 1
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
52 #define METHOD_MEDIAN 2
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
53 #define DECORR_FLAG 64
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
54 #define METHOD_LEFT_DECORR (METHOD_LEFT | DECORR_FLAG)
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
55 #define METHOD_GRAD_DECORR (METHOD_GRAD | DECORR_FLAG)
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
56 #define METHOD_OLD -2
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
57
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
58 #define FOURCC_HFYU mmioFOURCC('H','F','Y','U')
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
59
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
60 #define HUFFTABLE_CLASSIC_YUV ((unsigned char*) -1)
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
61 #define HUFFTABLE_CLASSIC_RGB ((unsigned char*) -2)
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
62 #define HUFFTABLE_CLASSIC_YUV_CHROMA ((unsigned char*) -3)
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
63
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
64
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
65 /*
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
66 * Huffman table
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
67 */
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
68 typedef struct {
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
69 unsigned char* table_pointers[32];
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
70 unsigned char table_data[129*25];
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
71 } DecodeTable;
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
72
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
73
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
74 /*
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
75 * Decoder context
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
76 */
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
77 typedef struct {
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
78 // Real image depth
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
79 int bitcount;
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
80 // Prediction method
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
81 int method;
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
82 // Bitmap color type
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
83 int bitmaptype;
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
84 // Huffman tables
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
85 unsigned char decode1_shift[256];
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
86 unsigned char decode2_shift[256];
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
87 unsigned char decode3_shift[256];
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
88 DecodeTable decode1, decode2, decode3;
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
89 // Above line buffers
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
90 unsigned char *abovebuf1, *abovebuf2;
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
91 } huffyuv_context_t;
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
92
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
93
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
94 /*
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
95 * Classic Huffman tables
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
96 */
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
97 unsigned char classic_shift_luma[] = {
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
98 34,36,35,69,135,232,9,16,10,24,11,23,12,16,13,10,14,8,15,8,
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
99 16,8,17,20,16,10,207,206,205,236,11,8,10,21,9,23,8,8,199,70,
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
100 69,68, 0
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
101 };
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
102
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
103 unsigned char classic_shift_chroma[] = {
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
104 66,36,37,38,39,40,41,75,76,77,110,239,144,81,82,83,84,85,118,183,
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
105 56,57,88,89,56,89,154,57,58,57,26,141,57,56,58,57,58,57,184,119,
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
106 214,245,116,83,82,49,80,79,78,77,44,75,41,40,39,38,37,36,34, 0
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
107 };
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
108
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
109 unsigned char classic_add_luma[256] = {
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
110 3, 9, 5, 12, 10, 35, 32, 29, 27, 50, 48, 45, 44, 41, 39, 37,
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
111 73, 70, 68, 65, 64, 61, 58, 56, 53, 50, 49, 46, 44, 41, 38, 36,
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
112 68, 65, 63, 61, 58, 55, 53, 51, 48, 46, 45, 43, 41, 39, 38, 36,
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
113 35, 33, 32, 30, 29, 27, 26, 25, 48, 47, 46, 44, 43, 41, 40, 39,
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
114 37, 36, 35, 34, 32, 31, 30, 28, 27, 26, 24, 23, 22, 20, 19, 37,
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
115 35, 34, 33, 31, 30, 29, 27, 26, 24, 23, 21, 20, 18, 17, 15, 29,
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
116 27, 26, 24, 22, 21, 19, 17, 16, 14, 26, 25, 23, 21, 19, 18, 16,
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
117 15, 27, 25, 23, 21, 19, 17, 16, 14, 26, 25, 23, 21, 18, 17, 14,
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
118 12, 17, 19, 13, 4, 9, 2, 11, 1, 7, 8, 0, 16, 3, 14, 6,
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
119 12, 10, 5, 15, 18, 11, 10, 13, 15, 16, 19, 20, 22, 24, 27, 15,
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
120 18, 20, 22, 24, 26, 14, 17, 20, 22, 24, 27, 15, 18, 20, 23, 25,
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
121 28, 16, 19, 22, 25, 28, 32, 36, 21, 25, 29, 33, 38, 42, 45, 49,
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
122 28, 31, 34, 37, 40, 42, 44, 47, 49, 50, 52, 54, 56, 57, 59, 60,
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
123 62, 64, 66, 67, 69, 35, 37, 39, 40, 42, 43, 45, 47, 48, 51, 52,
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
124 54, 55, 57, 59, 60, 62, 63, 66, 67, 69, 71, 72, 38, 40, 42, 43,
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
125 46, 47, 49, 51, 26, 28, 30, 31, 33, 34, 18, 19, 11, 13, 7, 8,
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
126 };
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
127
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
128 unsigned char classic_add_chroma[256] = {
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
129 3, 1, 2, 2, 2, 2, 3, 3, 7, 5, 7, 5, 8, 6, 11, 9,
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
130 7, 13, 11, 10, 9, 8, 7, 5, 9, 7, 6, 4, 7, 5, 8, 7,
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
131 11, 8, 13, 11, 19, 15, 22, 23, 20, 33, 32, 28, 27, 29, 51, 77,
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
132 43, 45, 76, 81, 46, 82, 75, 55, 56,144, 58, 80, 60, 74,147, 63,
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
133 143, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79,
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
134 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 27, 30, 21, 22,
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
135 17, 14, 5, 6,100, 54, 47, 50, 51, 53,106,107,108,109,110,111,
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
136 112,113,114,115, 4,117,118, 92, 94,121,122, 3,124,103, 2, 1,
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
137 0,129,130,131,120,119,126,125,136,137,138,139,140,141,142,134,
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
138 135,132,133,104, 64,101, 62, 57,102, 95, 93, 59, 61, 28, 97, 96,
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
139 52, 49, 48, 29, 32, 25, 24, 46, 23, 98, 45, 44, 43, 20, 42, 41,
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
140 19, 18, 99, 40, 15, 39, 38, 16, 13, 12, 11, 37, 10, 9, 8, 36,
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
141 7,128,127,105,123,116, 35, 34, 33,145, 31, 79, 42,146, 78, 26,
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
142 83, 48, 49, 50, 44, 47, 26, 31, 30, 18, 17, 19, 21, 24, 25, 13,
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
143 14, 16, 17, 18, 20, 21, 12, 14, 15, 9, 10, 6, 9, 6, 5, 8,
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
144 6, 12, 8, 10, 7, 9, 6, 4, 6, 2, 2, 3, 3, 3, 3, 2,
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
145 };
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
146
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
147
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
148 /*
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
149 * Internal function prototypes
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
150 */
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
151 unsigned char* InitializeDecodeTable(unsigned char* hufftable,
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
152 unsigned char* shift, DecodeTable* decode_table);
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
153 unsigned char* InitializeShiftAddTables(unsigned char* hufftable,
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
154 unsigned char* shift, unsigned* add_shifted);
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
155 unsigned char* DecompressHuffmanTable(unsigned char* hufftable,
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
156 unsigned char* dst);
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
157 unsigned char huff_decompress(unsigned int* in, unsigned int *pos,
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
158 DecodeTable *decode_table, unsigned char *decode_shift);
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
159
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
160
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
161
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
162
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
163 // to set/get/query special features/parameters
5261
9e80ac615570 committed Roberto Togni's patch for control() function in HuffYUV decoder
melanson
parents: 5235
diff changeset
164 static int control(sh_video_t *sh,int cmd,void* arg,...)
9e80ac615570 committed Roberto Togni's patch for control() function in HuffYUV decoder
melanson
parents: 5235
diff changeset
165 {
9e80ac615570 committed Roberto Togni's patch for control() function in HuffYUV decoder
melanson
parents: 5235
diff changeset
166 switch(cmd) {
9e80ac615570 committed Roberto Togni's patch for control() function in HuffYUV decoder
melanson
parents: 5235
diff changeset
167 case VDCTRL_QUERY_FORMAT:
9e80ac615570 committed Roberto Togni's patch for control() function in HuffYUV decoder
melanson
parents: 5235
diff changeset
168 if (((huffyuv_context_t *)(sh->context))->bitmaptype == BMPTYPE_YUV) {
9e80ac615570 committed Roberto Togni's patch for control() function in HuffYUV decoder
melanson
parents: 5235
diff changeset
169 if (*((int*)arg) == IMGFMT_YUY2)
9e80ac615570 committed Roberto Togni's patch for control() function in HuffYUV decoder
melanson
parents: 5235
diff changeset
170 return CONTROL_TRUE;
9e80ac615570 committed Roberto Togni's patch for control() function in HuffYUV decoder
melanson
parents: 5235
diff changeset
171 else
9e80ac615570 committed Roberto Togni's patch for control() function in HuffYUV decoder
melanson
parents: 5235
diff changeset
172 return CONTROL_FALSE;
9e80ac615570 committed Roberto Togni's patch for control() function in HuffYUV decoder
melanson
parents: 5235
diff changeset
173 } else {
9e80ac615570 committed Roberto Togni's patch for control() function in HuffYUV decoder
melanson
parents: 5235
diff changeset
174 if ((*((int*)arg) == IMGFMT_BGR32) || (*((int*)arg) == IMGFMT_BGR24))
9e80ac615570 committed Roberto Togni's patch for control() function in HuffYUV decoder
melanson
parents: 5235
diff changeset
175 return CONTROL_TRUE;
9e80ac615570 committed Roberto Togni's patch for control() function in HuffYUV decoder
melanson
parents: 5235
diff changeset
176 else
9e80ac615570 committed Roberto Togni's patch for control() function in HuffYUV decoder
melanson
parents: 5235
diff changeset
177 return CONTROL_FALSE;
9e80ac615570 committed Roberto Togni's patch for control() function in HuffYUV decoder
melanson
parents: 5235
diff changeset
178 }
9e80ac615570 committed Roberto Togni's patch for control() function in HuffYUV decoder
melanson
parents: 5235
diff changeset
179 }
9e80ac615570 committed Roberto Togni's patch for control() function in HuffYUV decoder
melanson
parents: 5235
diff changeset
180 return CONTROL_UNKNOWN;
5235
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
181 }
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
182
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
183
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
184 /*
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
185 *
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
186 * Init HuffYUV decoder
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
187 *
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
188 */
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
189 static int init(sh_video_t *sh)
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
190 {
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
191 int vo_ret; // Video output init ret value
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
192 huffyuv_context_t *hc; // Decoder context
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
193 unsigned char *hufftable; // Compressed huffman tables
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
194 BITMAPINFOHEADER *bih = sh->bih;
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
195
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
196 if ((hc = malloc(sizeof(huffyuv_context_t))) == NULL) {
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
197 mp_msg(MSGT_DECVIDEO, MSGL_ERR, "Can't allocate memory for HuffYUV decoder context\n");
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
198 return 0;
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
199 }
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
200
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
201 sh->context = (void *)hc;
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
202
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
203 mp_msg(MSGT_DECVIDEO, MSGL_V, "[HuffYUV] Allocating above line buffer\n");
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
204 if ((hc->abovebuf1 = malloc(sizeof(char) * 4 * bih->biWidth)) == NULL) {
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
205 mp_msg(MSGT_DECVIDEO, MSGL_ERR, "Can't allocate memory for HuffYUV above buffer 1\n");
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
206 return 0;
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
207 }
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
208
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
209 if ((hc->abovebuf2 = malloc(sizeof(char) * 4 * bih->biWidth)) == NULL) {
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
210 mp_msg(MSGT_DECVIDEO, MSGL_ERR, "Can't allocate memory for HuffYUV above buffer 2\n");
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
211 return 0;
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
212 }
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
213
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
214 if (bih->biCompression != FOURCC_HFYU) {
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
215 mp_msg(MSGT_DECVIDEO, MSGL_WARN, "[HuffYUV] BITMAPHEADER fourcc != HFYU\n");
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
216 return 0;
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
217 }
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
218
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
219 /* Get bitcount */
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
220 hc->bitcount = 0;
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
221 if (bih->biSize > sizeof(BITMAPINFOHEADER)+1)
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
222 hc->bitcount = *((char*)bih + sizeof(BITMAPINFOHEADER) + 1);
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
223 if (hc->bitcount == 0)
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
224 hc->bitcount = bih->biBitCount;
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
225
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
226 /* Get bitmap type */
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
227 switch (hc->bitcount & ~7) {
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
228 case 16:
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
229 hc->bitmaptype = BMPTYPE_YUV; // -1
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
230 mp_msg(MSGT_DECVIDEO, MSGL_V, "[HuffYUV] Image type is YUV\n");
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
231 break;
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
232 case 24:
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
233 hc->bitmaptype = BMPTYPE_RGB; // -2
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
234 mp_msg(MSGT_DECVIDEO, MSGL_V, "[HuffYUV] Image type is RGB\n");
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
235 break;
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
236 case 32:
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
237 hc->bitmaptype = BMPTYPE_RGBA; //-3
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
238 mp_msg(MSGT_DECVIDEO, MSGL_V, "[HuffYUV] Image type is RGBA\n");
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
239 break;
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
240 default:
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
241 hc->bitmaptype = 0; // ERR
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
242 mp_msg(MSGT_DECVIDEO, MSGL_WARN, "[HuffYUV] Image type is unknown\n");
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
243 }
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
244
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
245 /* Get method */
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
246 switch (bih->biBitCount & 7) {
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
247 case 0:
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
248 if (bih->biSize > sizeof(BITMAPINFOHEADER)) {
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
249 hc->method = *((unsigned char*)bih + sizeof(BITMAPINFOHEADER));
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
250 mp_msg(MSGT_DECVIDEO, MSGL_V, "[HuffYUV] Method stored in extra data\n");
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
251 } else
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
252 hc->method = METHOD_OLD; // Is it really needed?
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
253 break;
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
254 case 1:
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
255 hc->method = METHOD_LEFT;
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
256 break;
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
257 case 2:
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
258 hc->method = METHOD_LEFT_DECORR;
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
259 break;
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
260 case 3:
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
261 if (hc->bitmaptype == BMPTYPE_YUV) {
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
262 hc->method = METHOD_GRAD;
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
263 } else {
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
264 hc->method = METHOD_GRAD_DECORR;
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
265 }
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
266 break;
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
267 case 4:
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
268 hc->method = METHOD_MEDIAN;
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
269 break;
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
270 default:
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
271 mp_msg(MSGT_DECVIDEO, MSGL_V, "[HuffYUV] Method: fallback to METHOD_OLD\n");
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
272 hc->method = METHOD_OLD;
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
273 }
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
274
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
275 /* Print method info */
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
276 switch (hc->method) {
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
277 case METHOD_LEFT:
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
278 mp_msg(MSGT_DECVIDEO, MSGL_V, "[HuffYUV] Method: Predict Left\n");
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
279 break;
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
280 case METHOD_GRAD:
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
281 mp_msg(MSGT_DECVIDEO, MSGL_V, "[HuffYUV] Method: Predict Gradient\n");
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
282 break;
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
283 case METHOD_MEDIAN:
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
284 mp_msg(MSGT_DECVIDEO, MSGL_V, "[HuffYUV] Method: Predict Median\n");
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
285 break;
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
286 case METHOD_LEFT_DECORR:
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
287 mp_msg(MSGT_DECVIDEO, MSGL_V, "[HuffYUV] Method: Predict Left with decorrelation\n");
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
288 break;
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
289 case METHOD_GRAD_DECORR:
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
290 mp_msg(MSGT_DECVIDEO, MSGL_V, "[HuffYUV] Method: Predict Gradient with decorrelation\n");
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
291 break;
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
292 case METHOD_OLD:
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
293 mp_msg(MSGT_DECVIDEO, MSGL_V, "[HuffYUV] Method Old\n");
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
294 break;
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
295 default:
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
296 mp_msg(MSGT_DECVIDEO, MSGL_WARN, "[HuffYUV] Method unknown\n");
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
297 }
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
298
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
299 /* Get compressed Huffman tables */
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
300 if (bih->biSize == sizeof(BITMAPINFOHEADER) /*&& !(bih->biBitCount&7)*/) {
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
301 hufftable = (hc->bitmaptype == BMPTYPE_YUV) ? HUFFTABLE_CLASSIC_YUV : HUFFTABLE_CLASSIC_RGB;
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
302 mp_msg(MSGT_DECVIDEO, MSGL_V, "[HuffYUV] Using classic static Huffman tables\n");
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
303 } else {
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
304 hufftable = (unsigned char*)bih + sizeof(BITMAPINFOHEADER) + ((bih->biBitCount&7) ? 0 : 4);
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
305 mp_msg(MSGT_DECVIDEO, MSGL_V, "[HuffYUV] Using Huffman tables stored in file\n");
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
306 }
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
307
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
308 /* Initialize decoder Huffman tables */
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
309 hufftable = InitializeDecodeTable(hufftable, hc->decode1_shift, &(hc->decode1));
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
310 hufftable = InitializeDecodeTable(hufftable, hc->decode2_shift, &(hc->decode2));
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
311 InitializeDecodeTable(hufftable, hc->decode3_shift, &(hc->decode3));
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
312
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
313 /*
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
314 * Initialize video output device
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
315 */
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
316 switch (hc->bitmaptype) {
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
317 case BMPTYPE_YUV:
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
318 vo_ret = mpcodecs_config_vo(sh,sh->disp_w,sh->disp_h,IMGFMT_YUY2);
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
319 break;
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
320 case BMPTYPE_RGB:
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
321 vo_ret = mpcodecs_config_vo(sh,sh->disp_w,sh->disp_h,IMGFMT_BGR24);
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
322 break;
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
323 case BMPTYPE_RGBA:
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
324 mp_msg(MSGT_DECVIDEO, MSGL_ERR, "[HuffYUV] RGBA not supported yet.\n");
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
325 return 0;
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
326 default:
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
327 mp_msg(MSGT_DECVIDEO, MSGL_ERR, "[HuffYUV] BUG! Unknown bitmaptype in vo config.\n");
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
328 return 0;
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
329 }
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
330
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
331 return vo_ret;
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
332 }
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
333
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
334
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
335
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
336
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
337 /*
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
338 *
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
339 * Uninit HuffYUV decoder
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
340 *
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
341 */
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
342 static void uninit(sh_video_t *sh)
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
343 {
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
344 if (sh->context) {
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
345 if (((huffyuv_context_t*)&sh->context)->abovebuf1)
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
346 free(((huffyuv_context_t*)sh->context)->abovebuf1);
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
347 if (((huffyuv_context_t*)&sh->context)->abovebuf2)
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
348 free(((huffyuv_context_t*)sh->context)->abovebuf2);
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
349 free(sh->context);
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
350 }
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
351 }
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
352
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
353
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
354
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
355 #define HUFF_DECOMPRESS_YUYV() \
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
356 { \
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
357 y1 = huff_decompress((unsigned int *)encoded, &pos, &(hc->decode1), hc->decode1_shift); \
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
358 u = huff_decompress((unsigned int *)encoded, &pos, &(hc->decode2), hc->decode2_shift); \
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
359 y2 = huff_decompress((unsigned int *)encoded, &pos, &(hc->decode1), hc->decode1_shift); \
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
360 v = huff_decompress((unsigned int *)encoded, &pos, &(hc->decode3), hc->decode3_shift); \
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
361 }
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
362
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
363
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
364
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
365 #define HUFF_DECOMPRESS_RGB_DECORR() \
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
366 { \
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
367 g = huff_decompress((unsigned int *)encoded, &pos, &(hc->decode2), hc->decode2_shift); \
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
368 b = huff_decompress((unsigned int *)encoded, &pos, &(hc->decode1), hc->decode1_shift); \
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
369 r = huff_decompress((unsigned int *)encoded, &pos, &(hc->decode3), hc->decode3_shift); \
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
370 }
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
371
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
372
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
373
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
374 #define HUFF_DECOMPRESS_RGB() \
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
375 { \
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
376 b = huff_decompress((unsigned int *)encoded, &pos, &(hc->decode1), hc->decode1_shift); \
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
377 g = huff_decompress((unsigned int *)encoded, &pos, &(hc->decode2), hc->decode2_shift); \
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
378 r = huff_decompress((unsigned int *)encoded, &pos, &(hc->decode3), hc->decode3_shift); \
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
379 }
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
380
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
381
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
382
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
383 #define MEDIAN(left, above, aboveleft) \
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
384 { \
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
385 if ((mi = (above)) > (left)) { \
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
386 mx = mi; \
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
387 mi = (left); \
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
388 } else \
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
389 mx = (left); \
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
390 tmp = (above) + (left) - (aboveleft); \
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
391 if (tmp < mi) \
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
392 med = mi; \
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
393 else if (tmp > mx) \
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
394 med = mx; \
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
395 else \
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
396 med = tmp; \
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
397 }
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
398
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
399
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
400
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
401 #define YUV_STORE1ST_ABOVEBUF() \
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
402 { \
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
403 abovebuf[0] = outptr[0] = encoded[0]; \
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
404 abovebuf[1] = left_u = outptr[1] = encoded[1]; \
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
405 abovebuf[2] = left_y = outptr[2] = encoded[2]; \
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
406 abovebuf[3] = left_v = outptr[3] = encoded[3]; \
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
407 pixel_ptr = 4; \
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
408 }
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
409
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
410
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
411
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
412 #define YUV_STORE1ST() \
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
413 { \
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
414 outptr[0] = encoded[0]; \
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
415 left_u = outptr[1] = encoded[1]; \
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
416 left_y = outptr[2] = encoded[2]; \
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
417 left_v = outptr[3] = encoded[3]; \
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
418 pixel_ptr = 4; \
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
419 }
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
420
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
421
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
422
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
423 #define RGB_STORE1ST() \
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
424 { \
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
425 pixel_ptr = (height-1)*mpi->stride[0]; \
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
426 left_b = outptr[pixel_ptr++] = encoded[1]; \
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
427 left_g = outptr[pixel_ptr++] = encoded[2]; \
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
428 left_r = outptr[pixel_ptr++] = encoded[3]; \
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
429 pixel_ptr += bgr32; \
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
430 }
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
431
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
432
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
433
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
434 #define RGB_STORE1ST_ABOVEBUF() \
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
435 { \
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
436 pixel_ptr = (height-1)*mpi->stride[0]; \
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
437 abovebuf[0] = left_b = outptr[pixel_ptr++] = encoded[1]; \
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
438 abovebuf[1] = left_g = outptr[pixel_ptr++] = encoded[2]; \
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
439 abovebuf[2] = left_r = outptr[pixel_ptr++] = encoded[3]; \
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
440 pixel_ptr += bgr32; \
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
441 }
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
442
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
443
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
444
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
445
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
446 #define YUV_PREDLEFT() \
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
447 { \
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
448 outptr[pixel_ptr++] = left_y += y1; \
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
449 outptr[pixel_ptr++] = left_u += u; \
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
450 outptr[pixel_ptr++] = left_y += y2; \
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
451 outptr[pixel_ptr++] = left_v += v; \
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
452 }
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
453
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
454
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
455
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
456 #define YUV_PREDLEFT_BUF(buf, offs) \
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
457 { \
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
458 (buf)[(offs)] = outptr[pixel_ptr++] = left_y += y1; \
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
459 (buf)[(offs)+1] = outptr[pixel_ptr++] = left_u += u; \
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
460 (buf)[(offs)+2] = outptr[pixel_ptr++] = left_y += y2; \
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
461 (buf)[(offs)+3] = outptr[pixel_ptr++] = left_v += v; \
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
462 }
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
463
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
464
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
465
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
466 #define YUV_PREDMED() \
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
467 { \
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
468 MEDIAN (left_y, abovebuf[col], abovebuf[col-2]); \
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
469 curbuf[col] = outptr[pixel_ptr++] = left_y = med + y1; \
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
470 MEDIAN (left_u, abovebuf[col+1], abovebuf[col+1-4]); \
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
471 curbuf[col+1] = outptr[pixel_ptr++] = left_u = med + u; \
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
472 MEDIAN (left_y, abovebuf[col+2], abovebuf[col+2-2]); \
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
473 curbuf[col+2] = outptr[pixel_ptr++] = left_y = med + y2; \
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
474 MEDIAN (left_v, abovebuf[col+3], abovebuf[col+3-4]); \
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
475 curbuf[col+3] = outptr[pixel_ptr++] = left_v = med + v; \
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
476 }
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
477
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
478
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
479
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
480 #define RGB_PREDLEFT_DECORR() \
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
481 { \
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
482 outptr[pixel_ptr++] = left_b += b + g; \
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
483 outptr[pixel_ptr++] = left_g += g; \
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
484 outptr[pixel_ptr++] = left_r += r + g; \
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
485 pixel_ptr += bgr32; \
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
486 }
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
487
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
488
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
489
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
490 #define RGB_PREDLEFT() \
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
491 { \
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
492 outptr[pixel_ptr++] = left_b += b; \
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
493 outptr[pixel_ptr++] = left_g += g; \
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
494 outptr[pixel_ptr++] = left_r += r; \
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
495 pixel_ptr += bgr32; \
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
496 }
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
497
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
498
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
499
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
500
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
501 /*
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
502 *
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
503 * Decode a HuffYUV frame
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
504 *
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
505 */
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
506 static mp_image_t* decode(sh_video_t *sh,void* data,int len,int flags)
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
507 {
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
508 mp_image_t* mpi;
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
509 int pixel_ptr;
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
510 unsigned char y1, y2, u, v, r, g, b, a;
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
511 unsigned char left_y, left_u, left_v, left_r, left_g, left_b;
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
512 unsigned char tmp, mi, mx, med;
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
513 unsigned char *swap;
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
514 int row, col;
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
515 unsigned int pos = 32;
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
516 unsigned char *encoded = (unsigned char *)data;
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
517 huffyuv_context_t *hc = (huffyuv_context_t *) sh->context; // Decoder context
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
518 unsigned char *abovebuf = hc->abovebuf1;
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
519 unsigned char *curbuf = hc->abovebuf2;
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
520 unsigned char *outptr;
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
521 int width = sh->disp_w; // Real image width
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
522 int height = sh->disp_h; // Real image height
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
523 int bgr32;
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
524
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
525 // skipped frame
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
526 if(len <= 0)
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
527 return NULL;
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
528
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
529 /* Do not accept stride for rgb, it gives me wrong output :-( */
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
530 if (hc->bitmaptype == BMPTYPE_YUV)
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
531 mpi=mpcodecs_get_image(sh, MP_IMGTYPE_TEMP, MP_IMGFLAG_ACCEPT_STRIDE, sh->disp_w, sh->disp_h);
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
532 else
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
533 mpi=mpcodecs_get_image(sh, MP_IMGTYPE_TEMP, 0, sh->disp_w, sh->disp_h);
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
534
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
535 if (!mpi) {
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
536 mp_msg(MSGT_DECVIDEO, MSGL_ERR, "Can't allocate mpi image for huffyuv codec.\n");
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
537 return NULL;
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
538 }
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
539
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
540 outptr = mpi->planes[0]; // Output image pointer
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
541
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
542 if (hc->bitmaptype == BMPTYPE_YUV) {
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
543 width >>= 1; // Each cycle stores two pixels
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
544 if (hc->method == METHOD_GRAD) {
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
545 /*
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
546 * YUV predict gradient
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
547 */
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
548 /* Store 1st pixel */
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
549 YUV_STORE1ST_ABOVEBUF();
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
550 // Decompress 1st row (always stored with left prediction)
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
551 for (col = 1*4; col < width*4; col += 4) {
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
552 HUFF_DECOMPRESS_YUYV();
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
553 YUV_PREDLEFT_BUF(abovebuf, col);
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
554 }
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
555 curbuf[width*4-1] = curbuf[width*4-2] = curbuf[width*4-3] = 0;
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
556 for (row = 1; row < height; row++) {
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
557 pixel_ptr = row * mpi->stride[0];
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
558 HUFF_DECOMPRESS_YUYV();
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
559 curbuf[0] = outptr[pixel_ptr++] = left_y += y1 + abovebuf[0] - curbuf[width*4-2];
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
560 curbuf[1] = outptr[pixel_ptr++] = left_u += u + abovebuf[1] - curbuf[width*4+1-4];
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
561 curbuf[2] = outptr[pixel_ptr++] = left_y += y2 + abovebuf[2] - abovebuf[0];
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
562 curbuf[3] = outptr[pixel_ptr++] = left_v += v + abovebuf[3] - curbuf[width*4+3-4];
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
563 for (col = 1*4; col < width*4; col += 4) {
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
564 HUFF_DECOMPRESS_YUYV();
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
565 curbuf[col] = outptr[pixel_ptr++] = left_y += y1 + abovebuf[col]-abovebuf[col-2];
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
566 curbuf[col+1] = outptr[pixel_ptr++] = left_u += u + abovebuf[col+1]-abovebuf[col+1-4];
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
567 curbuf[col+2] = outptr[pixel_ptr++] = left_y += y2 + abovebuf[col+2]-abovebuf[col+2-2];
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
568 curbuf[col+3] = outptr[pixel_ptr++] = left_v += v + abovebuf[col+3]-abovebuf[col+3-4];
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
569 }
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
570 swap = abovebuf;
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
571 abovebuf = curbuf;
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
572 curbuf = swap;
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
573 }
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
574 } else if (hc->method == METHOD_MEDIAN) {
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
575 /*
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
576 * YUV predict median
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
577 */
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
578 /* Store 1st pixel */
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
579 YUV_STORE1ST_ABOVEBUF();
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
580 // Decompress 1st row (always stored with left prediction)
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
581 for (col = 1*4; col < width*4; col += 4) {
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
582 HUFF_DECOMPRESS_YUYV();
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
583 YUV_PREDLEFT_BUF (abovebuf, col);
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
584 }
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
585 // Decompress 1st two pixels of 2nd row
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
586 pixel_ptr = mpi->stride[0];
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
587 HUFF_DECOMPRESS_YUYV();
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
588 YUV_PREDLEFT_BUF (curbuf, 0);
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
589 HUFF_DECOMPRESS_YUYV();
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
590 YUV_PREDLEFT_BUF (curbuf, 4);
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
591 // Complete 2nd row
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
592 for (col = 2*4; col < width*4; col += 4) {
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
593 HUFF_DECOMPRESS_YUYV();
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
594 YUV_PREDMED();
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
595 }
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
596 swap = abovebuf;
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
597 abovebuf = curbuf;
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
598 curbuf = swap;
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
599 for (row = 2; row < height; row++) {
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
600 pixel_ptr = row * mpi->stride[0];
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
601 HUFF_DECOMPRESS_YUYV();
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
602 MEDIAN (left_y, abovebuf[0], curbuf[width*4-2]);
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
603 curbuf[0] = outptr[pixel_ptr++] = left_y = med + y1;
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
604 MEDIAN (left_u, abovebuf[1], curbuf[width*4+1-4]);
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
605 curbuf[1] = outptr[pixel_ptr++] = left_u = med + u;
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
606 MEDIAN (left_y, abovebuf[2], abovebuf[0]);
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
607 curbuf[2] = outptr[pixel_ptr++] = left_y = med + y2;
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
608 MEDIAN (left_v, abovebuf[3], curbuf[width*4+3-4]);
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
609 curbuf[3] = outptr[pixel_ptr++] = left_v = med + v;
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
610 for (col = 1*4; col < width*4; col += 4) {
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
611 HUFF_DECOMPRESS_YUYV();
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
612 YUV_PREDMED();
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
613 }
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
614 swap = abovebuf;
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
615 abovebuf = curbuf;
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
616 curbuf = swap;
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
617 }
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
618 } else {
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
619 /*
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
620 * YUV predict left and predict old
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
621 */
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
622 /* Store 1st pixel */
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
623 YUV_STORE1ST();
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
624 // Decompress 1st row (always stored with left prediction)
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
625 for (col = 1*4; col < width*4; col += 4) {
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
626 HUFF_DECOMPRESS_YUYV();
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
627 YUV_PREDLEFT();
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
628 }
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
629 for (row = 1; row < height; row++) {
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
630 pixel_ptr = row * mpi->stride[0];
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
631 for (col = 0; col < width*4; col += 4) {
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
632 HUFF_DECOMPRESS_YUYV();
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
633 YUV_PREDLEFT();
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
634 }
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
635 }
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
636 }
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
637 } else {
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
638 bgr32 = (mpi->bpp) >> 5; // 1 if bpp = 32, 0 if bpp = 24
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
639 if (hc->method == METHOD_LEFT_DECORR) {
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
640 /*
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
641 * RGB predict left with decorrelation
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
642 */
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
643 /* Store 1st pixel */
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
644 RGB_STORE1ST();
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
645 // Decompress 1st row
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
646 for (col = 1; col < width; col ++) {
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
647 HUFF_DECOMPRESS_RGB_DECORR();
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
648 RGB_PREDLEFT_DECORR();
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
649 }
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
650 for (row = 1; row < height; row++) {
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
651 pixel_ptr = (height - row - 1) * mpi->stride[0];
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
652 for (col = 0; col < width; col++) {
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
653 HUFF_DECOMPRESS_RGB_DECORR();
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
654 RGB_PREDLEFT_DECORR();
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
655 }
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
656 }
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
657 } else if (hc->method == METHOD_GRAD_DECORR) {
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
658 /*
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
659 * RGB predict gradient with decorrelation
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
660 */
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
661 /* Store 1st pixel */
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
662 RGB_STORE1ST_ABOVEBUF();
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
663 // Decompress 1st row (always stored with left prediction)
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
664 for (col = 1*3; col < width*3; col += 3) {
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
665 HUFF_DECOMPRESS_RGB_DECORR();
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
666 abovebuf[col] = outptr[pixel_ptr++] = left_b += b + g;
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
667 abovebuf[col+1] = outptr[pixel_ptr++] = left_g += g;
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
668 abovebuf[col+2] = outptr[pixel_ptr++] = left_r += r + g;
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
669 pixel_ptr += bgr32;
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
670 }
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
671 curbuf[width*3-1] = curbuf[width*3-2] = curbuf[width*3-3] = 0;
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
672 for (row = 1; row < height; row++) {
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
673 pixel_ptr = (height - row - 1) * mpi->stride[0];
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
674 HUFF_DECOMPRESS_RGB_DECORR();
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
675 curbuf[0] = outptr[pixel_ptr++] = left_b += b + g + abovebuf[0] - curbuf[width*3-3];
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
676 curbuf[1] = outptr[pixel_ptr++] = left_g += g + abovebuf[1] - curbuf[width*3+1-3];
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
677 curbuf[2] = outptr[pixel_ptr++] = left_r += r + g + abovebuf[2] - curbuf[width*3+2-3];
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
678 pixel_ptr += bgr32;
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
679 for (col = 1*3; col < width*3; col += 3) {
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
680 HUFF_DECOMPRESS_RGB_DECORR();
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
681 curbuf[col] = outptr[pixel_ptr++] = left_b += b + g + abovebuf[col]-abovebuf[col-3];
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
682 curbuf[col+1] = outptr[pixel_ptr++] = left_g += g + abovebuf[col+1]-abovebuf[col+1-3];
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
683 curbuf[col+2] = outptr[pixel_ptr++] = left_r += r + g + abovebuf[col+2]-abovebuf[col+2-3];
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
684 pixel_ptr += bgr32;
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
685 }
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
686 swap = abovebuf;
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
687 abovebuf = curbuf;
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
688 curbuf = swap;
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
689 }
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
690 } else {
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
691 /*
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
692 * RGB predict left (no decorrelation) and predict old
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
693 */
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
694 /* Store 1st pixel */
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
695 RGB_STORE1ST();
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
696 // Decompress 1st row
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
697 for (col = 1; col < width; col++) {
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
698 HUFF_DECOMPRESS_RGB();
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
699 RGB_PREDLEFT();
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
700 }
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
701 for (row = 1; row < height; row++) {
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
702 pixel_ptr = (height - row - 1) * mpi->stride[0];
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
703 for (col = 0; col < width; col++) {
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
704 HUFF_DECOMPRESS_RGB();
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
705 RGB_PREDLEFT();
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
706 }
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
707 }
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
708 }
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
709 }
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
710
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
711 return mpi;
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
712 }
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
713
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
714
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
715
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
716 unsigned char* InitializeDecodeTable(unsigned char* hufftable,
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
717 unsigned char* shift, DecodeTable* decode_table)
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
718 {
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
719 unsigned int add_shifted[256];
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
720 char code_lengths[256];
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
721 char code_firstbits[256];
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
722 char table_lengths[32];
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
723 int all_zero_code=-1;
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
724 int i, j, k;
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
725 int firstbit, length, val;
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
726 unsigned char* p;
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
727 unsigned char * table;
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
728
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
729 /* Initialize shift[] and add_shifted[] */
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
730 hufftable = InitializeShiftAddTables(hufftable, shift, add_shifted);
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
731
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
732 memset(table_lengths, -1, 32);
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
733
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
734 /* Fill code_firstbits[], code_legths[] and table_lengths[] */
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
735 for (i = 0; i < 256; ++i) {
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
736 if (add_shifted[i]) {
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
737 for (firstbit = 31; firstbit >= 0; firstbit--) {
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
738 if (add_shifted[i] & (1 << firstbit)) {
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
739 code_firstbits[i] = firstbit;
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
740 length = shift[i] - (32 - firstbit);
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
741 code_lengths[i] = length;
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
742 table_lengths[firstbit] = max(table_lengths[firstbit], length);
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
743 break;
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
744 }
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
745 }
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
746 } else {
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
747 all_zero_code = i;
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
748 }
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
749 }
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
750
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
751 p = decode_table->table_data;
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
752 *p++ = 31;
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
753 *p++ = all_zero_code;
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
754 for (j = 0; j < 32; ++j) {
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
755 if (table_lengths[j] == -1) {
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
756 decode_table->table_pointers[j] = decode_table->table_data;
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
757 } else {
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
758 decode_table->table_pointers[j] = p;
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
759 *p++ = j - table_lengths[j];
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
760 p += 1 << table_lengths[j];
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
761 }
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
762 }
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
763
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
764 for (k=0; k<256; ++k) {
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
765 if (add_shifted[k]) {
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
766 firstbit = code_firstbits[k];
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
767 val = add_shifted[k] - (1 << firstbit);
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
768 table = decode_table->table_pointers[firstbit];
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
769 memset(&table[1 + (val >> table[0])], k,
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
770 1 << (table_lengths[firstbit] - code_lengths[k]));
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
771 }
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
772 }
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
773
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
774 return hufftable;
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
775 }
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
776
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
777
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
778
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
779 unsigned char* InitializeShiftAddTables(unsigned char* hufftable,
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
780 unsigned char* shift, unsigned* add_shifted)
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
781 {
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
782 int i, j;
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
783 unsigned int bits; // must be 32bit unsigned
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
784 int min_already_processed;
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
785 int max_not_processed;
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
786 int bit;
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
787
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
788 // special-case the old tables, since they don't fit the new rules
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
789 if (hufftable == HUFFTABLE_CLASSIC_YUV || hufftable == HUFFTABLE_CLASSIC_RGB) {
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
790 DecompressHuffmanTable(classic_shift_luma, shift);
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
791 for (i = 0; i < 256; ++i)
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
792 add_shifted[i] = classic_add_luma[i] << (32 - shift[i]);
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
793 return (hufftable == HUFFTABLE_CLASSIC_YUV) ? HUFFTABLE_CLASSIC_YUV_CHROMA : hufftable;
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
794 } else if (hufftable == HUFFTABLE_CLASSIC_YUV_CHROMA) {
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
795 DecompressHuffmanTable(classic_shift_chroma, shift);
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
796 for (i = 0; i < 256; ++i)
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
797 add_shifted[i] = classic_add_chroma[i] << (32 - shift[i]);
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
798 return hufftable;
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
799 }
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
800
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
801 hufftable = DecompressHuffmanTable(hufftable, shift);
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
802
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
803 // derive the actual bit patterns from the code lengths
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
804 min_already_processed = 32;
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
805 bits = 0;
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
806 do {
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
807 max_not_processed = 0;
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
808 for (i = 0; i < 256; ++i) {
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
809 if (shift[i] < min_already_processed && shift[i] > max_not_processed)
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
810 max_not_processed = shift[i];
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
811 }
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
812 bit = 1 << (32 - max_not_processed);
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
813 // assert (!(bits & (bit - 1)));
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
814 for (j = 0; j < 256; ++j) {
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
815 if (shift[j] == max_not_processed) {
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
816 add_shifted[j] = bits;
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
817 bits += bit;
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
818 }
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
819 }
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
820 min_already_processed = max_not_processed;
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
821 } while (bits & 0xFFFFFFFF);
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
822
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
823 return hufftable;
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
824 }
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
825
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
826
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
827
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
828 unsigned char* DecompressHuffmanTable(unsigned char* hufftable,
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
829 unsigned char* dst)
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
830 {
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
831 int val;
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
832 int repeat;
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
833 int i = 0;
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
834
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
835 do {
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
836 val = *hufftable & 31;
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
837 repeat = *hufftable++ >> 5;
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
838 if (!repeat)
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
839 repeat = *hufftable++;
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
840 while (repeat--)
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
841 dst[i++] = val;
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
842 } while (i < 256);
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
843
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
844 return hufftable;
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
845 }
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
846
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
847
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
848 unsigned char huff_decompress(unsigned int* in, unsigned int *pos, DecodeTable *decode_table,
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
849 unsigned char *decode_shift)
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
850 {
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
851 unsigned int word = *pos >> 5;
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
852 unsigned int bit = *pos & 31;
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
853 unsigned int val = in[word];
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
854 unsigned char outbyte;
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
855 unsigned char *tableptr;
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
856 int i;
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
857
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
858 if (bit)
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
859 val = (val << bit) | (in[word + 1] >> (32 - bit));
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
860 // figure out the appropriate lookup table based on the number of leading zeros
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
861 i = 31;
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
862 val |= 1;
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
863 while ((val & (1 << i--)) == 0);
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
864 val &= ~(1 << (i+1));
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
865 tableptr = decode_table->table_pointers[i+1];
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
866 val >>= *tableptr;
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
867
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
868 outbyte = tableptr[val+1];
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
869 *pos += decode_shift[outbyte];
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
870
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
871 return outbyte;
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
872 }