24#include <fvutils/color/yuv.h>
25#include <fvutils/scalers/lossy.h>
43 orig_width = orig_height = 0;
44 scal_width = scal_height = 0;
59 if ((factor <= 0) || (factor > 1)) {
62 scale_factor = factor;
65 if (orig_width != 0) {
66 scal_width = (
unsigned int)ceilf(orig_width * scale_factor);
67 scal_width += (scal_width % 2);
69 if (orig_height != 0) {
70 scal_height = (
unsigned int)ceilf(orig_height * scale_factor);
71 scal_height += (scal_width % 2);
88 float scale_factor_width = 1.0;
89 float scale_factor_height = 1.0;
91 if (orig_width != 0) {
92 scale_factor_width = scal_width / float(orig_width);
94 if (orig_height != 0) {
95 scale_factor_height = scal_height / float(orig_height);
99 (scale_factor_width < scale_factor_height) ? scale_factor_width : scale_factor_height;
101 scal_width = (
unsigned int)floorf(orig_width * scale_factor);
102 scal_height = (
unsigned int)floorf(orig_height * scale_factor);
104 scal_width += (scal_width % 2);
105 scal_height += (scal_height % 2);
111 orig_buffer = buffer;
117 scal_buffer = buffer;
143 if (orig_height == 0)
147 if (scal_height == 0)
149 if (orig_buffer == NULL)
151 if (scal_buffer == NULL)
158 float skip = 1 / scale_factor;
159 unsigned char *oyp = orig_buffer;
160 unsigned char *oup = YUV422_PLANAR_U_PLANE(orig_buffer, orig_width, orig_height);
161 unsigned char *ovp = YUV422_PLANAR_V_PLANE(orig_buffer, orig_width, orig_height);
163 unsigned char *syp = scal_buffer;
164 unsigned char *sup = YUV422_PLANAR_U_PLANE(scal_buffer, scal_width, scal_height);
165 unsigned char *svp = YUV422_PLANAR_V_PLANE(scal_buffer, scal_width, scal_height);
167 memset(syp, 0, (
size_t)scal_width * scal_height);
168 memset(sup, 128, (
size_t)scal_width * scal_height);
170 float oh_float = 0.0;
171 float ow_float = 0.0;
173 unsigned int oh_pixel;
174 unsigned int ow_pixel;
175 unsigned int ow_pixel_next;
177 for (
unsigned int h = 0; h < scal_height; ++h) {
178 oh_pixel = (
unsigned int)rint(oh_float);
181 if (oh_pixel >= orig_height) {
182 oh_pixel = orig_height - 1;
184 for (
unsigned int w = 0; w < scal_width; w += 2) {
185 ow_pixel = (
unsigned int)rint(ow_float);
186 ow_pixel_next = (
unsigned int)rint(ow_float + skip);
188 if (ow_pixel >= orig_width) {
189 ow_pixel = orig_width - 1;
192 if (ow_pixel_next >= orig_width) {
193 ow_pixel_next = orig_width - 1;
196 syp[h * scal_width + w] = oyp[oh_pixel * orig_width + ow_pixel];
197 syp[h * scal_width + w + 1] = oyp[oh_pixel * orig_width + ow_pixel_next];
198 sup[(h * scal_width + w) / 2] = (oup[(oh_pixel * orig_width + ow_pixel) / 2]
199 + oup[(oh_pixel * orig_width + ow_pixel_next) / 2])
201 svp[(h * scal_width + w) / 2] = (ovp[(oh_pixel * orig_width + ow_pixel) / 2]
202 + ovp[(oh_pixel * orig_width + ow_pixel_next) / 2])
205 ow_float += 2 * skip;
virtual ~LossyScaler()
Destructor.
virtual void set_scale_factor(float factor)
Set scale factor.
virtual void scale()
Scale image.
virtual unsigned int needed_scaled_height()
Minimum needed height of scaled image depending on factor and original image height.
virtual void set_scaled_dimensions(unsigned int width, unsigned int height)
Set dimenins of scaled image buffer.
virtual void set_original_dimensions(unsigned int width, unsigned int height)
Set original image dimensions.
LossyScaler()
Constructor.
virtual float get_scale_factor()
Returns the scale factor.
virtual unsigned int needed_scaled_width()
Minimum needed width of scaled image depending on factor and original image width.
virtual void set_original_buffer(unsigned char *buffer)
Set original image buffer.
virtual void set_scaled_buffer(unsigned char *buffer)
Set scaled image buffer.