genericopenlibs/liboil/src/jpeg/convert8x8_c.c
changeset 31 ce057bb09d0b
parent 18 47c74d1534e1
equal deleted inserted replaced
30:e20de85af2ee 31:ce057bb09d0b
       
     1 /*
       
     2  * LIBOIL - Library of Optimized Inner Loops
       
     3  * Copyright (c) 2001,2002,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 #include <liboil/liboil.h>
       
    33 #include "jpeg.h"
       
    34 
       
    35 #include <math.h>
       
    36 
       
    37 /**
       
    38  * oil_conv8x8_s16_f64:
       
    39  * @d_8x8:
       
    40  * @dstr:
       
    41  * @s_8x8:
       
    42  * @sstr:
       
    43  *
       
    44  * Converts elements in source array @s_8x8 to the destination
       
    45  * type, placing the results in @d_8x8.
       
    46  */
       
    47 OIL_DEFINE_CLASS (conv8x8_s16_f64,
       
    48     "int16_t * d_8x8, int dstr, double *s_8x8, int sstr");
       
    49 /**
       
    50  * oil_conv8x8_f64_s16:
       
    51  * @d_8x8:
       
    52  * @dstr:
       
    53  * @s_8x8:
       
    54  * @sstr:
       
    55  *
       
    56  * Converts elements in source array @s_8x8 to the destination
       
    57  * type, placing the results in @d_8x8.  The conversion of source
       
    58  * values outside the destination range are undefined and
       
    59  * implementation dependent.
       
    60  */
       
    61 OIL_DEFINE_CLASS (conv8x8_f64_s16,
       
    62     "double *d_8x8, int dstr, int16_t * s_8x8, int sstr");
       
    63 /**
       
    64  * oil_clipconv8x8_u8_s16:
       
    65  * @d_8x8:
       
    66  * @dstr:
       
    67  * @s_8x8:
       
    68  * @sstr:
       
    69  *
       
    70  * Converts elements in source array @s_8x8 to the destination
       
    71  * type, placing the results in @d_8x8.  Source values outside
       
    72  * the destination range are clipped to the destination range.
       
    73  */
       
    74 OIL_DEFINE_CLASS (clipconv8x8_u8_s16,
       
    75     "uint8_t * d_8x8, int dstr, int16_t * s_8x8, int sstr");
       
    76 
       
    77 #define BLOCK8x8_F64(ptr, stride, row, column) \
       
    78 	(*((double *)((unsigned char *)ptr + stride*row) + column))
       
    79 
       
    80 #define BLOCK8x8_PTR_F64(ptr, stride, row, column) \
       
    81 	((double *)((unsigned char *)ptr + stride*row) + column)
       
    82 
       
    83 #define BLOCK8x8_S16(ptr, stride, row, column) \
       
    84 	(*((int16_t *)((unsigned char *)ptr + stride*row) + column))
       
    85 
       
    86 #define BLOCK8x8_U8(ptr, stride, row, column) \
       
    87 	(*((uint8_t *)((unsigned char *)ptr + stride*row) + column))
       
    88 
       
    89 
       
    90 static void
       
    91 conv8x8_s16_f64_c (int16_t * dest, int dstr, double *src, int sstr)
       
    92 {
       
    93   int i, j;
       
    94 
       
    95   for (i = 0; i < 8; i++) {
       
    96     for (j = 0; j < 8; j++) {
       
    97       BLOCK8x8_S16 (dest, dstr, i, j) = floor (0.5 + BLOCK8x8_F64 (src, sstr, i, j));
       
    98     }
       
    99   }
       
   100 }
       
   101 
       
   102 OIL_DEFINE_IMPL_REF (conv8x8_s16_f64_c, conv8x8_s16_f64);
       
   103 
       
   104 static void
       
   105 conv8x8_f64_s16_c (double *dest, int dstr, int16_t * src, int sstr)
       
   106 {
       
   107   int i, j;
       
   108 
       
   109   for (i = 0; i < 8; i++) {
       
   110     for (j = 0; j < 8; j++) {
       
   111       BLOCK8x8_F64 (dest, dstr, i, j) = BLOCK8x8_S16 (src, sstr, i, j);
       
   112     }
       
   113   }
       
   114 }
       
   115 
       
   116 OIL_DEFINE_IMPL_REF (conv8x8_f64_s16_c, conv8x8_f64_s16);
       
   117 
       
   118 static void
       
   119 clipconv8x8_u8_s16_c (uint8_t * dest, int dstr, int16_t * src, int sstr)
       
   120 {
       
   121   int i, j;
       
   122   int16_t x;
       
   123 
       
   124   for (i = 0; i < 8; i++) {
       
   125     for (j = 0; j < 8; j++) {
       
   126       x = BLOCK8x8_S16 (src, sstr, i, j);
       
   127       if (x < 0)
       
   128 	x = 0;
       
   129       if (x > 255)
       
   130 	x = 255;
       
   131       BLOCK8x8_U8 (dest, dstr, i, j) = x;
       
   132     }
       
   133   }
       
   134 }
       
   135 
       
   136 OIL_DEFINE_IMPL_REF (clipconv8x8_u8_s16_c, clipconv8x8_u8_s16);
       
   137 
       
   138 
       
   139 #ifdef	__SYMBIAN32__
       
   140  
       
   141 OilFunctionClass* __oil_function_class_conv8x8_s16_f64() {
       
   142 		return &_oil_function_class_conv8x8_s16_f64;
       
   143 }
       
   144 #endif
       
   145 
       
   146 #ifdef	__SYMBIAN32__
       
   147  
       
   148 OilFunctionClass* __oil_function_class_conv8x8_f64_s16() {
       
   149 		return &_oil_function_class_conv8x8_f64_s16;
       
   150 }
       
   151 #endif
       
   152 
       
   153 #ifdef	__SYMBIAN32__
       
   154  
       
   155 OilFunctionClass* __oil_function_class_clipconv8x8_u8_s16() {
       
   156 		return &_oil_function_class_clipconv8x8_u8_s16;
       
   157 }
       
   158 #endif
       
   159 
       
   160 
       
   161 
       
   162 #ifdef	__SYMBIAN32__
       
   163  
       
   164 OilFunctionImpl* __oil_function_impl_conv8x8_s16_f64_c() {
       
   165 		return &_oil_function_impl_conv8x8_s16_f64_c;
       
   166 }
       
   167 #endif
       
   168 
       
   169 #ifdef	__SYMBIAN32__
       
   170  
       
   171 OilFunctionImpl* __oil_function_impl_conv8x8_f64_s16_c() {
       
   172 		return &_oil_function_impl_conv8x8_f64_s16_c;
       
   173 }
       
   174 #endif
       
   175 
       
   176 #ifdef	__SYMBIAN32__
       
   177  
       
   178 OilFunctionImpl* __oil_function_impl_clipconv8x8_u8_s16_c() {
       
   179 		return &_oil_function_impl_clipconv8x8_u8_s16_c;
       
   180 }
       
   181 #endif
       
   182 
       
   183 
       
   184 
       
   185 #ifdef	__SYMBIAN32__
       
   186  
       
   187 EXPORT_C void** _oil_function_class_ptr_conv8x8_s16_f64 ()	{
       
   188 	oil_function_class_ptr_conv8x8_s16_f64 = __oil_function_class_conv8x8_s16_f64();
       
   189 	return &oil_function_class_ptr_conv8x8_s16_f64->func;
       
   190 	}
       
   191 #endif
       
   192 
       
   193 #ifdef	__SYMBIAN32__
       
   194  
       
   195 EXPORT_C void** _oil_function_class_ptr_conv8x8_f64_s16 ()	{
       
   196 	oil_function_class_ptr_conv8x8_f64_s16 = __oil_function_class_conv8x8_f64_s16();
       
   197 	return &oil_function_class_ptr_conv8x8_f64_s16->func;
       
   198 	}
       
   199 #endif
       
   200 
       
   201 #ifdef	__SYMBIAN32__
       
   202  
       
   203 EXPORT_C void** _oil_function_class_ptr_clipconv8x8_u8_s16 ()	{
       
   204 	oil_function_class_ptr_clipconv8x8_u8_s16 = __oil_function_class_clipconv8x8_u8_s16();
       
   205 	return &oil_function_class_ptr_clipconv8x8_u8_s16->func;
       
   206 	}
       
   207 #endif
       
   208