10 #include "newpacket.hpp"
13 int real_main(int argc
, char** argv
)
16 std::cerr
<< "Syntax: testresizer.exe <picture> <algo> <width> <height>" << std::endl
;
22 unsigned twidth
= strtoul(argv
[3], &ptr1
, 10);
23 unsigned theight
= strtoul(argv
[4], &ptr2
, 10);
24 if(!twidth
|| !theight
|| *ptr1
|| *ptr2
) {
25 std::cerr
<< "Error: Bad target size." << std::endl
;
31 SDL_Surface
* img
= IMG_Load(argv
[1]);
33 std::cerr
<< "Can't load image '" << argv
[1] << "':" << IMG_GetError() << std::endl
;
37 //Convert the SDL surface into raw image.
38 unsigned width
= img
->w
;
39 unsigned height
= img
->h
;
40 image_frame_rgbx
src(width
, height
);
41 unsigned char* pixels
= src
.get_pixels();
43 for(uint32_t y
= 0; y
< height
; y
++)
44 for(uint32_t x
= 0; x
< width
; x
++) {
46 size_t addr
= y
* img
->pitch
+ x
* img
->format
->BytesPerPixel
;
47 SDL_GetRGB(*(Uint32
*)((unsigned char*)img
->pixels
+ addr
), img
->format
, &r
, &g
, &b
);
48 pixels
[4 * width
* y
+ 4 * x
+ 0] = r
;
49 pixels
[4 * width
* y
+ 4 * x
+ 1] = g
;
50 pixels
[4 * width
* y
+ 4 * x
+ 2] = b
;
51 pixels
[4 * width
* y
+ 4 * x
+ 3] = 0;
53 SDL_UnlockSurface(img
);
56 resizer
& r
= resizer_factory::make_by_type(argv
[2]);
57 image_frame_rgbx
& dest
= src
.resize(twidth
, theight
, r
);
59 //Now, display the image.
60 SDL_Surface
* swsurf
= NULL
;
61 SDL_Surface
* hwsurf
= NULL
;
63 if(SDL_Init(SDL_INIT_VIDEO
) < 0) {
64 std::cerr
<< "Can't Initialize SDL." << std::endl
;
68 #if SDL_BYTEORDER == SDL_BIG_ENDIAN
69 uint32_t rmask
= 0xFF000000;
70 uint32_t gmask
= 0x00FF0000;
71 uint32_t bmask
= 0x0000FF00;
73 uint32_t rmask
= 0x000000FF;
74 uint32_t gmask
= 0x0000FF00;
75 uint32_t bmask
= 0x00FF0000;
78 hwsurf
= SDL_SetVideoMode(dest
.get_width(), dest
.get_height(), 0, SDL_SWSURFACE
|
79 SDL_DOUBLEBUF
| SDL_ANYFORMAT
);
80 swsurf
= SDL_CreateRGBSurface(SDL_SWSURFACE
, dest
.get_width(), dest
.get_height(), 32,
81 rmask
, gmask
, bmask
, 0);
82 if(!swsurf
|| !hwsurf
) {
83 std::cerr
<< "Can't Set video mode." << std::endl
;
87 //Copy the picture to surface.
88 SDL_LockSurface(swsurf
);
89 memcpy((unsigned char*)swsurf
->pixels
, dest
.get_pixels(), 4 * twidth
* theight
);
90 SDL_UnlockSurface(swsurf
);
93 SDL_BlitSurface(swsurf
, NULL
, hwsurf
, NULL
);
96 while(SDL_PollEvent(&e
) != 1 || e
.type
!= SDL_QUIT
);