1
/* Copyright (C) 2005 Ole André Vadla Ravnås <oleavr@gmail.com>
3
* This library is free software; you can redistribute it and/or
4
* modify it under the terms of the GNU Lesser General Public
5
* License as published by the Free Software Foundation; either
6
* version 2.1 of the License, or (at your option) any later version.
8
* This library is distributed in the hope that it will be useful,
9
* but WITHOUT ANY WARRANTY; without even the implied warranty of
10
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11
* Lesser General Public License for more details.
13
* You should have received a copy of the GNU Lesser General Public
14
* License along with this library; if not, write to the Free Software
15
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18
#include "mimic-private.h"
21
#define GREEN_INDEX_1 1
22
#define BLUE_INDEX_1 2
25
#define GREEN_INDEX_2 4
26
#define BLUE_INDEX_2 5
31
* Internal helper-function used to convert an image
32
* from RGB 24-bpp packed-pixel to YUV420 planar.
34
void _rgb_to_yuv(const guchar *input_rgb,
43
for (y = 0; y < height; y += 2) {
45
const guchar *src1, *src2;
46
guchar *dst1, *dst2, *dst3, *dst4;
49
src1 = input_rgb + ((height - 1 - y) * width * 3);
50
src2 = input_rgb + ((height - 2 - y) * width * 3);
52
dst1 = output_y + (y * width);
53
dst2 = output_y + ((y + 1) * width);
54
dst3 = output_cb + ((y / 2) * (width / 2));
55
dst4 = output_cr + ((y / 2) * (width / 2));
59
for (x = 0; x < num_cols; x++) {
61
gint expr1, expr2, expr3, expr4, expr5, v;
63
expr1 = (src1[BLUE_INDEX_1] * 19595) + (src1[GREEN_INDEX_1] * 38470) + (src1[RED_INDEX_1] * 7471);
64
expr2 = (src1[BLUE_INDEX_2] * 19595) + (src1[GREEN_INDEX_2] * 38470) + (src1[RED_INDEX_2] * 7471);
65
expr3 = (src2[BLUE_INDEX_1] * 19595) + (src2[GREEN_INDEX_1] * 38470) + (src2[RED_INDEX_1] * 7471);
66
expr4 = (src2[BLUE_INDEX_2] * 19595) + (src2[GREEN_INDEX_2] * 38470) + (src2[RED_INDEX_2] * 7471);
68
expr5 = expr1 + expr2 + expr3 + expr4;
70
dst1[0] = expr1 >> 16;
71
dst1[1] = expr2 >> 16;
72
dst2[0] = expr3 >> 16;
73
dst2[1] = expr4 >> 16;
75
v = (((src1[BLUE_INDEX_1] + src1[BLUE_INDEX_2] + src2[BLUE_INDEX_1] + src2[BLUE_INDEX_2]) << 16) - expr5 + 131071) >> 16;
76
dst3[0] = _clamp_value(((v * 57475) >> 18) + 128);
78
v = (((src1[RED_INDEX_1] + src1[RED_INDEX_2] + src2[RED_INDEX_1] + src2[RED_INDEX_2]) << 16) - expr5 + 131071) >> 16;
79
dst4[0] = ((v * 32244) >> 18) + 128;
98
* Internal helper-function used to convert an image
99
* from YUV420 planar to RGB 24-bpp packed-pixel.
101
void _yuv_to_rgb(const guchar *input_y,
102
const guchar *input_cb,
103
const guchar *input_cr,
108
const guchar *src_y, *src_cb, *src_cr;
110
guint i, j, rgb_stride;
116
rgb_stride = width * 3;
117
dst_rgb = output_rgb + (rgb_stride * (height - 1));
119
for (i = 0; i < height; i++) {
120
const guchar *p_y, *p_cb, *p_cr;
129
for (j = 0; j < width; j++) {
132
v = ((p_y[0] * 65536) + ((p_cr[0] - 128) * 133169)) / 65536;
133
p_rgb[0] = _clamp_value(v);
135
v = ((p_y[0] * 65536) - ((p_cr[0] - 128) * 25821) - ((p_cb[0] - 128) * 38076)) / 65536;
136
p_rgb[1] = _clamp_value(v);
138
v = ((p_y[0] * 65536) + ((p_cb[0] - 128) * 74711)) / 65536;
139
p_rgb[2] = _clamp_value(v);
142
if ((j + 1) % 2 == 0) {
151
if ((i + 1) % 2 == 0) {
152
src_cb += (width + 1) / 2;
153
src_cr += (width + 1) / 2;
156
dst_rgb -= rgb_stride;