• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2012 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #include <cstdint>
18 
19 #include "RenderScriptToolkit.h"
20 #include "TaskProcessor.h"
21 #include "Utils.h"
22 
23 #define LOG_TAG "renderscript.toolkit.Lut"
24 
25 namespace android {
26 namespace renderscript {
27 
28 class LutTask : public Task {
29     const uchar4* mIn;
30     uchar4* mOut;
31     const uchar* mRedTable;
32     const uchar* mGreenTable;
33     const uchar* mBlueTable;
34     const uchar* mAlphaTable;
35 
36     // Process a 2D tile of the overall work. threadIndex identifies which thread does the work.
37     virtual void processData(int threadIndex, size_t startX, size_t startY, size_t endX,
38                              size_t endY) override;
39 
40    public:
LutTask(const uint8_t * input,uint8_t * output,size_t sizeX,size_t sizeY,const uint8_t * red,const uint8_t * green,const uint8_t * blue,const uint8_t * alpha,const Restriction * restriction)41     LutTask(const uint8_t* input, uint8_t* output, size_t sizeX, size_t sizeY, const uint8_t* red,
42             const uint8_t* green, const uint8_t* blue, const uint8_t* alpha,
43             const Restriction* restriction)
44         : Task{sizeX, sizeY, 4, true, restriction},
45           mIn{reinterpret_cast<const uchar4*>(input)},
46           mOut{reinterpret_cast<uchar4*>(output)},
47           mRedTable{red},
48           mGreenTable{green},
49           mBlueTable{blue},
50           mAlphaTable{alpha} {}
51 };
52 
processData(int,size_t startX,size_t startY,size_t endX,size_t endY)53 void LutTask::processData(int /* threadIndex */, size_t startX, size_t startY, size_t endX,
54                           size_t endY) {
55     for (size_t y = startY; y < endY; y++) {
56         size_t offset = mSizeX * y + startX;
57         const uchar4* in = mIn + offset;
58         uchar4* out = mOut + offset;
59         for (size_t x = startX; x < endX; x++) {
60             auto v = *in;
61             *out = uchar4{mRedTable[v.x], mGreenTable[v.y], mBlueTable[v.z], mAlphaTable[v.w]};
62             in++;
63             out++;
64         }
65     }
66 }
67 
lut(const uint8_t * input,uint8_t * output,size_t sizeX,size_t sizeY,const uint8_t * red,const uint8_t * green,const uint8_t * blue,const uint8_t * alpha,const Restriction * restriction)68 void RenderScriptToolkit::lut(const uint8_t* input, uint8_t* output, size_t sizeX, size_t sizeY,
69                               const uint8_t* red, const uint8_t* green, const uint8_t* blue,
70                               const uint8_t* alpha, const Restriction* restriction) {
71 #ifdef ANDROID_RENDERSCRIPT_TOOLKIT_VALIDATE
72     if (!validRestriction(LOG_TAG, sizeX, sizeY, restriction)) {
73         return;
74     }
75 #endif
76 
77     LutTask task(input, output, sizeX, sizeY, red, green, blue, alpha, restriction);
78     processor->doTask(&task);
79 }
80 
81 }  // namespace renderscript
82 }  // namespace android
83