00001
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026 #ifdef HAVE_CONFIG_H
00027 # include <config.h>
00028 #endif
00029
00030 #include "imagewin.h"
00031 #include "scale.h"
00032 #ifndef ALPHA_LINUX_CXX
00033 # include <cstring>
00034 #endif
00035 #include "exult_types.h"
00036
00037
00038
00039
00040 class Manip8to16
00041 {
00042 protected:
00043 SDL_Color *colors;
00044 SDL_PixelFormat *fmt;
00045 public:
00046 Manip8to16(SDL_Color *c, SDL_PixelFormat *f)
00047 : colors(c), fmt(f)
00048 { }
00049 uint16 rgb(unsigned int r, unsigned int g,
00050 unsigned int b) const
00051 {
00052 return ((r>>fmt->Rloss)<<fmt->Rshift) |
00053 ((g>>fmt->Gloss)<<fmt->Gshift) |
00054 ((b>>fmt->Bloss)<<fmt->Bshift);
00055 }
00056 void copy(uint16& dest, unsigned char src) const
00057 {
00058 SDL_Color& color = colors[src];
00059 dest = rgb(color.r, color.g, color.b);
00060 }
00061 void split_source(unsigned char pix, unsigned int& r,
00062 unsigned int& g, unsigned int& b) const
00063 {
00064 SDL_Color& color = colors[pix];
00065 r = color.r;
00066 g = color.g;
00067 b = color.b;
00068 }
00069 void split_dest(uint16 pix, unsigned int& r,
00070 unsigned int& g, unsigned int& b) const
00071 {
00072 r = ((pix&fmt->Rmask)>>fmt->Rshift)<<fmt->Rloss;
00073 g = ((pix&fmt->Gmask)>>fmt->Gshift)<<fmt->Gloss;
00074 b = ((pix&fmt->Bmask)>>fmt->Bshift)<<fmt->Bloss;
00075 }
00076 };
00077
00078
00079
00080
00081 class Manip8to555 : public Manip8to16
00082 {
00083 public:
00084 Manip8to555(SDL_Color *c) : Manip8to16(c, 0)
00085 { }
00086 uint16 rgb(unsigned int r, unsigned int g,
00087 unsigned int b) const
00088 { return ((r>>3)<<10)|((g>>3)<<5)|(b>>3); }
00089 void copy(uint16& dest, unsigned char src) const
00090 {
00091 SDL_Color& color = colors[src];
00092 dest = rgb(color.r, color.g, color.b);
00093 }
00094 void split_dest(uint16 pix, unsigned int& r,
00095 unsigned int& g, unsigned int& b) const
00096 {
00097 r = (((pix&0x7c00)>>10)<<3);
00098 g = (((pix&0x03e0)>>5)<<3);
00099 b = ((pix&0x001f)<<3);
00100 }
00101 };
00102
00103
00104
00105
00106 class Manip8to565 : public Manip8to16
00107 {
00108 public:
00109 Manip8to565(SDL_Color *c) : Manip8to16(c, 0)
00110 { }
00111 uint16 rgb(unsigned int r, unsigned int g,
00112 unsigned int b) const
00113 { return ((r>>3)<<11)|((g>>2)<<5)|(b>>3); }
00114 void copy(uint16& dest, unsigned char src) const
00115 {
00116 SDL_Color& color = colors[src];
00117 dest = rgb(color.r, color.g, color.b);
00118 }
00119 void split_dest(uint16 pix, unsigned int& r,
00120 unsigned int& g, unsigned int& b) const
00121 {
00122 r = (((pix&0xf800)>>11)<<3);
00123 g = (((pix&0x07e0)>>5)<<2);
00124 b = ((pix&0x001f)<<3);
00125 }
00126 };
00127
00128
00129
00130
00131 class Manip8to32
00132 {
00133 SDL_Color *colors;
00134 SDL_PixelFormat *fmt;
00135 public:
00136 Manip8to32(SDL_Color *c, SDL_PixelFormat *f)
00137 : colors(c), fmt(f)
00138 { }
00139 uint32 rgb(unsigned int r, unsigned int g,
00140 unsigned int b) const
00141 {
00142 return ((r>>fmt->Rloss)<<fmt->Rshift) |
00143 ((g>>fmt->Gloss)<<fmt->Gshift) |
00144 ((b>>fmt->Bloss)<<fmt->Bshift);
00145 }
00146 void copy(uint32& dest, unsigned char src) const
00147 {
00148 SDL_Color& color = colors[src];
00149 dest = rgb(color.r, color.g, color.b);
00150 }
00151 void split_source(unsigned char pix, unsigned int& r,
00152 unsigned int& g, unsigned int& b) const
00153 {
00154 SDL_Color& color = colors[pix];
00155 r = color.r;
00156 g = color.g;
00157 b = color.b;
00158 }
00159 void split_dest(uint32 pix, unsigned int& r,
00160 unsigned int& g, unsigned int& b) const
00161 {
00162 r = ((pix&fmt->Rmask)>>fmt->Rshift)<<fmt->Rloss;
00163 g = ((pix&fmt->Gmask)>>fmt->Gshift)<<fmt->Gloss;
00164 b = ((pix&fmt->Bmask)>>fmt->Bshift)<<fmt->Bloss;
00165 }
00166 };
00167
00168
00169
00170
00171 class Manip16to16
00172 {
00173 public:
00174 static void copy(uint16& dest, uint16 src)
00175 { dest = src; }
00176 static void split_source(uint16 pix, unsigned int& r,
00177 unsigned int& g, unsigned int& b)
00178 {
00179 r = (pix>>10)&0x1f;
00180 g = (pix>>5)&0x1f;
00181 b = pix&0x1f;
00182 }
00183 static void split_dest(uint16 pix, unsigned int& r,
00184 unsigned int& g, unsigned int& b)
00185 { split_source(pix, r, g, b); }
00186 static uint16 rgb(unsigned int r, unsigned int g,
00187 unsigned int b)
00188 { return ((r&0x1f)<<10) | ((g&0x1f)<<5) | (b&0x1f); }
00189 };
00190
00191
00192 inline void increase_area(int& x, int& y, int& w, int& h,
00193 int left, int right, int top, int bottom,
00194 int buf_width, int buf_height)
00195 {
00196 x -= left; w += left+right;
00197 y -= top; h += top+bottom;
00198
00199 if (x < 0) { w += x; x = 0; }
00200 if (y < 0) { h += y; y = 0; }
00201
00202 if (x + w > buf_width) w = buf_width - x;
00203 if (y + h > buf_height) h = buf_height - y;
00204 }
00205
00206
00207
00208
00209
00210
00211
00212
00213 void Image_window::show_scaled8to16_2xSaI
00214 (
00215 int x, int y, int w, int h
00216 )
00217 {
00218 increase_area(x,y,w,h, 2,2,1,1, ibuf->width, ibuf->height);
00219
00220 Manip8to16 manip(surface->format->palette->colors,
00221 scaled_surface->format);
00222 Scale_2xSaI<unsigned char, uint16, Manip8to16>
00223 (ibuf->get_bits(), x, y, w, h,
00224 ibuf->line_width, ibuf->height,
00225 (uint16 *) scaled_surface->pixels,
00226 scaled_surface->pitch/
00227 scaled_surface->format->BytesPerPixel,
00228 manip);
00229 SDL_UpdateRect(scaled_surface, 2*x, 2*y, 2*w, 2*h);
00230 }
00231
00232 void Image_window::show_scaled8to555_2xSaI
00233 (
00234 int x, int y, int w, int h
00235 )
00236 {
00237 increase_area(x,y,w,h, 2,2,1,1, ibuf->width, ibuf->height);
00238
00239 Manip8to555 manip(surface->format->palette->colors);
00240 Scale_2xSaI<unsigned char, uint16, Manip8to555>
00241 (ibuf->get_bits(), x, y, w, h,
00242 ibuf->line_width, ibuf->height,
00243 (uint16 *) scaled_surface->pixels,
00244 scaled_surface->pitch/
00245 scaled_surface->format->BytesPerPixel,
00246 manip);
00247 SDL_UpdateRect(scaled_surface, 2*x, 2*y, 2*w, 2*h);
00248 }
00249
00250 void Image_window::show_scaled8to565_2xSaI
00251 (
00252 int x, int y, int w, int h
00253 )
00254 {
00255 increase_area(x,y,w,h, 2,2,1,1, ibuf->width, ibuf->height);
00256
00257 Manip8to565 manip(surface->format->palette->colors);
00258 Scale_2xSaI<unsigned char, uint16, Manip8to565>
00259 (ibuf->get_bits(), x, y, w, h,
00260 ibuf->line_width, ibuf->height,
00261 (uint16 *) scaled_surface->pixels,
00262 scaled_surface->pitch/
00263 scaled_surface->format->BytesPerPixel,
00264 manip);
00265 SDL_UpdateRect(scaled_surface, 2*x, 2*y, 2*w, 2*h);
00266 }
00267
00268 void Image_window::show_scaled8to32_2xSaI
00269 (
00270 int x, int y, int w, int h
00271 )
00272 {
00273 increase_area(x,y,w,h, 2,2,1,1, ibuf->width, ibuf->height);
00274
00275 Manip8to32 manip(surface->format->palette->colors,
00276 scaled_surface->format);
00277 Scale_2xSaI<unsigned char, uint32, Manip8to32>
00278 (ibuf->get_bits(), x, y, w, h,
00279 ibuf->line_width, ibuf->height,
00280 (uint32 *) scaled_surface->pixels,
00281 scaled_surface->pitch/
00282 scaled_surface->format->BytesPerPixel,
00283 manip);
00284 SDL_UpdateRect(scaled_surface, 2*x, 2*y, 2*w, 2*h);
00285 }
00286
00287
00288
00289
00290
00291 void Image_window::show_scaled8to16_Super2xSaI
00292 (
00293 int x, int y, int w, int h
00294 )
00295 {
00296 increase_area(x,y,w,h, 2,2,1,1, ibuf->width, ibuf->height);
00297
00298 Manip8to16 manip(surface->format->palette->colors,
00299 scaled_surface->format);
00300 Scale_Super2xSaI<unsigned char, uint16, Manip8to16>
00301 (ibuf->get_bits(), x, y, w, h,
00302 ibuf->line_width, ibuf->height,
00303 (uint16 *) scaled_surface->pixels,
00304 scaled_surface->pitch/
00305 scaled_surface->format->BytesPerPixel,
00306 manip);
00307 SDL_UpdateRect(scaled_surface, 2*x, 2*y, 2*w, 2*h);
00308 }
00309
00310 void Image_window::show_scaled8to555_Super2xSaI
00311 (
00312 int x, int y, int w, int h
00313 )
00314 {
00315 increase_area(x,y,w,h, 2,2,1,1, ibuf->width, ibuf->height);
00316
00317 Manip8to555 manip(surface->format->palette->colors);
00318 Scale_Super2xSaI<unsigned char, uint16, Manip8to555>
00319 (ibuf->get_bits(), x, y, w, h,
00320 ibuf->line_width, ibuf->height,
00321 (uint16 *) scaled_surface->pixels,
00322 scaled_surface->pitch/
00323 scaled_surface->format->BytesPerPixel,
00324 manip);
00325 SDL_UpdateRect(scaled_surface, 2*x, 2*y, 2*w, 2*h);
00326 }
00327
00328 void Image_window::show_scaled8to565_Super2xSaI
00329 (
00330 int x, int y, int w, int h
00331 )
00332 {
00333 increase_area(x,y,w,h, 2,2,1,1, ibuf->width, ibuf->height);
00334
00335 Manip8to565 manip(surface->format->palette->colors);
00336 Scale_Super2xSaI<unsigned char, uint16, Manip8to565>
00337 (ibuf->get_bits(), x, y, w, h,
00338 ibuf->line_width, ibuf->height,
00339 (uint16 *) scaled_surface->pixels,
00340 scaled_surface->pitch/
00341 scaled_surface->format->BytesPerPixel,
00342 manip);
00343 SDL_UpdateRect(scaled_surface, 2*x, 2*y, 2*w, 2*h);
00344 }
00345
00346 void Image_window::show_scaled8to32_Super2xSaI
00347 (
00348 int x, int y, int w, int h
00349 )
00350 {
00351 increase_area(x,y,w,h, 2,2,1,1, ibuf->width, ibuf->height);
00352
00353 Manip8to32 manip(surface->format->palette->colors,
00354 scaled_surface->format);
00355 Scale_Super2xSaI<unsigned char, uint32, Manip8to32>
00356 (ibuf->get_bits(), x, y, w, h,
00357 ibuf->line_width, ibuf->height,
00358 (uint32 *) scaled_surface->pixels,
00359 scaled_surface->pitch/
00360 scaled_surface->format->BytesPerPixel,
00361 manip);
00362 SDL_UpdateRect(scaled_surface, 2*x, 2*y, 2*w, 2*h);
00363 }
00364
00365
00366
00367
00368
00369 void Image_window::show_scaled8to16_SuperEagle
00370 (
00371 int x, int y, int w, int h
00372 )
00373 {
00374 increase_area(x,y,w,h, 2,2,1,1, ibuf->width, ibuf->height);
00375
00376 Manip8to16 manip(surface->format->palette->colors,
00377 scaled_surface->format);
00378 Scale_SuperEagle<unsigned char, uint16, Manip8to16>
00379 (ibuf->get_bits(), x, y, w, h,
00380 ibuf->line_width, ibuf->height,
00381 (uint16 *) scaled_surface->pixels,
00382 scaled_surface->pitch/
00383 scaled_surface->format->BytesPerPixel,
00384 manip);
00385 SDL_UpdateRect(scaled_surface, 2*x, 2*y, 2*w, 2*h);
00386 }
00387
00388 void Image_window::show_scaled8to555_SuperEagle
00389 (
00390 int x, int y, int w, int h
00391 )
00392 {
00393 increase_area(x,y,w,h, 2,2,1,1, ibuf->width, ibuf->height);
00394
00395 Manip8to555 manip(surface->format->palette->colors);
00396 Scale_SuperEagle<unsigned char, uint16, Manip8to555>
00397 (ibuf->get_bits(), x, y, w, h,
00398 ibuf->line_width, ibuf->height,
00399 (uint16 *) scaled_surface->pixels,
00400 scaled_surface->pitch/
00401 scaled_surface->format->BytesPerPixel,
00402 manip);
00403 SDL_UpdateRect(scaled_surface, 2*x, 2*y, 2*w, 2*h);
00404 }
00405
00406 void Image_window::show_scaled8to565_SuperEagle
00407 (
00408 int x, int y, int w, int h
00409 )
00410 {
00411 increase_area(x,y,w,h, 2,2,1,1, ibuf->width, ibuf->height);
00412
00413 Manip8to565 manip(surface->format->palette->colors);
00414 Scale_SuperEagle<unsigned char, uint16, Manip8to565>
00415 (ibuf->get_bits(), x, y, w, h,
00416 ibuf->line_width, ibuf->height,
00417 (uint16 *) scaled_surface->pixels,
00418 scaled_surface->pitch/
00419 scaled_surface->format->BytesPerPixel,
00420 manip);
00421 SDL_UpdateRect(scaled_surface, 2*x, 2*y, 2*w, 2*h);
00422 }
00423
00424 void Image_window::show_scaled8to32_SuperEagle
00425 (
00426 int x, int y, int w, int h
00427 )
00428 {
00429 increase_area(x,y,w,h, 2,2,1,1, ibuf->width, ibuf->height);
00430
00431 Manip8to32 manip(surface->format->palette->colors,
00432 scaled_surface->format);
00433 Scale_SuperEagle<unsigned char, uint32, Manip8to32>
00434 (ibuf->get_bits(), x, y, w, h,
00435 ibuf->line_width, ibuf->height,
00436 (uint32 *) scaled_surface->pixels,
00437 scaled_surface->pitch/
00438 scaled_surface->format->BytesPerPixel,
00439 manip);
00440 SDL_UpdateRect(scaled_surface, 2*x, 2*y, 2*w, 2*h);
00441 }
00442
00443
00444
00445
00446 void Image_window::show_scaled8to16_bilinear
00447 (
00448 int x, int y, int w, int h
00449 )
00450 {
00451 increase_area(x,y,w,h, 1,1,1,1, ibuf->width, ibuf->height);
00452
00453 Manip8to16 manip(surface->format->palette->colors,
00454 scaled_surface->format);
00455 Scale_2xBilinear<unsigned char, uint16, Manip8to16>
00456 (ibuf->get_bits(), x, y, w, h,
00457 ibuf->line_width, ibuf->height,
00458 (uint16 *) scaled_surface->pixels,
00459 scaled_surface->pitch/
00460 scaled_surface->format->BytesPerPixel,
00461 manip);
00462 SDL_UpdateRect(scaled_surface, 2*x, 2*y, 2*w, 2*h);
00463 }
00464
00465 void Image_window::show_scaled8to555_bilinear
00466 (
00467 int x, int y, int w, int h
00468 )
00469 {
00470 increase_area(x,y,w,h, 1,1,1,1, ibuf->width, ibuf->height);
00471
00472 Manip8to555 manip(surface->format->palette->colors);
00473 Scale_2xBilinear<unsigned char, uint16, Manip8to555>
00474 (ibuf->get_bits(), x, y, w, h,
00475 ibuf->line_width, ibuf->height,
00476 (uint16 *) scaled_surface->pixels,
00477 scaled_surface->pitch/
00478 scaled_surface->format->BytesPerPixel,
00479 manip);
00480 SDL_UpdateRect(scaled_surface, 2*x, 2*y, 2*w, 2*h);
00481 }
00482
00483 void Image_window::show_scaled8to565_bilinear
00484 (
00485 int x, int y, int w, int h
00486 )
00487 {
00488 increase_area(x,y,w,h, 1,1,1,1, ibuf->width, ibuf->height);
00489
00490 Manip8to565 manip(surface->format->palette->colors);
00491 Scale_2xBilinear<unsigned char, uint16, Manip8to565>
00492 (ibuf->get_bits(), x, y, w, h,
00493 ibuf->line_width, ibuf->height,
00494 (uint16 *) scaled_surface->pixels,
00495 scaled_surface->pitch/
00496 scaled_surface->format->BytesPerPixel,
00497 manip);
00498 SDL_UpdateRect(scaled_surface, 2*x, 2*y, 2*w, 2*h);
00499 }
00500
00501 void Image_window::show_scaled8to32_bilinear
00502 (
00503 int x, int y, int w, int h
00504 )
00505 {
00506 increase_area(x,y,w,h, 1,1,1,1, ibuf->width, ibuf->height);
00507
00508 Manip8to32 manip(surface->format->palette->colors,
00509 scaled_surface->format);
00510 Scale_2xBilinear<unsigned char, uint32, Manip8to32>
00511 (ibuf->get_bits(), x, y, w, h,
00512 ibuf->line_width, ibuf->height,
00513 (uint32 *) scaled_surface->pixels,
00514 scaled_surface->pitch/
00515 scaled_surface->format->BytesPerPixel,
00516 manip);
00517 SDL_UpdateRect(scaled_surface, 2*x, 2*y, 2*w, 2*h);
00518 }
00519
00520
00521
00522
00523 void Image_window::show_scaled8to16_BilinearPlus
00524 (
00525 int x, int y, int w, int h
00526 )
00527 {
00528 increase_area(x,y,w,h, 1,1,1,1, ibuf->width, ibuf->height);
00529
00530 Manip8to16 manip(surface->format->palette->colors,
00531 scaled_surface->format);
00532 Scale_2xBilinearPlus<unsigned char, uint16, Manip8to16>
00533 (ibuf->get_bits(), x, y, w, h,
00534 ibuf->line_width, ibuf->height,
00535 (uint16 *) scaled_surface->pixels,
00536 scaled_surface->pitch/
00537 scaled_surface->format->BytesPerPixel,
00538 manip);
00539 SDL_UpdateRect(scaled_surface, 2*x, 2*y, 2*w, 2*h);
00540 }
00541
00542 void Image_window::show_scaled8to555_BilinearPlus
00543 (
00544 int x, int y, int w, int h
00545 )
00546 {
00547 increase_area(x,y,w,h, 1,1,1,1, ibuf->width, ibuf->height);
00548
00549 Manip8to555 manip(surface->format->palette->colors);
00550 Scale_2xBilinearPlus<unsigned char, uint16, Manip8to555>
00551 (ibuf->get_bits(), x, y, w, h,
00552 ibuf->line_width, ibuf->height,
00553 (uint16 *) scaled_surface->pixels,
00554 scaled_surface->pitch/
00555 scaled_surface->format->BytesPerPixel,
00556 manip);
00557 SDL_UpdateRect(scaled_surface, 2*x, 2*y, 2*w, 2*h);
00558 }
00559
00560 void Image_window::show_scaled8to565_BilinearPlus
00561 (
00562 int x, int y, int w, int h
00563 )
00564 {
00565 increase_area(x,y,w,h, 1,1,1,1, ibuf->width, ibuf->height);
00566
00567 Manip8to565 manip(surface->format->palette->colors);
00568 Scale_2xBilinearPlus<unsigned char, uint16, Manip8to565>
00569 (ibuf->get_bits(), x, y, w, h,
00570 ibuf->line_width, ibuf->height,
00571 (uint16 *) scaled_surface->pixels,
00572 scaled_surface->pitch/
00573 scaled_surface->format->BytesPerPixel,
00574 manip);
00575 SDL_UpdateRect(scaled_surface, 2*x, 2*y, 2*w, 2*h);
00576 }
00577
00578 void Image_window::show_scaled8to32_BilinearPlus
00579 (
00580 int x, int y, int w, int h
00581 )
00582 {
00583 increase_area(x,y,w,h, 1,1,1,1, ibuf->width, ibuf->height);
00584
00585 Manip8to32 manip(surface->format->palette->colors,
00586 scaled_surface->format);
00587 Scale_2xBilinearPlus<unsigned char, uint32, Manip8to32>
00588 (ibuf->get_bits(), x, y, w, h,
00589 ibuf->line_width, ibuf->height,
00590 (uint32 *) scaled_surface->pixels,
00591 scaled_surface->pitch/
00592 scaled_surface->format->BytesPerPixel,
00593 manip);
00594 SDL_UpdateRect(scaled_surface, 2*x, 2*y, 2*w, 2*h);
00595 }
00596
00597
00598
00599
00600 void Image_window::show_scaled_point
00601 (
00602 int x, int y, int w, int h
00603 )
00604 {
00605 Scale_point ((unsigned char *)ibuf->get_bits(), x, y, w, h,
00606 ibuf->line_width, ibuf->height,
00607 (unsigned char *) surface->pixels, surface->pitch,
00608 scale);
00609
00610 SDL_UpdateRect(surface, scale*x, scale*y, scale*w, scale*h);
00611 }
00612
00613
00614
00615
00616 void Image_window::show_scaled_interlace
00617 (
00618 int x, int y, int w, int h
00619 )
00620 {
00621 Scale_interlace ((unsigned char *)ibuf->get_bits(), x, y, w, h,
00622 ibuf->line_width, ibuf->height,
00623 (unsigned char *) surface->pixels, surface->pitch,
00624 scale);
00625
00626 SDL_UpdateRect(surface, scale*x, scale*y, scale*w, scale*h);
00627 }
00628
00629
00630
00631
00632 void Image_window::show_scale2x_noblur
00633 (
00634 int x, int y, int w, int h
00635 )
00636 {
00637 Scale2x_noblur ((unsigned char *)ibuf->get_bits(), x, y, w, h,
00638 ibuf->line_width, ibuf->height,
00639 (unsigned char *) surface->pixels,
00640 surface->pitch
00641 );
00642
00643 SDL_UpdateRect(surface, scale*x, scale*y, scale*w, scale*h);
00644 }
00645
00646
00647
00648
00649
00650 void Image_window::show_scaledOpenGL
00651 (
00652 int x, int y, int w, int h
00653 )
00654 {
00655 SDL_GL_SwapBuffers();
00656 }