filters/gp_filter_resize_alloc: Check w and h
[gfxprim.git] / doc / filters_resize.txt
blob768b83599ba2d89f5dd4ec8d7df9e7ac33c8e08f
1 Resize filters
2 --------------
4 Common API
5 ~~~~~~~~~~
7 [source,c]
8 -------------------------------------------------------------------------------
9 #include <gfxprim.h>
10 /* or */
11 #include <filters/GP_Resize.h>
13 typedef enum gp_interpolation_type {
14         GP_INTERP_NN,            /* Nearest Neighbour                         */
15         GP_INTERP_LINEAR_INT,    /* Bilinear - fixed point arithmetics        */
16         GP_INTERP_LINEAR_LF_INT, /* Bilinear + low pass filter on downscaling */
17         GP_INTERP_CUBIC,         /* Bicubic                                   */
18         GP_INTERP_CUBIC_INT,     /* Bicubic - fixed point arithmetics         */
19         GP_INTERP_MAX = GP_INTERP_CUBIC_INT,
20 } gp_interpolation_type;
22 const char *gp_interpolation_type_name(enum gp_interpolation_type interp_type);
24 int gp_filter_resize(const gp_pixmap *src, gp_pixmap *dst,
25                     gp_interpolation_type type,
26                     gp_progress_cb *callback);
28 gp_pixmap *gp_filter_resize_alloc(const gp_pixmap *src,
29                                   gp_size w, gp_size h,
30                                   gp_interpolation_type type,
31                                   gp_progress_cb *callback);
32 -------------------------------------------------------------------------------
34 Interpolate (resize) the pixmap.
36 Resize image given size and interpolation type.
38 gp_filter_resize
39 ^^^^^^^^^^^^^^^^
41 The +gp_filter_reize()+ function resizes 'src' to fit 'dst' exactly.
43 Both 'src' and 'dst' must have the same pixel type.
45 Returns zero on success, non-zero on failure and sets errno.
47 gp_filter_resize_alloc
48 ^^^^^^^^^^^^^^^^^^^^^^
50 The +gp_filter_resize_alloc()+ allocates the destination give it's size.
52 Returns pointer to newly allocated pixmap or NULL in case of failure and
53 errno is set.
55 Nearest Neighbour Interpolation
56 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
58 [source,c]
59 -------------------------------------------------------------------------------
60 #include <gfxprim.h>
61 /* or */
62 #include <filters/GP_ResizeNN.h>
64 int gp_filter_resize_nn(const gp_pixmap *src, gp_pixmap *dst,
65                         gp_progress_cb *callback);
67 gp_pixmap *gp_filter_resize_nn_alloc(const gp_pixmap *src,
68                                      gp_size w, gp_size h,
69                                      gp_progress_cb *callback);
70 -------------------------------------------------------------------------------
72 Pixel value is choosen as value of the closest pixel in the source bitmap
73 (after destination coodinates are mapped to the source coordinates).
75 Fast, but produces "pixelated" images. May however work better for images with
76 sharp edges mostly consisting of big one color regions (it doesn't blur the
77 result on upscaling).
79 Is commonly used to show preview before you resample the image correctly.
81 Bilinear Interpolation
82 ~~~~~~~~~~~~~~~~~~~~~~
84 [source,c]
85 -------------------------------------------------------------------------------
86 #include <gfxprim.h>
87 /* or */
88 #include <filters/GP_ResizeLinear.h>
90 int gp_filter_resize_linear_int(const gp_pixmap *src, gp_pixmap *dst,
91                                 gp_progress_cb *callback);
93 int gp_filter_resize_linear_lf_int(const gp_pixmap *src, gp_pixmap *dst,
94                                    gp_progress_cb *callback);
96 gp_pixmap *gp_filter_resize_linear_int_alloc(const gp_pixmap *src,
97                                              gp_size w, gp_size h,
98                                              gp_progress_cb *callback);
100 gp_pixmap *gp_filter_resize_linear_lf_int_alloc(const gp_pixmap *src,
101                                                 gp_size w, gp_size h,
102                                                 gp_progress_cb *callback);
103 -------------------------------------------------------------------------------
105 Bilinear is faster than bicubic interpolation and produces quite good results
106 especially the low pass (LF) variant doesn't need additional low-pass filter
107 on down-sampling.
109 Bicubic Interpolation
110 ~~~~~~~~~~~~~~~~~~~~~
112 [source,c]
113 -------------------------------------------------------------------------------
114 #include <gfxprim.h>
115 /* or */
116 #include <filters/GP_ResizeCubic.h>
118 int gp_filter_resize_cubic_int(const gp_pixmap *src, gp_pixmap *dst,
119                                gp_progress_cb *callback);
121 int gp_filter_resize_cubic(const gp_pixmap *src, gp_pixmap *dst,
122                            gp_progress_cb *callback);
124 gp_pixmap *gp_filter_resize_cubic_int_alloc(const gp_pixmap *src,
125                                             gp_size w, gp_size h,
126                                             gp_progress_cb *callback);
128 gp_pixmap *gp_filter_resize_cubic_alloc(const gp_pixmap *src,
129                                         gp_size w, gp_size h,
130                                         gp_progress_cb *callback);
131 -------------------------------------------------------------------------------
133 Works well as is on image upscaling. To get decent result on downscaling
134 low-pass filter (Gaussian blur) must be used on original image before actual
135 downscaling.
137 To do this reasonably fast we could cheat a little: first resize big images a
138 little without the low-pass filter, then apply low-pass filter and finally
139 downscale it to desired size.