Alien-FreeImage
view release on metacpan or search on metacpan
src/Source/FreeImage/PluginPNM.cpp view on Meta::CPAN
if (memcmp(ppm_id1, signature, sizeof(ppm_id1)) == 0)
return TRUE;
if (memcmp(ppm_id2, signature, sizeof(ppm_id2)) == 0)
return TRUE;
return FALSE;
}
static BOOL DLL_CALLCONV
SupportsExportDepth(int depth) {
return (
(depth == 1) ||
(depth == 8) ||
(depth == 24)
);
}
static BOOL DLL_CALLCONV
SupportsExportType(FREE_IMAGE_TYPE type) {
return (
(type == FIT_BITMAP) ||
(type == FIT_UINT16) ||
(type == FIT_RGB16)
);
}
static BOOL DLL_CALLCONV
SupportsNoPixels() {
return TRUE;
}
// ----------------------------------------------------------
static FIBITMAP * DLL_CALLCONV
Load(FreeImageIO *io, fi_handle handle, int page, int flags, void *data) {
char id_one = 0, id_two = 0;
int x, y;
FIBITMAP *dib = NULL;
RGBQUAD *pal; // pointer to dib palette
int i;
if (!handle) {
return NULL;
}
BOOL header_only = (flags & FIF_LOAD_NOPIXELS) == FIF_LOAD_NOPIXELS;
try {
FREE_IMAGE_TYPE image_type = FIT_BITMAP; // standard image: 1-, 8-, 24-bit
// Read the first two bytes of the file to determine the file format
// "P1" = ascii bitmap, "P2" = ascii greymap, "P3" = ascii pixmap,
// "P4" = raw bitmap, "P5" = raw greymap, "P6" = raw pixmap
io->read_proc(&id_one, 1, 1, handle);
io->read_proc(&id_two, 1, 1, handle);
if ((id_one != 'P') || (id_two < '1') || (id_two > '6')) {
// signature error
throw FI_MSG_ERROR_MAGIC_NUMBER;
}
// Read the header information: width, height and the 'max' value if any
int width = GetInt(io, handle);
int height = GetInt(io, handle);
int maxval = 1;
if((id_two == '2') || (id_two == '5') || (id_two == '3') || (id_two == '6')) {
maxval = GetInt(io, handle);
if((maxval <= 0) || (maxval > 65535)) {
FreeImage_OutputMessageProc(s_format_id, "Invalid max value : %d", maxval);
throw (const char*)NULL;
}
}
// Create a new DIB
switch (id_two) {
case '1':
case '4':
// 1-bit
dib = FreeImage_AllocateHeader(header_only, width, height, 1);
break;
case '2':
case '5':
if(maxval > 255) {
// 16-bit greyscale
image_type = FIT_UINT16;
dib = FreeImage_AllocateHeaderT(header_only, image_type, width, height);
} else {
// 8-bit greyscale
dib = FreeImage_AllocateHeader(header_only, width, height, 8);
}
break;
case '3':
case '6':
if(maxval > 255) {
// 48-bit RGB
image_type = FIT_RGB16;
dib = FreeImage_AllocateHeaderT(header_only, image_type, width, height);
} else {
// 24-bit RGB
dib = FreeImage_AllocateHeader(header_only, width, height, 24, FI_RGBA_RED_MASK, FI_RGBA_GREEN_MASK, FI_RGBA_BLUE_MASK);
}
break;
}
if (dib == NULL) {
throw FI_MSG_ERROR_DIB_MEMORY;
}
// Build a greyscale palette if needed
if(image_type == FIT_BITMAP) {
switch(id_two) {
case '1':
( run in 1.319 second using v1.01-cache-2.11-cpan-5735350b133 )