annotate libmpcodecs/vd_huffyuv.c @ 9278:caea8ed36b48

The reason why mplayer crashes (in some cases) when using x11 output and -wid (>0) parameter is this: Mplayer by default creates a colormap using DirectColor visual. If the window given to mplayer uses TrueColor visual there will be an error when mplayer sets the colormap for the window. This patch modifies mplayer to use TrueColor visual if the window given to mplayer uses TrueColor. Another solution is to make sure that the window given to mplayer is created using DirectColor visual if it is supported by the display. Jouni Tulkki <jitulkki@cc.hut.fi>
author arpi
date Tue, 04 Feb 2003 18:31:44 +0000
parents 772d6d27fd66
children
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 "Roberto Togni",
7191
1eadce15446c -afm/-vfm help implemenetd, some cosmetics of ad/vd codec names/comments
arpi
parents: 7180
diff changeset
32 "Roberto Togni, original win32 by Ben Rudiak-Gould http://www.math.berkeley.edu/~benrg/huffyuv.html",
1eadce15446c -afm/-vfm help implemenetd, some cosmetics of ad/vd codec names/comments
arpi
parents: 7180
diff changeset
33 "native codec"
5235
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
34 };
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 LIBVD_EXTERN(huffyuv)
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
37
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 * Bitmap types
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
41 */
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
42 #define BMPTYPE_YUV -1
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
43 #define BMPTYPE_RGB -2
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
44 #define BMPTYPE_RGBA -3
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
45
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 * Compression methods
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
48 */
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
49 #define METHOD_LEFT 0
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
50 #define METHOD_GRAD 1
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
51 #define METHOD_MEDIAN 2
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
52 #define DECORR_FLAG 64
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
53 #define METHOD_LEFT_DECORR (METHOD_LEFT | DECORR_FLAG)
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
54 #define METHOD_GRAD_DECORR (METHOD_GRAD | DECORR_FLAG)
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
55 #define METHOD_OLD -2
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
56
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
57 #define FOURCC_HFYU mmioFOURCC('H','F','Y','U')
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
58
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
59 #define HUFFTABLE_CLASSIC_YUV ((unsigned char*) -1)
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
60 #define HUFFTABLE_CLASSIC_RGB ((unsigned char*) -2)
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
61 #define HUFFTABLE_CLASSIC_YUV_CHROMA ((unsigned char*) -3)
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
62
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 * Huffman table
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
66 */
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
67 typedef struct {
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
68 unsigned char* table_pointers[32];
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
69 unsigned char table_data[129*25];
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
70 } DecodeTable;
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
71
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 * Decoder context
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
75 */
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
76 typedef struct {
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
77 // Real image depth
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
78 int bitcount;
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
79 // Prediction method
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
80 int method;
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
81 // Bitmap color type
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
82 int bitmaptype;
6512
e2fe4801a98e Fix for interlaced huffyuv by roberto togni <rtogni at bresciaonline.it>
atmos4
parents: 5261
diff changeset
83 // Interlaced flag
e2fe4801a98e Fix for interlaced huffyuv by roberto togni <rtogni at bresciaonline.it>
atmos4
parents: 5261
diff changeset
84 int interlaced;
5235
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
85 // Huffman tables
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
86 unsigned char decode1_shift[256];
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
87 unsigned char decode2_shift[256];
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
88 unsigned char decode3_shift[256];
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
89 DecodeTable decode1, decode2, decode3;
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
90 // Above line buffers
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
91 unsigned char *abovebuf1, *abovebuf2;
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
92 } huffyuv_context_t;
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
93
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
94
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
95 /*
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
96 * Classic Huffman tables
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
97 */
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
98 unsigned char classic_shift_luma[] = {
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
99 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
100 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
101 69,68, 0
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
102 };
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
103
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
104 unsigned char classic_shift_chroma[] = {
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
105 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
106 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
107 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
108 };
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 unsigned char classic_add_luma[256] = {
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
111 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
112 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
113 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
114 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
115 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
116 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
117 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
118 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
119 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
120 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
121 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
122 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
123 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
124 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
125 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
126 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
127 };
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 unsigned char classic_add_chroma[256] = {
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
130 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
131 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
132 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
133 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
134 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
135 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
136 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
137 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
138 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
139 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
140 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
141 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
142 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
143 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
144 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
145 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
146 };
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
147
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
148
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
149 /*
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
150 * Internal function prototypes
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
151 */
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
152 unsigned char* InitializeDecodeTable(unsigned char* hufftable,
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
153 unsigned char* shift, DecodeTable* decode_table);
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
154 unsigned char* InitializeShiftAddTables(unsigned char* hufftable,
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
155 unsigned char* shift, unsigned* add_shifted);
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
156 unsigned char* DecompressHuffmanTable(unsigned char* hufftable,
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
157 unsigned char* dst);
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
158 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
159 DecodeTable *decode_table, unsigned char *decode_shift);
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
160
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
161
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
162
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
163
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
164 // 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
165 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
166 {
9e80ac615570 committed Roberto Togni's patch for control() function in HuffYUV decoder
melanson
parents: 5235
diff changeset
167 switch(cmd) {
9e80ac615570 committed Roberto Togni's patch for control() function in HuffYUV decoder
melanson
parents: 5235
diff changeset
168 case VDCTRL_QUERY_FORMAT:
9e80ac615570 committed Roberto Togni's patch for control() function in HuffYUV decoder
melanson
parents: 5235
diff changeset
169 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
170 if (*((int*)arg) == IMGFMT_YUY2)
9e80ac615570 committed Roberto Togni's patch for control() function in HuffYUV decoder
melanson
parents: 5235
diff changeset
171 return CONTROL_TRUE;
9e80ac615570 committed Roberto Togni's patch for control() function in HuffYUV decoder
melanson
parents: 5235
diff changeset
172 else
9e80ac615570 committed Roberto Togni's patch for control() function in HuffYUV decoder
melanson
parents: 5235
diff changeset
173 return CONTROL_FALSE;
9e80ac615570 committed Roberto Togni's patch for control() function in HuffYUV decoder
melanson
parents: 5235
diff changeset
174 } else {
9e80ac615570 committed Roberto Togni's patch for control() function in HuffYUV decoder
melanson
parents: 5235
diff changeset
175 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
176 return CONTROL_TRUE;
9e80ac615570 committed Roberto Togni's patch for control() function in HuffYUV decoder
melanson
parents: 5235
diff changeset
177 else
9e80ac615570 committed Roberto Togni's patch for control() function in HuffYUV decoder
melanson
parents: 5235
diff changeset
178 return CONTROL_FALSE;
9e80ac615570 committed Roberto Togni's patch for control() function in HuffYUV decoder
melanson
parents: 5235
diff changeset
179 }
9e80ac615570 committed Roberto Togni's patch for control() function in HuffYUV decoder
melanson
parents: 5235
diff changeset
180 }
9e80ac615570 committed Roberto Togni's patch for control() function in HuffYUV decoder
melanson
parents: 5235
diff changeset
181 return CONTROL_UNKNOWN;
5235
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
182 }
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
183
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
184
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
185 /*
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
186 *
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
187 * Init HuffYUV decoder
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
188 *
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
189 */
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
190 static int init(sh_video_t *sh)
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
191 {
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
192 int vo_ret; // Video output init ret value
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
193 huffyuv_context_t *hc; // Decoder context
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
194 unsigned char *hufftable; // Compressed huffman tables
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
195 BITMAPINFOHEADER *bih = sh->bih;
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
196
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
197 if ((hc = malloc(sizeof(huffyuv_context_t))) == NULL) {
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
198 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
199 return 0;
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
200 }
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
201
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
202 sh->context = (void *)hc;
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
203
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
204 if (bih->biCompression != FOURCC_HFYU) {
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
205 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
206 return 0;
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
207 }
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
208
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
209 /* Get bitcount */
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
210 hc->bitcount = 0;
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
211 if (bih->biSize > sizeof(BITMAPINFOHEADER)+1)
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
212 hc->bitcount = *((char*)bih + sizeof(BITMAPINFOHEADER) + 1);
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
213 if (hc->bitcount == 0)
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
214 hc->bitcount = bih->biBitCount;
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
215
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
216 /* Get bitmap type */
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
217 switch (hc->bitcount & ~7) {
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
218 case 16:
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
219 hc->bitmaptype = BMPTYPE_YUV; // -1
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
220 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
221 break;
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
222 case 24:
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
223 hc->bitmaptype = BMPTYPE_RGB; // -2
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
224 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
225 break;
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
226 case 32:
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
227 hc->bitmaptype = BMPTYPE_RGBA; //-3
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
228 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
229 break;
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
230 default:
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
231 hc->bitmaptype = 0; // ERR
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
232 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
233 }
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 /* Get method */
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
236 switch (bih->biBitCount & 7) {
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
237 case 0:
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
238 if (bih->biSize > sizeof(BITMAPINFOHEADER)) {
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
239 hc->method = *((unsigned char*)bih + sizeof(BITMAPINFOHEADER));
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
240 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
241 } else
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
242 hc->method = METHOD_OLD; // Is it really needed?
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
243 break;
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
244 case 1:
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
245 hc->method = METHOD_LEFT;
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
246 break;
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
247 case 2:
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
248 hc->method = METHOD_LEFT_DECORR;
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
249 break;
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
250 case 3:
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
251 if (hc->bitmaptype == BMPTYPE_YUV) {
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
252 hc->method = METHOD_GRAD;
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
253 } else {
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
254 hc->method = METHOD_GRAD_DECORR;
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
255 }
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
256 break;
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
257 case 4:
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
258 hc->method = METHOD_MEDIAN;
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
259 break;
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
260 default:
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
261 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
262 hc->method = METHOD_OLD;
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
263 }
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 /* Print method info */
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
266 switch (hc->method) {
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
267 case METHOD_LEFT:
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
268 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
269 break;
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
270 case METHOD_GRAD:
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
271 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
272 break;
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
273 case METHOD_MEDIAN:
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
274 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
275 break;
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
276 case METHOD_LEFT_DECORR:
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
277 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
278 break;
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
279 case METHOD_GRAD_DECORR:
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
280 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
281 break;
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
282 case METHOD_OLD:
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
283 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
284 break;
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
285 default:
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
286 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
287 }
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
288
6512
e2fe4801a98e Fix for interlaced huffyuv by roberto togni <rtogni at bresciaonline.it>
atmos4
parents: 5261
diff changeset
289 /* Take care of interlaced images */
e2fe4801a98e Fix for interlaced huffyuv by roberto togni <rtogni at bresciaonline.it>
atmos4
parents: 5261
diff changeset
290 hc->interlaced = 0;
e2fe4801a98e Fix for interlaced huffyuv by roberto togni <rtogni at bresciaonline.it>
atmos4
parents: 5261
diff changeset
291 if (bih->biHeight > 288) {
e2fe4801a98e Fix for interlaced huffyuv by roberto togni <rtogni at bresciaonline.it>
atmos4
parents: 5261
diff changeset
292 // 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
293 hc->interlaced = 1;
e2fe4801a98e Fix for interlaced huffyuv by roberto togni <rtogni at bresciaonline.it>
atmos4
parents: 5261
diff changeset
294 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
295 }
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 /* Allocate buffers */
e2fe4801a98e Fix for interlaced huffyuv by roberto togni <rtogni at bresciaonline.it>
atmos4
parents: 5261
diff changeset
298 hc->abovebuf1 = NULL;
e2fe4801a98e Fix for interlaced huffyuv by roberto togni <rtogni at bresciaonline.it>
atmos4
parents: 5261
diff changeset
299 hc->abovebuf2 = NULL;
e2fe4801a98e Fix for interlaced huffyuv by roberto togni <rtogni at bresciaonline.it>
atmos4
parents: 5261
diff changeset
300 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
301 (hc->method == METHOD_GRAD_DECORR)) {
e2fe4801a98e Fix for interlaced huffyuv by roberto togni <rtogni at bresciaonline.it>
atmos4
parents: 5261
diff changeset
302 // If inetrlaced flag will be 2
e2fe4801a98e Fix for interlaced huffyuv by roberto togni <rtogni at bresciaonline.it>
atmos4
parents: 5261
diff changeset
303 (hc->interlaced)++;
e2fe4801a98e Fix for interlaced huffyuv by roberto togni <rtogni at bresciaonline.it>
atmos4
parents: 5261
diff changeset
304 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
305 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
306 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
307 return 0;
e2fe4801a98e Fix for interlaced huffyuv by roberto togni <rtogni at bresciaonline.it>
atmos4
parents: 5261
diff changeset
308 }
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 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
311 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
312 return 0;
e2fe4801a98e Fix for interlaced huffyuv by roberto togni <rtogni at bresciaonline.it>
atmos4
parents: 5261
diff changeset
313 }
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
5235
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
316 /* Get compressed Huffman tables */
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
317 if (bih->biSize == sizeof(BITMAPINFOHEADER) /*&& !(bih->biBitCount&7)*/) {
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
318 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
319 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
320 } else {
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
321 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
322 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
323 }
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 /* Initialize decoder Huffman tables */
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
326 hufftable = InitializeDecodeTable(hufftable, hc->decode1_shift, &(hc->decode1));
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
327 hufftable = InitializeDecodeTable(hufftable, hc->decode2_shift, &(hc->decode2));
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
328 InitializeDecodeTable(hufftable, hc->decode3_shift, &(hc->decode3));
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
329
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
330 /*
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
331 * Initialize video output device
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
332 */
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
333 switch (hc->bitmaptype) {
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
334 case BMPTYPE_YUV:
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
335 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
336 break;
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
337 case BMPTYPE_RGB:
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
338 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
339 break;
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
340 case BMPTYPE_RGBA:
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
341 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
342 return 0;
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
343 default:
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
344 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
345 return 0;
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
346 }
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 return vo_ret;
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
349 }
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 * Uninit HuffYUV decoder
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
357 *
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 static void uninit(sh_video_t *sh)
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
360 {
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
361 if (sh->context) {
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
362 if (((huffyuv_context_t*)&sh->context)->abovebuf1)
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
363 free(((huffyuv_context_t*)sh->context)->abovebuf1);
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
364 if (((huffyuv_context_t*)&sh->context)->abovebuf2)
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
365 free(((huffyuv_context_t*)sh->context)->abovebuf2);
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
366 free(sh->context);
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
367 }
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 #define HUFF_DECOMPRESS_YUYV() \
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
373 { \
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
374 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
375 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
376 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
377 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
378 }
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 #define HUFF_DECOMPRESS_RGB_DECORR() \
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
383 { \
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
384 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
385 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
386 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
387 }
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 #define HUFF_DECOMPRESS_RGB() \
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
392 { \
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
393 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
394 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
395 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
396 }
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 #define MEDIAN(left, above, aboveleft) \
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
401 { \
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
402 if ((mi = (above)) > (left)) { \
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
403 mx = mi; \
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
404 mi = (left); \
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
405 } else \
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
406 mx = (left); \
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
407 tmp = (above) + (left) - (aboveleft); \
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
408 if (tmp < mi) \
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
409 med = mi; \
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
410 else if (tmp > mx) \
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
411 med = mx; \
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
412 else \
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
413 med = tmp; \
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
414 }
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 #define YUV_STORE1ST_ABOVEBUF() \
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
419 { \
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
420 abovebuf[0] = outptr[0] = encoded[0]; \
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
421 abovebuf[1] = left_u = outptr[1] = encoded[1]; \
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
422 abovebuf[2] = left_y = outptr[2] = encoded[2]; \
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
423 abovebuf[3] = left_v = outptr[3] = encoded[3]; \
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
424 pixel_ptr = 4; \
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
425 }
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 #define YUV_STORE1ST() \
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
430 { \
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
431 outptr[0] = encoded[0]; \
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
432 left_u = outptr[1] = encoded[1]; \
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
433 left_y = outptr[2] = encoded[2]; \
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
434 left_v = outptr[3] = encoded[3]; \
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
435 pixel_ptr = 4; \
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
436 }
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 #define RGB_STORE1ST() \
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
441 { \
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
442 pixel_ptr = (height-1)*mpi->stride[0]; \
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
443 left_b = outptr[pixel_ptr++] = encoded[1]; \
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
444 left_g = outptr[pixel_ptr++] = encoded[2]; \
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
445 left_r = outptr[pixel_ptr++] = encoded[3]; \
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
446 pixel_ptr += bgr32; \
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
447 }
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
448
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 #define RGB_STORE1ST_ABOVEBUF() \
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
452 { \
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
453 pixel_ptr = (height-1)*mpi->stride[0]; \
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
454 abovebuf[0] = left_b = outptr[pixel_ptr++] = encoded[1]; \
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
455 abovebuf[1] = left_g = outptr[pixel_ptr++] = encoded[2]; \
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
456 abovebuf[2] = left_r = outptr[pixel_ptr++] = encoded[3]; \
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
457 pixel_ptr += bgr32; \
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
458 }
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 #define YUV_PREDLEFT() \
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
464 { \
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
465 outptr[pixel_ptr++] = left_y += y1; \
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
466 outptr[pixel_ptr++] = left_u += u; \
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
467 outptr[pixel_ptr++] = left_y += y2; \
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
468 outptr[pixel_ptr++] = left_v += v; \
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
469 }
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 #define YUV_PREDLEFT_BUF(buf, offs) \
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
474 { \
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
475 (buf)[(offs)] = outptr[pixel_ptr++] = left_y += y1; \
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
476 (buf)[(offs)+1] = outptr[pixel_ptr++] = left_u += u; \
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
477 (buf)[(offs)+2] = outptr[pixel_ptr++] = left_y += y2; \
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
478 (buf)[(offs)+3] = outptr[pixel_ptr++] = left_v += v; \
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
479 }
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
480
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 #define YUV_PREDMED() \
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
484 { \
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
485 MEDIAN (left_y, abovebuf[col], abovebuf[col-2]); \
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
486 curbuf[col] = outptr[pixel_ptr++] = left_y = med + y1; \
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
487 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
488 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
489 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
490 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
491 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
492 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
493 }
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
6512
e2fe4801a98e Fix for interlaced huffyuv by roberto togni <rtogni at bresciaonline.it>
atmos4
parents: 5261
diff changeset
497 #define YUV_PREDMED_1ST() \
e2fe4801a98e Fix for interlaced huffyuv by roberto togni <rtogni at bresciaonline.it>
atmos4
parents: 5261
diff changeset
498 { \
e2fe4801a98e Fix for interlaced huffyuv by roberto togni <rtogni at bresciaonline.it>
atmos4
parents: 5261
diff changeset
499 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
500 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
501 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
502 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
503 MEDIAN (left_y, abovebuf[2], abovebuf[0]); \
e2fe4801a98e Fix for interlaced huffyuv by roberto togni <rtogni at bresciaonline.it>
atmos4
parents: 5261
diff changeset
504 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
505 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
506 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
507 }
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 #define YUV_PREDGRAD() \
e2fe4801a98e Fix for interlaced huffyuv by roberto togni <rtogni at bresciaonline.it>
atmos4
parents: 5261
diff changeset
512 { \
e2fe4801a98e Fix for interlaced huffyuv by roberto togni <rtogni at bresciaonline.it>
atmos4
parents: 5261
diff changeset
513 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
514 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
515 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
516 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
517 }
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 #define YUV_PREDGRAD_1ST() \
e2fe4801a98e Fix for interlaced huffyuv by roberto togni <rtogni at bresciaonline.it>
atmos4
parents: 5261
diff changeset
522 { \
e2fe4801a98e Fix for interlaced huffyuv by roberto togni <rtogni at bresciaonline.it>
atmos4
parents: 5261
diff changeset
523 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
524 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
525 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
526 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
527 }
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
5235
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
531 #define RGB_PREDLEFT_DECORR() \
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
532 { \
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
533 outptr[pixel_ptr++] = left_b += b + g; \
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
534 outptr[pixel_ptr++] = left_g += g; \
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
535 outptr[pixel_ptr++] = left_r += r + g; \
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
536 pixel_ptr += bgr32; \
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
537 }
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
6512
e2fe4801a98e Fix for interlaced huffyuv by roberto togni <rtogni at bresciaonline.it>
atmos4
parents: 5261
diff changeset
541 #define RGB_PREDLEFT_DECORR_BUF() \
e2fe4801a98e Fix for interlaced huffyuv by roberto togni <rtogni at bresciaonline.it>
atmos4
parents: 5261
diff changeset
542 { \
e2fe4801a98e Fix for interlaced huffyuv by roberto togni <rtogni at bresciaonline.it>
atmos4
parents: 5261
diff changeset
543 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
544 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
545 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
546 pixel_ptr += bgr32; \
e2fe4801a98e Fix for interlaced huffyuv by roberto togni <rtogni at bresciaonline.it>
atmos4
parents: 5261
diff changeset
547 }
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
5235
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
550 #define RGB_PREDLEFT() \
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
551 { \
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
552 outptr[pixel_ptr++] = left_b += b; \
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
553 outptr[pixel_ptr++] = left_g += g; \
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
554 outptr[pixel_ptr++] = left_r += r; \
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
555 pixel_ptr += bgr32; \
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
556 }
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
6512
e2fe4801a98e Fix for interlaced huffyuv by roberto togni <rtogni at bresciaonline.it>
atmos4
parents: 5261
diff changeset
560 #define RGB_PREDGRAD_DECORR() \
e2fe4801a98e Fix for interlaced huffyuv by roberto togni <rtogni at bresciaonline.it>
atmos4
parents: 5261
diff changeset
561 { \
e2fe4801a98e Fix for interlaced huffyuv by roberto togni <rtogni at bresciaonline.it>
atmos4
parents: 5261
diff changeset
562 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
563 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
564 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
565 pixel_ptr += bgr32; \
e2fe4801a98e Fix for interlaced huffyuv by roberto togni <rtogni at bresciaonline.it>
atmos4
parents: 5261
diff changeset
566 }
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 #define RGB_PREDGRAD_DECORR_1ST() \
e2fe4801a98e Fix for interlaced huffyuv by roberto togni <rtogni at bresciaonline.it>
atmos4
parents: 5261
diff changeset
571 { \
e2fe4801a98e Fix for interlaced huffyuv by roberto togni <rtogni at bresciaonline.it>
atmos4
parents: 5261
diff changeset
572 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
573 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
574 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
575 pixel_ptr += bgr32; \
e2fe4801a98e Fix for interlaced huffyuv by roberto togni <rtogni at bresciaonline.it>
atmos4
parents: 5261
diff changeset
576 }
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 #define SWAPBUF() \
e2fe4801a98e Fix for interlaced huffyuv by roberto togni <rtogni at bresciaonline.it>
atmos4
parents: 5261
diff changeset
581 { \
e2fe4801a98e Fix for interlaced huffyuv by roberto togni <rtogni at bresciaonline.it>
atmos4
parents: 5261
diff changeset
582 swap = abovebuf; \
e2fe4801a98e Fix for interlaced huffyuv by roberto togni <rtogni at bresciaonline.it>
atmos4
parents: 5261
diff changeset
583 abovebuf = curbuf; \
e2fe4801a98e Fix for interlaced huffyuv by roberto togni <rtogni at bresciaonline.it>
atmos4
parents: 5261
diff changeset
584 curbuf = swap; \
e2fe4801a98e Fix for interlaced huffyuv by roberto togni <rtogni at bresciaonline.it>
atmos4
parents: 5261
diff changeset
585 }
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
5235
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
588
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 * Decode a HuffYUV frame
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
592 *
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 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
595 {
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
596 mp_image_t* mpi;
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
597 int pixel_ptr;
8254
772d6d27fd66 warning patch by (Dominik Mierzejewski <dominik at rangers dot eu dot org>)
michael
parents: 7191
diff changeset
598 unsigned char y1, y2, u, v, r, g, b/*, a*/;
5235
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
599 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
600 unsigned char tmp, mi, mx, med;
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
601 unsigned char *swap;
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
602 int row, col;
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
603 unsigned int pos = 32;
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
604 unsigned char *encoded = (unsigned char *)data;
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
605 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
606 unsigned char *abovebuf = hc->abovebuf1;
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
607 unsigned char *curbuf = hc->abovebuf2;
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
608 unsigned char *outptr;
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
609 int width = sh->disp_w; // Real image width
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
610 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
611 int width2, height2;
5235
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
612 int bgr32;
6512
e2fe4801a98e Fix for interlaced huffyuv by roberto togni <rtogni at bresciaonline.it>
atmos4
parents: 5261
diff changeset
613 int interlaced, oddlines;
5235
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
614
6512
e2fe4801a98e Fix for interlaced huffyuv by roberto togni <rtogni at bresciaonline.it>
atmos4
parents: 5261
diff changeset
615 // Skipped frame
5235
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
616 if(len <= 0)
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
617 return NULL;
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
618
6512
e2fe4801a98e Fix for interlaced huffyuv by roberto togni <rtogni at bresciaonline.it>
atmos4
parents: 5261
diff changeset
619 /* 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
620 if (hc->interlaced == 2) {
e2fe4801a98e Fix for interlaced huffyuv by roberto togni <rtogni at bresciaonline.it>
atmos4
parents: 5261
diff changeset
621 width2 = width*2; // Double image width
e2fe4801a98e Fix for interlaced huffyuv by roberto togni <rtogni at bresciaonline.it>
atmos4
parents: 5261
diff changeset
622 height2 = height/2; // Half image height
e2fe4801a98e Fix for interlaced huffyuv by roberto togni <rtogni at bresciaonline.it>
atmos4
parents: 5261
diff changeset
623 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
624 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
625 } else {
e2fe4801a98e Fix for interlaced huffyuv by roberto togni <rtogni at bresciaonline.it>
atmos4
parents: 5261
diff changeset
626 width2 = width; // Real image width
e2fe4801a98e Fix for interlaced huffyuv by roberto togni <rtogni at bresciaonline.it>
atmos4
parents: 5261
diff changeset
627 height2 = height; // Real image height
e2fe4801a98e Fix for interlaced huffyuv by roberto togni <rtogni at bresciaonline.it>
atmos4
parents: 5261
diff changeset
628 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
629 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
630 }
5235
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
631
6512
e2fe4801a98e Fix for interlaced huffyuv by roberto togni <rtogni at bresciaonline.it>
atmos4
parents: 5261
diff changeset
632
e2fe4801a98e Fix for interlaced huffyuv by roberto togni <rtogni at bresciaonline.it>
atmos4
parents: 5261
diff changeset
633 /* Get output image buffer */
e2fe4801a98e Fix for interlaced huffyuv by roberto togni <rtogni at bresciaonline.it>
atmos4
parents: 5261
diff changeset
634 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
635 if (!mpi) {
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
636 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
637 return NULL;
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
638 }
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 outptr = mpi->planes[0]; // Output image pointer
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
641
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
642 if (hc->bitmaptype == BMPTYPE_YUV) {
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
643 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
644 width2 >>= 1;
5235
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
645 if (hc->method == METHOD_GRAD) {
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
646 /*
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
647 * YUV predict gradient
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
648 */
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
649 /* Store 1st pixel */
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
650 YUV_STORE1ST_ABOVEBUF();
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
651 // Decompress 1st row (always stored with left prediction)
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
652 for (col = 1*4; col < width*4; col += 4) {
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
653 HUFF_DECOMPRESS_YUYV();
6512
e2fe4801a98e Fix for interlaced huffyuv by roberto togni <rtogni at bresciaonline.it>
atmos4
parents: 5261
diff changeset
654 YUV_PREDLEFT_BUF (abovebuf, col);
5235
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
655 }
6512
e2fe4801a98e Fix for interlaced huffyuv by roberto togni <rtogni at bresciaonline.it>
atmos4
parents: 5261
diff changeset
656 if (interlaced) {
e2fe4801a98e Fix for interlaced huffyuv by roberto togni <rtogni at bresciaonline.it>
atmos4
parents: 5261
diff changeset
657 pixel_ptr = mpi->stride[0];
e2fe4801a98e Fix for interlaced huffyuv by roberto togni <rtogni at bresciaonline.it>
atmos4
parents: 5261
diff changeset
658 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
659 HUFF_DECOMPRESS_YUYV();
e2fe4801a98e Fix for interlaced huffyuv by roberto togni <rtogni at bresciaonline.it>
atmos4
parents: 5261
diff changeset
660 YUV_PREDLEFT_BUF (abovebuf, col);
e2fe4801a98e Fix for interlaced huffyuv by roberto togni <rtogni at bresciaonline.it>
atmos4
parents: 5261
diff changeset
661 }
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 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
664 for (row = 1; row < height2; row++) {
e2fe4801a98e Fix for interlaced huffyuv by roberto togni <rtogni at bresciaonline.it>
atmos4
parents: 5261
diff changeset
665 pixel_ptr = (interlaced + 1) * row * mpi->stride[0];
5235
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
666 HUFF_DECOMPRESS_YUYV();
6512
e2fe4801a98e Fix for interlaced huffyuv by roberto togni <rtogni at bresciaonline.it>
atmos4
parents: 5261
diff changeset
667 YUV_PREDGRAD_1ST();
5235
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
668 for (col = 1*4; col < width*4; col += 4) {
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
669 HUFF_DECOMPRESS_YUYV();
6512
e2fe4801a98e Fix for interlaced huffyuv by roberto togni <rtogni at bresciaonline.it>
atmos4
parents: 5261
diff changeset
670 YUV_PREDGRAD();
e2fe4801a98e Fix for interlaced huffyuv by roberto togni <rtogni at bresciaonline.it>
atmos4
parents: 5261
diff changeset
671 }
e2fe4801a98e Fix for interlaced huffyuv by roberto togni <rtogni at bresciaonline.it>
atmos4
parents: 5261
diff changeset
672 if (interlaced) {
e2fe4801a98e Fix for interlaced huffyuv by roberto togni <rtogni at bresciaonline.it>
atmos4
parents: 5261
diff changeset
673 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
674 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
675 HUFF_DECOMPRESS_YUYV();
e2fe4801a98e Fix for interlaced huffyuv by roberto togni <rtogni at bresciaonline.it>
atmos4
parents: 5261
diff changeset
676 YUV_PREDGRAD();
e2fe4801a98e Fix for interlaced huffyuv by roberto togni <rtogni at bresciaonline.it>
atmos4
parents: 5261
diff changeset
677 }
5235
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
678 }
6512
e2fe4801a98e Fix for interlaced huffyuv by roberto togni <rtogni at bresciaonline.it>
atmos4
parents: 5261
diff changeset
679 SWAPBUF();
e2fe4801a98e Fix for interlaced huffyuv by roberto togni <rtogni at bresciaonline.it>
atmos4
parents: 5261
diff changeset
680 }
e2fe4801a98e Fix for interlaced huffyuv by roberto togni <rtogni at bresciaonline.it>
atmos4
parents: 5261
diff changeset
681 if (oddlines) {
e2fe4801a98e Fix for interlaced huffyuv by roberto togni <rtogni at bresciaonline.it>
atmos4
parents: 5261
diff changeset
682 pixel_ptr = 2 * height * mpi->stride[0];
e2fe4801a98e Fix for interlaced huffyuv by roberto togni <rtogni at bresciaonline.it>
atmos4
parents: 5261
diff changeset
683 HUFF_DECOMPRESS_YUYV();
e2fe4801a98e Fix for interlaced huffyuv by roberto togni <rtogni at bresciaonline.it>
atmos4
parents: 5261
diff changeset
684 YUV_PREDGRAD_1ST();
e2fe4801a98e Fix for interlaced huffyuv by roberto togni <rtogni at bresciaonline.it>
atmos4
parents: 5261
diff changeset
685 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
686 HUFF_DECOMPRESS_YUYV();
e2fe4801a98e Fix for interlaced huffyuv by roberto togni <rtogni at bresciaonline.it>
atmos4
parents: 5261
diff changeset
687 YUV_PREDGRAD();
e2fe4801a98e Fix for interlaced huffyuv by roberto togni <rtogni at bresciaonline.it>
atmos4
parents: 5261
diff changeset
688 }
5235
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
689 }
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
690 } else if (hc->method == METHOD_MEDIAN) {
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
691 /*
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
692 * YUV predict median
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
693 */
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
694 /* Store 1st pixel */
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
695 YUV_STORE1ST_ABOVEBUF();
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
696 // Decompress 1st row (always stored with left prediction)
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
697 for (col = 1*4; col < width*4; col += 4) {
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
698 HUFF_DECOMPRESS_YUYV();
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
699 YUV_PREDLEFT_BUF (abovebuf, col);
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
700 }
6512
e2fe4801a98e Fix for interlaced huffyuv by roberto togni <rtogni at bresciaonline.it>
atmos4
parents: 5261
diff changeset
701 if (interlaced) {
e2fe4801a98e Fix for interlaced huffyuv by roberto togni <rtogni at bresciaonline.it>
atmos4
parents: 5261
diff changeset
702 pixel_ptr = mpi->stride[0];
e2fe4801a98e Fix for interlaced huffyuv by roberto togni <rtogni at bresciaonline.it>
atmos4
parents: 5261
diff changeset
703 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
704 HUFF_DECOMPRESS_YUYV();
e2fe4801a98e Fix for interlaced huffyuv by roberto togni <rtogni at bresciaonline.it>
atmos4
parents: 5261
diff changeset
705 YUV_PREDLEFT_BUF (abovebuf, col);
e2fe4801a98e Fix for interlaced huffyuv by roberto togni <rtogni at bresciaonline.it>
atmos4
parents: 5261
diff changeset
706 }
e2fe4801a98e Fix for interlaced huffyuv by roberto togni <rtogni at bresciaonline.it>
atmos4
parents: 5261
diff changeset
707 }
5235
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
708 // 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
709 pixel_ptr = mpi->stride[0] * (interlaced + 1);
5235
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
710 HUFF_DECOMPRESS_YUYV();
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
711 YUV_PREDLEFT_BUF (curbuf, 0);
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
712 HUFF_DECOMPRESS_YUYV();
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
713 YUV_PREDLEFT_BUF (curbuf, 4);
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
714 // Complete 2nd row
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
715 for (col = 2*4; col < width*4; col += 4) {
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
716 HUFF_DECOMPRESS_YUYV();
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
717 YUV_PREDMED();
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
718 }
6512
e2fe4801a98e Fix for interlaced huffyuv by roberto togni <rtogni at bresciaonline.it>
atmos4
parents: 5261
diff changeset
719 if (interlaced) {
e2fe4801a98e Fix for interlaced huffyuv by roberto togni <rtogni at bresciaonline.it>
atmos4
parents: 5261
diff changeset
720 pixel_ptr = mpi->stride[0] * 3;
e2fe4801a98e Fix for interlaced huffyuv by roberto togni <rtogni at bresciaonline.it>
atmos4
parents: 5261
diff changeset
721 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
722 HUFF_DECOMPRESS_YUYV();
e2fe4801a98e Fix for interlaced huffyuv by roberto togni <rtogni at bresciaonline.it>
atmos4
parents: 5261
diff changeset
723 YUV_PREDMED();
e2fe4801a98e Fix for interlaced huffyuv by roberto togni <rtogni at bresciaonline.it>
atmos4
parents: 5261
diff changeset
724 }
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 SWAPBUF();
e2fe4801a98e Fix for interlaced huffyuv by roberto togni <rtogni at bresciaonline.it>
atmos4
parents: 5261
diff changeset
727 for (row = 2; row < height2; row++) {
e2fe4801a98e Fix for interlaced huffyuv by roberto togni <rtogni at bresciaonline.it>
atmos4
parents: 5261
diff changeset
728 pixel_ptr = (interlaced + 1) * row * mpi->stride[0];
5235
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
729 HUFF_DECOMPRESS_YUYV();
6512
e2fe4801a98e Fix for interlaced huffyuv by roberto togni <rtogni at bresciaonline.it>
atmos4
parents: 5261
diff changeset
730 YUV_PREDMED_1ST();
5235
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
731 for (col = 1*4; col < width*4; col += 4) {
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
732 HUFF_DECOMPRESS_YUYV();
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
733 YUV_PREDMED();
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
734 }
6512
e2fe4801a98e Fix for interlaced huffyuv by roberto togni <rtogni at bresciaonline.it>
atmos4
parents: 5261
diff changeset
735 if (interlaced) {
e2fe4801a98e Fix for interlaced huffyuv by roberto togni <rtogni at bresciaonline.it>
atmos4
parents: 5261
diff changeset
736 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
737 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
738 HUFF_DECOMPRESS_YUYV();
e2fe4801a98e Fix for interlaced huffyuv by roberto togni <rtogni at bresciaonline.it>
atmos4
parents: 5261
diff changeset
739 YUV_PREDMED();
e2fe4801a98e Fix for interlaced huffyuv by roberto togni <rtogni at bresciaonline.it>
atmos4
parents: 5261
diff changeset
740 }
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 SWAPBUF();
e2fe4801a98e Fix for interlaced huffyuv by roberto togni <rtogni at bresciaonline.it>
atmos4
parents: 5261
diff changeset
743 }
e2fe4801a98e Fix for interlaced huffyuv by roberto togni <rtogni at bresciaonline.it>
atmos4
parents: 5261
diff changeset
744 if (oddlines) {
e2fe4801a98e Fix for interlaced huffyuv by roberto togni <rtogni at bresciaonline.it>
atmos4
parents: 5261
diff changeset
745 pixel_ptr = 2 * height2 * mpi->stride[0];
e2fe4801a98e Fix for interlaced huffyuv by roberto togni <rtogni at bresciaonline.it>
atmos4
parents: 5261
diff changeset
746 HUFF_DECOMPRESS_YUYV();
e2fe4801a98e Fix for interlaced huffyuv by roberto togni <rtogni at bresciaonline.it>
atmos4
parents: 5261
diff changeset
747 YUV_PREDMED_1ST();
e2fe4801a98e Fix for interlaced huffyuv by roberto togni <rtogni at bresciaonline.it>
atmos4
parents: 5261
diff changeset
748 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
749 HUFF_DECOMPRESS_YUYV();
e2fe4801a98e Fix for interlaced huffyuv by roberto togni <rtogni at bresciaonline.it>
atmos4
parents: 5261
diff changeset
750 YUV_PREDMED();
e2fe4801a98e Fix for interlaced huffyuv by roberto togni <rtogni at bresciaonline.it>
atmos4
parents: 5261
diff changeset
751 }
5235
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
752 }
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
753 } else {
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
754 /*
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
755 * YUV predict left and predict old
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
756 */
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
757 /* Store 1st pixel */
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
758 YUV_STORE1ST();
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
759 // Decompress 1st row (always stored with left prediction)
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
760 for (col = 1*4; col < width*4; col += 4) {
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
761 HUFF_DECOMPRESS_YUYV();
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
762 YUV_PREDLEFT();
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
763 }
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
764 for (row = 1; row < height; row++) {
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
765 pixel_ptr = row * mpi->stride[0];
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
766 for (col = 0; col < width*4; col += 4) {
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
767 HUFF_DECOMPRESS_YUYV();
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
768 YUV_PREDLEFT();
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
769 }
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 } else {
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
773 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
774 if (hc->method == METHOD_LEFT_DECORR) {
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
775 /*
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
776 * RGB predict left with decorrelation
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
777 */
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
778 /* Store 1st pixel */
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
779 RGB_STORE1ST();
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
780 // Decompress 1st row
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
781 for (col = 1; col < width; col ++) {
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
782 HUFF_DECOMPRESS_RGB_DECORR();
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
783 RGB_PREDLEFT_DECORR();
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
784 }
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
785 for (row = 1; row < height; row++) {
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
786 pixel_ptr = (height - row - 1) * mpi->stride[0];
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
787 for (col = 0; col < width; col++) {
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
788 HUFF_DECOMPRESS_RGB_DECORR();
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
789 RGB_PREDLEFT_DECORR();
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
790 }
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 } else if (hc->method == METHOD_GRAD_DECORR) {
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
793 /*
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
794 * RGB predict gradient with decorrelation
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
795 */
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
796 /* Store 1st pixel */
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
797 RGB_STORE1ST_ABOVEBUF();
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
798 // Decompress 1st row (always stored with left prediction)
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
799 for (col = 1*3; col < width*3; col += 3) {
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
800 HUFF_DECOMPRESS_RGB_DECORR();
6512
e2fe4801a98e Fix for interlaced huffyuv by roberto togni <rtogni at bresciaonline.it>
atmos4
parents: 5261
diff changeset
801 RGB_PREDLEFT_DECORR_BUF();
5235
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
802 }
6512
e2fe4801a98e Fix for interlaced huffyuv by roberto togni <rtogni at bresciaonline.it>
atmos4
parents: 5261
diff changeset
803 if (interlaced) {
e2fe4801a98e Fix for interlaced huffyuv by roberto togni <rtogni at bresciaonline.it>
atmos4
parents: 5261
diff changeset
804 pixel_ptr = (height-2)*mpi->stride[0];
e2fe4801a98e Fix for interlaced huffyuv by roberto togni <rtogni at bresciaonline.it>
atmos4
parents: 5261
diff changeset
805 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
806 HUFF_DECOMPRESS_RGB_DECORR();
e2fe4801a98e Fix for interlaced huffyuv by roberto togni <rtogni at bresciaonline.it>
atmos4
parents: 5261
diff changeset
807 RGB_PREDLEFT_DECORR_BUF();
e2fe4801a98e Fix for interlaced huffyuv by roberto togni <rtogni at bresciaonline.it>
atmos4
parents: 5261
diff changeset
808 }
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 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
811 for (row = 1; row < height2; row++) {
e2fe4801a98e Fix for interlaced huffyuv by roberto togni <rtogni at bresciaonline.it>
atmos4
parents: 5261
diff changeset
812 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
813 HUFF_DECOMPRESS_RGB_DECORR();
6512
e2fe4801a98e Fix for interlaced huffyuv by roberto togni <rtogni at bresciaonline.it>
atmos4
parents: 5261
diff changeset
814 RGB_PREDGRAD_DECORR_1ST();
5235
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
815 for (col = 1*3; col < width*3; col += 3) {
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
816 HUFF_DECOMPRESS_RGB_DECORR();
6512
e2fe4801a98e Fix for interlaced huffyuv by roberto togni <rtogni at bresciaonline.it>
atmos4
parents: 5261
diff changeset
817 RGB_PREDGRAD_DECORR();
e2fe4801a98e Fix for interlaced huffyuv by roberto togni <rtogni at bresciaonline.it>
atmos4
parents: 5261
diff changeset
818 }
e2fe4801a98e Fix for interlaced huffyuv by roberto togni <rtogni at bresciaonline.it>
atmos4
parents: 5261
diff changeset
819 if (interlaced) {
e2fe4801a98e Fix for interlaced huffyuv by roberto togni <rtogni at bresciaonline.it>
atmos4
parents: 5261
diff changeset
820 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
821 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
822 HUFF_DECOMPRESS_RGB_DECORR();
e2fe4801a98e Fix for interlaced huffyuv by roberto togni <rtogni at bresciaonline.it>
atmos4
parents: 5261
diff changeset
823 RGB_PREDGRAD_DECORR();
e2fe4801a98e Fix for interlaced huffyuv by roberto togni <rtogni at bresciaonline.it>
atmos4
parents: 5261
diff changeset
824 }
5235
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
825 }
6512
e2fe4801a98e Fix for interlaced huffyuv by roberto togni <rtogni at bresciaonline.it>
atmos4
parents: 5261
diff changeset
826 SWAPBUF();
e2fe4801a98e Fix for interlaced huffyuv by roberto togni <rtogni at bresciaonline.it>
atmos4
parents: 5261
diff changeset
827 }
e2fe4801a98e Fix for interlaced huffyuv by roberto togni <rtogni at bresciaonline.it>
atmos4
parents: 5261
diff changeset
828 if (oddlines) {
e2fe4801a98e Fix for interlaced huffyuv by roberto togni <rtogni at bresciaonline.it>
atmos4
parents: 5261
diff changeset
829 pixel_ptr = mpi->stride[0];
e2fe4801a98e Fix for interlaced huffyuv by roberto togni <rtogni at bresciaonline.it>
atmos4
parents: 5261
diff changeset
830 HUFF_DECOMPRESS_RGB_DECORR();
e2fe4801a98e Fix for interlaced huffyuv by roberto togni <rtogni at bresciaonline.it>
atmos4
parents: 5261
diff changeset
831 RGB_PREDGRAD_DECORR_1ST();
e2fe4801a98e Fix for interlaced huffyuv by roberto togni <rtogni at bresciaonline.it>
atmos4
parents: 5261
diff changeset
832 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
833 HUFF_DECOMPRESS_RGB_DECORR();
e2fe4801a98e Fix for interlaced huffyuv by roberto togni <rtogni at bresciaonline.it>
atmos4
parents: 5261
diff changeset
834 RGB_PREDGRAD_DECORR();
e2fe4801a98e Fix for interlaced huffyuv by roberto togni <rtogni at bresciaonline.it>
atmos4
parents: 5261
diff changeset
835 }
5235
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
836 }
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
837 } else {
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
838 /*
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
839 * RGB predict left (no decorrelation) and predict old
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
840 */
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
841 /* Store 1st pixel */
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
842 RGB_STORE1ST();
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
843 // Decompress 1st row
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
844 for (col = 1; col < width; col++) {
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
845 HUFF_DECOMPRESS_RGB();
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
846 RGB_PREDLEFT();
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
847 }
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
848 for (row = 1; row < height; row++) {
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
849 pixel_ptr = (height - row - 1) * mpi->stride[0];
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
850 for (col = 0; col < width; col++) {
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
851 HUFF_DECOMPRESS_RGB();
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
852 RGB_PREDLEFT();
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
853 }
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 return mpi;
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
859 }
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 unsigned char* InitializeDecodeTable(unsigned char* hufftable,
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
864 unsigned char* shift, DecodeTable* decode_table)
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
865 {
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
866 unsigned int add_shifted[256];
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
867 char code_lengths[256];
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
868 char code_firstbits[256];
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
869 char table_lengths[32];
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
870 int all_zero_code=-1;
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
871 int i, j, k;
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
872 int firstbit, length, val;
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
873 unsigned char* p;
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
874 unsigned char * table;
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
875
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
876 /* Initialize shift[] and add_shifted[] */
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
877 hufftable = InitializeShiftAddTables(hufftable, shift, add_shifted);
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
878
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
879 memset(table_lengths, -1, 32);
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
880
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
881 /* Fill code_firstbits[], code_legths[] and table_lengths[] */
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
882 for (i = 0; i < 256; ++i) {
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
883 if (add_shifted[i]) {
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
884 for (firstbit = 31; firstbit >= 0; firstbit--) {
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
885 if (add_shifted[i] & (1 << firstbit)) {
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
886 code_firstbits[i] = firstbit;
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
887 length = shift[i] - (32 - firstbit);
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
888 code_lengths[i] = length;
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
889 table_lengths[firstbit] = max(table_lengths[firstbit], length);
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
890 break;
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
891 }
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 } else {
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
894 all_zero_code = i;
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
895 }
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 p = decode_table->table_data;
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
899 *p++ = 31;
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
900 *p++ = all_zero_code;
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
901 for (j = 0; j < 32; ++j) {
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
902 if (table_lengths[j] == -1) {
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
903 decode_table->table_pointers[j] = decode_table->table_data;
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
904 } else {
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
905 decode_table->table_pointers[j] = p;
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
906 *p++ = j - table_lengths[j];
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
907 p += 1 << table_lengths[j];
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
908 }
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 for (k=0; k<256; ++k) {
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
912 if (add_shifted[k]) {
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
913 firstbit = code_firstbits[k];
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
914 val = add_shifted[k] - (1 << firstbit);
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
915 table = decode_table->table_pointers[firstbit];
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
916 memset(&table[1 + (val >> table[0])], k,
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
917 1 << (table_lengths[firstbit] - code_lengths[k]));
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
918 }
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 return hufftable;
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
922 }
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 unsigned char* InitializeShiftAddTables(unsigned char* hufftable,
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
927 unsigned char* shift, unsigned* add_shifted)
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
928 {
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
929 int i, j;
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
930 unsigned int bits; // must be 32bit unsigned
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
931 int min_already_processed;
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
932 int max_not_processed;
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
933 int bit;
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
934
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
935 // 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
936 if (hufftable == HUFFTABLE_CLASSIC_YUV || hufftable == HUFFTABLE_CLASSIC_RGB) {
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
937 DecompressHuffmanTable(classic_shift_luma, shift);
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
938 for (i = 0; i < 256; ++i)
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
939 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
940 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
941 } else if (hufftable == HUFFTABLE_CLASSIC_YUV_CHROMA) {
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
942 DecompressHuffmanTable(classic_shift_chroma, shift);
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
943 for (i = 0; i < 256; ++i)
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
944 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
945 return hufftable;
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
946 }
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 hufftable = DecompressHuffmanTable(hufftable, shift);
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
949
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
950 // derive the actual bit patterns from the code lengths
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
951 min_already_processed = 32;
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
952 bits = 0;
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
953 do {
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
954 max_not_processed = 0;
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
955 for (i = 0; i < 256; ++i) {
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
956 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
957 max_not_processed = shift[i];
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
958 }
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
959 bit = 1 << (32 - max_not_processed);
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
960 // assert (!(bits & (bit - 1)));
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
961 for (j = 0; j < 256; ++j) {
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
962 if (shift[j] == max_not_processed) {
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
963 add_shifted[j] = bits;
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
964 bits += bit;
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
965 }
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 min_already_processed = max_not_processed;
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
968 } while (bits & 0xFFFFFFFF);
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
969
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
970 return hufftable;
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
971 }
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 unsigned char* DecompressHuffmanTable(unsigned char* hufftable,
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
976 unsigned char* dst)
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
977 {
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
978 int val;
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
979 int repeat;
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
980 int i = 0;
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
981
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
982 do {
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
983 val = *hufftable & 31;
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
984 repeat = *hufftable++ >> 5;
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
985 if (!repeat)
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
986 repeat = *hufftable++;
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
987 while (repeat--)
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
988 dst[i++] = val;
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
989 } while (i < 256);
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
990
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
991 return hufftable;
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
992 }
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 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
996 unsigned char *decode_shift)
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
997 {
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
998 unsigned int word = *pos >> 5;
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
999 unsigned int bit = *pos & 31;
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
1000 unsigned int val = in[word];
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
1001 unsigned char outbyte;
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
1002 unsigned char *tableptr;
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
1003 int i;
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
1004
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
1005 if (bit)
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
1006 val = (val << bit) | (in[word + 1] >> (32 - bit));
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
1007 // 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
1008 i = 31;
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
1009 val |= 1;
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
1010 while ((val & (1 << i--)) == 0);
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
1011 val &= ~(1 << (i+1));
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
1012 tableptr = decode_table->table_pointers[i+1];
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
1013 val >>= *tableptr;
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
1014
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
1015 outbyte = tableptr[val+1];
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
1016 *pos += decode_shift[outbyte];
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
1017
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
1018 return outbyte;
3e04fd1074d3 added HuffYUV support, courtesy of Roberto Togni <rtogni@bresciaonline.it>
melanson
parents:
diff changeset
1019 }