1*e1eccf28SAndroid Build Coastguard Worker /* 2*e1eccf28SAndroid Build Coastguard Worker * Copyright (C) 2021 The Android Open Source Project 3*e1eccf28SAndroid Build Coastguard Worker * 4*e1eccf28SAndroid Build Coastguard Worker * Licensed under the Apache License, Version 2.0 (the "License"); 5*e1eccf28SAndroid Build Coastguard Worker * you may not use this file except in compliance with the License. 6*e1eccf28SAndroid Build Coastguard Worker * You may obtain a copy of the License at 7*e1eccf28SAndroid Build Coastguard Worker * 8*e1eccf28SAndroid Build Coastguard Worker * http://www.apache.org/licenses/LICENSE-2.0 9*e1eccf28SAndroid Build Coastguard Worker * 10*e1eccf28SAndroid Build Coastguard Worker * Unless required by applicable law or agreed to in writing, software 11*e1eccf28SAndroid Build Coastguard Worker * distributed under the License is distributed on an "AS IS" BASIS, 12*e1eccf28SAndroid Build Coastguard Worker * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13*e1eccf28SAndroid Build Coastguard Worker * See the License for the specific language governing permissions and 14*e1eccf28SAndroid Build Coastguard Worker * limitations under the License. 15*e1eccf28SAndroid Build Coastguard Worker */ 16*e1eccf28SAndroid Build Coastguard Worker 17*e1eccf28SAndroid Build Coastguard Worker #ifndef ANDROID_RENDERSCRIPT_TOOLKIT_TOOLKIT_H 18*e1eccf28SAndroid Build Coastguard Worker #define ANDROID_RENDERSCRIPT_TOOLKIT_TOOLKIT_H 19*e1eccf28SAndroid Build Coastguard Worker 20*e1eccf28SAndroid Build Coastguard Worker #include <cstdint> 21*e1eccf28SAndroid Build Coastguard Worker #include <memory> 22*e1eccf28SAndroid Build Coastguard Worker 23*e1eccf28SAndroid Build Coastguard Worker namespace android { 24*e1eccf28SAndroid Build Coastguard Worker namespace renderscript { 25*e1eccf28SAndroid Build Coastguard Worker 26*e1eccf28SAndroid Build Coastguard Worker class TaskProcessor; 27*e1eccf28SAndroid Build Coastguard Worker 28*e1eccf28SAndroid Build Coastguard Worker /** 29*e1eccf28SAndroid Build Coastguard Worker * Define a range of data to process. 30*e1eccf28SAndroid Build Coastguard Worker * 31*e1eccf28SAndroid Build Coastguard Worker * This class is used to restrict a Toolkit operation to a rectangular subset of the input 32*e1eccf28SAndroid Build Coastguard Worker * tensor. 33*e1eccf28SAndroid Build Coastguard Worker * 34*e1eccf28SAndroid Build Coastguard Worker * @property startX The index of the first value to be included on the X axis. 35*e1eccf28SAndroid Build Coastguard Worker * @property endX The index after the last value to be included on the X axis. 36*e1eccf28SAndroid Build Coastguard Worker * @property startY The index of the first value to be included on the Y axis. 37*e1eccf28SAndroid Build Coastguard Worker * @property endY The index after the last value to be included on the Y axis. 38*e1eccf28SAndroid Build Coastguard Worker */ 39*e1eccf28SAndroid Build Coastguard Worker struct Restriction { 40*e1eccf28SAndroid Build Coastguard Worker size_t startX; 41*e1eccf28SAndroid Build Coastguard Worker size_t endX; 42*e1eccf28SAndroid Build Coastguard Worker size_t startY; 43*e1eccf28SAndroid Build Coastguard Worker size_t endY; 44*e1eccf28SAndroid Build Coastguard Worker }; 45*e1eccf28SAndroid Build Coastguard Worker 46*e1eccf28SAndroid Build Coastguard Worker /** 47*e1eccf28SAndroid Build Coastguard Worker * A collection of high-performance graphic utility functions like blur and blend. 48*e1eccf28SAndroid Build Coastguard Worker * 49*e1eccf28SAndroid Build Coastguard Worker * This toolkit provides ten image manipulation functions: blend, blur, color matrix, convolve, 50*e1eccf28SAndroid Build Coastguard Worker * histogram, histogramDot, lut, lut3d, resize, and YUV to RGB. These functions execute 51*e1eccf28SAndroid Build Coastguard Worker * multithreaded on the CPU. 52*e1eccf28SAndroid Build Coastguard Worker * 53*e1eccf28SAndroid Build Coastguard Worker * These functions work over raw byte arrays. You'll need to specify the width and height of 54*e1eccf28SAndroid Build Coastguard Worker * the data to be processed, as well as the number of bytes per pixel. For most use cases, 55*e1eccf28SAndroid Build Coastguard Worker * this will be 4. 56*e1eccf28SAndroid Build Coastguard Worker * 57*e1eccf28SAndroid Build Coastguard Worker * You should instantiate the Toolkit once and reuse it throughout your application. 58*e1eccf28SAndroid Build Coastguard Worker * On instantiation, the Toolkit creates a thread pool that's used for processing all the functions. 59*e1eccf28SAndroid Build Coastguard Worker * You can limit the number of pool threads used by the Toolkit via the constructor. The pool 60*e1eccf28SAndroid Build Coastguard Worker * threads are destroyed once the Toolkit is destroyed, after any pending work is done. 61*e1eccf28SAndroid Build Coastguard Worker * 62*e1eccf28SAndroid Build Coastguard Worker * This library is thread safe. You can call methods from different pool threads. The functions will 63*e1eccf28SAndroid Build Coastguard Worker * execute sequentially. 64*e1eccf28SAndroid Build Coastguard Worker * 65*e1eccf28SAndroid Build Coastguard Worker * A Java/Kotlin Toolkit is available. It calls this library through JNI. 66*e1eccf28SAndroid Build Coastguard Worker * 67*e1eccf28SAndroid Build Coastguard Worker * This toolkit can be used as a replacement for most RenderScript Intrinsic functions. Compared 68*e1eccf28SAndroid Build Coastguard Worker * to RenderScript, it's simpler to use and more than twice as fast on the CPU. However RenderScript 69*e1eccf28SAndroid Build Coastguard Worker * Intrinsics allow more flexibility for the type of allocation supported. In particular, this 70*e1eccf28SAndroid Build Coastguard Worker * toolkit does not support allocations of floats. 71*e1eccf28SAndroid Build Coastguard Worker */ 72*e1eccf28SAndroid Build Coastguard Worker class RenderScriptToolkit { 73*e1eccf28SAndroid Build Coastguard Worker /** Each Toolkit method call is converted to a Task. The processor owns the thread pool. It 74*e1eccf28SAndroid Build Coastguard Worker * tiles the tasks and schedule them over the pool threads. 75*e1eccf28SAndroid Build Coastguard Worker */ 76*e1eccf28SAndroid Build Coastguard Worker std::unique_ptr<TaskProcessor> processor; 77*e1eccf28SAndroid Build Coastguard Worker 78*e1eccf28SAndroid Build Coastguard Worker public: 79*e1eccf28SAndroid Build Coastguard Worker /** 80*e1eccf28SAndroid Build Coastguard Worker * Creates the pool threads that are used for processing the method calls. 81*e1eccf28SAndroid Build Coastguard Worker */ 82*e1eccf28SAndroid Build Coastguard Worker RenderScriptToolkit(int numberOfThreads = 0); 83*e1eccf28SAndroid Build Coastguard Worker /** 84*e1eccf28SAndroid Build Coastguard Worker * Destroys the thread pool. This stops any in-progress work; the Toolkit methods called from 85*e1eccf28SAndroid Build Coastguard Worker * other pool threads will return without having completed the work. Because of the undefined 86*e1eccf28SAndroid Build Coastguard Worker * state of the output buffers, an application should avoid destroying the Toolkit if other pool 87*e1eccf28SAndroid Build Coastguard Worker * threads are executing Toolkit methods. 88*e1eccf28SAndroid Build Coastguard Worker */ 89*e1eccf28SAndroid Build Coastguard Worker ~RenderScriptToolkit(); 90*e1eccf28SAndroid Build Coastguard Worker 91*e1eccf28SAndroid Build Coastguard Worker /** 92*e1eccf28SAndroid Build Coastguard Worker * Determines how a source buffer is blended into a destination buffer. 93*e1eccf28SAndroid Build Coastguard Worker * 94*e1eccf28SAndroid Build Coastguard Worker * See {@link RenderScriptToolkit::blend}. 95*e1eccf28SAndroid Build Coastguard Worker * 96*e1eccf28SAndroid Build Coastguard Worker * blend only works on 4 byte RGBA data. In the descriptions below, ".a" represents 97*e1eccf28SAndroid Build Coastguard Worker * the alpha channel. 98*e1eccf28SAndroid Build Coastguard Worker */ 99*e1eccf28SAndroid Build Coastguard Worker enum class BlendingMode { 100*e1eccf28SAndroid Build Coastguard Worker /** 101*e1eccf28SAndroid Build Coastguard Worker * dest = 0 102*e1eccf28SAndroid Build Coastguard Worker * 103*e1eccf28SAndroid Build Coastguard Worker * The destination is cleared, i.e. each pixel is set to (0, 0, 0, 0) 104*e1eccf28SAndroid Build Coastguard Worker */ 105*e1eccf28SAndroid Build Coastguard Worker CLEAR = 0, 106*e1eccf28SAndroid Build Coastguard Worker /** 107*e1eccf28SAndroid Build Coastguard Worker * dest = src 108*e1eccf28SAndroid Build Coastguard Worker * 109*e1eccf28SAndroid Build Coastguard Worker * Sets each pixel of the destination to the corresponding one in the source. 110*e1eccf28SAndroid Build Coastguard Worker */ 111*e1eccf28SAndroid Build Coastguard Worker SRC = 1, 112*e1eccf28SAndroid Build Coastguard Worker /** 113*e1eccf28SAndroid Build Coastguard Worker * dest = dest 114*e1eccf28SAndroid Build Coastguard Worker * 115*e1eccf28SAndroid Build Coastguard Worker * Leaves the destination untouched. This is a no-op. 116*e1eccf28SAndroid Build Coastguard Worker */ 117*e1eccf28SAndroid Build Coastguard Worker DST = 2, 118*e1eccf28SAndroid Build Coastguard Worker /** 119*e1eccf28SAndroid Build Coastguard Worker * dest = src + dest * (1.0 - src.a) 120*e1eccf28SAndroid Build Coastguard Worker */ 121*e1eccf28SAndroid Build Coastguard Worker SRC_OVER = 3, 122*e1eccf28SAndroid Build Coastguard Worker /** 123*e1eccf28SAndroid Build Coastguard Worker * dest = dest + src * (1.0 - dest.a) 124*e1eccf28SAndroid Build Coastguard Worker */ 125*e1eccf28SAndroid Build Coastguard Worker DST_OVER = 4, 126*e1eccf28SAndroid Build Coastguard Worker /** 127*e1eccf28SAndroid Build Coastguard Worker * dest = src * dest.a 128*e1eccf28SAndroid Build Coastguard Worker */ 129*e1eccf28SAndroid Build Coastguard Worker SRC_IN = 5, 130*e1eccf28SAndroid Build Coastguard Worker /** 131*e1eccf28SAndroid Build Coastguard Worker * dest = dest * src.a 132*e1eccf28SAndroid Build Coastguard Worker */ 133*e1eccf28SAndroid Build Coastguard Worker DST_IN = 6, 134*e1eccf28SAndroid Build Coastguard Worker /** 135*e1eccf28SAndroid Build Coastguard Worker * dest = src * (1.0 - dest.a) 136*e1eccf28SAndroid Build Coastguard Worker */ 137*e1eccf28SAndroid Build Coastguard Worker SRC_OUT = 7, 138*e1eccf28SAndroid Build Coastguard Worker /** 139*e1eccf28SAndroid Build Coastguard Worker * dest = dest * (1.0 - src.a) 140*e1eccf28SAndroid Build Coastguard Worker */ 141*e1eccf28SAndroid Build Coastguard Worker DST_OUT = 8, 142*e1eccf28SAndroid Build Coastguard Worker /** 143*e1eccf28SAndroid Build Coastguard Worker * dest.rgb = src.rgb * dest.a + (1.0 - src.a) * dest.rgb, dest.a = dest.a 144*e1eccf28SAndroid Build Coastguard Worker */ 145*e1eccf28SAndroid Build Coastguard Worker SRC_ATOP = 9, 146*e1eccf28SAndroid Build Coastguard Worker /** 147*e1eccf28SAndroid Build Coastguard Worker * dest = dest.rgb * src.a + (1.0 - dest.a) * src.rgb, dest.a = src.a 148*e1eccf28SAndroid Build Coastguard Worker */ 149*e1eccf28SAndroid Build Coastguard Worker DST_ATOP = 10, 150*e1eccf28SAndroid Build Coastguard Worker /** 151*e1eccf28SAndroid Build Coastguard Worker * dest = {src.r ^ dest.r, src.g ^ dest.g, src.b ^ dest.b, src.a ^ dest.a} 152*e1eccf28SAndroid Build Coastguard Worker * 153*e1eccf28SAndroid Build Coastguard Worker * Note: this is NOT the Porter/Duff XOR mode; this is a bitwise xor. 154*e1eccf28SAndroid Build Coastguard Worker */ 155*e1eccf28SAndroid Build Coastguard Worker XOR = 11, 156*e1eccf28SAndroid Build Coastguard Worker /** 157*e1eccf28SAndroid Build Coastguard Worker * dest = src * dest 158*e1eccf28SAndroid Build Coastguard Worker */ 159*e1eccf28SAndroid Build Coastguard Worker MULTIPLY = 12, 160*e1eccf28SAndroid Build Coastguard Worker /** 161*e1eccf28SAndroid Build Coastguard Worker * dest = min(src + dest, 1.0) 162*e1eccf28SAndroid Build Coastguard Worker */ 163*e1eccf28SAndroid Build Coastguard Worker ADD = 13, 164*e1eccf28SAndroid Build Coastguard Worker /** 165*e1eccf28SAndroid Build Coastguard Worker * dest = max(dest - src, 0.0) 166*e1eccf28SAndroid Build Coastguard Worker */ 167*e1eccf28SAndroid Build Coastguard Worker SUBTRACT = 14 168*e1eccf28SAndroid Build Coastguard Worker }; 169*e1eccf28SAndroid Build Coastguard Worker 170*e1eccf28SAndroid Build Coastguard Worker /** 171*e1eccf28SAndroid Build Coastguard Worker * Blend a source buffer with the destination buffer. 172*e1eccf28SAndroid Build Coastguard Worker * 173*e1eccf28SAndroid Build Coastguard Worker * Blends a source buffer and a destination buffer, placing the result in the destination 174*e1eccf28SAndroid Build Coastguard Worker * buffer. The blending is done pairwise between two corresponding RGBA values found in 175*e1eccf28SAndroid Build Coastguard Worker * each buffer. The mode parameter specifies one of fifteen blending operations. 176*e1eccf28SAndroid Build Coastguard Worker * See {@link BlendingMode}. 177*e1eccf28SAndroid Build Coastguard Worker * 178*e1eccf28SAndroid Build Coastguard Worker * An optional range parameter can be set to restrict the operation to a rectangular subset 179*e1eccf28SAndroid Build Coastguard Worker * of each buffer. If provided, the range must be wholly contained with the dimensions 180*e1eccf28SAndroid Build Coastguard Worker * described by sizeX and sizeY. 181*e1eccf28SAndroid Build Coastguard Worker * 182*e1eccf28SAndroid Build Coastguard Worker * The source and destination buffers must have the same dimensions. Both buffers should be 183*e1eccf28SAndroid Build Coastguard Worker * large enough for sizeX * sizeY * 4 bytes. The buffers have a row-major layout. 184*e1eccf28SAndroid Build Coastguard Worker * 185*e1eccf28SAndroid Build Coastguard Worker * @param mode The specific blending operation to do. 186*e1eccf28SAndroid Build Coastguard Worker * @param source The RGBA input buffer. 187*e1eccf28SAndroid Build Coastguard Worker * @param dest The destination buffer. Used for input and output. 188*e1eccf28SAndroid Build Coastguard Worker * @param sizeX The width of both buffers, as a number of RGBA values. 189*e1eccf28SAndroid Build Coastguard Worker * @param sizeY The height of both buffers, as a number of RGBA values. 190*e1eccf28SAndroid Build Coastguard Worker * @param restriction When not null, restricts the operation to a 2D range of pixels. 191*e1eccf28SAndroid Build Coastguard Worker */ 192*e1eccf28SAndroid Build Coastguard Worker void blend(BlendingMode mode, const uint8_t* _Nonnull source, uint8_t* _Nonnull dst, 193*e1eccf28SAndroid Build Coastguard Worker size_t sizeX, size_t sizeY, const Restriction* _Nullable restriction = nullptr); 194*e1eccf28SAndroid Build Coastguard Worker 195*e1eccf28SAndroid Build Coastguard Worker /** 196*e1eccf28SAndroid Build Coastguard Worker * Blur an image. 197*e1eccf28SAndroid Build Coastguard Worker * 198*e1eccf28SAndroid Build Coastguard Worker * Performs a Gaussian blur of the input image and stores the result in the out buffer. 199*e1eccf28SAndroid Build Coastguard Worker * 200*e1eccf28SAndroid Build Coastguard Worker * The radius determines which pixels are used to compute each blurred pixels. This Toolkit 201*e1eccf28SAndroid Build Coastguard Worker * accepts values between 1 and 25. Larger values create a more blurred effect but also 202*e1eccf28SAndroid Build Coastguard Worker * take longer to compute. When the radius extends past the edge, the edge pixel will 203*e1eccf28SAndroid Build Coastguard Worker * be used as replacement for the pixel that's out off boundary. 204*e1eccf28SAndroid Build Coastguard Worker * 205*e1eccf28SAndroid Build Coastguard Worker * Each input pixel can either be represented by four bytes (RGBA format) or one byte 206*e1eccf28SAndroid Build Coastguard Worker * for the less common blurring of alpha channel only image. 207*e1eccf28SAndroid Build Coastguard Worker * 208*e1eccf28SAndroid Build Coastguard Worker * An optional range parameter can be set to restrict the operation to a rectangular subset 209*e1eccf28SAndroid Build Coastguard Worker * of each buffer. If provided, the range must be wholly contained with the dimensions 210*e1eccf28SAndroid Build Coastguard Worker * described by sizeX and sizeY. 211*e1eccf28SAndroid Build Coastguard Worker * 212*e1eccf28SAndroid Build Coastguard Worker * The input and output buffers must have the same dimensions. Both buffers should be 213*e1eccf28SAndroid Build Coastguard Worker * large enough for sizeX * sizeY * vectorSize bytes. The buffers have a row-major layout. 214*e1eccf28SAndroid Build Coastguard Worker * 215*e1eccf28SAndroid Build Coastguard Worker * @param in The buffer of the image to be blurred. 216*e1eccf28SAndroid Build Coastguard Worker * @param out The buffer that receives the blurred image. 217*e1eccf28SAndroid Build Coastguard Worker * @param sizeX The width of both buffers, as a number of 1 or 4 byte cells. 218*e1eccf28SAndroid Build Coastguard Worker * @param sizeY The height of both buffers, as a number of 1 or 4 byte cells. 219*e1eccf28SAndroid Build Coastguard Worker * @param vectorSize Either 1 or 4, the number of bytes in each cell, i.e. A vs. RGBA. 220*e1eccf28SAndroid Build Coastguard Worker * @param radius The radius of the pixels used to blur. 221*e1eccf28SAndroid Build Coastguard Worker * @param restriction When not null, restricts the operation to a 2D range of pixels. 222*e1eccf28SAndroid Build Coastguard Worker */ 223*e1eccf28SAndroid Build Coastguard Worker void blur(const uint8_t* _Nonnull in, uint8_t* _Nonnull out, size_t sizeX, size_t sizeY, 224*e1eccf28SAndroid Build Coastguard Worker size_t vectorSize, int radius, const Restriction* _Nullable restriction = nullptr); 225*e1eccf28SAndroid Build Coastguard Worker 226*e1eccf28SAndroid Build Coastguard Worker /** 227*e1eccf28SAndroid Build Coastguard Worker * Identity matrix that can be passed to the {@link RenderScriptToolkit::colorMatrix} method. 228*e1eccf28SAndroid Build Coastguard Worker * 229*e1eccf28SAndroid Build Coastguard Worker * Using this matrix will result in no change to the pixel through multiplication although 230*e1eccf28SAndroid Build Coastguard Worker * the pixel value can still be modified by the add vector, or transformed to a different 231*e1eccf28SAndroid Build Coastguard Worker * format. 232*e1eccf28SAndroid Build Coastguard Worker */ 233*e1eccf28SAndroid Build Coastguard Worker static constexpr float kIdentityMatrix[] = { 234*e1eccf28SAndroid Build Coastguard Worker 1.0f, 0.0f, 0.0f, 0.0f, 235*e1eccf28SAndroid Build Coastguard Worker 0.0f, 1.0f, 0.0f, 0.0f, 236*e1eccf28SAndroid Build Coastguard Worker 0.0f, 0.0f, 1.0f, 0.0f, 237*e1eccf28SAndroid Build Coastguard Worker 0.0f, 0.0f, 0.0f, 1.0f 238*e1eccf28SAndroid Build Coastguard Worker }; 239*e1eccf28SAndroid Build Coastguard Worker 240*e1eccf28SAndroid Build Coastguard Worker /** 241*e1eccf28SAndroid Build Coastguard Worker * Matrix to turn color pixels to a grey scale. 242*e1eccf28SAndroid Build Coastguard Worker * 243*e1eccf28SAndroid Build Coastguard Worker * Use this matrix with the {@link RenderScriptToolkit::colorMatrix} method to convert an 244*e1eccf28SAndroid Build Coastguard Worker * image from color to greyscale. 245*e1eccf28SAndroid Build Coastguard Worker */ 246*e1eccf28SAndroid Build Coastguard Worker static constexpr float kGreyScaleColorMatrix[] = { 247*e1eccf28SAndroid Build Coastguard Worker 0.299f, 0.299f, 0.299f, 0.0f, 248*e1eccf28SAndroid Build Coastguard Worker 0.587f, 0.587f, 0.587f, 0.0f, 249*e1eccf28SAndroid Build Coastguard Worker 0.114f, 0.114f, 0.114f, 0.0f, 250*e1eccf28SAndroid Build Coastguard Worker 0.0f, 0.0f, 0.0f, 1.0f 251*e1eccf28SAndroid Build Coastguard Worker }; 252*e1eccf28SAndroid Build Coastguard Worker 253*e1eccf28SAndroid Build Coastguard Worker /** 254*e1eccf28SAndroid Build Coastguard Worker * Matrix to convert RGB to YUV. 255*e1eccf28SAndroid Build Coastguard Worker * 256*e1eccf28SAndroid Build Coastguard Worker * Use this matrix with the {@link RenderScriptToolkit::colorMatrix} method to convert the 257*e1eccf28SAndroid Build Coastguard Worker * first three bytes of each pixel from RGB to YUV. This leaves the last byte (the alpha 258*e1eccf28SAndroid Build Coastguard Worker * channel) untouched. 259*e1eccf28SAndroid Build Coastguard Worker * 260*e1eccf28SAndroid Build Coastguard Worker * This is a simplistic conversion. Most YUV buffers have more complicated format, not supported 261*e1eccf28SAndroid Build Coastguard Worker * by this method. 262*e1eccf28SAndroid Build Coastguard Worker */ 263*e1eccf28SAndroid Build Coastguard Worker static constexpr float kRgbToYuvMatrix[] = { 264*e1eccf28SAndroid Build Coastguard Worker 0.299f, -0.14713f, 0.615f, 0.0f, 265*e1eccf28SAndroid Build Coastguard Worker 0.587f, -0.28886f, -0.51499f, 0.0f, 266*e1eccf28SAndroid Build Coastguard Worker 0.114f, 0.436f, -0.10001f, 0.0f, 267*e1eccf28SAndroid Build Coastguard Worker 0.0f, 0.0f, 0.0f, 1.0f 268*e1eccf28SAndroid Build Coastguard Worker }; 269*e1eccf28SAndroid Build Coastguard Worker 270*e1eccf28SAndroid Build Coastguard Worker /** 271*e1eccf28SAndroid Build Coastguard Worker * Matrix to convert YUV to RGB. 272*e1eccf28SAndroid Build Coastguard Worker * 273*e1eccf28SAndroid Build Coastguard Worker * Use this matrix with the {@link RenderScriptToolkit::colorMatrix} method to convert the 274*e1eccf28SAndroid Build Coastguard Worker * first three bytes of each pixel from YUV to RGB. This leaves the last byte (the alpha 275*e1eccf28SAndroid Build Coastguard Worker * channel) untouched. 276*e1eccf28SAndroid Build Coastguard Worker * 277*e1eccf28SAndroid Build Coastguard Worker * This is a simplistic conversion. Most YUV buffers have more complicated format, not supported 278*e1eccf28SAndroid Build Coastguard Worker * by this method. Use {@link RenderScriptToolkit::yuvToRgb} to convert these buffers. 279*e1eccf28SAndroid Build Coastguard Worker */ 280*e1eccf28SAndroid Build Coastguard Worker static constexpr float kYuvToRgbMatrix[] = { 281*e1eccf28SAndroid Build Coastguard Worker 1.0f, 1.0f, 1.0f, 0.0f, 282*e1eccf28SAndroid Build Coastguard Worker 0.0f, -0.39465f, 2.03211f, 0.0f, 283*e1eccf28SAndroid Build Coastguard Worker 1.13983f, -0.5806f, 0.0f, 0.0f, 284*e1eccf28SAndroid Build Coastguard Worker 0.0f, 0.0f, 0.0f, 1.0f 285*e1eccf28SAndroid Build Coastguard Worker }; 286*e1eccf28SAndroid Build Coastguard Worker 287*e1eccf28SAndroid Build Coastguard Worker /** 288*e1eccf28SAndroid Build Coastguard Worker * Transform an image using a color matrix. 289*e1eccf28SAndroid Build Coastguard Worker * 290*e1eccf28SAndroid Build Coastguard Worker * Converts a 2D array of vectors of unsigned bytes, multiplying each vectors by a 4x4 matrix 291*e1eccf28SAndroid Build Coastguard Worker * and adding an optional vector. 292*e1eccf28SAndroid Build Coastguard Worker * 293*e1eccf28SAndroid Build Coastguard Worker * Each input vector is composed of 1-4 unsigned bytes. If less than 4 bytes, it's extended to 294*e1eccf28SAndroid Build Coastguard Worker * 4, padding with zeroes. The unsigned bytes are converted from 0-255 to 0.0-1.0 floats 295*e1eccf28SAndroid Build Coastguard Worker * before the multiplication is done. 296*e1eccf28SAndroid Build Coastguard Worker * 297*e1eccf28SAndroid Build Coastguard Worker * The resulting value is normalized from 0.0-1.0 to a 0-255 value and stored in the output. 298*e1eccf28SAndroid Build Coastguard Worker * If the output vector size is less than four, the unused channels are discarded. 299*e1eccf28SAndroid Build Coastguard Worker * 300*e1eccf28SAndroid Build Coastguard Worker * If addVector is null, a vector of zeroes is added, i.e. a noop. 301*e1eccf28SAndroid Build Coastguard Worker * 302*e1eccf28SAndroid Build Coastguard Worker * Check kIdentityMatrix, kGreyScaleColorMatrix, kRgbToYuvMatrix, and kYuvToRgbMatrix for sample 303*e1eccf28SAndroid Build Coastguard Worker * matrices. The YUV conversion may not work for all color spaces. 304*e1eccf28SAndroid Build Coastguard Worker * 305*e1eccf28SAndroid Build Coastguard Worker * @param in The buffer of the image to be converted. 306*e1eccf28SAndroid Build Coastguard Worker * @param out The buffer that receives the converted image. 307*e1eccf28SAndroid Build Coastguard Worker * @param inputVectorSize The number of bytes in each input cell, a value from 1 to 4. 308*e1eccf28SAndroid Build Coastguard Worker * @param outputVectorSize The number of bytes in each output cell, a value from 1 to 4. 309*e1eccf28SAndroid Build Coastguard Worker * @param sizeX The width of both buffers, as a number of 1 to 4 byte cells. 310*e1eccf28SAndroid Build Coastguard Worker * @param sizeY The height of both buffers, as a number of 1 to 4 byte cells. 311*e1eccf28SAndroid Build Coastguard Worker * @param matrix The 4x4 matrix to multiply, in row major format. 312*e1eccf28SAndroid Build Coastguard Worker * @param addVector A vector of four floats that's added to the result of the multiplication. 313*e1eccf28SAndroid Build Coastguard Worker * @param restriction When not null, restricts the operation to a 2D range of pixels. 314*e1eccf28SAndroid Build Coastguard Worker */ 315*e1eccf28SAndroid Build Coastguard Worker void colorMatrix(const void* _Nonnull in, void* _Nonnull out, size_t inputVectorSize, 316*e1eccf28SAndroid Build Coastguard Worker size_t outputVectorSize, size_t sizeX, size_t sizeY, 317*e1eccf28SAndroid Build Coastguard Worker const float* _Nonnull matrix, const float* _Nullable addVector = nullptr, 318*e1eccf28SAndroid Build Coastguard Worker const Restriction* _Nullable restriction = nullptr); 319*e1eccf28SAndroid Build Coastguard Worker 320*e1eccf28SAndroid Build Coastguard Worker /** 321*e1eccf28SAndroid Build Coastguard Worker * Convolve a ByteArray. 322*e1eccf28SAndroid Build Coastguard Worker * 323*e1eccf28SAndroid Build Coastguard Worker * Applies a 3x3 or 5x5 convolution to the input array using the provided coefficients. 324*e1eccf28SAndroid Build Coastguard Worker * 325*e1eccf28SAndroid Build Coastguard Worker * For 3x3 convolutions, 9 coefficients must be provided. For 5x5, 25 coefficients are needed. 326*e1eccf28SAndroid Build Coastguard Worker * The coefficients should be provided in row-major format. 327*e1eccf28SAndroid Build Coastguard Worker * 328*e1eccf28SAndroid Build Coastguard Worker * When the square extends past the edge, the edge values will be used as replacement for the 329*e1eccf28SAndroid Build Coastguard Worker * values that's are off boundary. 330*e1eccf28SAndroid Build Coastguard Worker * 331*e1eccf28SAndroid Build Coastguard Worker * Each input cell can either be represented by one to four bytes. Each byte is multiplied 332*e1eccf28SAndroid Build Coastguard Worker * and accumulated independently of the other bytes of the cell. 333*e1eccf28SAndroid Build Coastguard Worker * 334*e1eccf28SAndroid Build Coastguard Worker * An optional range parameter can be set to restrict the operation to a rectangular subset 335*e1eccf28SAndroid Build Coastguard Worker * of each buffer. If provided, the range must be wholly contained with the dimensions 336*e1eccf28SAndroid Build Coastguard Worker * described by sizeX and sizeY. 337*e1eccf28SAndroid Build Coastguard Worker * 338*e1eccf28SAndroid Build Coastguard Worker * The input and output buffers must have the same dimensions. Both buffers should be 339*e1eccf28SAndroid Build Coastguard Worker * large enough for sizeX * sizeY * vectorSize bytes. The buffers have a row-major layout. 340*e1eccf28SAndroid Build Coastguard Worker * 341*e1eccf28SAndroid Build Coastguard Worker * @param in The buffer of the image to be blurred. 342*e1eccf28SAndroid Build Coastguard Worker * @param out The buffer that receives the blurred image. 343*e1eccf28SAndroid Build Coastguard Worker * @param vectorSize The number of bytes in each cell, a value from 1 to 4. 344*e1eccf28SAndroid Build Coastguard Worker * @param sizeX The width of both buffers, as a number of 1 or 4 byte cells. 345*e1eccf28SAndroid Build Coastguard Worker * @param sizeY The height of both buffers, as a number of 1 or 4 byte cells. 346*e1eccf28SAndroid Build Coastguard Worker * @param coefficients 9 or 25 multipliers. 347*e1eccf28SAndroid Build Coastguard Worker * @param restriction When not null, restricts the operation to a 2D range of pixels. 348*e1eccf28SAndroid Build Coastguard Worker */ 349*e1eccf28SAndroid Build Coastguard Worker void convolve3x3(const void* _Nonnull in, void* _Nonnull out, size_t vectorSize, size_t sizeX, 350*e1eccf28SAndroid Build Coastguard Worker size_t sizeY, const float* _Nonnull coefficients, 351*e1eccf28SAndroid Build Coastguard Worker const Restriction* _Nullable restriction = nullptr); 352*e1eccf28SAndroid Build Coastguard Worker 353*e1eccf28SAndroid Build Coastguard Worker void convolve5x5(const void* _Nonnull in, void* _Nonnull out, size_t vectorSize, size_t sizeX, 354*e1eccf28SAndroid Build Coastguard Worker size_t sizeY, const float* _Nonnull coefficients, 355*e1eccf28SAndroid Build Coastguard Worker const Restriction* _Nullable restriction = nullptr); 356*e1eccf28SAndroid Build Coastguard Worker 357*e1eccf28SAndroid Build Coastguard Worker /** 358*e1eccf28SAndroid Build Coastguard Worker * Compute the histogram of an image. 359*e1eccf28SAndroid Build Coastguard Worker * 360*e1eccf28SAndroid Build Coastguard Worker * Tallies how many times each of the 256 possible values of a byte is found in the input. 361*e1eccf28SAndroid Build Coastguard Worker * 362*e1eccf28SAndroid Build Coastguard Worker * An input cell can be represented by one to four bytes. The tally is done independently 363*e1eccf28SAndroid Build Coastguard Worker * for each of the bytes of the cell. Correspondingly, the out array will have 364*e1eccf28SAndroid Build Coastguard Worker * 256 * vectorSize entries. The counts for value 0 are consecutive, followed by those for 365*e1eccf28SAndroid Build Coastguard Worker * value 1, etc. 366*e1eccf28SAndroid Build Coastguard Worker * 367*e1eccf28SAndroid Build Coastguard Worker * An optional range parameter can be set to restrict the operation to a rectangular subset 368*e1eccf28SAndroid Build Coastguard Worker * of each buffer. If provided, the range must be wholly contained with the dimensions 369*e1eccf28SAndroid Build Coastguard Worker * described by sizeX and sizeY. 370*e1eccf28SAndroid Build Coastguard Worker * 371*e1eccf28SAndroid Build Coastguard Worker * The source buffers should be large enough for sizeX * sizeY * vectorSize bytes. The buffers 372*e1eccf28SAndroid Build Coastguard Worker * have a row-major layout. The out buffer should be large enough for 256 * vectorSize ints. 373*e1eccf28SAndroid Build Coastguard Worker * 374*e1eccf28SAndroid Build Coastguard Worker * @param in The buffer of the image to be analyzed. 375*e1eccf28SAndroid Build Coastguard Worker * @param out The resulting vector of counts. 376*e1eccf28SAndroid Build Coastguard Worker * @param sizeX The width of the input buffers, as a number of 1 or 4 byte cells. 377*e1eccf28SAndroid Build Coastguard Worker * @param sizeY The height of the input buffers, as a number of 1 or 4 byte cells. 378*e1eccf28SAndroid Build Coastguard Worker * @param vectorSize The number of bytes in each cell, a value from 1 to 4. 379*e1eccf28SAndroid Build Coastguard Worker * @param restriction When not null, restricts the operation to a 2D range of pixels. 380*e1eccf28SAndroid Build Coastguard Worker */ 381*e1eccf28SAndroid Build Coastguard Worker void histogram(const uint8_t* _Nonnull in, int32_t* _Nonnull out, size_t sizeX, size_t sizeY, 382*e1eccf28SAndroid Build Coastguard Worker size_t vectorSize, const Restriction* _Nullable restriction = nullptr); 383*e1eccf28SAndroid Build Coastguard Worker 384*e1eccf28SAndroid Build Coastguard Worker /** 385*e1eccf28SAndroid Build Coastguard Worker * Compute the histogram of the dot product of an image. 386*e1eccf28SAndroid Build Coastguard Worker * 387*e1eccf28SAndroid Build Coastguard Worker * This method supports cells of 1 to 4 bytes in length. For each cell of the array, 388*e1eccf28SAndroid Build Coastguard Worker * the dot product of its bytes with the provided coefficients is computed. The resulting 389*e1eccf28SAndroid Build Coastguard Worker * floating point value is converted to an unsigned byte and tallied in the histogram. 390*e1eccf28SAndroid Build Coastguard Worker * 391*e1eccf28SAndroid Build Coastguard Worker * If coefficients is null, the coefficients used for RGBA luminosity calculation will be used, 392*e1eccf28SAndroid Build Coastguard Worker * i.e. the values [0.299f, 0.587f, 0.114f, 0.f]. 393*e1eccf28SAndroid Build Coastguard Worker * 394*e1eccf28SAndroid Build Coastguard Worker * Each coefficients must be >= 0 and their sum must be 1.0 or less. There must be the same 395*e1eccf28SAndroid Build Coastguard Worker * number of coefficients as vectorSize. 396*e1eccf28SAndroid Build Coastguard Worker * 397*e1eccf28SAndroid Build Coastguard Worker * An optional range parameter can be set to restrict the operation to a rectangular subset 398*e1eccf28SAndroid Build Coastguard Worker * of each buffer. If provided, the range must be wholly contained with the dimensions 399*e1eccf28SAndroid Build Coastguard Worker * described by sizeX and sizeY. 400*e1eccf28SAndroid Build Coastguard Worker * 401*e1eccf28SAndroid Build Coastguard Worker * The source buffers should be large enough for sizeX * sizeY * vectorSize bytes. The buffers 402*e1eccf28SAndroid Build Coastguard Worker * have a row-major layout. The out array should be large enough for 256 ints. 403*e1eccf28SAndroid Build Coastguard Worker * 404*e1eccf28SAndroid Build Coastguard Worker * @param in The buffer of the image to be analyzed. 405*e1eccf28SAndroid Build Coastguard Worker * @param out The resulting vector of counts. 406*e1eccf28SAndroid Build Coastguard Worker * @param sizeX The width of the input buffers, as a number of 1 or 4 byte cells. 407*e1eccf28SAndroid Build Coastguard Worker * @param sizeY The height of the input buffers, as a number of 1 or 4 byte cells. 408*e1eccf28SAndroid Build Coastguard Worker * @param vectorSize The number of bytes in each cell, a value from 1 to 4. 409*e1eccf28SAndroid Build Coastguard Worker * @param coefficients The values used for the dot product. Can be nullptr. 410*e1eccf28SAndroid Build Coastguard Worker * @param restriction When not null, restricts the operation to a 2D range of pixels. 411*e1eccf28SAndroid Build Coastguard Worker */ 412*e1eccf28SAndroid Build Coastguard Worker void histogramDot(const uint8_t* _Nonnull in, int32_t* _Nonnull out, size_t sizeX, size_t sizeY, 413*e1eccf28SAndroid Build Coastguard Worker size_t vectorSize, const float* _Nullable coefficients, 414*e1eccf28SAndroid Build Coastguard Worker const Restriction* _Nullable restriction = nullptr); 415*e1eccf28SAndroid Build Coastguard Worker 416*e1eccf28SAndroid Build Coastguard Worker /** 417*e1eccf28SAndroid Build Coastguard Worker * Transform an image using a look up table 418*e1eccf28SAndroid Build Coastguard Worker * 419*e1eccf28SAndroid Build Coastguard Worker * Transforms an image by using a per-channel lookup table. Each channel of the input has an 420*e1eccf28SAndroid Build Coastguard Worker * independent lookup table. The tables are 256 entries in size and can cover the full value 421*e1eccf28SAndroid Build Coastguard Worker * range of a byte. 422*e1eccf28SAndroid Build Coastguard Worker * 423*e1eccf28SAndroid Build Coastguard Worker * The input array should be in RGBA format, where four consecutive bytes form an cell. 424*e1eccf28SAndroid Build Coastguard Worker * 425*e1eccf28SAndroid Build Coastguard Worker * An optional range parameter can be set to restrict the operation to a rectangular subset 426*e1eccf28SAndroid Build Coastguard Worker * of each buffer. If provided, the range must be wholly contained with the dimensions 427*e1eccf28SAndroid Build Coastguard Worker * described by sizeX and sizeY. 428*e1eccf28SAndroid Build Coastguard Worker * 429*e1eccf28SAndroid Build Coastguard Worker * The input and output buffers must have the same dimensions. Both buffers should be 430*e1eccf28SAndroid Build Coastguard Worker * large enough for sizeX * sizeY * vectorSize bytes. The buffers have a row-major layout. 431*e1eccf28SAndroid Build Coastguard Worker * 432*e1eccf28SAndroid Build Coastguard Worker * @param in The buffer of the image to be transformed. 433*e1eccf28SAndroid Build Coastguard Worker * @param out The buffer that receives the transformed image. 434*e1eccf28SAndroid Build Coastguard Worker * @param sizeX The width of both buffers, as a number of 4 byte cells. 435*e1eccf28SAndroid Build Coastguard Worker * @param sizeY The height of both buffers, as a number of 4 byte cells. 436*e1eccf28SAndroid Build Coastguard Worker * @param red An array of 256 values that's used to convert the R channel. 437*e1eccf28SAndroid Build Coastguard Worker * @param green An array of 256 values that's used to convert the G channel. 438*e1eccf28SAndroid Build Coastguard Worker * @param blue An array of 256 values that's used to convert the B channel. 439*e1eccf28SAndroid Build Coastguard Worker * @param alpha An array of 256 values that's used to convert the A channel. 440*e1eccf28SAndroid Build Coastguard Worker * @param restriction When not null, restricts the operation to a 2D range of pixels. 441*e1eccf28SAndroid Build Coastguard Worker */ 442*e1eccf28SAndroid Build Coastguard Worker void lut(const uint8_t* _Nonnull in, uint8_t* _Nonnull out, size_t sizeX, size_t sizeY, 443*e1eccf28SAndroid Build Coastguard Worker const uint8_t* _Nonnull red, const uint8_t* _Nonnull green, 444*e1eccf28SAndroid Build Coastguard Worker const uint8_t* _Nonnull blue, const uint8_t* _Nonnull alpha, 445*e1eccf28SAndroid Build Coastguard Worker const Restriction* _Nullable restriction = nullptr); 446*e1eccf28SAndroid Build Coastguard Worker 447*e1eccf28SAndroid Build Coastguard Worker /** 448*e1eccf28SAndroid Build Coastguard Worker * Transform an image using a 3D look up table 449*e1eccf28SAndroid Build Coastguard Worker * 450*e1eccf28SAndroid Build Coastguard Worker * Transforms an image, converting RGB to RGBA by using a 3D lookup table. The incoming R, G, 451*e1eccf28SAndroid Build Coastguard Worker * and B values are normalized to the dimensions of the provided 3D buffer. The eight nearest 452*e1eccf28SAndroid Build Coastguard Worker * values in that 3D buffer are sampled and linearly interpolated. The resulting RGBA entry 453*e1eccf28SAndroid Build Coastguard Worker * is stored in the output. 454*e1eccf28SAndroid Build Coastguard Worker * 455*e1eccf28SAndroid Build Coastguard Worker * The input array should be in RGBA format, where four consecutive bytes form an cell. 456*e1eccf28SAndroid Build Coastguard Worker * The fourth byte of each input cell is ignored. 457*e1eccf28SAndroid Build Coastguard Worker * 458*e1eccf28SAndroid Build Coastguard Worker * An optional range parameter can be set to restrict the operation to a rectangular subset 459*e1eccf28SAndroid Build Coastguard Worker * of each buffer. If provided, the range must be wholly contained with the dimensions 460*e1eccf28SAndroid Build Coastguard Worker * described by sizeX and sizeY. 461*e1eccf28SAndroid Build Coastguard Worker * 462*e1eccf28SAndroid Build Coastguard Worker * The input and output buffers must have the same dimensions. Both buffers should be 463*e1eccf28SAndroid Build Coastguard Worker * large enough for sizeX * sizeY * vectorSize bytes. The buffers have a row-major layout. 464*e1eccf28SAndroid Build Coastguard Worker * 465*e1eccf28SAndroid Build Coastguard Worker * @param in The buffer of the image to be transformed. 466*e1eccf28SAndroid Build Coastguard Worker * @param out The buffer that receives the transformed image. 467*e1eccf28SAndroid Build Coastguard Worker * @param sizeX The width of both buffers, as a number of 4 byte cells. 468*e1eccf28SAndroid Build Coastguard Worker * @param sizeY The height of both buffers, as a number of 4 byte cells. 469*e1eccf28SAndroid Build Coastguard Worker * @param cube The translation cube, in row major-format. 470*e1eccf28SAndroid Build Coastguard Worker * @param cubeSizeX The number of RGBA entries in the cube in the X direction. 471*e1eccf28SAndroid Build Coastguard Worker * @param cubeSizeY The number of RGBA entries in the cube in the Y direction. 472*e1eccf28SAndroid Build Coastguard Worker * @param cubeSizeZ The number of RGBA entries in the cube in the Z direction. 473*e1eccf28SAndroid Build Coastguard Worker * @param restriction When not null, restricts the operation to a 2D range of pixels. 474*e1eccf28SAndroid Build Coastguard Worker */ 475*e1eccf28SAndroid Build Coastguard Worker void lut3d(const uint8_t* _Nonnull in, uint8_t* _Nonnull out, size_t sizeX, size_t sizeY, 476*e1eccf28SAndroid Build Coastguard Worker const uint8_t* _Nonnull cube, size_t cubeSizeX, size_t cubeSizeY, size_t cubeSizeZ, 477*e1eccf28SAndroid Build Coastguard Worker const Restriction* _Nullable restriction = nullptr); 478*e1eccf28SAndroid Build Coastguard Worker 479*e1eccf28SAndroid Build Coastguard Worker /** 480*e1eccf28SAndroid Build Coastguard Worker * Resize an image. 481*e1eccf28SAndroid Build Coastguard Worker * 482*e1eccf28SAndroid Build Coastguard Worker * Resizes an image using bicubic interpolation. 483*e1eccf28SAndroid Build Coastguard Worker * 484*e1eccf28SAndroid Build Coastguard Worker * This method supports cells of 1 to 4 bytes in length. Each byte of the cell is 485*e1eccf28SAndroid Build Coastguard Worker * interpolated independently from the others. 486*e1eccf28SAndroid Build Coastguard Worker * 487*e1eccf28SAndroid Build Coastguard Worker * An optional range parameter can be set to restrict the operation to a rectangular subset 488*e1eccf28SAndroid Build Coastguard Worker * of the output buffer. The corresponding scaled range of the input will be used. If provided, 489*e1eccf28SAndroid Build Coastguard Worker * the range must be wholly contained with the dimensions described by outputSizeX and 490*e1eccf28SAndroid Build Coastguard Worker * outputSizeY. 491*e1eccf28SAndroid Build Coastguard Worker * 492*e1eccf28SAndroid Build Coastguard Worker * The input and output buffers have a row-major layout. Both buffers should be 493*e1eccf28SAndroid Build Coastguard Worker * large enough for sizeX * sizeY * vectorSize bytes. 494*e1eccf28SAndroid Build Coastguard Worker * 495*e1eccf28SAndroid Build Coastguard Worker * @param in The buffer of the image to be resized. 496*e1eccf28SAndroid Build Coastguard Worker * @param out The buffer that receives the resized image. 497*e1eccf28SAndroid Build Coastguard Worker * @param inputSizeX The width of the input buffer, as a number of 1-4 byte cells. 498*e1eccf28SAndroid Build Coastguard Worker * @param inputSizeY The height of the input buffer, as a number of 1-4 byte cells. 499*e1eccf28SAndroid Build Coastguard Worker * @param vectorSize The number of bytes in each cell of both buffers. A value from 1 to 4. 500*e1eccf28SAndroid Build Coastguard Worker * @param outputSizeX The width of the output buffer, as a number of 1-4 byte cells. 501*e1eccf28SAndroid Build Coastguard Worker * @param outputSizeY The height of the output buffer, as a number of 1-4 byte cells. 502*e1eccf28SAndroid Build Coastguard Worker * @param restriction When not null, restricts the operation to a 2D range of pixels. 503*e1eccf28SAndroid Build Coastguard Worker */ 504*e1eccf28SAndroid Build Coastguard Worker void resize(const uint8_t* _Nonnull in, uint8_t* _Nonnull out, size_t inputSizeX, 505*e1eccf28SAndroid Build Coastguard Worker size_t inputSizeY, size_t vectorSize, size_t outputSizeX, size_t outputSizeY, 506*e1eccf28SAndroid Build Coastguard Worker const Restriction* _Nullable restriction = nullptr); 507*e1eccf28SAndroid Build Coastguard Worker 508*e1eccf28SAndroid Build Coastguard Worker /** 509*e1eccf28SAndroid Build Coastguard Worker * The YUV formats supported by yuvToRgb. 510*e1eccf28SAndroid Build Coastguard Worker */ 511*e1eccf28SAndroid Build Coastguard Worker enum class YuvFormat { 512*e1eccf28SAndroid Build Coastguard Worker NV21 = 0x11, 513*e1eccf28SAndroid Build Coastguard Worker YV12 = 0x32315659, 514*e1eccf28SAndroid Build Coastguard Worker }; 515*e1eccf28SAndroid Build Coastguard Worker 516*e1eccf28SAndroid Build Coastguard Worker /** 517*e1eccf28SAndroid Build Coastguard Worker * Convert an image from YUV to RGB. 518*e1eccf28SAndroid Build Coastguard Worker * 519*e1eccf28SAndroid Build Coastguard Worker * Converts an Android YUV buffer to RGB. The input allocation should be 520*e1eccf28SAndroid Build Coastguard Worker * supplied in a supported YUV format as a YUV cell Allocation. 521*e1eccf28SAndroid Build Coastguard Worker * The output is RGBA; the alpha channel will be set to 255. 522*e1eccf28SAndroid Build Coastguard Worker * 523*e1eccf28SAndroid Build Coastguard Worker * Note that for YV12 and a sizeX that's not a multiple of 32, the 524*e1eccf28SAndroid Build Coastguard Worker * RenderScript Intrinsic may not have converted the image correctly. 525*e1eccf28SAndroid Build Coastguard Worker * This Toolkit method should. 526*e1eccf28SAndroid Build Coastguard Worker * 527*e1eccf28SAndroid Build Coastguard Worker * @param in The buffer of the image to be converted. 528*e1eccf28SAndroid Build Coastguard Worker * @param out The buffer that receives the converted image. 529*e1eccf28SAndroid Build Coastguard Worker * @param sizeX The width in pixels of the image. Must be even. 530*e1eccf28SAndroid Build Coastguard Worker * @param sizeY The height in pixels of the image. 531*e1eccf28SAndroid Build Coastguard Worker * @param format Either YV12 or NV21. 532*e1eccf28SAndroid Build Coastguard Worker */ 533*e1eccf28SAndroid Build Coastguard Worker void yuvToRgb(const uint8_t* _Nonnull in, uint8_t* _Nonnull out, size_t sizeX, size_t sizeY, 534*e1eccf28SAndroid Build Coastguard Worker YuvFormat format); 535*e1eccf28SAndroid Build Coastguard Worker }; 536*e1eccf28SAndroid Build Coastguard Worker 537*e1eccf28SAndroid Build Coastguard Worker } // namespace renderscript 538*e1eccf28SAndroid Build Coastguard Worker } // namespace android 539*e1eccf28SAndroid Build Coastguard Worker 540*e1eccf28SAndroid Build Coastguard Worker #endif // ANDROID_RENDERSCRIPT_TOOLKIT_TOOLKIT_H 541