1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286
|
/* Framebuffer Graphics Libary for Linux, Copyright 1993 Harm Hanemaayer */
/* scale.c Scaling routine */
#include <stdlib.h>
#include <vga.h>
#include "inlstring.h" /* include inline string operations */
#include "vgagl.h"
#include "def.h"
#if defined (NO_ASSEMBLY)
#undef USE_ASM
#else
/*
* XXX: The asm code needs fixing
#define USE_ASM
*/
#undef USE_ASM
#endif
#ifdef NO_ASSEMBLY
static inline int muldiv64(int m1, int m2, int d)
{
return (long) m1 *(long) m2 / (long) d;
}
#else
/* We use the 32-bit to 64-bit multiply and 64-bit to 32-bit divide of the */
/* 386 (which gcc doesn't know well enough) to efficiently perform integer */
/* scaling without having to worry about overflows. */
static inline int muldiv64(int m1, int m2, int d)
{
/* int32 * int32 -> int64 / int32 -> int32 */
int result;
int dummy;
__asm__(
"imull %%edx\n\t"
"idivl %4\n\t"
: "=a"(result), "=d"(dummy) /* out */
: "0"(m1), "1"(m2), "g"(d) /* in */
/***rjr***: "ax", "dx"***/ /* mod */
);
return result;
}
#endif
/* This is a DDA-based algorithm. */
/* Iteration over target bitmap. */
void gl_scalebox(int w1, int h1, void *_dp1, int w2, int h2, void *_dp2)
{
uchar *dp1 = _dp1;
uchar *dp2 = _dp2;
int xfactor;
int yfactor;
if (w2 == 0 || h2 == 0)
return;
xfactor = muldiv64(w1, 65536, w2); /* scaled by 65536 */
yfactor = muldiv64(h1, 65536, h2); /* scaled by 65536 */
switch (BYTESPERPIXEL) {
case 1:
{
int y, sy;
sy = 0;
for (y = 0; y < h2;) {
int sx = 0;
uchar *dp2old = dp2;
int x;
x = 0;
while (x < w2 - 8) {
#ifdef USE_ASM
/* This saves just a couple of cycles per */
/* pixel on a 486, but I couldn't resist. */
__asm__ __volatile__("movl %4, %%eax\n\t"
"shrl $16, %%eax\n\t"
"addl %5, %4\n\t"
"movb (%3, %%eax), %%al\n\t"
"movb %%al, (%1, %2)\n\t"
"movl %4, %%eax\n\t"
"shrl $16, %%eax\n\t"
"addl %5, %4\n\t"
"movb (%3, %%eax), %%al\n\t"
"movb %%al, 1 (%1, %2)\n\t"
"movl %4, %%eax\n\t"
"shrl $16, %%eax\n\t"
"addl %5, %4\n\t"
"movb (%3, %%eax), %%al\n\t"
"movb %%al, 2 (%1, %2)\n\t"
"movl %4, %%eax\n\t"
"shrl $16, %%eax\n\t"
"addl %5, %4\n\t"
"movb (%3, %%eax), %%al\n\t"
"movb %%al, 3 (%1, %2)\n\t"
"movl %4, %%eax\n\t"
"shrl $16, %%eax\n\t"
"addl %5, %4\n\t"
"movb (%3, %%eax), %%al\n\t"
"movb %%al, 4 (%1, %2)\n\t"
"movl %4, %%eax\n\t"
"shrl $16, %%eax\n\t"
"addl %5, %4\n\t"
"movb (%3, %%eax), %%al\n\t"
"movb %%al, 5 (%1, %2)\n\t"
"movl %4, %%eax\n\t"
"shrl $16, %%eax\n\t"
"addl %5, %4\n\t"
"movb (%3, %%eax), %%al\n\t"
"movb %%al, 6 (%1, %2)\n\t"
"movl %4, %%eax\n\t"
"shrl $16, %%eax\n\t"
"addl %5, %4\n\t"
"movb (%3, %%eax), %%al\n\t"
"movb %%al, 7 (%1, %2)\n\t"
: /* output */
: /* input */
"ax"(0), "r"(dp2), "r"(x), "r"(dp1),
"r"(sx), "r"(xfactor)
:"ax", "4"
);
#else
*(dp2 + x) = *(dp1 + (sx >> 16));
sx += xfactor;
*(dp2 + x + 1) = *(dp1 + (sx >> 16));
sx += xfactor;
*(dp2 + x + 2) = *(dp1 + (sx >> 16));
sx += xfactor;
*(dp2 + x + 3) = *(dp1 + (sx >> 16));
sx += xfactor;
*(dp2 + x + 4) = *(dp1 + (sx >> 16));
sx += xfactor;
*(dp2 + x + 5) = *(dp1 + (sx >> 16));
sx += xfactor;
*(dp2 + x + 6) = *(dp1 + (sx >> 16));
sx += xfactor;
*(dp2 + x + 7) = *(dp1 + (sx >> 16));
sx += xfactor;
#endif
x += 8;
}
while (x < w2) {
*(dp2 + x) = *(dp1 + (sx >> 16));
sx += xfactor;
x++;
}
dp2 += w2;
y++;
while (y < h2) {
int l;
int syint = sy >> 16;
sy += yfactor;
if ((sy >> 16) != syint)
break;
/* Copy identical lines. */
l = dp2 - dp2old;
__memcpy(dp2, dp2old, l);
dp2old = dp2;
dp2 += l;
y++;
}
dp1 = _dp1 + (sy >> 16) * w1;
}
}
break;
case 2:
{
int y, sy;
sy = 0;
for (y = 0; y < h2;) {
int sx = 0;
uchar *dp2old = dp2;
int x;
x = 0;
/* This can be greatly optimized with loop */
/* unrolling; omitted to save space. */
while (x < w2) {
*(unsigned short *) (dp2 + x * 2) =
*(unsigned short *) (dp1 + (sx >> 16) * 2);
sx += xfactor;
x++;
}
dp2 += w2 * 2;
y++;
while (y < h2) {
int l;
int syint = sy >> 16;
sy += yfactor;
if ((sy >> 16) != syint)
break;
/* Copy identical lines. */
l = dp2 - dp2old;
__memcpy(dp2, dp2old, l);
dp2old = dp2;
dp2 += l;
y++;
}
dp1 = _dp1 + (sy >> 16) * w1 * 2;
}
}
break;
case 3:
{
int y, sy;
sy = 0;
for (y = 0; y < h2;) {
int sx = 0;
uchar *dp2old = dp2;
int x;
x = 0;
/* This can be greatly optimized with loop */
/* unrolling; omitted to save space. */
while (x < w2) {
*(unsigned short *) (dp2 + x * 3) =
*(unsigned short *) (dp1 + (sx >> 16) * 3);
*(unsigned char *) (dp2 + x * 3 + 2) =
*(unsigned char *) (dp1 + (sx >> 16) * 3 + 2);
sx += xfactor;
x++;
}
dp2 += w2 * 3;
y++;
while (y < h2) {
int l;
int syint = sy >> 16;
sy += yfactor;
if ((sy >> 16) != syint)
break;
/* Copy identical lines. */
l = dp2 - dp2old;
__memcpy(dp2, dp2old, l);
dp2old = dp2;
dp2 += l;
y++;
}
dp1 = _dp1 + (sy >> 16) * w1 * 3;
}
}
break;
case 4:
{
int y, sy;
sy = 0;
for (y = 0; y < h2;) {
int sx = 0;
uchar *dp2old = dp2;
int x;
x = 0;
/* This can be greatly optimized with loop */
/* unrolling; omitted to save space. */
while (x < w2) {
*(unsigned *) (dp2 + x * 4) =
*(unsigned *) (dp1 + (sx >> 16) * 4);
sx += xfactor;
x++;
}
dp2 += w2 * 4;
y++;
while (y < h2) {
int l;
int syint = sy >> 16;
sy += yfactor;
if ((sy >> 16) != syint)
break;
/* Copy identical lines. */
l = dp2 - dp2old;
__memcpy(dp2, dp2old, l);
dp2old = dp2;
dp2 += l;
y++;
}
dp1 = _dp1 + (sy >> 16) * w1 * 4;
}
}
break;
}
}
|