sl@0: /* sl@0: * LIBOIL - Library of Optimized Inner Loops sl@0: * Copyright (c) 2003,2004 David A. Schleef sl@0: * All rights reserved. sl@0: * sl@0: * Redistribution and use in source and binary forms, with or without sl@0: * modification, are permitted provided that the following conditions sl@0: * are met: sl@0: * 1. Redistributions of source code must retain the above copyright sl@0: * notice, this list of conditions and the following disclaimer. sl@0: * 2. Redistributions in binary form must reproduce the above copyright sl@0: * notice, this list of conditions and the following disclaimer in the sl@0: * documentation and/or other materials provided with the distribution. sl@0: * sl@0: * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR sl@0: * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED sl@0: * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE sl@0: * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, sl@0: * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES sl@0: * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR sl@0: * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) sl@0: * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, sl@0: * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING sl@0: * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE sl@0: * POSSIBILITY OF SUCH DAMAGE. sl@0: */ sl@0: //Portions Copyright (c) 2008-2009 Nokia Corporation and/or its subsidiary(-ies). All rights reserved. sl@0: sl@0: #ifdef HAVE_CONFIG_H sl@0: #include "config.h" sl@0: #endif sl@0: sl@0: #include "liboil/liboil.h" sl@0: #include "liboilfunction.h" sl@0: #include "liboil/liboilcolorspace.h" sl@0: #include "liboil/liboiltest.h" sl@0: #include sl@0: sl@0: /** sl@0: * oil_ayuv2argb_u8: sl@0: * @d_4xn: sl@0: * @s_4xn: sl@0: * @n: sl@0: * sl@0: * Converts AYUV pixels to ARGB pixels. AYUV pixels are in the sl@0: * JPEG colorspace. Note that this function doesn't follow normal sl@0: * liboil pixel conventions. sl@0: * sl@0: * (This function should be replaced by one that handles other sl@0: * conversion factors.) sl@0: */ sl@0: OIL_DEFINE_CLASS (ayuv2argb_u8, "uint8_t *d_4xn, uint8_t *s_4xn, int n"); sl@0: sl@0: sl@0: #define clamp(x,a,b) clamp_lower(clamp_upper(x,b),a) sl@0: #define clamp_lower(x,a) ((xb)?(b):(x)) sl@0: sl@0: /* from the JFIF spec */ sl@0: #define YUV_TO_R(y,u,v) clamp((y) + 1.402*((v)-128.0),0,255) sl@0: #define YUV_TO_G(y,u,v) clamp((y) - 0.34414*((u)-128.0) - 0.71414*((v)-128.0),0,255) sl@0: #define YUV_TO_B(y,u,v) clamp((y) + 1.772*((u)-128.0),0,255) sl@0: sl@0: #define muldiv256(x,y) (((x)*(y) + 128)>>8) sl@0: #define YUV_TO_R_INT8(y,u,v) clamp((y) + muldiv256(359,(v)-128),0,255) sl@0: #define YUV_TO_G_INT8(y,u,v) clamp((y) + muldiv256(-88,(u)-128) + muldiv256(-183,(v)-128),0,255) sl@0: #define YUV_TO_B_INT8(y,u,v) clamp((y) + muldiv256(454,(u)-128),0,255) sl@0: sl@0: #define muldiv65536(x,y) (((x)*(y) + 32768)>>16) sl@0: #define YUV_TO_R_INT16(y,u,v) clamp((y) + muldiv65536(91881,(v)-128),0,255) sl@0: #define YUV_TO_G_INT16(y,u,v) clamp((y) - muldiv65536(22554,(u)-128) - muldiv65536(46802,(v)-128),0,255) sl@0: #define YUV_TO_B_INT16(y,u,v) clamp((y) + muldiv65536(116130,(u)-128),0,255) sl@0: sl@0: sl@0: #define SHIFT 6 sl@0: #define MULT (1<<6) sl@0: #define X(x) ((int)((x)*(1<<(SHIFT+8)) + 0.5)) sl@0: static int16_t jfif_matrix[][4] = { sl@0: { 0, 0, -8192, -8192 }, sl@0: { 16384, 0, 0, 0 }, sl@0: { 0, 16384, 16384, 16384 }, sl@0: { 0, 0, -5638, 29032 }, sl@0: { 0, 22970, -11700, 0 }, sl@0: { 0, 0, 0, 0 } sl@0: }; sl@0: sl@0: static void sl@0: colorspace_argb_test (OilTest *test) sl@0: { sl@0: int16_t *data = oil_test_get_source_data (test, OIL_ARG_SRC2); sl@0: sl@0: memcpy (data, jfif_matrix, 4*2*6); sl@0: } sl@0: sl@0: OIL_DEFINE_CLASS_FULL (colorspace_argb, "uint32_t *d, uint32_t *s, int16_t *s2_24, int n", colorspace_argb_test); sl@0: sl@0: static void sl@0: colorspace_argb_ref (uint32_t *dest, const uint32_t *src, const int16_t *matrix, int n) sl@0: { sl@0: int i; sl@0: sl@0: for(i=0;i>16) sl@0: da = (MUL(sa,matrix[1*4+0]) + MUL(sr,matrix[2*4+0]) + MUL(sg,matrix[3*4+0]) + sl@0: MUL(sb,matrix[4*4+0]) + matrix[5*4+0] + 8)>>(2*SHIFT - 8); sl@0: dr = (MUL(sa,matrix[1*4+1]) + MUL(sr,matrix[2*4+1]) + MUL(sg,matrix[3*4+1]) + sl@0: MUL(sb,matrix[4*4+1]) + matrix[5*4+1] + 8)>>(2*SHIFT - 8); sl@0: dg = (MUL(sa,matrix[1*4+2]) + MUL(sr,matrix[2*4+2]) + MUL(sg,matrix[3*4+2]) + sl@0: MUL(sb,matrix[4*4+2]) + matrix[5*4+2] + 8)>>(2*SHIFT - 8); sl@0: db = (MUL(sa,matrix[1*4+3]) + MUL(sr,matrix[2*4+3]) + MUL(sg,matrix[3*4+3]) + sl@0: MUL(sb,matrix[4*4+3]) + matrix[5*4+3] + 8)>>(2*SHIFT - 8); sl@0: dest[i] = oil_argb(da, dr, dg, db); sl@0: } sl@0: sl@0: } sl@0: OIL_DEFINE_IMPL_REF (colorspace_argb_ref, colorspace_argb); sl@0: sl@0: sl@0: static void sl@0: ayuv2argb_u8_ref (uint8_t *argb, const uint8_t *ayuv, int n) sl@0: { sl@0: int i; sl@0: sl@0: for(i=0;ifunc; sl@0: } sl@0: #endif sl@0: sl@0: #ifdef __SYMBIAN32__ sl@0: sl@0: EXPORT_C void** _oil_function_class_ptr_colorspace_argb () { sl@0: oil_function_class_ptr_colorspace_argb = __oil_function_class_colorspace_argb(); sl@0: return &oil_function_class_ptr_colorspace_argb->func; sl@0: } sl@0: #endif sl@0: