os/ossrv/genericopenlibs/liboil/src/jpeg/zigzag8x8_c.c
author sl
Tue, 10 Jun 2014 14:32:02 +0200
changeset 1 260cb5ec6c19
permissions -rw-r--r--
Update contrib.
     1 /*
     2  * LIBOIL - Library of Optimized Inner Loops
     3  * Copyright (c) 2003,2004 David A. Schleef <ds@schleef.org>
     4  * All rights reserved.
     5  *
     6  * Redistribution and use in source and binary forms, with or without
     7  * modification, are permitted provided that the following conditions
     8  * are met:
     9  * 1. Redistributions of source code must retain the above copyright
    10  *    notice, this list of conditions and the following disclaimer.
    11  * 2. Redistributions in binary form must reproduce the above copyright
    12  *    notice, this list of conditions and the following disclaimer in the
    13  *    documentation and/or other materials provided with the distribution.
    14  * 
    15  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
    16  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
    17  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
    18  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
    19  * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
    20  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
    21  * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
    22  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
    23  * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
    24  * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
    25  * POSSIBILITY OF SUCH DAMAGE.
    26  */
    27 //Portions Copyright (c)  2008-2009 Nokia Corporation and/or its subsidiary(-ies). All rights reserved. 
    28 
    29 #ifdef HAVE_CONFIG_H
    30 #include "config.h"
    31 #endif
    32 
    33 #include <liboil/liboil.h>
    34 #include "jpeg.h"
    35 
    36 /**
    37  * oil_zigzag8x8_s16:
    38  * @d_8x8:
    39  * @ds:
    40  * @s_8x8:
    41  * @ss:
    42  *
    43  * Reorders an 8x8 block using a zig-zag pattern.  The zig-zag pattern
    44  * is described in the JPEG specification.
    45  * 
    46  * FIXME: describe zigzag pattern
    47  */
    48 OIL_DEFINE_CLASS (zigzag8x8_s16,
    49     "int16_t *d_8x8, int ds, int16_t *s_8x8, int ss");
    50 /**
    51  * oil_unzigzag8x8_s16:
    52  * @d_8x8:
    53  * @ds:
    54  * @s_8x8:
    55  * @ss:
    56  *
    57  * Reorders an 8x8 block to reverse the zig-zag reordering of
    58  * @oil_zigzag8x8_s16.
    59  */
    60 OIL_DEFINE_CLASS (unzigzag8x8_s16,
    61     "int16_t *d_8x8, int ds, int16_t *s_8x8, int ss");
    62 
    63 
    64 
    65 #define BLOCK8x8_S16(ptr, stride, row, column) \
    66 	(*((int16_t *)((void *)ptr + stride*row) + column))
    67 
    68 static const unsigned char zigzag_order[64] = {
    69 	0,
    70 	8, 1,
    71 	2, 9, 16,
    72 	24, 17, 10, 3, 
    73 	4, 11, 18, 25, 32,
    74 	40, 33, 26, 19, 12, 5, 
    75 	6, 13, 20, 27, 34, 41, 48,
    76 	56, 49, 42, 35, 28, 21, 14, 7,
    77 	15, 22, 29, 36, 43, 50, 57,
    78 	58, 51, 44, 37, 30, 23,
    79 	31, 38, 45, 52, 59,
    80 	60, 53, 46, 39,
    81 	47, 54, 61,
    82 	62, 55,
    83 	63
    84 };
    85 
    86 static const unsigned char unzigzag_order[64] = {
    87 	0,  1,  5,  6,  14, 15, 27, 28,
    88 	2,  4,  7,  13, 16, 26, 29, 42,
    89 	3,  8,  12, 17, 25, 30, 41, 43,
    90 	9,  11, 18, 24, 31, 40, 44, 53,
    91 	10, 19, 23, 32, 39, 45, 52, 54,
    92 	20, 22, 33, 38, 46, 51, 55, 60,
    93 	21, 34, 37, 47, 50, 56, 59, 61,
    94 	35, 36, 48, 49, 57, 58, 62, 63,
    95 };
    96 
    97 
    98 static void
    99 zigzag8x8_s16_ref(int16_t *dest, int dstr, int16_t *src, int sstr)
   100 {
   101 	int i,j;
   102 	unsigned int z;
   103 
   104 	for(j=0;j<8;j++){
   105 		for(i=0;i<8;i++){
   106 			z = zigzag_order[j*8+i];
   107 			OIL_GET(dest,j*dstr +i*sizeof(int16_t), int16_t) =
   108                           OIL_GET(src, sstr*(z>>3)+(z&7)*sizeof(int16_t),
   109                               int16_t);
   110 		}
   111 	}
   112 }
   113 OIL_DEFINE_IMPL_REF (zigzag8x8_s16_ref, zigzag8x8_s16);
   114 
   115 static void
   116 unzigzag8x8_s16_ref (int16_t *dest, int dstr, int16_t *src, int sstr)
   117 {
   118 	int i,j;
   119 	unsigned int z;
   120 
   121 	for(i=0;i<8;i++){
   122 		for(j=0;j<8;j++){
   123 			z = unzigzag_order[i*8+j];
   124 			OIL_GET(dest,j*dstr +i*sizeof(int16_t), int16_t) =
   125                           OIL_GET(src, sstr*(z>>3)+(z&7)*sizeof(int16_t),
   126                               int16_t);
   127 		}
   128 	}
   129 }
   130 OIL_DEFINE_IMPL_REF (unzigzag8x8_s16_ref, unzigzag8x8_s16);
   131 
   132 
   133 static void
   134 zigzag8x8_s16_unroll (int16_t *dest, int dstr, int16_t *src, int sstr)
   135 {
   136 #define ACK(x,y) \
   137         OIL_GET(dest, ((x)>>3) * dstr + ((x)&7) * sizeof(int16_t), int16_t) = \
   138           OIL_GET(src, ((y)>>3) * sstr + ((y)&7) * sizeof(int16_t), int16_t);
   139 
   140         ACK(0, 0);
   141         ACK(1, 8);
   142         ACK(2, 1);
   143         ACK(3, 2);
   144         ACK(4, 9);
   145         ACK(5, 16);
   146         ACK(6, 24);
   147         ACK(7, 17);
   148         ACK(8, 10);
   149         ACK(9, 3);
   150         ACK(10, 4);
   151         ACK(11, 11);
   152         ACK(12, 18);
   153         ACK(13, 25);
   154         ACK(14, 32);
   155         ACK(15, 40);
   156         ACK(16, 33);
   157         ACK(17, 26);
   158         ACK(18, 19);
   159         ACK(19, 12);
   160         ACK(20, 5);
   161         ACK(21, 6);
   162         ACK(22, 13);
   163         ACK(23, 20);
   164         ACK(24, 27);
   165         ACK(25, 34);
   166         ACK(26, 41);
   167         ACK(27, 48);
   168         ACK(28, 56);
   169         ACK(29, 49);
   170         ACK(30, 42);
   171         ACK(31, 35);
   172         ACK(32, 28);
   173         ACK(33, 21);
   174         ACK(34, 14);
   175         ACK(35, 7);
   176         ACK(36, 15);
   177         ACK(37, 22);
   178         ACK(38, 29);
   179         ACK(39, 36);
   180         ACK(40, 43);
   181         ACK(41, 50);
   182         ACK(42, 57);
   183         ACK(43, 58);
   184         ACK(44, 51);
   185         ACK(45, 44);
   186         ACK(46, 37);
   187         ACK(47, 30);
   188         ACK(48, 23);
   189         ACK(49, 31);
   190         ACK(50, 38);
   191         ACK(51, 45);
   192         ACK(52, 52);
   193         ACK(53, 59);
   194         ACK(54, 60);
   195         ACK(55, 53);
   196         ACK(56, 46);
   197         ACK(57, 39);
   198         ACK(58, 47);
   199         ACK(59, 54);
   200         ACK(60, 61);
   201         ACK(61, 62);
   202         ACK(62, 55);
   203         ACK(63, 63);
   204 }
   205 OIL_DEFINE_IMPL (zigzag8x8_s16_unroll, zigzag8x8_s16);
   206 
   207 static void
   208 unzigzag8x8_s16_unroll (int16_t *dest, int dstr, int16_t *src, int sstr)
   209 {
   210 	ACK(0, 0)
   211 	ACK(1, 2)
   212 	ACK(2, 3)
   213 	ACK(3, 9)
   214 	ACK(4, 10)
   215 	ACK(5, 20)
   216 	ACK(6, 21)
   217 	ACK(7, 35)
   218 	ACK(8, 1)
   219 	ACK(9, 4)
   220 	ACK(10, 8)
   221 	ACK(11, 11)
   222 	ACK(12, 19)
   223 	ACK(13, 22)
   224 	ACK(14, 34)
   225 	ACK(15, 36)
   226 	ACK(16, 5)
   227 	ACK(17, 7)
   228 	ACK(18, 12)
   229 	ACK(19, 18)
   230 	ACK(20, 23)
   231 	ACK(21, 33)
   232 	ACK(22, 37)
   233 	ACK(23, 48)
   234 	ACK(24, 6)
   235 	ACK(25, 13)
   236 	ACK(26, 17)
   237 	ACK(27, 24)
   238 	ACK(28, 32)
   239 	ACK(29, 38)
   240 	ACK(30, 47)
   241 	ACK(31, 49)
   242 	ACK(32, 14)
   243 	ACK(33, 16)
   244 	ACK(34, 25)
   245 	ACK(35, 31)
   246 	ACK(36, 39)
   247 	ACK(37, 46)
   248 	ACK(38, 50)
   249 	ACK(39, 57)
   250 	ACK(40, 15)
   251 	ACK(41, 26)
   252 	ACK(42, 30)
   253 	ACK(43, 40)
   254 	ACK(44, 45)
   255 	ACK(45, 51)
   256 	ACK(46, 56)
   257 	ACK(47, 58)
   258 	ACK(48, 27)
   259 	ACK(49, 29)
   260 	ACK(50, 41)
   261 	ACK(51, 44)
   262 	ACK(52, 52)
   263 	ACK(53, 55)
   264 	ACK(54, 59)
   265 	ACK(55, 62)
   266 	ACK(56, 28)
   267 	ACK(57, 42)
   268 	ACK(58, 43)
   269 	ACK(59, 53)
   270 	ACK(60, 54)
   271 	ACK(61, 60)
   272 	ACK(62, 61)
   273 	ACK(63, 63)
   274 }
   275 OIL_DEFINE_IMPL (unzigzag8x8_s16_unroll, unzigzag8x8_s16);
   276 
   277 
   278 #ifdef	__SYMBIAN32__
   279  
   280 OilFunctionClass* __oil_function_class_zigzag8x8_s16() {
   281 		return &_oil_function_class_zigzag8x8_s16;
   282 }
   283 #endif
   284 
   285 #ifdef	__SYMBIAN32__
   286  
   287 OilFunctionClass* __oil_function_class_unzigzag8x8_s16() {
   288 		return &_oil_function_class_unzigzag8x8_s16;
   289 }
   290 #endif
   291 
   292 
   293 
   294 #ifdef	__SYMBIAN32__
   295  
   296 OilFunctionImpl* __oil_function_impl_zigzag8x8_s16_ref() {
   297 		return &_oil_function_impl_zigzag8x8_s16_ref;
   298 }
   299 #endif
   300 
   301 #ifdef	__SYMBIAN32__
   302  
   303 OilFunctionImpl* __oil_function_impl_unzigzag8x8_s16_ref() {
   304 		return &_oil_function_impl_unzigzag8x8_s16_ref;
   305 }
   306 #endif
   307 
   308 #ifdef	__SYMBIAN32__
   309  
   310 OilFunctionImpl* __oil_function_impl_zigzag8x8_s16_unroll() {
   311 		return &_oil_function_impl_zigzag8x8_s16_unroll;
   312 }
   313 #endif
   314 
   315 #ifdef	__SYMBIAN32__
   316  
   317 OilFunctionImpl* __oil_function_impl_unzigzag8x8_s16_unroll() {
   318 		return &_oil_function_impl_unzigzag8x8_s16_unroll;
   319 }
   320 #endif
   321 
   322 
   323 
   324 #ifdef	__SYMBIAN32__
   325  
   326 EXPORT_C void** _oil_function_class_ptr_zigzag8x8_s16 ()	{
   327 	oil_function_class_ptr_zigzag8x8_s16 = __oil_function_class_zigzag8x8_s16();
   328 	return &oil_function_class_ptr_zigzag8x8_s16->func;
   329 	}
   330 #endif
   331 
   332 #ifdef	__SYMBIAN32__
   333  
   334 EXPORT_C void** _oil_function_class_ptr_unzigzag8x8_s16 ()	{
   335 	oil_function_class_ptr_unzigzag8x8_s16 = __oil_function_class_unzigzag8x8_s16();
   336 	return &oil_function_class_ptr_unzigzag8x8_s16->func;
   337 	}
   338 #endif
   339