GCC Code Coverage Report


Directory: avs_core/
Coverage: low: ≥ 0% medium: ≥ 75.0% high: ≥ 90.0%
Coverage Exec / Excl / Total
Lines: 0.0% 0 / 0 / 11
Functions: 0.0% 0 / 0 / 1
Branches: -% 0 / 0 / 0

convert/convert_matrix.h
Line Branch Exec Source
1 // Avisynth v2.5. Copyright 2002 Ben Rudiak-Gould et al.
2 // http://avisynth.nl
3
4 // This program is free software; you can redistribute it and/or modify
5 // it under the terms of the GNU General Public License as published by
6 // the Free Software Foundation; either version 2 of the License, or
7 // (at your option) any later version.
8 //
9 // This program is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU General Public License for more details.
13 //
14 // You should have received a copy of the GNU General Public License
15 // along with this program; if not, write to the Free Software
16 // Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA, or visit
17 // http://www.gnu.org/copyleft/gpl.html .
18 //
19 // Linking Avisynth statically or dynamically with other modules is making a
20 // combined work based on Avisynth. Thus, the terms and conditions of the GNU
21 // General Public License cover the whole combination.
22 //
23 // As a special exception, the copyright holders of Avisynth give you
24 // permission to link Avisynth with independent modules that communicate with
25 // Avisynth solely through the interfaces defined in avisynth.h, regardless of the license
26 // terms of these independent modules, and to copy and distribute the
27 // resulting combined work under terms of your choice, provided that
28 // every copy of the combined work is accompanied by a complete copy of
29 // the source code of Avisynth (the version of Avisynth used to produce the
30 // combined work), being distributed under the terms of the GNU General
31 // Public License plus this exception. An independent module is a module
32 // which is not derived from or based on Avisynth, such as 3rd-party filters,
33 // import and export plugins, or graphical user interfaces.
34
35 #ifndef __Convert_matrix_H__
36 #define __Convert_matrix_H__
37
38 #include "../core/internal.h"
39
40 struct ConversionMatrix {
41 int y_r, y_g, y_b;
42 // for grayscale conversion these may not needed
43 int u_r, u_g, u_b;
44 int v_r, v_g, v_b;
45
46 float y_r_f, y_g_f, y_b_f;
47 float u_r_f, u_g_f, u_b_f;
48 float v_r_f, v_g_f, v_b_f;
49
50 int offset_y;
51 float offset_y_f;
52 int offset_rgb;
53 float offset_rgb_f;
54
55 // and the w/o the y/rgb suffix, supporting yuv-yuv or rgb-rgb fused matrix calculations.
56 int offset_in;
57 float offset_in_f;
58 int offset_out;
59 float offset_out_f;
60
61 // Helper values for exact 32-bit target for hybric calculations, where
62 // conversion to 32-bits is done after the integer-integer conversion.
63 // E.g. yuv X-bit -> rgb X-bit -> rgb 32-bit
64 float target_span_f;
65 float target_span_f_32;
66 float offset_out_f_32;
67 };
68
69 bool GetKrKb(int matrix, double& Kr, double& Kb);
70 bool do_BuildMatrix_Rgb2Yuv(int _Matrix, int _ColorRange, int _ColorRange_Out, int int_arith_shift, int bits_per_pixel, ConversionMatrix& matrix);
71 bool do_BuildMatrix_Yuv2Rgb(int _Matrix, int _ColorRange, int _ColorRange_Out, int int_arith_shift, int bits_per_pixel, ConversionMatrix& matrix);
72
73 /*****************************************************
74 ******* Colorspace Single-Byte Conversions ******
75 ****************************************************/
76
77 // useful to other filters
78 inline int RGB2YUV_Rec601(int rgb) // limited range
79 {
80 const int cyb = int(0.114*219/255*65536+0.5);
81 const int cyg = int(0.587*219/255*65536+0.5);
82 const int cyr = int(0.299*219/255*65536+0.5);
83
84 // y can't overflow
85 int y = (cyb*(rgb&255) + cyg*((rgb>>8)&255) + cyr*((rgb>>16)&255) + 0x108000) >> 16;
86 int scaled_y = (y - 16) * int(255.0/219.0*65536+0.5);
87 int b_y = ((rgb&255) << 16) - scaled_y;
88 int u = ScaledPixelClip((b_y >> 10) * int(1/2.018*1024+0.5) + 0x800000);
89 int r_y = (rgb & 0xFF0000) - scaled_y;
90 int v = ScaledPixelClip((r_y >> 10) * int(1/1.596*1024+0.5) + 0x800000);
91 return ((y*256+u)*256+v) | (rgb & 0xff000000);
92 }
93
94 #endif // __Convert_matrix_H__
95