Jack Yoo | a02710a | 2016-04-06 16:07:22 -0700 | [diff] [blame] | 1 | /* |
| 2 | Copyright (c) 2016, The Linux Foundation. All rights reserved. |
| 3 | |
| 4 | Redistribution and use in source and binary forms, with or without |
| 5 | modification, are permitted provided that the following conditions are |
| 6 | met: |
| 7 | * Redistributions of source code must retain the above copyright |
| 8 | notice, this list of conditions and the following disclaimer. |
| 9 | * Redistributions in binary form must reproduce the above |
| 10 | copyright notice, this list of conditions and the following |
| 11 | disclaimer in the documentation and/or other materials provided |
| 12 | with the distribution. |
| 13 | * Neither the name of The Linux Foundation nor the names of its |
| 14 | contributors may be used to endorse or promote products derived |
| 15 | from this software without specific prior written permission. |
| 16 | |
| 17 | THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED |
| 18 | WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF |
| 19 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT |
| 20 | ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS |
| 21 | BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
| 22 | CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
| 23 | SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR |
| 24 | BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, |
| 25 | WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE |
| 26 | OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN |
| 27 | IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 28 | */ |
| 29 | #pragma version(1) |
| 30 | #pragma rs java_package_name(com.android.camera.imageprocessor) |
| 31 | #pragma rs_fp_relaxed |
| 32 | |
| 33 | rs_allocation gIn; |
| 34 | uint32_t width; |
| 35 | uint32_t height; |
| 36 | |
| 37 | uchar4 __attribute__((kernel)) nv21ToRgb(uint32_t x, uint32_t y) { |
| 38 | uint32_t ySize = width*height; |
| 39 | uint32_t index = ySize + (x/2*2) + ((y/2) * width); |
| 40 | int yV = (int)(rsGetElementAt_uchar(gIn, x + y*width) & 0xFF); |
| 41 | int vV = (int)(rsGetElementAt_uchar(gIn, index) & 0xFF ) -128; |
| 42 | int uV = (int)(rsGetElementAt_uchar(gIn, index+1) & 0xFF ) -128; |
| 43 | |
Jack Yoo | 53cd3dd | 2016-05-10 14:11:19 -0700 | [diff] [blame] | 44 | int r = (int) (yV + 1.370705f * vV ); |
| 45 | int g = (int) (yV - 0.698001f * vV - 0.337633f* uV); |
| 46 | int b = (int) (yV + 1.732446 * uV ); |
Jack Yoo | a02710a | 2016-04-06 16:07:22 -0700 | [diff] [blame] | 47 | |
| 48 | r = r>255? 255 : r<0 ? 0 : r; |
| 49 | g = g>255? 255 : g<0 ? 0 : g; |
| 50 | b = b>255? 255 : b<0 ? 0 : b; |
| 51 | uchar4 res4; |
| 52 | res4.r = (uchar)(r & 0xFF); |
| 53 | res4.g = (uchar)(g & 0xFF); |
| 54 | res4.b = (uchar)(b & 0xFF); |
| 55 | res4.a = 0xFF; |
| 56 | |
| 57 | return res4; |
| 58 | } |