Debian Codegraph @

src/gui/render_templates_hq.h

raw symbols SCIP
1 /*
2 * Copyright (C) 2002-2010 The DOSBox Team
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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
17 */
18
19 /*
20 * The HQ3x high quality 3x graphics filter.
21 * Original author Maxim Stepin (see http://www.hiend3d.com/hq3x.html).
22 * Adapted for DOSBox from ScummVM and HiEnd3D code by Kronuz.
23 */
24
25 #include <stdlib.h>
26
27 #ifndef RENDER_TEMPLATES_HQNX_TABLE_H
28 #define RENDER_TEMPLATES_HQNX_TABLE_H
29
30 static Bit32u *_RGBtoYUV = 0;
31 static inline bool diffYUV(Bit32u yuv1, Bit32u yuv2)
32 {
33 static const Bit32u Ymask = 0x00FF0000;
34 static const Bit32u Umask = 0x0000FF00;
35 static const Bit32u Vmask = 0x000000FF;
36 static const Bit32u trY = 0x00300000;
37 static const Bit32u trU = 0x00000700;
38 static const Bit32u trV = 0x00000006;
39
40 Bit32u diff;
41 Bit32u mask;
42
43 diff = ((yuv1 & Ymask) - (yuv2 & Ymask));
44 mask = ((Bit32s)diff) >> 31; // ~1/-1 if value < 0, 0 otherwise
45 diff = (diff ^ mask) - mask; //-1: ~value + 1; 0: value
46 if (diff > trY) return true;
47
48 diff = ((yuv1 & Umask) - (yuv2 & Umask));
49 mask = ((Bit32s)diff)>> 31; // ~1/-1 if value < 0, 0 otherwise
50 diff = (diff ^ mask) - mask; //-1: ~value + 1; 0: value
51 if (diff > trU) return true;
52
53 diff = ((yuv1 & Vmask) - (yuv2 & Vmask));
54 mask = ((Bit32s)diff) >> 31; // ~1/-1 if value < 0, 0 otherwise
55 diff = (diff ^ mask) - mask; //-1: ~value + 1; 0: value
56 if (diff > trV) return true;
57
58 return false;
59 }
60
61 #endif
62
63 static inline void conc2d(InitLUTs,SBPP)(void)
64 {
65 int r, g, b;
66 int Y, u, v;
67
68 _RGBtoYUV = (Bit32u *)malloc(65536 * sizeof(Bit32u));
69
70 for (int color = 0; color < 65536; ++color) {
71 #if SBPP == 32
72 r = ((color & 0xF800) >> 11) << (8 - 5);
73 g = ((color & 0x07E0) >> 5) << (8 - 6);
74 b = ((color & 0x001F) >> 0) << (8 - 5);
75 #else
76 r = ((color & redMask) >> redShift) << (8 - redBits);
77 g = ((color & greenMask) >> greenShift) << (8 - greenBits);
78 b = ((color & blueMask) >> blueShift) << (8 - blueBits);
79 #endif
80 Y = (r + g + b) >> 2;
81 u = 128 + ((r - b) >> 2);
82 v = 128 + ((-r + 2 * g - b) >> 3);
83 _RGBtoYUV[color] = (Y << 16) | (u << 8) | v;
84 }
85 }