| /* |
| * Copyright 2023 Google LLC |
| * |
| * Licensed under the Apache License, Version 2.0 (the "License"); |
| * you may not use this file except in compliance with the License. |
| * You may obtain a copy of the License at |
| * |
| * http://www.apache.org/licenses/LICENSE-2.0 |
| * |
| * Unless required by applicable law or agreed to in writing, software |
| * distributed under the License is distributed on an "AS IS" BASIS, |
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| * See the License for the specific language governing permissions and |
| * limitations under the License. |
| */ |
| |
| #include <riscv_vector.h> |
| |
| #include "risp4ml/common/utils.h" |
| #include "risp4ml/isp_stages/blc.h" |
| |
| static BlcParams blc_params = {.enable = true, |
| .offsets = {2048, 2048, 2048, 2048}}; |
| |
| void set_blc_params(BlcParams* params) { blc_params = *params; } |
| |
| void blc_process(Image* img) { |
| if (!blc_params.enable) return; |
| |
| size_t vl; |
| size_t n = img->height * img->width * img->num_channels; |
| uint16_t offset = blc_params.offsets[0]; |
| vuint16m8_t vx; // auxiliary variable |
| uint16_t* x; |
| for (size_t i = 0; i < n; i += vl) { |
| x = img->data + i; |
| vl = __riscv_vsetvl_e16m8(n - i); |
| vx = __riscv_vle16_v_u16m8(x, vl); // load |
| vx = __riscv_vssubu(vx, offset, vl); // subtract |
| __riscv_vse16(x, vx, vl); // save |
| } |
| } |