check if we have a working C++ compiler
[rofl0r-df-libgraphics.git] / g_src / resize++.h
blob8f9b0976247857924caaa21fb0bc444fcf4585c1
1 /*resize++.cpp :
2 High quality image scaling with Lanczos interpolation method adapted
3 from the Lanczos filtering code available on wikipedia.org.
4 -by David Olsen.
6 There are two methods to use the library, the only difference is in
7 whether the image should be scaled to a specific size in pixels,
8 or be scaled proportionally by a certain percentage(1.0 = 100%).
10 If scale_factor > 1.0 image will be enlarged, < 1.0 will shrink the image
12 All scaling operations will return an image that has been optimized(using
13 SDL_DisplayFormat or SDL_DisplayFormatAlpha, as appropriate) for the
14 current screen mode (Even images that were not resized will return an
15 optimized surface pointer, i.e. scale_factor = 1.0). The SDL_SRCALPHA flag
16 is also set for the returned image, if appropriate.
18 The option to free or not free the source image is given, so that if you
19 desire to make multiple copies of a source image at various sizes,
20 you do not need to reload the image for each operation.
22 The filter variable determines the radius of the Lanczos filter.
23 The following settings can be used:
24 1 = Quickest filtering mode, but when used for enlarging, produces
25 blocky results, similar to the nearest neighbor approach.
26 When used for reductions, it outputs very nice results.
27 2 = Medium filtering mode - slightly faster than 3, but slower than 1.
28 When enlarging, this mode produces high quality results similar
29 to (but a bit better than) bilinear interpolation.
30 3 = The highest quality mode, also the slowest, but only about 30%
31 slower than mode 1. This mode will produce the best enlargements.
32 There is no need for a filter radius greater than 3.
33 The default filtering value passed to the function is 4. Any number
34 greater than 3 will tell the library to automatically choose the quickest
35 filtering mode that still maintains highest quality output. Basically,
36 if you are shrinking an image greatly, it will choose radius of 1.
37 If you shrink an image a little bit, it will choose radius of 2.
38 For all other operations, it will choose a radius of 3.
39 You may therefore specify which filter mode to use manually, if speed
40 is a particular issue, or let it be automatically handled,
41 for highest quality results.
43 The typical usage pattern can be demonstrated as follows:
44 SDL_Surface *image = SDL_LoadBMP("myimage.bmp");
45 image = SDL_Resize(image,320,240); //scale image to 320x240
46 //the original image is freed, and image points to the new scaled surface.
50 SDL_Surface *image = SDL_LoadBMP("myimage.bmp");
51 SDL_Surface *small_image = SDL_Resize(image,0.5f,false); //shrink to 50% size
52 SDL_Surface *big_image = SDL_Resize(image,2.0f,false); //enlarge to 200% size
53 //image still points to the original loaded surface.
55 If you have any questions or comments, feel free to contact me(David Olsen) at:
56 jolynsbass@gmail.com
60 #ifndef __RESIZEpp__
61 #define __RESIZEpp__
63 #include <SDL/SDL.h>
65 SDL_Surface * SDL_Resize(SDL_Surface *src, float scale_factor, bool free_src = true, int filter = 4);
66 SDL_Surface * SDL_Resize(SDL_Surface *src, int new_w, int new_h, bool free_src = true, int filter = 4);
68 #endif