Home | History | Annotate | Download | only in col32cb16blend
      1 /*
      2  * Copyright (C) 2013 The Android Open Source Project
      3  * All rights reserved.
      4  *
      5  * Redistribution and use in source and binary forms, with or without
      6  * modification, are permitted provided that the following conditions
      7  * are met:
      8  *  * Redistributions of source code must retain the above copyright
      9  *    notice, this list of conditions and the following disclaimer.
     10  *  * Redistributions in binary form must reproduce the above copyright
     11  *    notice, this list of conditions and the following disclaimer in
     12  *    the documentation and/or other materials provided with the
     13  *    distribution.
     14  *
     15  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
     16  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
     17  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
     18  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
     19  * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
     20  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
     21  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
     22  * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
     23  * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
     24  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
     25  * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     26  * SUCH DAMAGE.
     27  */
     28 
     29 #include <assert.h>
     30 #include <stdlib.h>
     31 #include <stdio.h>
     32 #include <string.h>
     33 #include <inttypes.h>
     34 
     35 
     36 #define ARGB_8888_MAX   0xFFFFFFFF
     37 #define ARGB_8888_MIN   0x00000000
     38 #define RGB_565_MAX 0xFFFF
     39 #define RGB_565_MIN 0x0000
     40 
     41 struct test_t
     42 {
     43     char name[256];
     44     uint32_t dst_color;
     45     uint32_t src_color;
     46     size_t count;
     47 };
     48 
     49 struct test_t tests[] =
     50 {
     51     {"Count 1, Src=Max, Dst=Min", ARGB_8888_MAX, RGB_565_MIN, 1},
     52     {"Count 2, Src=Min, Dst=Max", ARGB_8888_MIN, RGB_565_MAX, 2},
     53     {"Count 3, Src=Max, Dst=Max", ARGB_8888_MAX, RGB_565_MAX, 3},
     54     {"Count 4, Src=Min, Dst=Min", ARGB_8888_MAX, RGB_565_MAX, 4},
     55     {"Count 1, Src=Rand, Dst=Rand", 0x12345678, 0x9ABC, 1},
     56     {"Count 2, Src=Rand, Dst=Rand", 0xABCDEF12, 0x2345, 2},
     57     {"Count 3, Src=Rand, Dst=Rand", 0x11111111, 0xEDFE, 3},
     58     {"Count 4, Src=Rand, Dst=Rand", 0x12345678, 0x9ABC, 4},
     59     {"Count 5, Src=Rand, Dst=Rand", 0xEFEFFEFE, 0xFACC, 5},
     60     {"Count 10, Src=Rand, Dst=Rand", 0x12345678, 0x9ABC, 10}
     61 };
     62 
     63 void scanline_col32cb16blend_arm64(uint16_t *dst, int32_t src, size_t count);
     64 void scanline_col32cb16blend_c(uint16_t * dst, int32_t src, size_t count)
     65 {
     66     int srcAlpha = (src>>24);
     67     int f = 0x100 - (srcAlpha + (srcAlpha>>7));
     68     while (count--)
     69     {
     70         uint16_t d = *dst;
     71         int dstR = (d>>11)&0x1f;
     72         int dstG = (d>>5)&0x3f;
     73         int dstB = (d)&0x1f;
     74         int srcR = (src >> (   3))&0x1F;
     75         int srcG = (src >> ( 8+2))&0x3F;
     76         int srcB = (src >> (16+3))&0x1F;
     77         srcR += (f*dstR)>>8;
     78         srcG += (f*dstG)>>8;
     79         srcB += (f*dstB)>>8;
     80         *dst++ = (uint16_t)((srcR<<11)|(srcG<<5)|srcB);
     81     }
     82 }
     83 
     84 void scanline_col32cb16blend_test()
     85 {
     86     uint16_t dst_c[16], dst_asm[16];
     87     uint32_t i, j;
     88 
     89     for(i = 0; i < sizeof(tests)/sizeof(struct test_t); ++i)
     90     {
     91         struct test_t test = tests[i];
     92 
     93         printf("Testing - %s:",test.name);
     94 
     95         memset(dst_c, 0, sizeof(dst_c));
     96         memset(dst_asm, 0, sizeof(dst_asm));
     97 
     98         for(j = 0; j < test.count; ++j)
     99         {
    100             dst_c[j]   = test.dst_color;
    101             dst_asm[j] = test.dst_color;
    102         }
    103 
    104 
    105         scanline_col32cb16blend_c(dst_c, test.src_color, test.count);
    106         scanline_col32cb16blend_arm64(dst_asm, test.src_color, test.count);
    107 
    108 
    109         if(memcmp(dst_c, dst_asm, sizeof(dst_c)) == 0)
    110             printf("Passed\n");
    111         else
    112             printf("Failed\n");
    113 
    114         for(j = 0; j < test.count; ++j)
    115         {
    116             printf("dst_c[%d] = %x, dst_asm[%d] = %x \n", j, dst_c[j], j, dst_asm[j]);
    117         }
    118     }
    119 }
    120 
    121 int main()
    122 {
    123     scanline_col32cb16blend_test();
    124     return 0;
    125 }
    126