2 * SDL_zoom - surface scaling
4 * Copyright (c) 2009 Citrix Systems, Inc.
6 * Derived from: SDL_rotozoom, LGPL (c) A. Schiffler from the SDL_gfx library.
7 * Modifications by Stefano Stabellini.
9 * This work is licensed under the terms of the GNU GPL version 2.
10 * See the COPYING file in the top-level directory.
14 #include "qemu/osdep.h"
17 static void sdl_zoom_rgb16(SDL_Surface
*src
, SDL_Surface
*dst
, int smooth
,
19 static void sdl_zoom_rgb32(SDL_Surface
*src
, SDL_Surface
*dst
, int smooth
,
23 #include "sdl_zoom_template.h"
26 #include "sdl_zoom_template.h"
29 int sdl_zoom_blit(SDL_Surface
*src_sfc
, SDL_Surface
*dst_sfc
, int smooth
,
32 SDL_Rect zoom
, src_rect
;
35 /* Grow the size of the modified rectangle to avoid edge artefacts */
36 src_rect
.x
= (in_rect
->x
> 0) ? (in_rect
->x
- 1) : 0;
37 src_rect
.y
= (in_rect
->y
> 0) ? (in_rect
->y
- 1) : 0;
39 src_rect
.w
= in_rect
->w
+ 1;
40 if (src_rect
.x
+ src_rect
.w
> src_sfc
->w
)
41 src_rect
.w
= src_sfc
->w
- src_rect
.x
;
43 src_rect
.h
= in_rect
->h
+ 1;
44 if (src_rect
.y
+ src_rect
.h
> src_sfc
->h
)
45 src_rect
.h
= src_sfc
->h
- src_rect
.y
;
47 /* (x,y) : round down */
48 zoom
.x
= (int)(((float)(src_rect
.x
* dst_sfc
->w
)) / (float)(src_sfc
->w
));
49 zoom
.y
= (int)(((float)(src_rect
.y
* dst_sfc
->h
)) / (float)(src_sfc
->h
));
51 /* (w,h) : round up */
52 zoom
.w
= (int)( ((double)((src_rect
.w
* dst_sfc
->w
) + (src_sfc
->w
- 1))) /
53 (double)(src_sfc
->w
));
55 zoom
.h
= (int)( ((double)((src_rect
.h
* dst_sfc
->h
) + (src_sfc
->h
- 1))) /
56 (double)(src_sfc
->h
));
58 /* Account for any (x,y) rounding by adding one-source-pixel's worth
59 * of destination pixels and then edge checking.
62 extra
= ((dst_sfc
->w
-1) / src_sfc
->w
) + 1;
64 if ((zoom
.x
+ zoom
.w
) < (dst_sfc
->w
- extra
))
67 zoom
.w
= dst_sfc
->w
- zoom
.x
;
69 extra
= ((dst_sfc
->h
-1) / src_sfc
->h
) + 1;
71 if ((zoom
.y
+ zoom
.h
) < (dst_sfc
->h
- extra
))
74 zoom
.h
= dst_sfc
->h
- zoom
.y
;
76 /* The rectangle (zoom.x, zoom.y, zoom.w, zoom.h) is the area on the
77 * destination surface that needs to be updated.
79 if (src_sfc
->format
->BitsPerPixel
== 32)
80 sdl_zoom_rgb32(src_sfc
, dst_sfc
, smooth
, &zoom
);
81 else if (src_sfc
->format
->BitsPerPixel
== 16)
82 sdl_zoom_rgb16(src_sfc
, dst_sfc
, smooth
, &zoom
);
84 fprintf(stderr
, "pixel format not supported\n");
88 /* Return the rectangle of the update to the caller */