annotate libmpcodecs/vd_huffyuv.c @ 6821:414ea538b99e

Document rectangle plugin.
author kmkaplan
date Sat, 27 Jul 2002 12:18:53 +0000
parents e2fe4801a98e
children 28677d779205
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;
6512
e2fe4801a98e Fix for interlaced huffyuv by roberto togni <rtogni at bresciaonline.it>
atmos4
parents: 5261
diff changeset
84 // Interlaced flag
e2fe4801a98e Fix for interlaced huffyuv by roberto togni <rtogni at bresciaonline.it>
atmos4
parents: 5261
diff changeset
85 int interlaced;
5235
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
86 // Huffman tables
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
87 unsigned char decode1_shift[256];
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
88 unsigned char decode2_shift[256];
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
89 unsigned char decode3_shift[256];
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
90 DecodeTable decode1, decode2, decode3;
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
91 // Above line buffers
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
92 unsigned char *abovebuf1, *abovebuf2;
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
93 } huffyuv_context_t;
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
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 * Classic Huffman tables
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
98 */
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
99 unsigned char classic_shift_luma[] = {
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
100 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
101 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
102 69,68, 0
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
103 };
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
104
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
105 unsigned char classic_shift_chroma[] = {
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
106 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
107 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
108 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
109 };
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
110
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
111 unsigned char classic_add_luma[256] = {
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
112 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
113 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
114 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
115 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
116 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
117 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
118 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
119 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
120 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
121 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
122 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
123 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
124 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
125 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
126 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
127 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
128 };
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
129
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
130 unsigned char classic_add_chroma[256] = {
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
131 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
132 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
133 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
134 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
135 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
136 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
137 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
138 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
139 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
140 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
141 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
142 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
143 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
144 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
145 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
146 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
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
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 * Internal function prototypes
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
152 */
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
153 unsigned char* InitializeDecodeTable(unsigned char* hufftable,
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
154 unsigned char* shift, DecodeTable* decode_table);
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
155 unsigned char* InitializeShiftAddTables(unsigned char* hufftable,
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
156 unsigned char* shift, unsigned* add_shifted);
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
157 unsigned char* DecompressHuffmanTable(unsigned char* hufftable,
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
158 unsigned char* dst);
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
159 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
160 DecodeTable *decode_table, unsigned char *decode_shift);
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
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
164
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
165 // 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
166 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
167 {
9e80ac615570 committed Roberto Togni's patch for control() function in HuffYUV decoder
melanson
parents: 5235
diff changeset
168 switch(cmd) {
9e80ac615570 committed Roberto Togni's patch for control() function in HuffYUV decoder
melanson
parents: 5235
diff changeset
169 case VDCTRL_QUERY_FORMAT:
9e80ac615570 committed Roberto Togni's patch for control() function in HuffYUV decoder
melanson
parents: 5235
diff changeset
170 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
171 if (*((int*)arg) == IMGFMT_YUY2)
9e80ac615570 committed Roberto Togni's patch for control() function in HuffYUV decoder
melanson
parents: 5235
diff changeset
172 return CONTROL_TRUE;
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 return CONTROL_FALSE;
9e80ac615570 committed Roberto Togni's patch for control() function in HuffYUV decoder
melanson
parents: 5235
diff changeset
175 } else {
9e80ac615570 committed Roberto Togni's patch for control() function in HuffYUV decoder
melanson
parents: 5235
diff changeset
176 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
177 return CONTROL_TRUE;
9e80ac615570 committed Roberto Togni's patch for control() function in HuffYUV decoder
melanson
parents: 5235
diff changeset
178 else
9e80ac615570 committed Roberto Togni's patch for control() function in HuffYUV decoder
melanson
parents: 5235
diff changeset
179 return CONTROL_FALSE;
9e80ac615570 committed Roberto Togni's patch for control() function in HuffYUV decoder
melanson
parents: 5235
diff changeset
180 }
9e80ac615570 committed Roberto Togni's patch for control() function in HuffYUV decoder
melanson
parents: 5235
diff changeset
181 }
9e80ac615570 committed Roberto Togni's patch for control() function in HuffYUV decoder
melanson
parents: 5235
diff changeset
182 return CONTROL_UNKNOWN;
5235
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 /*
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 * Init HuffYUV decoder
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
189 *
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 static int init(sh_video_t *sh)
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
192 {
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
193 int vo_ret; // Video output init ret value
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
194 huffyuv_context_t *hc; // Decoder context
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
195 unsigned char *hufftable; // Compressed huffman tables
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
196 BITMAPINFOHEADER *bih = sh->bih;
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
197
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
198 if ((hc = malloc(sizeof(huffyuv_context_t))) == NULL) {
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
199 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
200 return 0;
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
201 }
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 sh->context = (void *)hc;
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
204
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
205 if (bih->biCompression != FOURCC_HFYU) {
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
206 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
207 return 0;
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
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
210 /* Get bitcount */
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
211 hc->bitcount = 0;
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
212 if (bih->biSize > sizeof(BITMAPINFOHEADER)+1)
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
213 hc->bitcount = *((char*)bih + sizeof(BITMAPINFOHEADER) + 1);
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
214 if (hc->bitcount == 0)
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
215 hc->bitcount = bih->biBitCount;
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
216
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
217 /* Get bitmap type */
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
218 switch (hc->bitcount & ~7) {
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
219 case 16:
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
220 hc->bitmaptype = BMPTYPE_YUV; // -1
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
221 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
222 break;
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
223 case 24:
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
224 hc->bitmaptype = BMPTYPE_RGB; // -2
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
225 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
226 break;
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
227 case 32:
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
228 hc->bitmaptype = BMPTYPE_RGBA; //-3
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
229 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
230 break;
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
231 default:
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
232 hc->bitmaptype = 0; // ERR
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
233 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
234 }
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
235
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
236 /* Get method */
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
237 switch (bih->biBitCount & 7) {
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
238 case 0:
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
239 if (bih->biSize > sizeof(BITMAPINFOHEADER)) {
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
240 hc->method = *((unsigned char*)bih + sizeof(BITMAPINFOHEADER));
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
241 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
242 } else
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
243 hc->method = METHOD_OLD; // Is it really needed?
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
244 break;
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
245 case 1:
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
246 hc->method = METHOD_LEFT;
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
247 break;
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
248 case 2:
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
249 hc->method = METHOD_LEFT_DECORR;
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
250 break;
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
251 case 3:
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
252 if (hc->bitmaptype == BMPTYPE_YUV) {
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
253 hc->method = METHOD_GRAD;
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
254 } else {
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
255 hc->method = METHOD_GRAD_DECORR;
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
256 }
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
257 break;
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
258 case 4:
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
259 hc->method = METHOD_MEDIAN;
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
260 break;
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
261 default:
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
262 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
263 hc->method = METHOD_OLD;
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
264 }
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 /* Print method info */
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
267 switch (hc->method) {
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
268 case METHOD_LEFT:
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
269 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
270 break;
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
271 case METHOD_GRAD:
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
272 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
273 break;
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
274 case METHOD_MEDIAN:
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
275 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
276 break;
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
277 case METHOD_LEFT_DECORR:
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 with decorrelation\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_DECORR:
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 with decorrelation\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_OLD:
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
284 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
285 break;
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
286 default:
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
287 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
288 }
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
289
6512
e2fe4801a98e Fix for interlaced huffyuv by roberto togni <rtogni at bresciaonline.it>
atmos4
parents: 5261
diff changeset
290 /* Take care of interlaced images */
e2fe4801a98e Fix for interlaced huffyuv by roberto togni <rtogni at bresciaonline.it>
atmos4
parents: 5261
diff changeset
291 hc->interlaced = 0;
e2fe4801a98e Fix for interlaced huffyuv by roberto togni <rtogni at bresciaonline.it>
atmos4
parents: 5261
diff changeset
292 if (bih->biHeight > 288) {
e2fe4801a98e Fix for interlaced huffyuv by roberto togni <rtogni at bresciaonline.it>
atmos4
parents: 5261
diff changeset
293 // Image is interlaced (flag != 0), but we may not care
e2fe4801a98e Fix for interlaced huffyuv by roberto togni <rtogni at bresciaonline.it>
atmos4
parents: 5261
diff changeset
294 hc->interlaced = 1;
e2fe4801a98e Fix for interlaced huffyuv by roberto togni <rtogni at bresciaonline.it>
atmos4
parents: 5261
diff changeset
295 mp_msg(MSGT_DECVIDEO, MSGL_V, "[HuffYUV] Image is interlaced\n");
e2fe4801a98e Fix for interlaced huffyuv by roberto togni <rtogni at bresciaonline.it>
atmos4
parents: 5261
diff changeset
296 }
e2fe4801a98e Fix for interlaced huffyuv by roberto togni <rtogni at bresciaonline.it>
atmos4
parents: 5261
diff changeset
297
e2fe4801a98e Fix for interlaced huffyuv by roberto togni <rtogni at bresciaonline.it>
atmos4
parents: 5261
diff changeset
298 /* Allocate buffers */
e2fe4801a98e Fix for interlaced huffyuv by roberto togni <rtogni at bresciaonline.it>
atmos4
parents: 5261
diff changeset
299 hc->abovebuf1 = NULL;
e2fe4801a98e Fix for interlaced huffyuv by roberto togni <rtogni at bresciaonline.it>
atmos4
parents: 5261
diff changeset
300 hc->abovebuf2 = NULL;
e2fe4801a98e Fix for interlaced huffyuv by roberto togni <rtogni at bresciaonline.it>
atmos4
parents: 5261
diff changeset
301 if ((hc->method == METHOD_MEDIAN) || (hc->method == METHOD_GRAD) ||
e2fe4801a98e Fix for interlaced huffyuv by roberto togni <rtogni at bresciaonline.it>
atmos4
parents: 5261
diff changeset
302 (hc->method == METHOD_GRAD_DECORR)) {
e2fe4801a98e Fix for interlaced huffyuv by roberto togni <rtogni at bresciaonline.it>
atmos4
parents: 5261
diff changeset
303 // If inetrlaced flag will be 2
e2fe4801a98e Fix for interlaced huffyuv by roberto togni <rtogni at bresciaonline.it>
atmos4
parents: 5261
diff changeset
304 (hc->interlaced)++;
e2fe4801a98e Fix for interlaced huffyuv by roberto togni <rtogni at bresciaonline.it>
atmos4
parents: 5261
diff changeset
305 mp_msg(MSGT_DECVIDEO, MSGL_V, "[HuffYUV] Allocating above line buffer\n");
e2fe4801a98e Fix for interlaced huffyuv by roberto togni <rtogni at bresciaonline.it>
atmos4
parents: 5261
diff changeset
306 if ((hc->abovebuf1 = malloc(sizeof(char) * 4 * bih->biWidth * hc->interlaced)) == NULL) {
e2fe4801a98e Fix for interlaced huffyuv by roberto togni <rtogni at bresciaonline.it>
atmos4
parents: 5261
diff changeset
307 mp_msg(MSGT_DECVIDEO, MSGL_ERR, "Can't allocate memory for HuffYUV above buffer 1\n");
e2fe4801a98e Fix for interlaced huffyuv by roberto togni <rtogni at bresciaonline.it>
atmos4
parents: 5261
diff changeset
308 return 0;
e2fe4801a98e Fix for interlaced huffyuv by roberto togni <rtogni at bresciaonline.it>
atmos4
parents: 5261
diff changeset
309 }
e2fe4801a98e Fix for interlaced huffyuv by roberto togni <rtogni at bresciaonline.it>
atmos4
parents: 5261
diff changeset
310
e2fe4801a98e Fix for interlaced huffyuv by roberto togni <rtogni at bresciaonline.it>
atmos4
parents: 5261
diff changeset
311 if ((hc->abovebuf2 = malloc(sizeof(char) * 4 * bih->biWidth * hc->interlaced)) == NULL) {
e2fe4801a98e Fix for interlaced huffyuv by roberto togni <rtogni at bresciaonline.it>
atmos4
parents: 5261
diff changeset
312 mp_msg(MSGT_DECVIDEO, MSGL_ERR, "Can't allocate memory for HuffYUV above buffer 2\n");
e2fe4801a98e Fix for interlaced huffyuv by roberto togni <rtogni at bresciaonline.it>
atmos4
parents: 5261
diff changeset
313 return 0;
e2fe4801a98e Fix for interlaced huffyuv by roberto togni <rtogni at bresciaonline.it>
atmos4
parents: 5261
diff changeset
314 }
e2fe4801a98e Fix for interlaced huffyuv by roberto togni <rtogni at bresciaonline.it>
atmos4
parents: 5261
diff changeset
315 }
e2fe4801a98e Fix for interlaced huffyuv by roberto togni <rtogni at bresciaonline.it>
atmos4
parents: 5261
diff changeset
316
5235
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
317 /* Get compressed Huffman tables */
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
318 if (bih->biSize == sizeof(BITMAPINFOHEADER) /*&& !(bih->biBitCount&7)*/) {
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
319 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
320 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
321 } else {
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
322 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
323 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
324 }
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
325
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
326 /* Initialize decoder Huffman tables */
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
327 hufftable = InitializeDecodeTable(hufftable, hc->decode1_shift, &(hc->decode1));
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
328 hufftable = InitializeDecodeTable(hufftable, hc->decode2_shift, &(hc->decode2));
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
329 InitializeDecodeTable(hufftable, hc->decode3_shift, &(hc->decode3));
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 /*
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
332 * Initialize video output device
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 switch (hc->bitmaptype) {
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
335 case BMPTYPE_YUV:
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
336 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
337 break;
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
338 case BMPTYPE_RGB:
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
339 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
340 break;
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
341 case BMPTYPE_RGBA:
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
342 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
343 return 0;
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
344 default:
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
345 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
346 return 0;
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
347 }
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
348
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
349 return vo_ret;
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 /*
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 * Uninit HuffYUV decoder
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
358 *
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
359 */
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
360 static void uninit(sh_video_t *sh)
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 if (sh->context) {
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
363 if (((huffyuv_context_t*)&sh->context)->abovebuf1)
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
364 free(((huffyuv_context_t*)sh->context)->abovebuf1);
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
365 if (((huffyuv_context_t*)&sh->context)->abovebuf2)
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
366 free(((huffyuv_context_t*)sh->context)->abovebuf2);
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
367 free(sh->context);
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
368 }
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
369 }
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 #define HUFF_DECOMPRESS_YUYV() \
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
374 { \
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
375 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
376 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
377 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
378 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
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 HUFF_DECOMPRESS_RGB_DECORR() \
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 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
386 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
387 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
388 }
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
389
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
390
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
391
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
392 #define HUFF_DECOMPRESS_RGB() \
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
393 { \
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
394 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
395 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
396 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
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 MEDIAN(left, above, aboveleft) \
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 if ((mi = (above)) > (left)) { \
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
404 mx = mi; \
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
405 mi = (left); \
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
406 } else \
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
407 mx = (left); \
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
408 tmp = (above) + (left) - (aboveleft); \
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
409 if (tmp < mi) \
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
410 med = mi; \
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
411 else if (tmp > mx) \
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
412 med = mx; \
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
413 else \
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
414 med = tmp; \
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
415 }
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
416
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
417
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
418
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
419 #define YUV_STORE1ST_ABOVEBUF() \
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 abovebuf[0] = outptr[0] = encoded[0]; \
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
422 abovebuf[1] = left_u = outptr[1] = encoded[1]; \
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
423 abovebuf[2] = left_y = outptr[2] = encoded[2]; \
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
424 abovebuf[3] = left_v = outptr[3] = encoded[3]; \
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
425 pixel_ptr = 4; \
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
426 }
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
427
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
428
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
429
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
430 #define YUV_STORE1ST() \
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 outptr[0] = encoded[0]; \
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
433 left_u = outptr[1] = encoded[1]; \
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
434 left_y = outptr[2] = encoded[2]; \
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
435 left_v = outptr[3] = encoded[3]; \
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
436 pixel_ptr = 4; \
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
437 }
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
438
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
439
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
440
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
441 #define RGB_STORE1ST() \
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 pixel_ptr = (height-1)*mpi->stride[0]; \
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
444 left_b = outptr[pixel_ptr++] = encoded[1]; \
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
445 left_g = outptr[pixel_ptr++] = encoded[2]; \
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
446 left_r = outptr[pixel_ptr++] = encoded[3]; \
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
447 pixel_ptr += bgr32; \
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
448 }
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
449
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
450
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
451
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
452 #define RGB_STORE1ST_ABOVEBUF() \
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 pixel_ptr = (height-1)*mpi->stride[0]; \
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
455 abovebuf[0] = left_b = outptr[pixel_ptr++] = encoded[1]; \
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
456 abovebuf[1] = left_g = outptr[pixel_ptr++] = encoded[2]; \
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
457 abovebuf[2] = left_r = outptr[pixel_ptr++] = encoded[3]; \
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
458 pixel_ptr += bgr32; \
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
459 }
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
460
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
461
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 #define YUV_PREDLEFT() \
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 outptr[pixel_ptr++] = left_y += y1; \
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
467 outptr[pixel_ptr++] = left_u += u; \
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
468 outptr[pixel_ptr++] = left_y += y2; \
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
469 outptr[pixel_ptr++] = left_v += v; \
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
470 }
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
471
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
472
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
473
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
474 #define YUV_PREDLEFT_BUF(buf, offs) \
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
475 { \
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
476 (buf)[(offs)] = outptr[pixel_ptr++] = left_y += y1; \
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
477 (buf)[(offs)+1] = outptr[pixel_ptr++] = left_u += u; \
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
478 (buf)[(offs)+2] = outptr[pixel_ptr++] = left_y += y2; \
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
479 (buf)[(offs)+3] = outptr[pixel_ptr++] = left_v += v; \
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
480 }
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
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
483
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
484 #define YUV_PREDMED() \
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
485 { \
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
486 MEDIAN (left_y, abovebuf[col], abovebuf[col-2]); \
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
487 curbuf[col] = outptr[pixel_ptr++] = left_y = med + y1; \
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
488 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
489 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
490 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
491 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
492 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
493 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
494 }
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
495
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
6512
e2fe4801a98e Fix for interlaced huffyuv by roberto togni <rtogni at bresciaonline.it>
atmos4
parents: 5261
diff changeset
498 #define YUV_PREDMED_1ST() \
e2fe4801a98e Fix for interlaced huffyuv by roberto togni <rtogni at bresciaonline.it>
atmos4
parents: 5261
diff changeset
499 { \
e2fe4801a98e Fix for interlaced huffyuv by roberto togni <rtogni at bresciaonline.it>
atmos4
parents: 5261
diff changeset
500 MEDIAN (left_y, abovebuf[0], curbuf[width2*4-2]); \
e2fe4801a98e Fix for interlaced huffyuv by roberto togni <rtogni at bresciaonline.it>
atmos4
parents: 5261
diff changeset
501 curbuf[0] = outptr[pixel_ptr++] = left_y = med + y1; \
e2fe4801a98e Fix for interlaced huffyuv by roberto togni <rtogni at bresciaonline.it>
atmos4
parents: 5261
diff changeset
502 MEDIAN (left_u, abovebuf[1], curbuf[width2*4+1-4]); \
e2fe4801a98e Fix for interlaced huffyuv by roberto togni <rtogni at bresciaonline.it>
atmos4
parents: 5261
diff changeset
503 curbuf[1] = outptr[pixel_ptr++] = left_u = med + u; \
e2fe4801a98e Fix for interlaced huffyuv by roberto togni <rtogni at bresciaonline.it>
atmos4
parents: 5261
diff changeset
504 MEDIAN (left_y, abovebuf[2], abovebuf[0]); \
e2fe4801a98e Fix for interlaced huffyuv by roberto togni <rtogni at bresciaonline.it>
atmos4
parents: 5261
diff changeset
505 curbuf[2] = outptr[pixel_ptr++] = left_y = med + y2; \
e2fe4801a98e Fix for interlaced huffyuv by roberto togni <rtogni at bresciaonline.it>
atmos4
parents: 5261
diff changeset
506 MEDIAN (left_v, abovebuf[3], curbuf[width2*4+3-4]); \
e2fe4801a98e Fix for interlaced huffyuv by roberto togni <rtogni at bresciaonline.it>
atmos4
parents: 5261
diff changeset
507 curbuf[3] = outptr[pixel_ptr++] = left_v = med + v; \
e2fe4801a98e Fix for interlaced huffyuv by roberto togni <rtogni at bresciaonline.it>
atmos4
parents: 5261
diff changeset
508 }
e2fe4801a98e Fix for interlaced huffyuv by roberto togni <rtogni at bresciaonline.it>
atmos4
parents: 5261
diff changeset
509
e2fe4801a98e Fix for interlaced huffyuv by roberto togni <rtogni at bresciaonline.it>
atmos4
parents: 5261
diff changeset
510
e2fe4801a98e Fix for interlaced huffyuv by roberto togni <rtogni at bresciaonline.it>
atmos4
parents: 5261
diff changeset
511
e2fe4801a98e Fix for interlaced huffyuv by roberto togni <rtogni at bresciaonline.it>
atmos4
parents: 5261
diff changeset
512 #define YUV_PREDGRAD() \
e2fe4801a98e Fix for interlaced huffyuv by roberto togni <rtogni at bresciaonline.it>
atmos4
parents: 5261
diff changeset
513 { \
e2fe4801a98e Fix for interlaced huffyuv by roberto togni <rtogni at bresciaonline.it>
atmos4
parents: 5261
diff changeset
514 curbuf[col] = outptr[pixel_ptr++] = left_y += y1 + abovebuf[col]-abovebuf[col-2]; \
e2fe4801a98e Fix for interlaced huffyuv by roberto togni <rtogni at bresciaonline.it>
atmos4
parents: 5261
diff changeset
515 curbuf[col+1] = outptr[pixel_ptr++] = left_u += u + abovebuf[col+1]-abovebuf[col+1-4]; \
e2fe4801a98e Fix for interlaced huffyuv by roberto togni <rtogni at bresciaonline.it>
atmos4
parents: 5261
diff changeset
516 curbuf[col+2] = outptr[pixel_ptr++] = left_y += y2 + abovebuf[col+2]-abovebuf[col+2-2]; \
e2fe4801a98e Fix for interlaced huffyuv by roberto togni <rtogni at bresciaonline.it>
atmos4
parents: 5261
diff changeset
517 curbuf[col+3] = outptr[pixel_ptr++] = left_v += v + abovebuf[col+3]-abovebuf[col+3-4]; \
e2fe4801a98e Fix for interlaced huffyuv by roberto togni <rtogni at bresciaonline.it>
atmos4
parents: 5261
diff changeset
518 }
e2fe4801a98e Fix for interlaced huffyuv by roberto togni <rtogni at bresciaonline.it>
atmos4
parents: 5261
diff changeset
519
e2fe4801a98e Fix for interlaced huffyuv by roberto togni <rtogni at bresciaonline.it>
atmos4
parents: 5261
diff changeset
520
e2fe4801a98e Fix for interlaced huffyuv by roberto togni <rtogni at bresciaonline.it>
atmos4
parents: 5261
diff changeset
521
e2fe4801a98e Fix for interlaced huffyuv by roberto togni <rtogni at bresciaonline.it>
atmos4
parents: 5261
diff changeset
522 #define YUV_PREDGRAD_1ST() \
e2fe4801a98e Fix for interlaced huffyuv by roberto togni <rtogni at bresciaonline.it>
atmos4
parents: 5261
diff changeset
523 { \
e2fe4801a98e Fix for interlaced huffyuv by roberto togni <rtogni at bresciaonline.it>
atmos4
parents: 5261
diff changeset
524 curbuf[0] = outptr[pixel_ptr++] = left_y += y1 + abovebuf[0] - curbuf[width2*4-2]; \
e2fe4801a98e Fix for interlaced huffyuv by roberto togni <rtogni at bresciaonline.it>
atmos4
parents: 5261
diff changeset
525 curbuf[1] = outptr[pixel_ptr++] = left_u += u + abovebuf[1] - curbuf[width2*4+1-4]; \
e2fe4801a98e Fix for interlaced huffyuv by roberto togni <rtogni at bresciaonline.it>
atmos4
parents: 5261
diff changeset
526 curbuf[2] = outptr[pixel_ptr++] = left_y += y2 + abovebuf[2] - abovebuf[0]; \
e2fe4801a98e Fix for interlaced huffyuv by roberto togni <rtogni at bresciaonline.it>
atmos4
parents: 5261
diff changeset
527 curbuf[3] = outptr[pixel_ptr++] = left_v += v + abovebuf[3] - curbuf[width2*4+3-4]; \
e2fe4801a98e Fix for interlaced huffyuv by roberto togni <rtogni at bresciaonline.it>
atmos4
parents: 5261
diff changeset
528 }
e2fe4801a98e Fix for interlaced huffyuv by roberto togni <rtogni at bresciaonline.it>
atmos4
parents: 5261
diff changeset
529
e2fe4801a98e Fix for interlaced huffyuv by roberto togni <rtogni at bresciaonline.it>
atmos4
parents: 5261
diff changeset
530
e2fe4801a98e Fix for interlaced huffyuv by roberto togni <rtogni at bresciaonline.it>
atmos4
parents: 5261
diff changeset
531
5235
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
532 #define RGB_PREDLEFT_DECORR() \
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
533 { \
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
534 outptr[pixel_ptr++] = left_b += b + g; \
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
535 outptr[pixel_ptr++] = left_g += g; \
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
536 outptr[pixel_ptr++] = left_r += r + g; \
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
537 pixel_ptr += bgr32; \
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
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
541
6512
e2fe4801a98e Fix for interlaced huffyuv by roberto togni <rtogni at bresciaonline.it>
atmos4
parents: 5261
diff changeset
542 #define RGB_PREDLEFT_DECORR_BUF() \
e2fe4801a98e Fix for interlaced huffyuv by roberto togni <rtogni at bresciaonline.it>
atmos4
parents: 5261
diff changeset
543 { \
e2fe4801a98e Fix for interlaced huffyuv by roberto togni <rtogni at bresciaonline.it>
atmos4
parents: 5261
diff changeset
544 abovebuf[col] = outptr[pixel_ptr++] = left_b += b + g; \
e2fe4801a98e Fix for interlaced huffyuv by roberto togni <rtogni at bresciaonline.it>
atmos4
parents: 5261
diff changeset
545 abovebuf[col+1] = outptr[pixel_ptr++] = left_g += g; \
e2fe4801a98e Fix for interlaced huffyuv by roberto togni <rtogni at bresciaonline.it>
atmos4
parents: 5261
diff changeset
546 abovebuf[col+2] = outptr[pixel_ptr++] = left_r += r + g; \
e2fe4801a98e Fix for interlaced huffyuv by roberto togni <rtogni at bresciaonline.it>
atmos4
parents: 5261
diff changeset
547 pixel_ptr += bgr32; \
e2fe4801a98e Fix for interlaced huffyuv by roberto togni <rtogni at bresciaonline.it>
atmos4
parents: 5261
diff changeset
548 }
e2fe4801a98e Fix for interlaced huffyuv by roberto togni <rtogni at bresciaonline.it>
atmos4
parents: 5261
diff changeset
549
e2fe4801a98e Fix for interlaced huffyuv by roberto togni <rtogni at bresciaonline.it>
atmos4
parents: 5261
diff changeset
550
5235
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
551 #define RGB_PREDLEFT() \
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
552 { \
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
553 outptr[pixel_ptr++] = left_b += b; \
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
554 outptr[pixel_ptr++] = left_g += g; \
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
555 outptr[pixel_ptr++] = left_r += r; \
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
556 pixel_ptr += bgr32; \
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
557 }
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
558
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
559
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
560
6512
e2fe4801a98e Fix for interlaced huffyuv by roberto togni <rtogni at bresciaonline.it>
atmos4
parents: 5261
diff changeset
561 #define RGB_PREDGRAD_DECORR() \
e2fe4801a98e Fix for interlaced huffyuv by roberto togni <rtogni at bresciaonline.it>
atmos4
parents: 5261
diff changeset
562 { \
e2fe4801a98e Fix for interlaced huffyuv by roberto togni <rtogni at bresciaonline.it>
atmos4
parents: 5261
diff changeset
563 curbuf[col] = outptr[pixel_ptr++] = left_b += b + g + abovebuf[col]-abovebuf[col-3]; \
e2fe4801a98e Fix for interlaced huffyuv by roberto togni <rtogni at bresciaonline.it>
atmos4
parents: 5261
diff changeset
564 curbuf[col+1] = outptr[pixel_ptr++] = left_g += g + abovebuf[col+1]-abovebuf[col+1-3]; \
e2fe4801a98e Fix for interlaced huffyuv by roberto togni <rtogni at bresciaonline.it>
atmos4
parents: 5261
diff changeset
565 curbuf[col+2] = outptr[pixel_ptr++] = left_r += r + g + abovebuf[col+2]-abovebuf[col+2-3]; \
e2fe4801a98e Fix for interlaced huffyuv by roberto togni <rtogni at bresciaonline.it>
atmos4
parents: 5261
diff changeset
566 pixel_ptr += bgr32; \
e2fe4801a98e Fix for interlaced huffyuv by roberto togni <rtogni at bresciaonline.it>
atmos4
parents: 5261
diff changeset
567 }
e2fe4801a98e Fix for interlaced huffyuv by roberto togni <rtogni at bresciaonline.it>
atmos4
parents: 5261
diff changeset
568
e2fe4801a98e Fix for interlaced huffyuv by roberto togni <rtogni at bresciaonline.it>
atmos4
parents: 5261
diff changeset
569
e2fe4801a98e Fix for interlaced huffyuv by roberto togni <rtogni at bresciaonline.it>
atmos4
parents: 5261
diff changeset
570
e2fe4801a98e Fix for interlaced huffyuv by roberto togni <rtogni at bresciaonline.it>
atmos4
parents: 5261
diff changeset
571 #define RGB_PREDGRAD_DECORR_1ST() \
e2fe4801a98e Fix for interlaced huffyuv by roberto togni <rtogni at bresciaonline.it>
atmos4
parents: 5261
diff changeset
572 { \
e2fe4801a98e Fix for interlaced huffyuv by roberto togni <rtogni at bresciaonline.it>
atmos4
parents: 5261
diff changeset
573 curbuf[0] = outptr[pixel_ptr++] = left_b += b + g + abovebuf[0] - curbuf[width2*3-3]; \
e2fe4801a98e Fix for interlaced huffyuv by roberto togni <rtogni at bresciaonline.it>
atmos4
parents: 5261
diff changeset
574 curbuf[1] = outptr[pixel_ptr++] = left_g += g + abovebuf[1] - curbuf[width2*3+1-3]; \
e2fe4801a98e Fix for interlaced huffyuv by roberto togni <rtogni at bresciaonline.it>
atmos4
parents: 5261
diff changeset
575 curbuf[2] = outptr[pixel_ptr++] = left_r += r + g + abovebuf[2] - curbuf[width2*3+2-3]; \
e2fe4801a98e Fix for interlaced huffyuv by roberto togni <rtogni at bresciaonline.it>
atmos4
parents: 5261
diff changeset
576 pixel_ptr += bgr32; \
e2fe4801a98e Fix for interlaced huffyuv by roberto togni <rtogni at bresciaonline.it>
atmos4
parents: 5261
diff changeset
577 }
e2fe4801a98e Fix for interlaced huffyuv by roberto togni <rtogni at bresciaonline.it>
atmos4
parents: 5261
diff changeset
578
e2fe4801a98e Fix for interlaced huffyuv by roberto togni <rtogni at bresciaonline.it>
atmos4
parents: 5261
diff changeset
579
e2fe4801a98e Fix for interlaced huffyuv by roberto togni <rtogni at bresciaonline.it>
atmos4
parents: 5261
diff changeset
580
e2fe4801a98e Fix for interlaced huffyuv by roberto togni <rtogni at bresciaonline.it>
atmos4
parents: 5261
diff changeset
581 #define SWAPBUF() \
e2fe4801a98e Fix for interlaced huffyuv by roberto togni <rtogni at bresciaonline.it>
atmos4
parents: 5261
diff changeset
582 { \
e2fe4801a98e Fix for interlaced huffyuv by roberto togni <rtogni at bresciaonline.it>
atmos4
parents: 5261
diff changeset
583 swap = abovebuf; \
e2fe4801a98e Fix for interlaced huffyuv by roberto togni <rtogni at bresciaonline.it>
atmos4
parents: 5261
diff changeset
584 abovebuf = curbuf; \
e2fe4801a98e Fix for interlaced huffyuv by roberto togni <rtogni at bresciaonline.it>
atmos4
parents: 5261
diff changeset
585 curbuf = swap; \
e2fe4801a98e Fix for interlaced huffyuv by roberto togni <rtogni at bresciaonline.it>
atmos4
parents: 5261
diff changeset
586 }
e2fe4801a98e Fix for interlaced huffyuv by roberto togni <rtogni at bresciaonline.it>
atmos4
parents: 5261
diff changeset
587
e2fe4801a98e Fix for interlaced huffyuv by roberto togni <rtogni at bresciaonline.it>
atmos4
parents: 5261
diff changeset
588
5235
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
589
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
590 /*
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
591 *
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
592 * Decode a HuffYUV frame
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
593 *
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
594 */
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
595 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
596 {
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
597 mp_image_t* mpi;
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
598 int pixel_ptr;
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
599 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
600 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
601 unsigned char tmp, mi, mx, med;
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
602 unsigned char *swap;
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
603 int row, col;
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
604 unsigned int pos = 32;
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
605 unsigned char *encoded = (unsigned char *)data;
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
606 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
607 unsigned char *abovebuf = hc->abovebuf1;
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
608 unsigned char *curbuf = hc->abovebuf2;
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
609 unsigned char *outptr;
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
610 int width = sh->disp_w; // Real image width
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
611 int height = sh->disp_h; // Real image height
6512
e2fe4801a98e Fix for interlaced huffyuv by roberto togni <rtogni at bresciaonline.it>
atmos4
parents: 5261
diff changeset
612 int width2, height2;
5235
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
613 int bgr32;
6512
e2fe4801a98e Fix for interlaced huffyuv by roberto togni <rtogni at bresciaonline.it>
atmos4
parents: 5261
diff changeset
614 int interlaced, oddlines;
5235
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
615
6512
e2fe4801a98e Fix for interlaced huffyuv by roberto togni <rtogni at bresciaonline.it>
atmos4
parents: 5261
diff changeset
616 // Skipped frame
5235
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
617 if(len <= 0)
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
618 return NULL;
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
619
6512
e2fe4801a98e Fix for interlaced huffyuv by roberto togni <rtogni at bresciaonline.it>
atmos4
parents: 5261
diff changeset
620 /* If image is interlaced and we care about it fix size */
e2fe4801a98e Fix for interlaced huffyuv by roberto togni <rtogni at bresciaonline.it>
atmos4
parents: 5261
diff changeset
621 if (hc->interlaced == 2) {
e2fe4801a98e Fix for interlaced huffyuv by roberto togni <rtogni at bresciaonline.it>
atmos4
parents: 5261
diff changeset
622 width2 = width*2; // Double image width
e2fe4801a98e Fix for interlaced huffyuv by roberto togni <rtogni at bresciaonline.it>
atmos4
parents: 5261
diff changeset
623 height2 = height/2; // Half image height
e2fe4801a98e Fix for interlaced huffyuv by roberto togni <rtogni at bresciaonline.it>
atmos4
parents: 5261
diff changeset
624 oddlines = height%2; // Set if line number is odd
e2fe4801a98e Fix for interlaced huffyuv by roberto togni <rtogni at bresciaonline.it>
atmos4
parents: 5261
diff changeset
625 interlaced = 1; // Used also for row counter computation, must be exactly 1
e2fe4801a98e Fix for interlaced huffyuv by roberto togni <rtogni at bresciaonline.it>
atmos4
parents: 5261
diff changeset
626 } else {
e2fe4801a98e Fix for interlaced huffyuv by roberto togni <rtogni at bresciaonline.it>
atmos4
parents: 5261
diff changeset
627 width2 = width; // Real image width
e2fe4801a98e Fix for interlaced huffyuv by roberto togni <rtogni at bresciaonline.it>
atmos4
parents: 5261
diff changeset
628 height2 = height; // Real image height
e2fe4801a98e Fix for interlaced huffyuv by roberto togni <rtogni at bresciaonline.it>
atmos4
parents: 5261
diff changeset
629 interlaced = 0; // Flag is 0: no need to deinterlaced image
e2fe4801a98e Fix for interlaced huffyuv by roberto togni <rtogni at bresciaonline.it>
atmos4
parents: 5261
diff changeset
630 oddlines = 0; // Don't care about odd line number if not interlaced
e2fe4801a98e Fix for interlaced huffyuv by roberto togni <rtogni at bresciaonline.it>
atmos4
parents: 5261
diff changeset
631 }
5235
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
632
6512
e2fe4801a98e Fix for interlaced huffyuv by roberto togni <rtogni at bresciaonline.it>
atmos4
parents: 5261
diff changeset
633
e2fe4801a98e Fix for interlaced huffyuv by roberto togni <rtogni at bresciaonline.it>
atmos4
parents: 5261
diff changeset
634 /* Get output image buffer */
e2fe4801a98e Fix for interlaced huffyuv by roberto togni <rtogni at bresciaonline.it>
atmos4
parents: 5261
diff changeset
635 mpi=mpcodecs_get_image(sh, MP_IMGTYPE_TEMP, MP_IMGFLAG_ACCEPT_STRIDE, sh->disp_w, sh->disp_h);
5235
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
636 if (!mpi) {
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
637 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
638 return NULL;
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
639 }
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 outptr = mpi->planes[0]; // Output image pointer
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 if (hc->bitmaptype == BMPTYPE_YUV) {
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
644 width >>= 1; // Each cycle stores two pixels
6512
e2fe4801a98e Fix for interlaced huffyuv by roberto togni <rtogni at bresciaonline.it>
atmos4
parents: 5261
diff changeset
645 width2 >>= 1;
5235
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
646 if (hc->method == METHOD_GRAD) {
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
647 /*
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
648 * YUV predict gradient
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 /* Store 1st pixel */
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
651 YUV_STORE1ST_ABOVEBUF();
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
652 // Decompress 1st row (always stored with left prediction)
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
653 for (col = 1*4; col < width*4; col += 4) {
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
654 HUFF_DECOMPRESS_YUYV();
6512
e2fe4801a98e Fix for interlaced huffyuv by roberto togni <rtogni at bresciaonline.it>
atmos4
parents: 5261
diff changeset
655 YUV_PREDLEFT_BUF (abovebuf, col);
5235
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
656 }
6512
e2fe4801a98e Fix for interlaced huffyuv by roberto togni <rtogni at bresciaonline.it>
atmos4
parents: 5261
diff changeset
657 if (interlaced) {
e2fe4801a98e Fix for interlaced huffyuv by roberto togni <rtogni at bresciaonline.it>
atmos4
parents: 5261
diff changeset
658 pixel_ptr = mpi->stride[0];
e2fe4801a98e Fix for interlaced huffyuv by roberto togni <rtogni at bresciaonline.it>
atmos4
parents: 5261
diff changeset
659 for (col = width*4; col < width*8; col += 4) {
e2fe4801a98e Fix for interlaced huffyuv by roberto togni <rtogni at bresciaonline.it>
atmos4
parents: 5261
diff changeset
660 HUFF_DECOMPRESS_YUYV();
e2fe4801a98e Fix for interlaced huffyuv by roberto togni <rtogni at bresciaonline.it>
atmos4
parents: 5261
diff changeset
661 YUV_PREDLEFT_BUF (abovebuf, col);
e2fe4801a98e Fix for interlaced huffyuv by roberto togni <rtogni at bresciaonline.it>
atmos4
parents: 5261
diff changeset
662 }
e2fe4801a98e Fix for interlaced huffyuv by roberto togni <rtogni at bresciaonline.it>
atmos4
parents: 5261
diff changeset
663 }
e2fe4801a98e Fix for interlaced huffyuv by roberto togni <rtogni at bresciaonline.it>
atmos4
parents: 5261
diff changeset
664 curbuf[width2*4-1] = curbuf[width2*4-2] = curbuf[width2*4-3] = 0;
e2fe4801a98e Fix for interlaced huffyuv by roberto togni <rtogni at bresciaonline.it>
atmos4
parents: 5261
diff changeset
665 for (row = 1; row < height2; row++) {
e2fe4801a98e Fix for interlaced huffyuv by roberto togni <rtogni at bresciaonline.it>
atmos4
parents: 5261
diff changeset
666 pixel_ptr = (interlaced + 1) * row * mpi->stride[0];
5235
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
667 HUFF_DECOMPRESS_YUYV();
6512
e2fe4801a98e Fix for interlaced huffyuv by roberto togni <rtogni at bresciaonline.it>
atmos4
parents: 5261
diff changeset
668 YUV_PREDGRAD_1ST();
5235
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
669 for (col = 1*4; col < width*4; col += 4) {
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
670 HUFF_DECOMPRESS_YUYV();
6512
e2fe4801a98e Fix for interlaced huffyuv by roberto togni <rtogni at bresciaonline.it>
atmos4
parents: 5261
diff changeset
671 YUV_PREDGRAD();
e2fe4801a98e Fix for interlaced huffyuv by roberto togni <rtogni at bresciaonline.it>
atmos4
parents: 5261
diff changeset
672 }
e2fe4801a98e Fix for interlaced huffyuv by roberto togni <rtogni at bresciaonline.it>
atmos4
parents: 5261
diff changeset
673 if (interlaced) {
e2fe4801a98e Fix for interlaced huffyuv by roberto togni <rtogni at bresciaonline.it>
atmos4
parents: 5261
diff changeset
674 pixel_ptr = (2 * row + 1) * mpi->stride[0];
e2fe4801a98e Fix for interlaced huffyuv by roberto togni <rtogni at bresciaonline.it>
atmos4
parents: 5261
diff changeset
675 for (col = width*4; col < width*8; col += 4) {
e2fe4801a98e Fix for interlaced huffyuv by roberto togni <rtogni at bresciaonline.it>
atmos4
parents: 5261
diff changeset
676 HUFF_DECOMPRESS_YUYV();
e2fe4801a98e Fix for interlaced huffyuv by roberto togni <rtogni at bresciaonline.it>
atmos4
parents: 5261
diff changeset
677 YUV_PREDGRAD();
e2fe4801a98e Fix for interlaced huffyuv by roberto togni <rtogni at bresciaonline.it>
atmos4
parents: 5261
diff changeset
678 }
5235
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
679 }
6512
e2fe4801a98e Fix for interlaced huffyuv by roberto togni <rtogni at bresciaonline.it>
atmos4
parents: 5261
diff changeset
680 SWAPBUF();
e2fe4801a98e Fix for interlaced huffyuv by roberto togni <rtogni at bresciaonline.it>
atmos4
parents: 5261
diff changeset
681 }
e2fe4801a98e Fix for interlaced huffyuv by roberto togni <rtogni at bresciaonline.it>
atmos4
parents: 5261
diff changeset
682 if (oddlines) {
e2fe4801a98e Fix for interlaced huffyuv by roberto togni <rtogni at bresciaonline.it>
atmos4
parents: 5261
diff changeset
683 pixel_ptr = 2 * height * mpi->stride[0];
e2fe4801a98e Fix for interlaced huffyuv by roberto togni <rtogni at bresciaonline.it>
atmos4
parents: 5261
diff changeset
684 HUFF_DECOMPRESS_YUYV();
e2fe4801a98e Fix for interlaced huffyuv by roberto togni <rtogni at bresciaonline.it>
atmos4
parents: 5261
diff changeset
685 YUV_PREDGRAD_1ST();
e2fe4801a98e Fix for interlaced huffyuv by roberto togni <rtogni at bresciaonline.it>
atmos4
parents: 5261
diff changeset
686 for (col = 1*4; col < width*4; col += 4) {
e2fe4801a98e Fix for interlaced huffyuv by roberto togni <rtogni at bresciaonline.it>
atmos4
parents: 5261
diff changeset
687 HUFF_DECOMPRESS_YUYV();
e2fe4801a98e Fix for interlaced huffyuv by roberto togni <rtogni at bresciaonline.it>
atmos4
parents: 5261
diff changeset
688 YUV_PREDGRAD();
e2fe4801a98e Fix for interlaced huffyuv by roberto togni <rtogni at bresciaonline.it>
atmos4
parents: 5261
diff changeset
689 }
5235
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
690 }
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
691 } else if (hc->method == METHOD_MEDIAN) {
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
692 /*
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
693 * YUV predict median
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
694 */
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
695 /* Store 1st pixel */
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
696 YUV_STORE1ST_ABOVEBUF();
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
697 // Decompress 1st row (always stored with left prediction)
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
698 for (col = 1*4; col < width*4; col += 4) {
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
699 HUFF_DECOMPRESS_YUYV();
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
700 YUV_PREDLEFT_BUF (abovebuf, col);
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
701 }
6512
e2fe4801a98e Fix for interlaced huffyuv by roberto togni <rtogni at bresciaonline.it>
atmos4
parents: 5261
diff changeset
702 if (interlaced) {
e2fe4801a98e Fix for interlaced huffyuv by roberto togni <rtogni at bresciaonline.it>
atmos4
parents: 5261
diff changeset
703 pixel_ptr = mpi->stride[0];
e2fe4801a98e Fix for interlaced huffyuv by roberto togni <rtogni at bresciaonline.it>
atmos4
parents: 5261
diff changeset
704 for (col = width*4; col < width*8; col += 4) {
e2fe4801a98e Fix for interlaced huffyuv by roberto togni <rtogni at bresciaonline.it>
atmos4
parents: 5261
diff changeset
705 HUFF_DECOMPRESS_YUYV();
e2fe4801a98e Fix for interlaced huffyuv by roberto togni <rtogni at bresciaonline.it>
atmos4
parents: 5261
diff changeset
706 YUV_PREDLEFT_BUF (abovebuf, col);
e2fe4801a98e Fix for interlaced huffyuv by roberto togni <rtogni at bresciaonline.it>
atmos4
parents: 5261
diff changeset
707 }
e2fe4801a98e Fix for interlaced huffyuv by roberto togni <rtogni at bresciaonline.it>
atmos4
parents: 5261
diff changeset
708 }
5235
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
709 // Decompress 1st two pixels of 2nd row
6512
e2fe4801a98e Fix for interlaced huffyuv by roberto togni <rtogni at bresciaonline.it>
atmos4
parents: 5261
diff changeset
710 pixel_ptr = mpi->stride[0] * (interlaced + 1);
5235
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
711 HUFF_DECOMPRESS_YUYV();
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
712 YUV_PREDLEFT_BUF (curbuf, 0);
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
713 HUFF_DECOMPRESS_YUYV();
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
714 YUV_PREDLEFT_BUF (curbuf, 4);
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
715 // Complete 2nd row
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
716 for (col = 2*4; col < width*4; col += 4) {
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
717 HUFF_DECOMPRESS_YUYV();
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
718 YUV_PREDMED();
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
719 }
6512
e2fe4801a98e Fix for interlaced huffyuv by roberto togni <rtogni at bresciaonline.it>
atmos4
parents: 5261
diff changeset
720 if (interlaced) {
e2fe4801a98e Fix for interlaced huffyuv by roberto togni <rtogni at bresciaonline.it>
atmos4
parents: 5261
diff changeset
721 pixel_ptr = mpi->stride[0] * 3;
e2fe4801a98e Fix for interlaced huffyuv by roberto togni <rtogni at bresciaonline.it>
atmos4
parents: 5261
diff changeset
722 for (col = width*4; col < width*8; col += 4) {
e2fe4801a98e Fix for interlaced huffyuv by roberto togni <rtogni at bresciaonline.it>
atmos4
parents: 5261
diff changeset
723 HUFF_DECOMPRESS_YUYV();
e2fe4801a98e Fix for interlaced huffyuv by roberto togni <rtogni at bresciaonline.it>
atmos4
parents: 5261
diff changeset
724 YUV_PREDMED();
e2fe4801a98e Fix for interlaced huffyuv by roberto togni <rtogni at bresciaonline.it>
atmos4
parents: 5261
diff changeset
725 }
e2fe4801a98e Fix for interlaced huffyuv by roberto togni <rtogni at bresciaonline.it>
atmos4
parents: 5261
diff changeset
726 }
e2fe4801a98e Fix for interlaced huffyuv by roberto togni <rtogni at bresciaonline.it>
atmos4
parents: 5261
diff changeset
727 SWAPBUF();
e2fe4801a98e Fix for interlaced huffyuv by roberto togni <rtogni at bresciaonline.it>
atmos4
parents: 5261
diff changeset
728 for (row = 2; row < height2; row++) {
e2fe4801a98e Fix for interlaced huffyuv by roberto togni <rtogni at bresciaonline.it>
atmos4
parents: 5261
diff changeset
729 pixel_ptr = (interlaced + 1) * row * mpi->stride[0];
5235
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
730 HUFF_DECOMPRESS_YUYV();
6512
e2fe4801a98e Fix for interlaced huffyuv by roberto togni <rtogni at bresciaonline.it>
atmos4
parents: 5261
diff changeset
731 YUV_PREDMED_1ST();
5235
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
732 for (col = 1*4; col < width*4; col += 4) {
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
733 HUFF_DECOMPRESS_YUYV();
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
734 YUV_PREDMED();
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
735 }
6512
e2fe4801a98e Fix for interlaced huffyuv by roberto togni <rtogni at bresciaonline.it>
atmos4
parents: 5261
diff changeset
736 if (interlaced) {
e2fe4801a98e Fix for interlaced huffyuv by roberto togni <rtogni at bresciaonline.it>
atmos4
parents: 5261
diff changeset
737 pixel_ptr = (2 * row + 1) * mpi->stride[0];
e2fe4801a98e Fix for interlaced huffyuv by roberto togni <rtogni at bresciaonline.it>
atmos4
parents: 5261
diff changeset
738 for (col = width*4; col < width*8; col += 4) {
e2fe4801a98e Fix for interlaced huffyuv by roberto togni <rtogni at bresciaonline.it>
atmos4
parents: 5261
diff changeset
739 HUFF_DECOMPRESS_YUYV();
e2fe4801a98e Fix for interlaced huffyuv by roberto togni <rtogni at bresciaonline.it>
atmos4
parents: 5261
diff changeset
740 YUV_PREDMED();
e2fe4801a98e Fix for interlaced huffyuv by roberto togni <rtogni at bresciaonline.it>
atmos4
parents: 5261
diff changeset
741 }
e2fe4801a98e Fix for interlaced huffyuv by roberto togni <rtogni at bresciaonline.it>
atmos4
parents: 5261
diff changeset
742 }
e2fe4801a98e Fix for interlaced huffyuv by roberto togni <rtogni at bresciaonline.it>
atmos4
parents: 5261
diff changeset
743 SWAPBUF();
e2fe4801a98e Fix for interlaced huffyuv by roberto togni <rtogni at bresciaonline.it>
atmos4
parents: 5261
diff changeset
744 }
e2fe4801a98e Fix for interlaced huffyuv by roberto togni <rtogni at bresciaonline.it>
atmos4
parents: 5261
diff changeset
745 if (oddlines) {
e2fe4801a98e Fix for interlaced huffyuv by roberto togni <rtogni at bresciaonline.it>
atmos4
parents: 5261
diff changeset
746 pixel_ptr = 2 * height2 * mpi->stride[0];
e2fe4801a98e Fix for interlaced huffyuv by roberto togni <rtogni at bresciaonline.it>
atmos4
parents: 5261
diff changeset
747 HUFF_DECOMPRESS_YUYV();
e2fe4801a98e Fix for interlaced huffyuv by roberto togni <rtogni at bresciaonline.it>
atmos4
parents: 5261
diff changeset
748 YUV_PREDMED_1ST();
e2fe4801a98e Fix for interlaced huffyuv by roberto togni <rtogni at bresciaonline.it>
atmos4
parents: 5261
diff changeset
749 for (col = 1*4; col < width*4; col += 4) {
e2fe4801a98e Fix for interlaced huffyuv by roberto togni <rtogni at bresciaonline.it>
atmos4
parents: 5261
diff changeset
750 HUFF_DECOMPRESS_YUYV();
e2fe4801a98e Fix for interlaced huffyuv by roberto togni <rtogni at bresciaonline.it>
atmos4
parents: 5261
diff changeset
751 YUV_PREDMED();
e2fe4801a98e Fix for interlaced huffyuv by roberto togni <rtogni at bresciaonline.it>
atmos4
parents: 5261
diff changeset
752 }
5235
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
753 }
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
754 } else {
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
755 /*
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
756 * YUV predict left and predict old
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
757 */
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
758 /* Store 1st pixel */
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
759 YUV_STORE1ST();
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
760 // Decompress 1st row (always stored with left prediction)
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
761 for (col = 1*4; col < width*4; col += 4) {
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
762 HUFF_DECOMPRESS_YUYV();
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
763 YUV_PREDLEFT();
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
764 }
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
765 for (row = 1; row < height; row++) {
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
766 pixel_ptr = row * mpi->stride[0];
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
767 for (col = 0; col < width*4; col += 4) {
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
768 HUFF_DECOMPRESS_YUYV();
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
769 YUV_PREDLEFT();
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
770 }
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 } else {
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
774 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
775 if (hc->method == METHOD_LEFT_DECORR) {
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 * RGB predict left with decorrelation
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 /* Store 1st pixel */
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
780 RGB_STORE1ST();
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
781 // Decompress 1st row
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
782 for (col = 1; col < width; col ++) {
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
783 HUFF_DECOMPRESS_RGB_DECORR();
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
784 RGB_PREDLEFT_DECORR();
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
785 }
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
786 for (row = 1; row < height; row++) {
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
787 pixel_ptr = (height - row - 1) * mpi->stride[0];
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
788 for (col = 0; col < width; col++) {
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
789 HUFF_DECOMPRESS_RGB_DECORR();
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
790 RGB_PREDLEFT_DECORR();
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
791 }
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
792 }
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
793 } else if (hc->method == METHOD_GRAD_DECORR) {
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
794 /*
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
795 * RGB predict gradient with decorrelation
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
796 */
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
797 /* Store 1st pixel */
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
798 RGB_STORE1ST_ABOVEBUF();
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
799 // Decompress 1st row (always stored with left prediction)
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
800 for (col = 1*3; col < width*3; col += 3) {
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
801 HUFF_DECOMPRESS_RGB_DECORR();
6512
e2fe4801a98e Fix for interlaced huffyuv by roberto togni <rtogni at bresciaonline.it>
atmos4
parents: 5261
diff changeset
802 RGB_PREDLEFT_DECORR_BUF();
5235
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
803 }
6512
e2fe4801a98e Fix for interlaced huffyuv by roberto togni <rtogni at bresciaonline.it>
atmos4
parents: 5261
diff changeset
804 if (interlaced) {
e2fe4801a98e Fix for interlaced huffyuv by roberto togni <rtogni at bresciaonline.it>
atmos4
parents: 5261
diff changeset
805 pixel_ptr = (height-2)*mpi->stride[0];
e2fe4801a98e Fix for interlaced huffyuv by roberto togni <rtogni at bresciaonline.it>
atmos4
parents: 5261
diff changeset
806 for (col = width*3; col < width*6; col += 3) {
e2fe4801a98e Fix for interlaced huffyuv by roberto togni <rtogni at bresciaonline.it>
atmos4
parents: 5261
diff changeset
807 HUFF_DECOMPRESS_RGB_DECORR();
e2fe4801a98e Fix for interlaced huffyuv by roberto togni <rtogni at bresciaonline.it>
atmos4
parents: 5261
diff changeset
808 RGB_PREDLEFT_DECORR_BUF();
e2fe4801a98e Fix for interlaced huffyuv by roberto togni <rtogni at bresciaonline.it>
atmos4
parents: 5261
diff changeset
809 }
e2fe4801a98e Fix for interlaced huffyuv by roberto togni <rtogni at bresciaonline.it>
atmos4
parents: 5261
diff changeset
810 }
e2fe4801a98e Fix for interlaced huffyuv by roberto togni <rtogni at bresciaonline.it>
atmos4
parents: 5261
diff changeset
811 curbuf[width2*3-1] = curbuf[width2*3-2] = curbuf[width2*3-3] = 0;
e2fe4801a98e Fix for interlaced huffyuv by roberto togni <rtogni at bresciaonline.it>
atmos4
parents: 5261
diff changeset
812 for (row = 1; row < height2; row++) {
e2fe4801a98e Fix for interlaced huffyuv by roberto togni <rtogni at bresciaonline.it>
atmos4
parents: 5261
diff changeset
813 pixel_ptr = (height - (interlaced + 1) * row - 1) * mpi->stride[0];
5235
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
814 HUFF_DECOMPRESS_RGB_DECORR();
6512
e2fe4801a98e Fix for interlaced huffyuv by roberto togni <rtogni at bresciaonline.it>
atmos4
parents: 5261
diff changeset
815 RGB_PREDGRAD_DECORR_1ST();
5235
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
816 for (col = 1*3; col < width*3; col += 3) {
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
817 HUFF_DECOMPRESS_RGB_DECORR();
6512
e2fe4801a98e Fix for interlaced huffyuv by roberto togni <rtogni at bresciaonline.it>
atmos4
parents: 5261
diff changeset
818 RGB_PREDGRAD_DECORR();
e2fe4801a98e Fix for interlaced huffyuv by roberto togni <rtogni at bresciaonline.it>
atmos4
parents: 5261
diff changeset
819 }
e2fe4801a98e Fix for interlaced huffyuv by roberto togni <rtogni at bresciaonline.it>
atmos4
parents: 5261
diff changeset
820 if (interlaced) {
e2fe4801a98e Fix for interlaced huffyuv by roberto togni <rtogni at bresciaonline.it>
atmos4
parents: 5261
diff changeset
821 pixel_ptr = (height - 2 * row - 2) * mpi->stride[0];
e2fe4801a98e Fix for interlaced huffyuv by roberto togni <rtogni at bresciaonline.it>
atmos4
parents: 5261
diff changeset
822 for (col = width*3; col < width*6; col += 3) {
e2fe4801a98e Fix for interlaced huffyuv by roberto togni <rtogni at bresciaonline.it>
atmos4
parents: 5261
diff changeset
823 HUFF_DECOMPRESS_RGB_DECORR();
e2fe4801a98e Fix for interlaced huffyuv by roberto togni <rtogni at bresciaonline.it>
atmos4
parents: 5261
diff changeset
824 RGB_PREDGRAD_DECORR();
e2fe4801a98e Fix for interlaced huffyuv by roberto togni <rtogni at bresciaonline.it>
atmos4
parents: 5261
diff changeset
825 }
5235
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
826 }
6512
e2fe4801a98e Fix for interlaced huffyuv by roberto togni <rtogni at bresciaonline.it>
atmos4
parents: 5261
diff changeset
827 SWAPBUF();
e2fe4801a98e Fix for interlaced huffyuv by roberto togni <rtogni at bresciaonline.it>
atmos4
parents: 5261
diff changeset
828 }
e2fe4801a98e Fix for interlaced huffyuv by roberto togni <rtogni at bresciaonline.it>
atmos4
parents: 5261
diff changeset
829 if (oddlines) {
e2fe4801a98e Fix for interlaced huffyuv by roberto togni <rtogni at bresciaonline.it>
atmos4
parents: 5261
diff changeset
830 pixel_ptr = mpi->stride[0];
e2fe4801a98e Fix for interlaced huffyuv by roberto togni <rtogni at bresciaonline.it>
atmos4
parents: 5261
diff changeset
831 HUFF_DECOMPRESS_RGB_DECORR();
e2fe4801a98e Fix for interlaced huffyuv by roberto togni <rtogni at bresciaonline.it>
atmos4
parents: 5261
diff changeset
832 RGB_PREDGRAD_DECORR_1ST();
e2fe4801a98e Fix for interlaced huffyuv by roberto togni <rtogni at bresciaonline.it>
atmos4
parents: 5261
diff changeset
833 for (col = 1*3; col < width*3; col += 3) {
e2fe4801a98e Fix for interlaced huffyuv by roberto togni <rtogni at bresciaonline.it>
atmos4
parents: 5261
diff changeset
834 HUFF_DECOMPRESS_RGB_DECORR();
e2fe4801a98e Fix for interlaced huffyuv by roberto togni <rtogni at bresciaonline.it>
atmos4
parents: 5261
diff changeset
835 RGB_PREDGRAD_DECORR();
e2fe4801a98e Fix for interlaced huffyuv by roberto togni <rtogni at bresciaonline.it>
atmos4
parents: 5261
diff changeset
836 }
5235
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
837 }
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
838 } else {
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
839 /*
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
840 * RGB predict left (no decorrelation) and predict old
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
841 */
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
842 /* Store 1st pixel */
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
843 RGB_STORE1ST();
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
844 // Decompress 1st row
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
845 for (col = 1; col < width; col++) {
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
846 HUFF_DECOMPRESS_RGB();
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
847 RGB_PREDLEFT();
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
848 }
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
849 for (row = 1; row < height; row++) {
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
850 pixel_ptr = (height - row - 1) * mpi->stride[0];
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
851 for (col = 0; col < width; col++) {
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
852 HUFF_DECOMPRESS_RGB();
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
853 RGB_PREDLEFT();
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
854 }
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
855 }
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
856 }
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
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
859 return mpi;
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
860 }
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
861
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
862
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
863
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
864 unsigned char* InitializeDecodeTable(unsigned char* hufftable,
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
865 unsigned char* shift, DecodeTable* decode_table)
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
866 {
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
867 unsigned int add_shifted[256];
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
868 char code_lengths[256];
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
869 char code_firstbits[256];
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
870 char table_lengths[32];
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
871 int all_zero_code=-1;
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
872 int i, j, k;
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
873 int firstbit, length, val;
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
874 unsigned char* p;
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
875 unsigned char * table;
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
876
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
877 /* Initialize shift[] and add_shifted[] */
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
878 hufftable = InitializeShiftAddTables(hufftable, shift, add_shifted);
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
879
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
880 memset(table_lengths, -1, 32);
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
881
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
882 /* Fill code_firstbits[], code_legths[] and table_lengths[] */
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
883 for (i = 0; i < 256; ++i) {
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
884 if (add_shifted[i]) {
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
885 for (firstbit = 31; firstbit >= 0; firstbit--) {
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
886 if (add_shifted[i] & (1 << firstbit)) {
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
887 code_firstbits[i] = firstbit;
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
888 length = shift[i] - (32 - firstbit);
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
889 code_lengths[i] = length;
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
890 table_lengths[firstbit] = max(table_lengths[firstbit], length);
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
891 break;
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
892 }
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
893 }
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
894 } else {
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
895 all_zero_code = i;
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
896 }
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
897 }
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
898
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
899 p = decode_table->table_data;
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
900 *p++ = 31;
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
901 *p++ = all_zero_code;
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
902 for (j = 0; j < 32; ++j) {
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
903 if (table_lengths[j] == -1) {
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
904 decode_table->table_pointers[j] = decode_table->table_data;
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
905 } else {
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
906 decode_table->table_pointers[j] = p;
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
907 *p++ = j - table_lengths[j];
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
908 p += 1 << table_lengths[j];
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
909 }
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
910 }
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
911
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
912 for (k=0; k<256; ++k) {
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
913 if (add_shifted[k]) {
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
914 firstbit = code_firstbits[k];
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
915 val = add_shifted[k] - (1 << firstbit);
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
916 table = decode_table->table_pointers[firstbit];
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
917 memset(&table[1 + (val >> table[0])], k,
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
918 1 << (table_lengths[firstbit] - code_lengths[k]));
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
919 }
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
920 }
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
921
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
922 return hufftable;
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
923 }
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
924
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
925
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
926
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
927 unsigned char* InitializeShiftAddTables(unsigned char* hufftable,
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
928 unsigned char* shift, unsigned* add_shifted)
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
929 {
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
930 int i, j;
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
931 unsigned int bits; // must be 32bit unsigned
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
932 int min_already_processed;
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
933 int max_not_processed;
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
934 int bit;
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
935
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
936 // 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
937 if (hufftable == HUFFTABLE_CLASSIC_YUV || hufftable == HUFFTABLE_CLASSIC_RGB) {
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
938 DecompressHuffmanTable(classic_shift_luma, shift);
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
939 for (i = 0; i < 256; ++i)
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
940 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
941 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
942 } else if (hufftable == HUFFTABLE_CLASSIC_YUV_CHROMA) {
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
943 DecompressHuffmanTable(classic_shift_chroma, shift);
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
944 for (i = 0; i < 256; ++i)
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
945 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
946 return hufftable;
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
947 }
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
948
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
949 hufftable = DecompressHuffmanTable(hufftable, shift);
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
950
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
951 // derive the actual bit patterns from the code lengths
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
952 min_already_processed = 32;
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
953 bits = 0;
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
954 do {
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
955 max_not_processed = 0;
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
956 for (i = 0; i < 256; ++i) {
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
957 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
958 max_not_processed = shift[i];
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
959 }
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
960 bit = 1 << (32 - max_not_processed);
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
961 // assert (!(bits & (bit - 1)));
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
962 for (j = 0; j < 256; ++j) {
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
963 if (shift[j] == max_not_processed) {
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
964 add_shifted[j] = bits;
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
965 bits += bit;
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
966 }
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
967 }
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
968 min_already_processed = max_not_processed;
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
969 } while (bits & 0xFFFFFFFF);
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
970
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
971 return hufftable;
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
972 }
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
973
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
974
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
975
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
976 unsigned char* DecompressHuffmanTable(unsigned char* hufftable,
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
977 unsigned char* dst)
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
978 {
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
979 int val;
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
980 int repeat;
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
981 int i = 0;
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
982
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
983 do {
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
984 val = *hufftable & 31;
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
985 repeat = *hufftable++ >> 5;
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
986 if (!repeat)
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
987 repeat = *hufftable++;
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
988 while (repeat--)
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
989 dst[i++] = val;
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
990 } while (i < 256);
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
991
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
992 return hufftable;
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
993 }
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
994
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
995
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
996 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
997 unsigned char *decode_shift)
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
998 {
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
999 unsigned int word = *pos >> 5;
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
1000 unsigned int bit = *pos & 31;
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
1001 unsigned int val = in[word];
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
1002 unsigned char outbyte;
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
1003 unsigned char *tableptr;
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
1004 int i;
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
1005
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
1006 if (bit)
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
1007 val = (val << bit) | (in[word + 1] >> (32 - bit));
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
1008 // 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
1009 i = 31;
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
1010 val |= 1;
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
1011 while ((val & (1 << i--)) == 0);
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
1012 val &= ~(1 << (i+1));
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
1013 tableptr = decode_table->table_pointers[i+1];
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
1014 val >>= *tableptr;
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
1015
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
1016 outbyte = tableptr[val+1];
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
1017 *pos += decode_shift[outbyte];
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
1018
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
1019 return outbyte;
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
1020 }