1 /*
2 * geo_mapper.cpp - geometry mapper implementation
3 *
4 * Copyright (c) 2017 Intel Corporation
5 *
6 * Licensed under the Apache License, Version 2.0 (the "License");
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
9 *
10 * http://www.apache.org/licenses/LICENSE-2.0
11 *
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
17 *
18 * Author: Wind Yuan <feng.yuan@intel.com>
19 */
20
21 #include "geo_mapper.h"
22
23 namespace XCam {
24
GeoMapper()25 GeoMapper::GeoMapper ()
26 : _out_width (0)
27 , _out_height (0)
28 , _factor_x (0.0f)
29 , _factor_y (0.0f)
30 {}
31
~GeoMapper()32 GeoMapper::~GeoMapper ()
33 {
34 }
35
36 bool
set_factors(float x,float y)37 GeoMapper::set_factors (float x, float y)
38 {
39 XCAM_FAIL_RETURN (
40 ERROR, !XCAM_DOUBLE_EQUAL_AROUND (x, 0.0f) && !XCAM_DOUBLE_EQUAL_AROUND (y, 0.0f), false,
41 "GeoMapper set factors failed. (x:%.3f, h:%.3f)", x, y);
42 _factor_x = x;
43 _factor_y = y;
44
45 return true;
46 }
47
48 bool
set_output_size(uint32_t width,uint32_t height)49 GeoMapper::set_output_size (uint32_t width, uint32_t height)
50 {
51 XCAM_FAIL_RETURN (
52 ERROR, width && height, false,
53 "GeoMapper set output size failed. (w:%d, h:%d)",
54 width, height);
55
56 _out_width = width;
57 _out_height = height;
58 return true;
59 }
60
61 bool
auto_calculate_factors(uint32_t lut_w,uint32_t lut_h)62 GeoMapper::auto_calculate_factors (uint32_t lut_w, uint32_t lut_h)
63 {
64 XCAM_FAIL_RETURN (
65 ERROR, _out_width > 1 && _out_height > 1, false,
66 "GeoMapper auto calculate factors failed. output size was not set. (w:%d, h:%d)",
67 _out_width, _out_height);
68 XCAM_FAIL_RETURN (
69 ERROR, lut_w > 1 && lut_w > 1, false,
70 "GeoMapper auto calculate factors failed. lookuptable size need > 1. but set with (w:%d, h:%d)",
71 lut_w, lut_h);
72
73 XCAM_ASSERT (lut_w && lut_h);
74 _factor_x = (_out_width - 1.0f) / (lut_w - 1.0f);
75 _factor_y = (_out_height - 1.0f) / (lut_h - 1.0f);
76 return true;
77 }
78
79 }
80