Page MenuHomePhabricator (Chris)

No OneTemporary

Authored By
Unknown
Size
35 KB
Referenced Files
None
Subscribers
None
diff --git a/util/graphics/sdl/xbr.cpp b/util/graphics/sdl/xbr.cpp
index f32b932a..5bc6dfb3 100644
--- a/util/graphics/sdl/xbr.cpp
+++ b/util/graphics/sdl/xbr.cpp
@@ -1,758 +1,801 @@
#ifdef USE_SDL
#include <stdint.h>
#include <SDL.h>
namespace xbr{
/*
Hyllian's 2xBR v3.3b
Copyright (C) 2011, 2012 Hyllian/Jararaca - sergiogdb@gmail.com
- This program is free software; you can redistribute it and/or
- modify it under the terms of the GNU General Public License
- as published by the Free Software Foundation; either version 2
- of the License, or (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program; if not, write to the Free Software
- Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ Changed from GPL to GPL at Hyllians request on 4/6/2013.
+ On 04/06/2013 05:02 AM, paintown-message@paintown.sf.net wrote:
+ > Hi, Kazzmir. It's Hyllian here, xBR author. I'd like to change xBR sources license to LGPL. If you wanna a confirmation, I can post it in byuu's forum.
+
+ LGPL 3 http://www.gnu.org/copyleft/lesser.html
+
+ Everyone is permitted to copy and distribute verbatim copies of this license document, but changing it is not allowed.
+ This version of the GNU Lesser General Public License incorporates the terms and conditions of version 3 of the GNU General Public License, supplemented by the additional permissions listed below.
+
+ 0. Additional Definitions.
+ As used herein, “this License” refers to version 3 of the GNU Lesser General Public License, and the “GNU GPL” refers to version 3 of the GNU General Public License.
+
+ “The Library” refers to a covered work governed by this License, other than an Application or a Combined Work as defined below.
+
+ An “Application” is any work that makes use of an interface provided by the Library, but which is not otherwise based on the Library. Defining a subclass of a class defined by the Library is deemed a mode of using an interface provided by the Library.
+
+ A “Combined Work” is a work produced by combining or linking an Application with the Library. The particular version of the Library with which the Combined Work was made is also called the “Linked Version”.
+
+ The “Minimal Corresponding Source” for a Combined Work means the Corresponding Source for the Combined Work, excluding any source code for portions of the Combined Work that, considered in isolation, are based on the Application, and not on the Linked Version.
+
+ The “Corresponding Application Code” for a Combined Work means the object code and/or source code for the Application, including any data and utility programs needed for reproducing the Combined Work from the Application, but excluding the System Libraries of the Combined Work.
+
+ 1. Exception to Section 3 of the GNU GPL.
+ You may convey a covered work under sections 3 and 4 of this License without being bound by section 3 of the GNU GPL.
+
+ 2. Conveying Modified Versions.
+ If you modify a copy of the Library, and, in your modifications, a facility refers to a function or data to be supplied by an Application that uses the facility (other than as an argument passed when the facility is invoked), then you may convey a copy of the modified version:
+
+ a) under this License, provided that you make a good faith effort to ensure that, in the event an Application does not supply the function or data, the facility still operates, and performs whatever part of its purpose remains meaningful, or
+ b) under the GNU GPL, with none of the additional permissions of this License applicable to that copy.
+ 3. Object Code Incorporating Material from Library Header Files.
+ The object code form of an Application may incorporate material from a header file that is part of the Library. You may convey such object code under terms of your choice, provided that, if the incorporated material is not limited to numerical parameters, data structure layouts and accessors, or small macros, inline functions and templates (ten or fewer lines in length), you do both of the following:
+
+ a) Give prominent notice with each copy of the object code that the Library is used in it and that the Library and its use are covered by this License.
+ b) Accompany the object code with a copy of the GNU GPL and this license document.
+ 4. Combined Works.
+ You may convey a Combined Work under terms of your choice that, taken together, effectively do not restrict modification of the portions of the Library contained in the Combined Work and reverse engineering for debugging such modifications, if you also do each of the following:
+
+ a) Give prominent notice with each copy of the Combined Work that the Library is used in it and that the Library and its use are covered by this License.
+ b) Accompany the Combined Work with a copy of the GNU GPL and this license document.
+ c) For a Combined Work that displays copyright notices during execution, include the copyright notice for the Library among these notices, as well as a reference directing the user to the copies of the GNU GPL and this license document.
+ d) Do one of the following:
+ 0) Convey the Minimal Corresponding Source under the terms of this License, and the Corresponding Application Code in a form suitable for, and under terms that permit, the user to recombine or relink the Application with a modified version of the Linked Version to produce a modified Combined Work, in the manner specified by section 6 of the GNU GPL for conveying Corresponding Source.
+ 1) Use a suitable shared library mechanism for linking with the Library. A suitable mechanism is one that (a) uses at run time a copy of the Library already present on the user's computer system, and (b) will operate properly with a modified version of the Library that is interface-compatible with the Linked Version.
+ e) Provide Installation Information, but only if you would otherwise be required to provide such information under section 6 of the GNU GPL, and only to the extent that such information is necessary to install and execute a modified version of the Combined Work produced by recombining or relinking the Application with a modified version of the Linked Version. (If you use option 4d0, the Installation Information must accompany the Minimal Corresponding Source and Corresponding Application Code. If you use option 4d1, you must provide the Installation Information in the manner specified by section 6 of the GNU GPL for conveying Corresponding Source.)
+ 5. Combined Libraries.
+ You may place library facilities that are a work based on the Library side by side in a single library together with other library facilities that are not Applications and are not covered by this License, and convey such a combined library under terms of your choice, if you do both of the following:
+
+ a) Accompany the combined library with a copy of the same work based on the Library, uncombined with any other library facilities, conveyed under the terms of this License.
+ b) Give prominent notice with the combined library that part of it is a work based on the Library, and explaining where to find the accompanying uncombined form of the same work.
+ 6. Revised Versions of the GNU Lesser General Public License.
+ The Free Software Foundation may publish revised and/or new versions of the GNU Lesser General Public License from time to time. Such new versions will be similar in spirit to the present version, but may differ in detail to address new problems or concerns.
+
+ Each version is given a distinguishing version number. If the Library as you received it specifies that a certain numbered version of the GNU Lesser General Public License “or any later version” applies to it, you have the option of following the terms and conditions either of that published version or of any later version published by the Free Software Foundation. If the Library as you received it does not specify a version number of the GNU Lesser General Public License, you may choose any version of the GNU Lesser General Public License ever published by the Free Software Foundation.
+
+ If the Library as you received it specifies that a proxy can decide whether future versions of the GNU Lesser General Public License shall apply, that proxy's public statement of acceptance of any version is permanent authorization for you to choose that version for the Library.
*/
static unsigned int RGBtoYUV[65536];
static unsigned int tbl_5_to_8[32]={0, 8, 16, 25, 33, 41, 49, 58, 66, 74, 82, 90, 99, 107, 115, 123, 132, 140, 148, 156, 165, 173, 181, 189, 197, 206, 214, 222, 230, 239, 247, 255};
static unsigned int tbl_6_to_8[64]={0, 4, 8, 12, 16, 20, 24, 28, 32, 36, 40, 45, 49, 53, 57, 61, 65, 69, 73, 77, 81, 85, 89, 93, 97, 101, 105, 109, 113, 117, 121, 125, 130, 134, 138, 142, 146, 150, 154, 158, 162, 166, 170, 174, 178, 182, 186, 190, 194, 198, 202, 206, 210, 215, 219, 223, 227, 231, 235, 239, 243, 247, 251, 255};
#define RGB_MASK 0x07E0F81F
#define RED_BLUE_MASK565 0xF81F
#define RED_MASK565 0xF800
#define GREEN_MASK565 0x07E0
#define BLUE_MASK565 0x001F
#define RED_MASK555 0x7C00
#define GREEN_MASK555 0x03E0
#define BLUE_MASK555 0x001F
#define PG_LBMASK565 0xF7DE
#define PG_LBMASK555 0x7BDE
static const unsigned short int pg_red_blue_mask = RED_BLUE_MASK565;
static const unsigned short int pg_red_mask = RED_MASK565;
static const unsigned short int pg_green_mask = GREEN_MASK565;
static const unsigned short int pg_blue_mask = BLUE_MASK565;
static const unsigned short int pg_lbmask = PG_LBMASK565;
#define ALPHA_BLEND_128_W(dst, src) dst = ((src & pg_lbmask) >> 1) + ((dst & pg_lbmask) >> 1)
#define ALPHA_BLEND_32_W(dst, src) \
dst = ( \
(pg_red_blue_mask & ((dst & pg_red_blue_mask) + \
((((src & pg_red_blue_mask) - \
(dst & pg_red_blue_mask))) >>3))) | \
(pg_green_mask & ((dst & pg_green_mask) + \
((((src & pg_green_mask) - \
(dst & pg_green_mask))) >>3))))
#define ALPHA_BLEND_64_W(dst, src) \
dst = ( \
(pg_red_blue_mask & ((dst & pg_red_blue_mask) + \
((((src & pg_red_blue_mask) - \
(dst & pg_red_blue_mask))) >>2))) | \
(pg_green_mask & ((dst & pg_green_mask) + \
((((src & pg_green_mask) - \
(dst & pg_green_mask))) >>2))))
#define ALPHA_BLEND_X_W(dst, src, alpha) \
ts = src; td = dst;\
td = ((td|(td<<16)) & RGB_MASK); ts = ((ts|(ts<<16)) & RGB_MASK);\
td = ((( ( (ts-td)*alpha ) >> 5 ) + td ) & RGB_MASK); \
dst= (td|(td>>16));
#define ALPHA_BLEND_192_W(dst, src) ALPHA_BLEND_X_W(dst, src, 24)
#define ALPHA_BLEND_224_W(dst, src) ALPHA_BLEND_X_W(dst, src, 28)
/*
#define ALPHA_BLEND_192_W(dst, src) \
dst = ( \
(pg_red_blue_mask & ((dst & pg_red_blue_mask) + \
((((src & pg_red_blue_mask) - \
(dst & pg_red_blue_mask)) * 3) >>2))) | \
(pg_green_mask & ((dst & pg_green_mask) + \
((((src & pg_green_mask) - \
(dst & pg_green_mask)) * 3) >>2))))
#define ALPHA_BLEND_224_W(dst, src) \
dst = ( \
(pg_red_blue_mask & ((dst & pg_red_blue_mask) + \
((((src & pg_red_blue_mask) - \
(dst & pg_red_blue_mask)) * 7) >>3))) | \
(pg_green_mask & ((dst & pg_green_mask) + \
((((src & pg_green_mask) - \
(dst & pg_green_mask)) * 7) >>3))))
*/
/* Old alpha blend for separate red/green/blue components */
/*
#define ALPHA_BLEND_32_W(dst, src) \
dst = ( \
(pg_red_mask & ((dst & pg_red_mask) + \
((((src & pg_red_mask) - \
(dst & pg_red_mask))) >>3))) | \
(pg_green_mask & ((dst & pg_green_mask) + \
((((src & pg_green_mask) - \
(dst & pg_green_mask))) >>3))) | \
(pg_blue_mask & ((dst & pg_blue_mask) + \
((((src & pg_blue_mask) - \
(dst & pg_blue_mask))) >>3))) )
#define ALPHA_BLEND_64_W(dst, src) \
dst = ( \
(pg_red_mask & ((dst & pg_red_mask) + \
((((src & pg_red_mask) - \
(dst & pg_red_mask))) >>2))) | \
(pg_green_mask & ((dst & pg_green_mask) + \
((((src & pg_green_mask) - \
(dst & pg_green_mask))) >>2))) | \
(pg_blue_mask & ((dst & pg_blue_mask) + \
((((src & pg_blue_mask) - \
(dst & pg_blue_mask))) >>2))) )
#define ALPHA_BLEND_192_W(dst, src) \
dst = ( \
(pg_red_mask & ((dst & pg_red_mask) + \
((((src & pg_red_mask) - \
(dst & pg_red_mask)) * 192) >>8))) | \
(pg_green_mask & ((dst & pg_green_mask) + \
((((src & pg_green_mask) - \
(dst & pg_green_mask)) * 192) >>8))) | \
(pg_blue_mask & ((dst & pg_blue_mask) + \
((((src & pg_blue_mask) - \
(dst & pg_blue_mask)) * 192) >>8))) )
#define ALPHA_BLEND_224_W(dst, src) \
dst = ( \
(pg_red_mask & ((dst & pg_red_mask) + \
((((src & pg_red_mask) - \
(dst & pg_red_mask)) * 224) >>8))) | \
(pg_green_mask & ((dst & pg_green_mask) + \
((((src & pg_green_mask) - \
(dst & pg_green_mask)) * 224) >>8))) | \
(pg_blue_mask & ((dst & pg_blue_mask) + \
((((src & pg_blue_mask) - \
(dst & pg_blue_mask)) * 224) >>8))) );
*/
#define LEFT_UP_2_2X(N3, N2, N1, PIXEL)\
ALPHA_BLEND_224_W(E[N3], PIXEL); \
ALPHA_BLEND_64_W( E[N2], PIXEL); \
E[N1] = E[N2]; \
#define LEFT_2_2X(N3, N2, PIXEL)\
ALPHA_BLEND_192_W(E[N3], PIXEL); \
ALPHA_BLEND_64_W( E[N2], PIXEL); \
#define UP_2_2X(N3, N1, PIXEL)\
ALPHA_BLEND_192_W(E[N3], PIXEL); \
ALPHA_BLEND_64_W( E[N1], PIXEL); \
#define DIA_2X(N3, PIXEL)\
ALPHA_BLEND_128_W(E[N3], PIXEL); \
#define df(A, B)\
abs((int)(RGBtoYUV[A] - RGBtoYUV[B]))\
#define eq(A, B)\
(df(A, B) < 155)\
#define FILTRO(PE, PI, PH, PF, PG, PC, PD, PB, PA, G5, C4, G0, D0, C1, B1, F4, I4, H5, I5, A0, A1, N0, N1, N2, N3) \
ex = (PE!=PH && PE!=PF); \
if ( ex )\
{\
e = (df(PE,PC)+df(PE,PG)+df(PI,H5)+df(PI,F4))+(df(PH,PF)<<2); \
i = (df(PH,PD)+df(PH,I5)+df(PF,I4)+df(PF,PB))+(df(PE,PI)<<2); \
if ((e<i) && ( !eq(PF,PB) && !eq(PH,PD) || eq(PE,PI) && (!eq(PF,I4) && !eq(PH,I5)) || eq(PE,PG) || eq(PE,PC)) )\
{\
ke=df(PF,PG); ki=df(PH,PC); \
ex2 = (PE!=PC && PB!=PC); ex3 = (PE!=PG && PD!=PG); px = (df(PE,PF) <= df(PE,PH)) ? PF : PH; \
if ( ((ke<<1)<=ki) && ex3 && (ke>=(ki<<1)) && ex2 ) \
{\
LEFT_UP_2_2X(N3, N2, N1, px)\
}\
else if ( ((ke<<1)<=ki) && ex3 ) \
{\
LEFT_2_2X(N3, N2, px);\
}\
else if ( (ke>=(ki<<1)) && ex2 ) \
{\
UP_2_2X(N3, N1, px);\
}\
else \
{\
DIA_2X(N3, px);\
}\
}\
else if (e<=i)\
{\
ALPHA_BLEND_128_W( E[N3], ((df(PE,PF) <= df(PE,PH)) ? PF : PH)); \
}\
}\
static void initialize(){
static int initialized;
if (initialized){
return;
}
initialized = 1;
int format = 0;
if (format == 0){ //565
for (int c = 0; c < 65536; c++){
unsigned int r = tbl_5_to_8[(c & RED_MASK565) >> 11];
unsigned int g = tbl_6_to_8[(c & GREEN_MASK565) >> 5];
unsigned int b = tbl_5_to_8[(c & BLUE_MASK565) ];
unsigned int y = ((r<<4) + (g<<5) + (b<<2));
unsigned int u = ( -r - (g<<1) + (b<<2));
unsigned int v = ((r<<1) - (g<<1) - (b>>1));
RGBtoYUV[c] = y + u + v;
}
} else if (format == 1){ //555
for (int c = 0; c < 65536; c++) {
unsigned int r = tbl_5_to_8[(c & RED_MASK555) >> 10];
unsigned int g = tbl_5_to_8[(c & GREEN_MASK555) >> 5];
unsigned int b = tbl_5_to_8[(c & BLUE_MASK555) ];
unsigned int y = ((r<<4) + (g<<5) + (b<<2));
unsigned int u = ( -r - (g<<1) + (b<<2));
unsigned int v = ((r<<1) - (g<<1) - (b>>1));
RGBtoYUV[c] = y + u + v;
}
}
}
void xbr2x(SDL_Surface * input, SDL_Surface * output){
initialize();
unsigned int e, i, p[10], px;
unsigned int ex, ex2, ex3;
unsigned int ke, ki;
unsigned int ts, td;
int nextOutputLine = output->pitch / 2;
for (int y = 0; y < input->h; y++){
unsigned short int * E = (unsigned short *)((char*) output->pixels + y * output->pitch * 2);
/* middle. the -4 just makes the offsets later on work out */
unsigned short int * sa2 = (unsigned short *)((char*) input->pixels + y * input->pitch - 4);
/* up one */
unsigned short int * sa1 = sa2 - input->pitch / 2;
/* up two */
unsigned short int * sa0 = sa1 - input->pitch / 2;
/* down one */
unsigned short int * sa3 = sa2 + input->pitch / 2;
/* down two */
unsigned short int * sa4 = sa3 + input->pitch / 2;
if (y <= 1){
sa0 = sa1;
if (y == 0){
sa0 = sa1 = sa2;
}
}
if (y >= input->h - 2){
sa4 = sa3;
if (y == input->h - 1){
sa4 = sa3 = sa2;
}
}
unsigned char pprev;
unsigned char pprev2;
pprev = pprev2 = 2;
for (int x = 0; x < input->w; x++){
unsigned short B1 = sa0[2];
unsigned short PB = sa1[2];
unsigned short PE = sa2[2];
unsigned short PH = sa3[2];
unsigned short H5 = sa4[2];
unsigned short A1 = sa0[pprev];
unsigned short PA = sa1[pprev];
unsigned short PD = sa2[pprev];
unsigned short PG = sa3[pprev];
unsigned short G5 = sa4[pprev];
unsigned short A0 = sa1[pprev2];
unsigned short D0 = sa2[pprev2];
unsigned short G0 = sa3[pprev2];
unsigned short C1 = 0;
unsigned short PC = 0;
unsigned short PF = 0;
unsigned short PI = 0;
unsigned short I5 = 0;
unsigned short C4 = 0;
unsigned short F4 = 0;
unsigned short I4 = 0;
if (x >= input->w - 2){
/*
C4 = sa1[3];
F4 = sa2[3];
I4 = sa3[3];
*/
if (x == input->w - 1){
C1 = sa0[2];
PC = sa1[2];
PF = sa2[2];
PI = sa3[2];
I5 = sa4[2];
C4 = sa1[2];
F4 = sa2[2];
I4 = sa3[2];
} else {
C1 = sa0[3];
PC = sa1[3];
PF = sa2[3];
PI = sa3[3];
I5 = sa4[3];
C4 = sa1[3];
F4 = sa2[3];
I4 = sa3[3];
}
} else {
C1 = sa0[3];
PC = sa1[3];
PF = sa2[3];
PI = sa3[3];
I5 = sa4[3];
C4 = sa1[4];
F4 = sa2[4];
I4 = sa3[4];
}
E[0] = E[1] = E[nextOutputLine] = E[nextOutputLine + 1] = PE; // 0, 1, 2, 3
FILTRO(PE, PI, PH, PF, PG, PC, PD, PB, PA, G5, C4, G0, D0, C1, B1, F4, I4, H5, I5, A0, A1, 0, 1, nextOutputLine, nextOutputLine+1);
FILTRO(PE, PC, PF, PB, PI, PA, PH, PD, PG, I4, A1, I5, H5, A0, D0, B1, C1, F4, C4, G5, G0, nextOutputLine, 0, nextOutputLine+1, 1);
FILTRO(PE, PA, PB, PD, PC, PG, PF, PH, PI, C1, G0, C4, F4, G5, H5, D0, A0, B1, A1, I4, I5, nextOutputLine+1, nextOutputLine, 1, 0);
FILTRO(PE, PG, PD, PH, PA, PI, PB, PF, PC, A0, I5, A1, B1, I4, F4, H5, G5, D0, G0, C1, C4, 1, nextOutputLine+1, 0, nextOutputLine);
sa0 += 1;
sa1 += 1;
sa2 += 1;
sa3 += 1;
sa4 += 1;
E += 2;
if (pprev2){
pprev2--;
pprev = 1;
}
}
}
}
#undef FILTRO
#define LEFT_UP_2_3X(N7, N5, N6, N2, N8, PIXEL)\
ALPHA_BLEND_192_W(E[N7], PIXEL); \
ALPHA_BLEND_64_W( E[N6], PIXEL); \
E[N5] = E[N7]; \
E[N2] = E[N6]; \
E[N8] = PIXEL;\
#define LEFT_2_3X(N7, N5, N6, N8, PIXEL)\
ALPHA_BLEND_192_W(E[N7], PIXEL); \
ALPHA_BLEND_64_W( E[N5], PIXEL); \
ALPHA_BLEND_64_W( E[N6], PIXEL); \
E[N8] = PIXEL;\
#define UP_2_3X(N5, N7, N2, N8, PIXEL)\
ALPHA_BLEND_192_W(E[N5], PIXEL); \
ALPHA_BLEND_64_W( E[N7], PIXEL); \
ALPHA_BLEND_64_W( E[N2], PIXEL); \
E[N8] = PIXEL;\
#define DIA_3X(N8, N5, N7, PIXEL)\
ALPHA_BLEND_224_W(E[N8], PIXEL); \
ALPHA_BLEND_32_W(E[N5], PIXEL); \
ALPHA_BLEND_32_W(E[N7], PIXEL); \
#define FILTRO(PE, PI, PH, PF, PG, PC, PD, PB, PA, G5, C4, G0, D0, C1, B1, F4, I4, H5, I5, A0, A1, N0, N1, N2, N3, N4, N5, N6, N7, N8) \
ex = (PE!=PH && PE!=PF); \
if ( ex )\
{\
e = (df(PE,PC)+df(PE,PG)+df(PI,H5)+df(PI,F4))+(df(PH,PF)<<2); \
i = (df(PH,PD)+df(PH,I5)+df(PF,I4)+df(PF,PB))+(df(PE,PI)<<2); \
if ((e<i) && ( !eq(PF,PB) && !eq(PF,PC) || !eq(PH,PD) && !eq(PH,PG) || eq(PE,PI) && (!eq(PF,F4) && !eq(PF,I4) || !eq(PH,H5) && !eq(PH,I5)) || eq(PE,PG) || eq(PE,PC)) )\
{\
ke=df(PF,PG); ki=df(PH,PC); \
ex2 = (PE!=PC && PB!=PC); ex3 = (PE!=PG && PD!=PG); px = (df(PE,PF) <= df(PE,PH)) ? PF : PH; \
if ( ((ke<<1)<=ki) && ex3 && (ke>=(ki<<1)) && ex2 ) \
{\
LEFT_UP_2_3X(N7, N5, N6, N2, N8, px)\
}\
else if ( ((ke<<1)<=ki) && ex3 ) \
{\
LEFT_2_3X(N7, N5, N6, N8, px);\
}\
else if ( (ke>=(ki<<1)) && ex2 ) \
{\
UP_2_3X(N5, N7, N2, N8, px);\
}\
else \
{\
DIA_3X(N8, N5, N7, px);\
}\
}\
else if (e<=i)\
{\
ALPHA_BLEND_128_W( E[N8], ((df(PE,PF) <= df(PE,PH)) ? PF : PH)); \
}\
}\
void xbr3x(SDL_Surface * input, SDL_Surface * output){
initialize();
const int nl = output->pitch / 2;
const int nl1 = nl + nl;
unsigned int ts, td;
for (int y = 0; y < input->h; y++){
unsigned short int * E = (unsigned short *)((char*) output->pixels + y * output->pitch * 3);
/* middle. the -4 just makes the offsets later on work out */
unsigned short int * sa2 = (unsigned short *)((char*) input->pixels + y * input->pitch - 4);
/* up one */
unsigned short int * sa1 = sa2 - input->pitch / 2;
/* up two */
unsigned short int * sa0 = sa1 - input->pitch / 2;
/* down one */
unsigned short int * sa3 = sa2 + input->pitch / 2;
/* down two */
unsigned short int * sa4 = sa3 + input->pitch / 2;
if (y <= 1){
sa0 = sa1;
if (y == 0){
sa0 = sa1 = sa2;
}
}
if (y >= input->h - 2){
sa4 = sa3;
if (y == input->h - 1){
sa4 = sa3 = sa2;
}
}
unsigned char pprev;
unsigned char pprev2;
pprev = pprev2 = 2;
for (int x = 0; x < input->w; x++){
unsigned short B1 = sa0[2];
unsigned short PB = sa1[2];
unsigned short PE = sa2[2];
unsigned short PH = sa3[2];
unsigned short H5 = sa4[2];
unsigned short A1 = sa0[pprev];
unsigned short PA = sa1[pprev];
unsigned short PD = sa2[pprev];
unsigned short PG = sa3[pprev];
unsigned short G5 = sa4[pprev];
unsigned short A0 = sa1[pprev2];
unsigned short D0 = sa2[pprev2];
unsigned short G0 = sa3[pprev2];
unsigned short C1 = 0;
unsigned short PC = 0;
unsigned short PF = 0;
unsigned short PI = 0;
unsigned short I5 = 0;
unsigned short C4 = 0;
unsigned short F4 = 0;
unsigned short I4 = 0;
if (x >= input->w - 2){
if (x == input->w - 1){
C1 = sa0[2];
PC = sa1[2];
PF = sa2[2];
PI = sa3[2];
I5 = sa4[2];
C4 = sa1[2];
F4 = sa2[2];
I4 = sa3[2];
} else {
C1 = sa0[3];
PC = sa1[3];
PF = sa2[3];
PI = sa3[3];
I5 = sa4[3];
C4 = sa1[3];
F4 = sa2[3];
I4 = sa3[3];
}
} else {
C1 = sa0[3];
PC = sa1[3];
PF = sa2[3];
PI = sa3[3];
I5 = sa4[3];
C4 = sa1[4];
F4 = sa2[4];
I4 = sa3[4];
}
unsigned int e, i, p[10], px;
unsigned int ex, ex2, ex3;
unsigned int ke, ki;
E[0] = E[1] = E[2] = PE;
E[nl] = E[nl+1] = E[nl+2] = PE; // 3, 4, 5
E[nl1] = E[nl1+1] = E[nl1+2] = PE; // 6, 7, 8
FILTRO(PE, PI, PH, PF, PG, PC, PD, PB, PA, G5, C4, G0, D0, C1, B1, F4, I4, H5, I5, A0, A1, 0, 1, 2, nl, nl+1, nl+2, nl1, nl1+1, nl1+2);
FILTRO(PE, PC, PF, PB, PI, PA, PH, PD, PG, I4, A1, I5, H5, A0, D0, B1, C1, F4, C4, G5, G0, nl1, nl, 0, nl1+1, nl+1, 1, nl1+2, nl+2, 2);
FILTRO(PE, PA, PB, PD, PC, PG, PF, PH, PI, C1, G0, C4, F4, G5, H5, D0, A0, B1, A1, I4, I5, nl1+2, nl1+1, nl1, nl+2, nl+1, nl, 2, 1, 0);
FILTRO(PE, PG, PD, PH, PA, PI, PB, PF, PC, A0, I5, A1, B1, I4, F4, H5, G5, D0, G0, C1, C4, 2, nl+2, nl1+2, 1, nl+1, nl1+1, 0, nl, nl1);
sa0 += 1;
sa1 += 1;
sa2 += 1;
sa3 += 1;
sa4 += 1;
E += 3;
if (pprev2){
pprev2--;
pprev = 1;
}
}
}
}
#undef FILTRO
#define LEFT_UP_2(N15, N14, N11, N13, N12, N10, N7, N3, PIXEL)\
ALPHA_BLEND_192_W(E[N13], PIXEL); \
ALPHA_BLEND_64_W( E[N12], PIXEL); \
E[N15] = E[N14] = E[N11] = PIXEL; \
E[N10] = E[N3] = E[N12]; \
E[N7] = E[N13]; \
#define LEFT_2(N15, N14, N11, N13, N12, N10, PIXEL)\
ALPHA_BLEND_192_W(E[N11], PIXEL); \
ALPHA_BLEND_192_W(E[N13], PIXEL); \
ALPHA_BLEND_64_W( E[N10], PIXEL); \
ALPHA_BLEND_64_W( E[N12], PIXEL); \
E[N14] = PIXEL; \
E[N15] = PIXEL; \
#define UP_2(N15, N14, N11, N3, N7, N10, PIXEL)\
ALPHA_BLEND_192_W(E[N14], PIXEL); \
ALPHA_BLEND_192_W(E[N7 ], PIXEL); \
ALPHA_BLEND_64_W( E[N10], PIXEL); \
ALPHA_BLEND_64_W( E[N3 ], PIXEL); \
E[N11] = PIXEL; \
E[N15] = PIXEL; \
#define DIA(N15, N14, N11, PIXEL)\
ALPHA_BLEND_128_W(E[N11], PIXEL); \
ALPHA_BLEND_128_W(E[N14], PIXEL); \
E[N15] = PIXEL; \
#define FILTRO(PE, PI, PH, PF, PG, PC, PD, PB, PA, G5, C4, G0, D0, C1, B1, F4, I4, H5, I5, A0, A1, N15, N14, N11, N3, N7, N10, N13, N12, N9, N6, N2, N1, N5, N8, N4, N0) \
ex = (PE!=PH && PE!=PF); \
if ( ex )\
{\
e = (df(PE,PC)+df(PE,PG)+df(PI,H5)+df(PI,F4))+(df(PH,PF)<<2); \
i = (df(PH,PD)+df(PH,I5)+df(PF,I4)+df(PF,PB))+(df(PE,PI)<<2); \
if ((e<i) && ( !eq(PF,PB) && !eq(PH,PD) || eq(PE,PI) && (!eq(PF,I4) && !eq(PH,I5)) || eq(PE,PG) || eq(PE,PC)) )\
{\
ke=df(PF,PG); ki=df(PH,PC); \
ex2 = (PE!=PC && PB!=PC); ex3 = (PE!=PG && PD!=PG); px = (df(PE,PF) <= df(PE,PH)) ? PF : PH; \
if ( ((ke<<1)<=ki) && ex3 && (ke>=(ki<<1)) && ex2 ) \
{\
LEFT_UP_2(N15, N14, N11, N13, N12, N10, N7, N3, px)\
}\
else if ( ((ke<<1)<=ki) && ex3 ) \
{\
LEFT_2(N15, N14, N11, N13, N12, N10, px)\
}\
else if ( (ke>=(ki<<1)) && ex2 ) \
{\
UP_2(N15, N14, N11, N3, N7, N10, px)\
}\
else \
{\
DIA(N15, N14, N11, px)\
}\
}\
else if (e<=i)\
{\
ALPHA_BLEND_128_W( E[N15], ((df(PE,PF) <= df(PE,PH)) ? PF : PH)); \
}\
}\
void xbr4x(SDL_Surface * input, SDL_Surface * output){
initialize();
const int nl = output->pitch / 2;
const int nl1 = nl + nl;
const int nl2 = nl1 + nl;
unsigned int ts, td;
for (int y = 0; y < input->h; y++){
unsigned short int * E = (unsigned short *)((char*) output->pixels + y * output->pitch * 4);
/* middle. the -4 just makes the offsets later on work out */
unsigned short int * sa2 = (unsigned short *)((char*) input->pixels + y * input->pitch - 4);
/* up one */
unsigned short int * sa1 = sa2 - input->pitch / 2;
/* up two */
unsigned short int * sa0 = sa1 - input->pitch / 2;
/* down one */
unsigned short int * sa3 = sa2 + input->pitch / 2;
/* down two */
unsigned short int * sa4 = sa3 + input->pitch / 2;
if (y <= 1){
sa0 = sa1;
if (y == 0){
sa0 = sa1 = sa2;
}
}
if (y >= input->h - 2){
sa4 = sa3;
if (y == input->h - 1){
sa4 = sa3 = sa2;
}
}
unsigned char pprev;
unsigned char pprev2;
pprev = pprev2 = 2;
for (int x = 0; x < input->w; x++){
unsigned short B1 = sa0[2];
unsigned short PB = sa1[2];
unsigned short PE = sa2[2];
unsigned short PH = sa3[2];
unsigned short H5 = sa4[2];
unsigned short A1 = sa0[pprev];
unsigned short PA = sa1[pprev];
unsigned short PD = sa2[pprev];
unsigned short PG = sa3[pprev];
unsigned short G5 = sa4[pprev];
unsigned short A0 = sa1[pprev2];
unsigned short D0 = sa2[pprev2];
unsigned short G0 = sa3[pprev2];
unsigned short C1 = 0;
unsigned short PC = 0;
unsigned short PF = 0;
unsigned short PI = 0;
unsigned short I5 = 0;
unsigned short C4 = 0;
unsigned short F4 = 0;
unsigned short I4 = 0;
if (x >= input->w - 2){
if (x == input->w - 1){
C1 = sa0[2];
PC = sa1[2];
PF = sa2[2];
PI = sa3[2];
I5 = sa4[2];
C4 = sa1[2];
F4 = sa2[2];
I4 = sa3[2];
} else {
C1 = sa0[3];
PC = sa1[3];
PF = sa2[3];
PI = sa3[3];
I5 = sa4[3];
C4 = sa1[3];
F4 = sa2[3];
I4 = sa3[3];
}
} else {
C1 = sa0[3];
PC = sa1[3];
PF = sa2[3];
PI = sa3[3];
I5 = sa4[3];
C4 = sa1[4];
F4 = sa2[4];
I4 = sa3[4];
}
unsigned int e, i, p[10], px;
unsigned int ex, ex2, ex3;
unsigned int ke, ki;
E[0] = E[1] = E[2] = E[3] = PE;
E[nl] = E[nl+1] = E[nl+2] = E[nl+3] = PE; // 4, 5, 6, 7
E[nl1] = E[nl1+1] = E[nl1+2] = E[nl1+3] = PE; // 8, 9, 10, 11
E[nl2] = E[nl2+1] = E[nl2+2] = E[nl2+3] = PE; // 12, 13, 14, 15
FILTRO(PE, PI, PH, PF, PG, PC, PD, PB, PA, G5, C4, G0, D0, C1, B1, F4, I4, H5, I5, A0, A1, nl2+3, nl2+2, nl1+3, 3, nl+3, nl1+2, nl2+1, nl2, nl1+1, nl+2, 2, 1, nl+1, nl1, nl, 0);
FILTRO(PE, PC, PF, PB, PI, PA, PH, PD, PG, I4, A1, I5, H5, A0, D0, B1, C1, F4, C4, G5, G0, 3, nl+3, 2, 0, 1, nl+2, nl1+3, nl2+3, nl1+2, nl+1, nl, nl1, nl1+1,nl2+2,nl2+1,nl2);
FILTRO(PE, PA, PB, PD, PC, PG, PF, PH, PI, C1, G0, C4, F4, G5, H5, D0, A0, B1, A1, I4, I5, 0, 1, nl, nl2, nl1, nl+1, 2, 3, nl+2, nl1+1, nl2+1,nl2+2,nl1+2, nl+3,nl1+3,nl2+3);
FILTRO(PE, PG, PD, PH, PA, PI, PB, PF, PC, A0, I5, A1, B1, I4, F4, H5, G5, D0, G0, C1, C4, nl2, nl1, nl2+1, nl2+3, nl2+2, nl1+1, nl, 0, nl+1, nl1+2, nl1+3, nl+3, nl+2, 1, 2, 3);
sa0 += 1;
sa1 += 1;
sa2 += 1;
sa3 += 1;
sa4 += 1;
E += 4;
if (pprev2){
pprev2--;
pprev = 1;
}
}
}
}
#undef FILTRO
}
#endif

File Metadata

Mime Type
text/x-diff
Expires
Fri, Jun 19, 8:06 PM (1 w, 2 d ago)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
71404
Default Alt Text
(35 KB)

Event Timeline