| /* | |
| * Copyright 2022 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 "samples/risp4ml/common/utils.h" | |
| #include "samples/risp4ml/isp_stages/blc.h" | |
| #include "samples/risp4ml/isp_stages/demosaic.h" | |
| #include "samples/risp4ml/isp_stages/dg.h" | |
| #include "samples/risp4ml/isp_stages/downscale.h" | |
| #include "samples/risp4ml/isp_stages/gamma.h" | |
| #include "samples/risp4ml/isp_stages/wbg.h" | |
| #include "samples/risp4ml/pipeline/pipeline.h" | |
| void isp_pipeline(ImageU8 *input, ImageU8 *output) { | |
| Image *img_bayer = | |
| image_new(input->num_channels, input->height, input->width); | |
| // shift the 8bits wide input to 16bits (the processing pipeline bitwidth) | |
| const uint32_t input_dimensions = | |
| input->num_channels * input->height * input->width; | |
| for (uint32_t i = 0; i < input_dimensions; ++i) { | |
| img_bayer->data[i] = input->data[i] << kRawPipelineFraction; // 8 | |
| } | |
| // black level offset (in-place) | |
| blc_process(img_bayer); | |
| // digital gain (in-place) | |
| dg_process(img_bayer); | |
| // white balance gain (in-place) | |
| wbg_process(img_bayer); | |
| // demosaic | |
| Image *img_color = | |
| image_new(output->num_channels, input->height, input->width); | |
| demosaic_process(img_bayer, img_color); | |
| image_delete(img_bayer); | |
| // gamma correction (in-place) | |
| gamma_process(img_color); | |
| // downscaler | |
| set_downscale_factor(img_color, output); | |
| downscale_process(img_color, output); | |
| image_delete(img_color); | |
| } |