blob: d1666100c8468e75496bd4a6c207bdf2f0468135 [file] [log] [blame]
/*
* 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.
*/
#ifndef SAMPLES_RISP4ML_ISP_STAGES_DOWNSCALE_H_
#define SAMPLES_RISP4ML_ISP_STAGES_DOWNSCALE_H_
#include "samples/risp4ml/common/image.h"
#ifdef __cplusplus
extern "C" {
#endif // __cplusplus
typedef struct {
bool enable;
// scale_precision is the number of fractional bits used for scale factors and
// initial offsets
uint32_t scale_precision;
// interpolate_precision is the number of fractional bits used for
// interpolation weights
uint32_t interpolate_precision;
// interpolate_shift is the shift for pixel value before interpolation to
// avoid rounding error.
uint32_t interpolate_shift;
uint32_t scale_fixed_one;
uint32_t scale_fraction_mask;
uint32_t weight_shift;
// hor_scale_factor and ver_scale_factor are the downscaling ratios between
// input size and output size
// Example: Running the scaler on 4x4 image with hor_scale=2 and ver_scale=2
// will result in 2x2 image
// TODO(b/179302796): convert scaling factors to be floats.
// Use FloatToFixedPoint() to facilitate this.
uint32_t hor_scale_factor;
uint32_t ver_scale_factor;
// hor_initial_offset and ver_initial_offset are the offset of the first
// output pixel from the first input pixel in each direction respectively
uint32_t ver_initial_offset;
uint32_t hor_initial_offset;
} DownscaleParams;
void set_downscale_param(DownscaleParams* params);
void set_downscale_factor(Image* input, ImageU8* output);
void downscale_process(Image* input, ImageU8* output);
#ifdef __cplusplus
} // extern "C"
#endif // __cplusplus
#endif // SAMPLES_RISP4ML_ISP_STAGES_DOWNSCALE_H_