29 #include "nomlib/graphics/scale2x/scale2x.hpp"
34 bool scale2x (
void* source_buffer,
void* destination_buffer,
35 const int32 source_width,
const int32 source_height,
37 const int16 source_pitch, int16 destination_pitch
42 int32 width = source_width;
43 int32 height = source_height;
46 uint16 srcpitch = source_pitch;
50 uint16 dstpitch = destination_pitch;
53 uint8* srcpix =
static_cast<uint8*
> ( source_buffer );
54 uint8* dstpix =
static_cast<uint8*
> ( destination_buffer );
67 uint8 E0, E1, E2, E3, B, D, E, F, H;
69 for ( int32 looph = 0; looph < height; ++looph)
71 for ( int32 loopw = 0; loopw < width; ++loopw)
73 B = *(uint8*)(srcpix + (std::max ( 0, looph - 1 ) * srcpitch ) + ( 1 * loopw ) );
74 D = *(uint8*)(srcpix + ( looph * srcpitch ) + ( 1 * std::max ( 0,loopw - 1 ) ) );
75 E = *(uint8*)(srcpix + ( looph * srcpitch ) + ( 1 * loopw ) );
76 F = *(uint8*)(srcpix + ( looph * srcpitch ) + ( 1 * std::min ( width - 1,loopw + 1 ) ) );
77 H = *(uint8*)(srcpix + ( std::min ( height - 1, looph + 1 ) * srcpitch ) + ( 1 * loopw ) );
79 E0 = D == B && B != F && D != H ? D : E;
80 E1 = B == F && B != D && F != H ? F : E;
81 E2 = D == H && D != B && H != F ? D : E;
82 E3 = H == F && D != H && B != F ? F : E;
84 *(uint8*)(dstpix + looph*2*dstpitch + loopw*2*1) = E0;
85 *(uint8*)(dstpix + looph*2*dstpitch + (loopw*2+1)*1) = E1;
86 *(uint8*)(dstpix + (looph*2+1)*dstpitch + loopw*2*1) = E2;
87 *(uint8*)(dstpix + (looph*2+1)*dstpitch + (loopw*2+1)*1) = E3;
95 uint16 E0, E1, E2, E3, B, D, E, F, H;
97 for ( int32 looph = 0; looph < height; ++looph)
99 for ( int32 loopw = 0; loopw < width; ++loopw)
101 B = *(uint16*)(srcpix + ( std::max ( 0, looph - 1 ) * srcpitch ) + ( 2 * loopw ) );
102 D = *(uint16*)(srcpix + ( looph * srcpitch ) + ( 2 * std::max ( 0, loopw - 1 ) ) );
103 E = *(uint16*)(srcpix + ( looph * srcpitch ) + ( 2 * loopw ) );
104 F = *(uint16*)(srcpix + ( looph * srcpitch ) + ( 2 * std::min ( width - 1, loopw + 1 ) ) );
105 H = *(uint16*)(srcpix + ( std::min ( height - 1, looph + 1 ) * srcpitch ) + ( 2 * loopw ) );
107 E0 = D == B && B != F && D != H ? D : E;
108 E1 = B == F && B != D && F != H ? F : E;
109 E2 = D == H && D != B && H != F ? D : E;
110 E3 = H == F && D != H && B != F ? F : E;
112 *(uint16*)(dstpix + looph*2*dstpitch + loopw*2*2) = E0;
113 *(uint16*)(dstpix + looph*2*dstpitch + (loopw*2+1)*2) = E1;
114 *(uint16*)(dstpix + (looph*2+1)*dstpitch + loopw*2*2) = E2;
115 *(uint16*)(dstpix + (looph*2+1)*dstpitch + (loopw*2+1)*2) = E3;
123 int32 E0, E1, E2, E3, B, D, E, F, H;
125 for ( int32 looph = 0; looph < height; ++looph)
127 for ( int32 loopw = 0; loopw < width; ++loopw)
129 B = SCALE2x_READINT24(srcpix + (std::max(0,looph-1)*srcpitch) + (3*loopw));
130 D = SCALE2x_READINT24(srcpix + (looph*srcpitch) + (3*std::max(0,loopw-1)));
131 E = SCALE2x_READINT24(srcpix + (looph*srcpitch) + (3*loopw));
132 F = SCALE2x_READINT24(srcpix + (looph*srcpitch) + (3*std::min(width-1,loopw+1)));
133 H = SCALE2x_READINT24(srcpix + (std::min(height-1,looph+1)*srcpitch) + (3*loopw));
135 E0 = D == B && B != F && D != H ? D : E;
136 E1 = B == F && B != D && F != H ? F : E;
137 E2 = D == H && D != B && H != F ? D : E;
138 E3 = H == F && D != H && B != F ? F : E;
140 SCALE2x_WRITEINT24((dstpix + looph*2*dstpitch + loopw*2*3), E0);
141 SCALE2x_WRITEINT24((dstpix + looph*2*dstpitch + (loopw*2+1)*3), E1);
142 SCALE2x_WRITEINT24((dstpix + (looph*2+1)*dstpitch + loopw*2*3), E2);
143 SCALE2x_WRITEINT24((dstpix + (looph*2+1)*dstpitch + (loopw*2+1)*3), E3);
151 uint32 E0, E1, E2, E3, B, D, E, F, H;
153 for ( int32 looph = 0; looph < height; ++looph)
155 for ( int32 loopw = 0; loopw < width; ++loopw)
157 B = *(uint32*)(srcpix + (std::max(0,looph-1)*srcpitch) + (4*loopw));
158 D = *(uint32*)(srcpix + (looph*srcpitch) + (4*std::max(0,loopw-1)));
159 E = *(uint32*)(srcpix + (looph*srcpitch) + (4*loopw));
160 F = *(uint32*)(srcpix + (looph*srcpitch) + (4*std::min(width-1,loopw+1)));
161 H = *(uint32*)(srcpix + (std::min(height-1,looph+1)*srcpitch) + (4*loopw));
163 E0 = D == B && B != F && D != H ? D : E;
164 E1 = B == F && B != D && F != H ? F : E;
165 E2 = D == H && D != B && H != F ? D : E;
166 E3 = H == F && D != H && B != F ? F : E;
168 *(uint32*)(dstpix + looph*2*dstpitch + loopw*2*4) = E0;
169 *(uint32*)(dstpix + looph*2*dstpitch + (loopw*2+1)*4) = E1;
170 *(uint32*)(dstpix + (looph*2+1)*dstpitch + loopw*2*4) = E2;
171 *(uint32*)(dstpix + (looph*2+1)*dstpitch + (loopw*2+1)*4) = E3;