4 #include "rescalers/public.hpp"
11 #include "newpacket.hpp"
16 bool do_quit_on(SDL_Event
* e
)
18 if(e
->type
== SDL_QUIT
)
20 if(e
->type
== SDL_KEYUP
&& e
->key
.keysym
.sym
== 'q')
26 int real_main(int argc
, char** argv
)
29 std::cerr
<< "Syntax: testresizer.exe <picture> <algo> <width> <height>" << std::endl
;
35 unsigned twidth
= strtoul(argv
[3], &ptr1
, 10);
36 unsigned theight
= strtoul(argv
[4], &ptr2
, 10);
37 if(!twidth
|| !theight
|| *ptr1
|| *ptr2
) {
38 std::cerr
<< "Error: Bad target size." << std::endl
;
44 SDL_Surface
* img
= IMG_Load(argv
[1]);
46 std::cerr
<< "Can't load image '" << argv
[1] << "':" << IMG_GetError() << std::endl
;
50 //Convert the SDL surface into raw image.
51 unsigned width
= img
->w
;
52 unsigned height
= img
->h
;
53 image_frame_rgbx
src(width
, height
);
54 unsigned char* pixels
= src
.get_pixels();
56 for(uint32_t y
= 0; y
< height
; y
++)
57 for(uint32_t x
= 0; x
< width
; x
++) {
59 size_t addr
= y
* img
->pitch
+ x
* img
->format
->BytesPerPixel
;
60 if(img
->format
->BytesPerPixel
== 4)
61 SDL_GetRGB(*(Uint32
*)((unsigned char*)img
->pixels
+ addr
), img
->format
, &r
, &g
, &b
);
62 else if(img
->format
->BytesPerPixel
== 3)
63 SDL_GetRGB(*(Uint32
*)((unsigned char*)img
->pixels
+ addr
) & 0xFFFFFF, img
->format
,
65 else if(img
->format
->BytesPerPixel
== 2)
66 SDL_GetRGB(*(Uint16
*)((unsigned char*)img
->pixels
+ addr
), img
->format
, &r
, &g
, &b
);
68 SDL_GetRGB(*(Uint8
*)((unsigned char*)img
->pixels
+ addr
), img
->format
, &r
, &g
, &b
);
69 pixels
[4 * width
* y
+ 4 * x
+ 0] = r
;
70 pixels
[4 * width
* y
+ 4 * x
+ 1] = g
;
71 pixels
[4 * width
* y
+ 4 * x
+ 2] = b
;
72 pixels
[4 * width
* y
+ 4 * x
+ 3] = 0;
74 SDL_UnlockSurface(img
);
77 rescaler_group
grp(*(parse_rescaler_expression(argv
[2]).use_rescaler
));
78 image_frame_rgbx
& dest
= src
.resize(twidth
, theight
, grp
);
80 //Now, display the image.
81 SDL_Surface
* swsurf
= NULL
;
82 SDL_Surface
* hwsurf
= NULL
;
84 if(SDL_Init(SDL_INIT_VIDEO
) < 0) {
85 std::cerr
<< "Can't Initialize SDL." << std::endl
;
89 #if SDL_BYTEORDER == SDL_BIG_ENDIAN
90 uint32_t rmask
= 0xFF000000;
91 uint32_t gmask
= 0x00FF0000;
92 uint32_t bmask
= 0x0000FF00;
94 uint32_t rmask
= 0x000000FF;
95 uint32_t gmask
= 0x0000FF00;
96 uint32_t bmask
= 0x00FF0000;
99 hwsurf
= SDL_SetVideoMode(dest
.get_width(), dest
.get_height(), 0, SDL_SWSURFACE
|
100 SDL_DOUBLEBUF
| SDL_ANYFORMAT
);
101 swsurf
= SDL_CreateRGBSurface(SDL_SWSURFACE
, dest
.get_width(), dest
.get_height(), 32,
102 rmask
, gmask
, bmask
, 0);
103 if(!swsurf
|| !hwsurf
) {
104 std::cerr
<< "Can't Set video mode." << std::endl
;
108 //Copy the picture to surface.
109 SDL_LockSurface(swsurf
);
110 memcpy((unsigned char*)swsurf
->pixels
, dest
.get_pixels(), 4 * twidth
* theight
);
111 SDL_UnlockSurface(swsurf
);
114 SDL_BlitSurface(swsurf
, NULL
, hwsurf
, NULL
);
117 while(SDL_PollEvent(&e
) != 1 || !do_quit_on(&e
));