1 /*
<lambda>null2  * Copyright (C) 2021 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 package com.example.testapp
18 
19 import android.renderscript.toolkit.LookupTable
20 import android.renderscript.toolkit.Range2d
21 
22 /**
23  * Reference implementation of a LookUpTable operation.
24  */
25 @ExperimentalUnsignedTypes
26 fun referenceLut(
27     inputArray: ByteArray,
28     sizeX: Int,
29     sizeY: Int,
30     table: LookupTable,
31     restriction: Range2d?
32 ): ByteArray {
33     val input = Vector2dArray(inputArray.asUByteArray(), 4, sizeX, sizeY)
34 
35     val output = input.createSameSized()
36     input.forEach(restriction) { x, y ->
37         val oldValue = input[x, y]
38         val newValue = byteArrayOf(
39             table.red[oldValue[0].toInt()],
40             table.green[oldValue[1].toInt()],
41             table.blue[oldValue[2].toInt()],
42             table.alpha[oldValue[3].toInt()]
43         )
44         output[x, y] = newValue.asUByteArray()
45     }
46     return output.values.asByteArray()
47 }
48 
49