Dali 3D User Interface Engine
image-operations.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2014 Samsung Electronics Co., Ltd.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  *
16  */
17 
18 #ifndef DALI_INTERNAL_PLATFORM_IMAGE_OPERATIONS_H_
19 #define DALI_INTERNAL_PLATFORM_IMAGE_OPERATIONS_H_
20 
21 // EXTERNAL INCLUDES
22 #include <stdint.h>
23 
24 // INTERNAL INCLUDES
27 
28 namespace Dali
29 {
30 namespace Internal
31 {
32 namespace Platform
33 {
34 
39 {
44 };
45 
52 
62 
83 
111 void DownscaleInPlacePow2( unsigned char * const pixels,
112  Pixel::Format pixelFormat,
113  unsigned int inputWidth,
114  unsigned int inputHeight,
115  unsigned int desiredWidth,
116  unsigned int desiredHeight,
117  FittingMode::Type fittingMode,
118  SamplingMode::Type samplingMode,
119  unsigned& outWidth,
120  unsigned& outHeight );
121 
136 void DownscaleInPlacePow2RGB888( unsigned char * pixels,
137  unsigned int inputWidth,
138  unsigned int inputHeight,
139  unsigned int desiredWidth,
140  unsigned int desiredHeight,
141  BoxDimensionTest dimensionTest,
142  unsigned int& outWidth,
143  unsigned int& outHeight );
144 
148 void DownscaleInPlacePow2RGBA8888( unsigned char * pixels,
149  unsigned int inputWidth,
150  unsigned int inputHeight,
151  unsigned int desiredWidth,
152  unsigned int desiredHeight,
153  BoxDimensionTest dimensionTest,
154  unsigned int& outWidth,
155  unsigned int& outHeight );
156 
162 void DownscaleInPlacePow2RGB565( unsigned char * pixels,
163  unsigned int inputWidth,
164  unsigned int inputHeight,
165  unsigned int desiredWidth,
166  unsigned int desiredHeight,
167  BoxDimensionTest dimensionTest,
168  unsigned int& outWidth,
169  unsigned int& outHeight );
170 
176 void DownscaleInPlacePow2ComponentPair( unsigned char * pixels,
177  unsigned int inputWidth,
178  unsigned int inputHeight,
179  unsigned int desiredWidth,
180  unsigned int desiredHeight,
181  BoxDimensionTest dimensionTest,
182  unsigned int& outWidth,
183  unsigned int& outHeight );
184 
190 void DownscaleInPlacePow2SingleBytePerPixel( unsigned char * pixels,
191  unsigned int inputWidth,
192  unsigned int inputHeight,
193  unsigned int desiredWidth,
194  unsigned int desiredHeight,
195  BoxDimensionTest dimensionTest,
196  unsigned int& outWidth,
197  unsigned int& outHeight );
198 
207 void PointSample( const unsigned char * inPixels,
208  unsigned int inputWidth,
209  unsigned int inputHeight,
210  Pixel::Format pixelFormat,
211  unsigned char * outPixels,
212  unsigned int desiredWidth,
213  unsigned int desiredHeight );
214 
220 void PointSample4BPP( const unsigned char * inPixels,
221  unsigned int inputWidth,
222  unsigned int inputHeight,
223  unsigned char * outPixels,
224  unsigned int desiredWidth,
225  unsigned int desiredHeight );
226 
232 void PointSample3BPP( const unsigned char * inPixels,
233  unsigned int inputWidth,
234  unsigned int inputHeight,
235  unsigned char * outPixels,
236  unsigned int desiredWidth,
237  unsigned int desiredHeight );
238 
244 void PointSample2BPP( const unsigned char * inPixels,
245  unsigned int inputWidth,
246  unsigned int inputHeight,
247  unsigned char * outPixels,
248  unsigned int desiredWidth,
249  unsigned int desiredHeight );
250 
256 void PointSample1BPP( const unsigned char * inPixels,
257  unsigned int inputWidth,
258  unsigned int inputHeight,
259  unsigned char * outPixels,
260  unsigned int desiredWidth,
261  unsigned int desiredHeight );
262 
271 void LinearSample( const unsigned char * __restrict__ inPixels,
272  ImageDimensions inDimensions,
273  Pixel::Format pixelFormat,
274  unsigned char * __restrict__ outPixels,
275  ImageDimensions outDimensions );
276 
282 void LinearSample1BPP( const unsigned char * __restrict__ inPixels,
283  ImageDimensions inputDimensions,
284  unsigned char * __restrict__ outPixels,
285  ImageDimensions desiredDimensions );
286 
292 void LinearSample2BPP( const unsigned char * __restrict__ inPixels,
293  ImageDimensions inputDimensions,
294  unsigned char * __restrict__ outPixels,
295  ImageDimensions desiredDimensions );
296 
302 void LinearSampleRGB565( const unsigned char * __restrict__ inPixels,
303  ImageDimensions inputDimensions,
304  unsigned char * __restrict__ outPixels,
305  ImageDimensions desiredDimensions );
306 
312 void LinearSample3BPP( const unsigned char * __restrict__ inPixels,
313  ImageDimensions inputDimensions,
314  unsigned char * __restrict__ outPixels,
315  ImageDimensions desiredDimensions );
316 
323 void LinearSample4BPP( const unsigned char * __restrict__ inPixels,
324  ImageDimensions inputDimensions,
325  unsigned char * __restrict__ outPixels,
326  ImageDimensions desiredDimensions );
327 
340 void HalveScanlineInPlaceRGB888( unsigned char * pixels, unsigned int width );
341 
345 void HalveScanlineInPlaceRGBA8888( unsigned char * pixels, unsigned int width );
346 
350 void HalveScanlineInPlaceRGB565( unsigned char * pixels, unsigned int width );
351 
355 void HalveScanlineInPlace2Bytes( unsigned char * pixels, unsigned int width );
356 
360 void HalveScanlineInPlace1Byte( unsigned char * pixels, unsigned int width );
361 
371 void AverageScanlines1( const unsigned char * scanline1,
372  const unsigned char * scanline2,
373  unsigned char* outputScanline,
375  unsigned int width );
376 
380 void AverageScanlines2( const unsigned char * scanline1,
381  const unsigned char * scanline2,
382  unsigned char* outputScanline,
384  unsigned int width );
385 
389 void AverageScanlines3( const unsigned char * scanline1,
390  const unsigned char * scanline2,
391  unsigned char* outputScanline,
393  unsigned int width );
394 
398 void AverageScanlinesRGBA8888( const unsigned char * scanline1,
399  const unsigned char * scanline2,
400  unsigned char * outputScanline,
401  unsigned int width );
402 
406 void AverageScanlinesRGB565( const unsigned char * scanline1,
407  const unsigned char * scanline2,
408  unsigned char* outputScanline,
409  unsigned int width );
423 inline unsigned int AverageComponent( unsigned int a, unsigned int b )
424 {
425  unsigned int avg = (a + b) >> 1u;
426  return avg;
427 }
428 
435 inline uint32_t AveragePixelRGBA8888( uint32_t a, uint32_t b )
436 {
437  const unsigned int avg =
438  ((AverageComponent( (a & 0xff000000) >> 1u, (b & 0xff000000) >> 1u ) << 1u) & 0xff000000 ) +
439  (AverageComponent( a & 0x00ff0000, b & 0x00ff0000 ) & 0x00ff0000 ) +
440  (AverageComponent( a & 0x0000ff00, b & 0x0000ff00 ) & 0x0000ff00 ) +
441  (AverageComponent( a & 0x000000ff, b & 0x000000ff ) );
442  return avg;
445 }
446 
453 inline uint32_t AveragePixelRGB565( uint32_t a, uint32_t b )
454 {
455  const unsigned int avg =
456  (AverageComponent( a & 0xf800, b & 0xf800 ) & 0xf800 ) +
457  (AverageComponent( a & 0x7e0, b & 0x7e0 ) & 0x7e0 ) +
458  (AverageComponent( a & 0x1f, b & 0x1f ) );
459  return avg;
460 }
461 
463 inline unsigned int WeightedBlendIntToFixed1616(unsigned int a, unsigned int b, unsigned int fractBlend )
464 {
465  DALI_ASSERT_DEBUG( fractBlend <= 65535u && "Factor should be in 0.16 fixed-point." );
466  const unsigned int weightedAFixed = a * (65535u - fractBlend);
467  const unsigned int weightedBFixed = b * fractBlend;
468  const unsigned blended = (weightedAFixed + weightedBFixed);
469  return blended;
470 }
471 
473 inline uint64_t WeightedBlendFixed1616ToFixed1632(unsigned int a, unsigned int b, unsigned int fractBlend )
474 {
475  DALI_ASSERT_DEBUG( fractBlend <= 65535u && "Factor should be in 0.16 fixed-point." );
476  // Blend while promoting intermediates to 16.32 fixed point:
477  const uint64_t weightedAFixed = uint64_t(a) * (65535u - fractBlend);
478  const uint64_t weightedBFixed = uint64_t(b) * fractBlend;
479  const uint64_t blended = (weightedAFixed + weightedBFixed);
480  return blended;
481 }
482 
486 inline unsigned int BilinearFilter1Component(unsigned int tl, unsigned int tr, unsigned int bl, unsigned int br, unsigned int fractBlendHorizontal, unsigned int fractBlendVertical )
487 {
488  DALI_ASSERT_DEBUG( fractBlendHorizontal <= 65535u && "Factor should be in 0.16 fixed-point." );
489  DALI_ASSERT_DEBUG( fractBlendVertical <= 65535u && "Factor should be in 0.16 fixed-point." );
490 
491  const unsigned int topBlend = WeightedBlendIntToFixed1616( tl, tr, fractBlendHorizontal );
492  const unsigned int botBlend = WeightedBlendIntToFixed1616( bl, br, fractBlendHorizontal );
493  const uint64_t blended2x2 = WeightedBlendFixed1616ToFixed1632( topBlend, botBlend, fractBlendVertical );
494  const unsigned int rounded = (blended2x2 + (1u << 31u) ) >> 32u;
495  return rounded;
496 }
497 
500 } /* namespace Platform */
501 } /* namespace Internal */
502 } /* namespace Dali */
503 
504 #endif /* DALI_INTERNAL_PLATFORM_IMAGE_OPERATIONS_H_ */
Dali Docs Home
Read more about Dali