FreeImage_MakeThumbnail
1 4 8 16 24 32 16UINT16 48RGB16 64RGBA16 32FLOAT 96RGBF 128RGBAF
DLL_API FIBITMAP *DLL_CALLCONV FreeImage_MakeThumbnail(FIBITMAP *dib, int max_pixel_size, BOOL convert FI_DEFAULT(TRUE));
Crea una miniatura a partir de una imagen en escala de grises o RGB(A) de modo que la imagen de salida entre dentro de un cuadrado del tamaño max_pixel_size, manteniendo la relación de aspecto.
El submuestreo se realiza usando un filtro bilineal (ver FreeImage_Rescale). Un mapa de bits RGB de 16-bit se devuelven como de 24-bit. Los mapas de bits con paleta y los de 4-bit se devuelven como de 8-bit o como de 32-bit si contienen transparencia.
Cuando el parámetro convert es TRUE, las imágenes de alto rango dinámico (FIT_UINT16, FIT_RGB16, FIT_RGBA16, FIT_FLOAT) se convierten de forma transparente a imágenes estándar (es decir, imágenes 8-, 24 o 32-bit), usando una de las funciones de conversión FreeImage_ConvertToXXX.
En cuanto a las imágenes RBG[A]F images, son convertidas a 24-bit usando la función FreeImage_TmoDrago03 con las opciones por defecto.
#define THUMBNAIL_SIZE 90 // fit inside a square whose size is 90 pixels
FIBITMAP * makeThumbnail(const char *szPathName) {
FIBITMAP *dib = NULL;
int flags = 0; // default load flag
int originalWidth = 0; // original image width
int originalHeight = 0; // original image height
FREE_IMAGE_FORMAT fif = FreeImage_GetFileType(szPathName);
if(fif == FIF_UNKNOWN) return NULL;
if(fif == FIF_JPEG) {
FITAG *tag = NULL;
// for JPEG images, we can speedup the loading part
// using LibJPEG downsampling feature while loading the image...
flags |= THUMBNAIL_SIZE << 16;
// load the dib
dib = FreeImage_Load(fif, szPathName, flags);
if(!dib) return NULL;
// the dib may have been downscaled by 2x, 4x or 8x
// retrieve the original width & height (stored as comments for this special case)
if(FreeImage_GetMetadata(FIMD_COMMENTS, dib, "OriginalJPEGWidth", &tag)) {
originalWidth = atoi( (char*)FreeImage_GetTagValue(tag) );
} else {
originalWidth = FreeImage_GetWidth(dib);
}
if(FreeImage_GetMetadata(FIMD_COMMENTS, dib, "OriginalJPEGHeight", &tag)) {
originalHeight = atoi( (char*)FreeImage_GetTagValue(tag) );
} else {
originalHeight = FreeImage_GetHeight(dib);
}
} else {
// any cases other than the JPEG case: load the dib ...
if(fif == FIF_RAW) {
// ... except for RAW images, try to load the embedded JPEG preview
// or default to RGB 24-bit ...
flag = RAW_PREVIEW;
}
dib = FreeImage_Load(fif, szPathName, flags);
if(!dib) return NULL;
originalWidth = FreeImage_GetWidth(dib);
originalHeight = FreeImage_GetHeight(dib);
}
// store ‘originalWidth’ and ‘originalHeight’ for later use …
// store any other metadata (such as Exif) for later use …
// ...
// create the requested thumbnail
FIBITMAP *thumbnail = FreeImage_MakeThumbnail(dib, THUMBNAIL_SIZE, TRUE);
FreeImage_Unload(dib);
return thumbnail;
}