OLD | NEW |
1 // Copyright 2011 Google Inc. All Rights Reserved. | 1 // Copyright 2011 Google Inc. All Rights Reserved. |
2 // | 2 // |
3 // This code is licensed under the same terms as WebM: | 3 // This code is licensed under the same terms as WebM: |
4 // Software License Agreement: http://www.webmproject.org/license/software/ | 4 // Software License Agreement: http://www.webmproject.org/license/software/ |
5 // Additional IP Rights Grant: http://www.webmproject.org/license/additional/ | 5 // Additional IP Rights Grant: http://www.webmproject.org/license/additional/ |
6 // ----------------------------------------------------------------------------- | 6 // ----------------------------------------------------------------------------- |
7 // | 7 // |
8 // Alpha-plane decompression. | 8 // Alpha-plane decompression. |
9 // | 9 // |
10 // Author: Skal (pascal.massimino@gmail.com) | 10 // Author: Skal (pascal.massimino@gmail.com) |
11 | 11 |
12 #include <stdlib.h> | 12 #include <stdlib.h> |
13 #include "./vp8i.h" | 13 #include "./vp8i.h" |
14 #include "./vp8li.h" | 14 #include "./vp8li.h" |
15 #include "../utils/filters.h" | 15 #include "../utils/filters.h" |
16 #include "../utils/quant_levels.h" | 16 #include "../utils/quant_levels_dec.h" |
17 #include "../webp/format_constants.h" | 17 #include "../webp/format_constants.h" |
18 | 18 |
19 #if defined(__cplusplus) || defined(c_plusplus) | 19 #if defined(__cplusplus) || defined(c_plusplus) |
20 extern "C" { | 20 extern "C" { |
21 #endif | 21 #endif |
22 | 22 |
23 // TODO(skal): move to dsp/ ? | 23 // TODO(skal): move to dsp/ ? |
24 static void CopyPlane(const uint8_t* src, int src_stride, | 24 static void CopyPlane(const uint8_t* src, int src_stride, |
25 uint8_t* dst, int dst_stride, int width, int height) { | 25 uint8_t* dst, int dst_stride, int width, int height) { |
26 while (height-- > 0) { | 26 while (height-- > 0) { |
(...skipping 10 matching lines...) Expand all Loading... |
37 // | 37 // |
38 // Returns 1 on successfully decoding the compressed alpha and | 38 // Returns 1 on successfully decoding the compressed alpha and |
39 // 0 if either: | 39 // 0 if either: |
40 // error in bit-stream header (invalid compression mode or filter), or | 40 // error in bit-stream header (invalid compression mode or filter), or |
41 // error returned by appropriate compression method. | 41 // error returned by appropriate compression method. |
42 | 42 |
43 static int DecodeAlpha(const uint8_t* data, size_t data_size, | 43 static int DecodeAlpha(const uint8_t* data, size_t data_size, |
44 int width, int height, int stride, uint8_t* output) { | 44 int width, int height, int stride, uint8_t* output) { |
45 uint8_t* decoded_data = NULL; | 45 uint8_t* decoded_data = NULL; |
46 const size_t decoded_size = height * width; | 46 const size_t decoded_size = height * width; |
47 uint8_t* unfiltered_data = NULL; | |
48 WEBP_FILTER_TYPE filter; | 47 WEBP_FILTER_TYPE filter; |
49 int pre_processing; | 48 int pre_processing; |
50 int rsrv; | 49 int rsrv; |
51 int ok = 0; | 50 int ok = 0; |
52 int method; | 51 int method; |
53 | 52 |
54 assert(width > 0 && height > 0 && stride >= width); | 53 assert(width > 0 && height > 0 && stride >= width); |
55 assert(data != NULL && output != NULL); | 54 assert(data != NULL && output != NULL); |
56 | 55 |
57 if (data_size <= ALPHA_HEADER_LEN) { | 56 if (data_size <= ALPHA_HEADER_LEN) { |
(...skipping 18 matching lines...) Expand all Loading... |
76 } else { | 75 } else { |
77 decoded_data = (uint8_t*)malloc(decoded_size); | 76 decoded_data = (uint8_t*)malloc(decoded_size); |
78 if (decoded_data == NULL) return 0; | 77 if (decoded_data == NULL) return 0; |
79 ok = VP8LDecodeAlphaImageStream(width, height, | 78 ok = VP8LDecodeAlphaImageStream(width, height, |
80 data + ALPHA_HEADER_LEN, | 79 data + ALPHA_HEADER_LEN, |
81 data_size - ALPHA_HEADER_LEN, | 80 data_size - ALPHA_HEADER_LEN, |
82 decoded_data); | 81 decoded_data); |
83 } | 82 } |
84 | 83 |
85 if (ok) { | 84 if (ok) { |
86 WebPFilterFunc unfilter_func = WebPUnfilters[filter]; | 85 WebPUnfilterFunc unfilter_func = WebPUnfilters[filter]; |
87 if (unfilter_func != NULL) { | 86 if (unfilter_func != NULL) { |
88 unfiltered_data = (uint8_t*)malloc(decoded_size); | |
89 if (unfiltered_data == NULL) { | |
90 ok = 0; | |
91 goto Error; | |
92 } | |
93 // TODO(vikas): Implement on-the-fly decoding & filter mechanism to decode | 87 // TODO(vikas): Implement on-the-fly decoding & filter mechanism to decode |
94 // and apply filter per image-row. | 88 // and apply filter per image-row. |
95 unfilter_func(decoded_data, width, height, 1, width, unfiltered_data); | 89 unfilter_func(width, height, width, decoded_data); |
96 // Construct raw_data (height x stride) from alpha data (height x width). | |
97 CopyPlane(unfiltered_data, width, output, stride, width, height); | |
98 free(unfiltered_data); | |
99 } else { | |
100 // Construct raw_data (height x stride) from alpha data (height x width). | |
101 CopyPlane(decoded_data, width, output, stride, width, height); | |
102 } | 90 } |
| 91 // Construct raw_data (height x stride) from alpha data (height x width). |
| 92 CopyPlane(decoded_data, width, output, stride, width, height); |
103 if (pre_processing == ALPHA_PREPROCESSED_LEVELS) { | 93 if (pre_processing == ALPHA_PREPROCESSED_LEVELS) { |
104 ok = DequantizeLevels(decoded_data, width, height); | 94 ok = DequantizeLevels(decoded_data, width, height); |
105 } | 95 } |
106 } | 96 } |
107 | 97 |
108 Error: | |
109 if (method != ALPHA_NO_COMPRESSION) { | 98 if (method != ALPHA_NO_COMPRESSION) { |
110 free(decoded_data); | 99 free(decoded_data); |
111 } | 100 } |
112 return ok; | 101 return ok; |
113 } | 102 } |
114 | 103 |
115 //------------------------------------------------------------------------------ | 104 //------------------------------------------------------------------------------ |
116 | 105 |
117 const uint8_t* VP8DecompressAlphaRows(VP8Decoder* const dec, | 106 const uint8_t* VP8DecompressAlphaRows(VP8Decoder* const dec, |
118 int row, int num_rows) { | 107 int row, int num_rows) { |
(...skipping 12 matching lines...) Expand all Loading... |
131 } | 120 } |
132 } | 121 } |
133 | 122 |
134 // Return a pointer to the current decoded row. | 123 // Return a pointer to the current decoded row. |
135 return dec->alpha_plane_ + row * stride; | 124 return dec->alpha_plane_ + row * stride; |
136 } | 125 } |
137 | 126 |
138 #if defined(__cplusplus) || defined(c_plusplus) | 127 #if defined(__cplusplus) || defined(c_plusplus) |
139 } // extern "C" | 128 } // extern "C" |
140 #endif | 129 #endif |
OLD | NEW |