python-dataproperty: bump version to 0.17.0
[buildroot-gz.git] / package / libsquish / 0001-kodi.patch
bloba9bca669046ac28e1f6de990e191ea916e7be307
1 Add Kodi-specific patch
3 Kodi 15.0 contains an updated version of libsquish:
4 https://github.com/xbmc/xbmc/tree/master/tools/depends/native/libsquish-native
6 The OpenElec project provides a separate tarball including the Kodi-
7 specific patches:
8 http://sources.openelec.tv/devel/libsquish-1.10-openelec.tar.gz
10 This patch contains the relevant diff between upstream libsquish 1.13
11 and the OpenElec tarball.
13 Signed-off-by: Bernd Kuhls <bernd.kuhls@t-online.de>
15 diff -uwNr 1.13/squish.cpp libsquish-1.10-openelec/squish.cpp
16 --- 1.13/squish.cpp 2015-04-30 12:48:49.000000000 +0200
17 +++ libsquish-1.10-openelec/squish.cpp 2015-01-09 10:58:43.000000000 +0100
18 @@ -23,6 +23,7 @@
20 -------------------------------------------------------------------------- */
22 +#include <string.h>
23 #include <squish.h>
24 #include "colourset.h"
25 #include "maths.h"
26 @@ -39,7 +40,7 @@
27 // grab the flag bits
28 int method = flags & ( kDxt1 | kDxt3 | kDxt5 );
29 int fit = flags & ( kColourIterativeClusterFit | kColourClusterFit | kColourRangeFit );
30 - int extra = flags & kWeightColourByAlpha;
31 + int extra = flags & ( kWeightColourByAlpha | kSourceBGRA );
33 // set defaults
34 if( method != kDxt3 && method != kDxt5 )
35 @@ -124,8 +125,30 @@
36 return blockcount*blocksize;
39 +void CopyRGBA( u8 const* source, u8* dest, int flags )
41 + if (flags & kSourceBGRA)
42 + {
43 + // convert from bgra to rgba
44 + dest[0] = source[2];
45 + dest[1] = source[1];
46 + dest[2] = source[0];
47 + dest[3] = source[3];
48 + }
49 + else
50 + {
51 + for( int i = 0; i < 4; ++i )
52 + *dest++ = *source++;
53 + }
56 void CompressImage( u8 const* rgba, int width, int height, void* blocks, int flags, float* metric )
58 + CompressImage(rgba, width, height, width*4, blocks, flags, metric);
61 +void CompressImage( u8 const* rgba, int width, int height, int pitch, void* blocks, int flags, float* metric )
63 // fix any bad flags
64 flags = FixFlags( flags );
66 @@ -154,20 +177,14 @@
67 if( sx < width && sy < height )
69 // copy the rgba value
70 - u8 const* sourcePixel = rgba + 4*( width*sy + sx );
71 - for( int i = 0; i < 4; ++i )
72 - *targetPixel++ = *sourcePixel++;
74 + u8 const* sourcePixel = rgba + pitch*sy + 4*sx;
75 + CopyRGBA(sourcePixel, targetPixel, flags);
76 // enable this pixel
77 mask |= ( 1 << ( 4*py + px ) );
79 - else
80 - {
81 - // skip this pixel as its outside the image
82 targetPixel += 4;
85 - }
87 // compress it into the output
88 CompressMasked( sourceRgba, mask, targetBlock, flags, metric );
89 @@ -180,6 +197,11 @@
91 void DecompressImage( u8* rgba, int width, int height, void const* blocks, int flags )
93 + DecompressImage( rgba, width, height, width*4, blocks, flags );
96 +void DecompressImage( u8* rgba, int width, int height, int pitch, void const* blocks, int flags )
98 // fix any bad flags
99 flags = FixFlags( flags );
101 @@ -207,24 +229,132 @@
102 int sy = y + py;
103 if( sx < width && sy < height )
105 - u8* targetPixel = rgba + 4*( width*sy + sx );
106 + u8* targetPixel = rgba + pitch*sy + 4*sx;
108 // copy the rgba value
109 + CopyRGBA(sourcePixel, targetPixel, flags);
111 + sourcePixel += 4;
115 + // advance
116 + sourceBlock += bytesPerBlock;
121 +static double ErrorSq(double x, double y)
123 + return (x - y) * (x - y);
126 +static void ComputeBlockWMSE(u8 const *original, u8 const *compressed, unsigned int w, unsigned int h, double &cmse, double &amse)
128 + // Computes the MSE for the block and weights it by the variance of the original block.
129 + // If the variance of the original block is less than 4 (i.e. a standard deviation of 1 per channel)
130 + // then the block is close to being a single colour. Quantisation errors in single colour blocks
131 + // are easier to see than similar errors in blocks that contain more colours, particularly when there
132 + // are many such blocks in a large area (eg a blue sky background) as they cause banding. Given that
133 + // banding is easier to see than small errors in "complex" blocks, we weight the errors by a factor
134 + // of 5. This implies that images with large, single colour areas will have a higher potential WMSE
135 + // than images with lots of detail.
137 + cmse = amse = 0;
138 + unsigned int sum_p[4]; // per channel sum of pixels
139 + unsigned int sum_p2[4]; // per channel sum of pixels squared
140 + memset(sum_p, 0, sizeof(sum_p));
141 + memset(sum_p2, 0, sizeof(sum_p2));
142 + for( unsigned int py = 0; py < 4; ++py )
144 + for( unsigned int px = 0; px < 4; ++px )
146 + if( px < w && py < h )
148 + double pixelCMSE = 0;
149 + for( int i = 0; i < 3; ++i )
151 + pixelCMSE += ErrorSq(original[i], compressed[i]);
152 + sum_p[i] += original[i];
153 + sum_p2[i] += (unsigned int)original[i]*original[i];
155 + if( original[3] == 0 && compressed[3] == 0 )
156 + pixelCMSE = 0; // transparent in both, so colour is inconsequential
157 + amse += ErrorSq(original[3], compressed[3]);
158 + cmse += pixelCMSE;
159 + sum_p[3] += original[3];
160 + sum_p2[3] += (unsigned int)original[3]*original[3];
162 + original += 4;
163 + compressed += 4;
166 + unsigned int variance = 0;
167 for( int i = 0; i < 4; ++i )
168 - *targetPixel++ = *sourcePixel++;
169 + variance += w*h*sum_p2[i] - sum_p[i]*sum_p[i];
170 + if( variance < 4 * w * w * h * h )
172 + amse *= 5;
173 + cmse *= 5;
175 - else
178 +void ComputeMSE( u8 const *rgba, int width, int height, u8 const *dxt, int flags, double &colourMSE, double &alphaMSE )
180 - // skip this pixel as its outside the image
181 - sourcePixel += 4;
182 + ComputeMSE(rgba, width, height, width*4, dxt, flags, colourMSE, alphaMSE);
185 +void ComputeMSE( u8 const *rgba, int width, int height, int pitch, u8 const *dxt, int flags, double &colourMSE, double &alphaMSE )
187 + // fix any bad flags
188 + flags = FixFlags( flags );
189 + colourMSE = alphaMSE = 0;
191 + // initialise the block input
192 + squish::u8 const* sourceBlock = dxt;
193 + int bytesPerBlock = ( ( flags & squish::kDxt1 ) != 0 ) ? 8 : 16;
195 + // loop over blocks
196 + for( int y = 0; y < height; y += 4 )
198 + for( int x = 0; x < width; x += 4 )
200 + // decompress the block
201 + u8 targetRgba[4*16];
202 + Decompress( targetRgba, sourceBlock, flags );
203 + u8 const* sourcePixel = targetRgba;
205 + // copy across to a similar pixel block
206 + u8 originalRgba[4*16];
207 + u8* originalPixel = originalRgba;
209 + for( int py = 0; py < 4; ++py )
211 + for( int px = 0; px < 4; ++px )
213 + int sx = x + px;
214 + int sy = y + py;
215 + if( sx < width && sy < height )
217 + u8 const* targetPixel = rgba + pitch*sy + 4*sx;
218 + CopyRGBA(targetPixel, originalPixel, flags);
220 + sourcePixel += 4;
221 + originalPixel += 4;
225 + // compute the weighted MSE of the block
226 + double blockCMSE, blockAMSE;
227 + ComputeBlockWMSE(originalRgba, targetRgba, std::min(4, width - x), std::min(4, height - y), blockCMSE, blockAMSE);
228 + colourMSE += blockCMSE;
229 + alphaMSE += blockAMSE;
230 // advance
231 sourceBlock += bytesPerBlock;
234 + colourMSE /= (width * height * 3);
235 + alphaMSE /= (width * height);
238 } // namespace squish
239 diff -uwNr 1.13/squish.h libsquish-1.10-openelec/squish.h
240 --- 1.13/squish.h 2015-04-30 12:55:27.000000000 +0200
241 +++ libsquish-1.10-openelec/squish.h 2015-01-09 10:58:43.000000000 +0100
242 @@ -57,7 +57,10 @@
243 kColourRangeFit = ( 1 << 4 ),
245 //! Weight the colour by alpha during cluster fit (disabled by default).
246 - kWeightColourByAlpha = ( 1 << 7 )
247 + kWeightColourByAlpha = ( 1 << 7 ),
249 + //! Source is BGRA rather than RGBA
250 + kSourceBGRA = ( 1 << 9 ),
253 // -----------------------------------------------------------------------------
254 @@ -194,6 +197,7 @@
255 @param rgba The pixels of the source.
256 @param width The width of the source image.
257 @param height The height of the source image.
258 + @param pitch The pitch of the source image.
259 @param blocks Storage for the compressed output.
260 @param flags Compression flags.
261 @param metric An optional perceptual metric.
262 @@ -231,6 +235,7 @@
263 to allocate for the compressed output.
265 void CompressImage( u8 const* rgba, int width, int height, void* blocks, int flags, float* metric = 0 );
266 +void CompressImage( u8 const* rgba, int width, int height, int pitch, void* blocks, int flags, float* metric = 0 );
268 // -----------------------------------------------------------------------------
270 @@ -239,6 +244,7 @@
271 @param rgba Storage for the decompressed pixels.
272 @param width The width of the source image.
273 @param height The height of the source image.
274 + @param pitch The pitch of the decompressed pixels.
275 @param blocks The compressed DXT blocks.
276 @param flags Compression flags.
278 @@ -254,6 +260,32 @@
279 Internally this function calls squish::Decompress for each block.
281 void DecompressImage( u8* rgba, int width, int height, void const* blocks, int flags );
282 +void DecompressImage( u8* rgba, int width, int height, int pitch, void const* blocks, int flags );
284 +// -----------------------------------------------------------------------------
286 +/*! @brief Computes MSE of an compressed image in memory.
288 + @param rgba The original image pixels.
289 + @param width The width of the source image.
290 + @param height The height of the source image.
291 + @param pitch The pitch of the source image.
292 + @param dxt The compressed dxt blocks
293 + @param flags Compression flags.
294 + @param colourMSE The MSE of the colour values.
295 + @param alphaMSE The MSE of the alpha values.
297 + The colour MSE and alpha MSE are computed across all pixels. The colour MSE is
298 + averaged across all rgb values (i.e. colourMSE = sum sum_k ||dxt.k - rgba.k||/3)
300 + The flags parameter should specify either kDxt1, kDxt3 or kDxt5 compression,
301 + however, DXT1 will be used by default if none is specified. All other flags
302 + are ignored.
304 + Internally this function calls squish::Decompress for each block.
306 +void ComputeMSE(u8 const *rgba, int width, int height, u8 const *dxt, int flags, double &colourMSE, double &alphaMSE);
307 +void ComputeMSE(u8 const *rgba, int width, int height, int pitch, u8 const *dxt, int flags, double &colourMSE, double &alphaMSE);
309 // -----------------------------------------------------------------------------
311 diff -uwNr 1.13/squish.pc.in libsquish-1.10-openelec/squish.pc.in
312 --- 1.13/squish.pc 1970-01-01 01:00:00.000000000 +0100
313 +++ libsquish-1.10-openelec/squish.pc 2015-01-09 10:58:43.000000000 +0100
314 @@ -0,0 +1,13 @@
315 +prefix=/usr
316 +exec_prefix=${prefix}
317 +libdir=${prefix}/lib
318 +sharedlibdir=${libdir}
319 +includedir=${prefix}/include
321 +Name: squish
322 +Description: squish DXT lib
323 +Version: 1.1.3-kodi
325 +Requires:
326 +Libs: -L${libdir} -L${sharedlibdir} -lsquish
327 +Cflags: -I${includedir}