freeimage.h

FreeImage_OpenMultiBitmapFromHandle

DLL_API FIMULTIBITMAP * DLL_CALLCONV
FreeImage_OpenMultiBitmapFromHandle(FREE_IMAGE_FORMAT fif, FreeImageIO *io, fi_handle
handle, int flags FI_DEFAULT(0));

Esta función permite abrir un mapa de bits multipágina existente a partir de un manipulador en modo de sólo lectura.

Al igual que FreeImage_LoadFromHandle, se debe especificar una estructura FreeImageIO y un fi_handle. La implementación actual del FreeImage_CloseMultiBitmap es suficiente para cerar un mapa de bits multipágina abierto desde un manipulador.

Aunque el manipulador de origen es abierto en modo de sólo lectura, usando esta función los manipuladores soportan operaciones de lectura o lectura/escritura. Cuando se modifica un fichero pultipágina usando funciones como FreeImage_AppendPage, FreeImage_InsertPage, FreeImage_MovePage o FreeImage_DeletePage, loc cambio se almacenan de forma transparente en una caché de memoria de modo que esos cambios pueden ser guardados más tarde a un canal de salida. El canal de entrada queda sin modificar: cerrr el canal de entrada no lo modificará. Por lo tanto será necesario utilizar algún fipo de función "Guardar como…” para guardar los cambios.

static unsigned DLL_CALLCONV
myReadProc(void *buffer, unsigned size, unsigned count, fi_handle handle) {
    return (unsigned)fread(buffer, size, count, (FILE *)handle);
}
static unsigned DLL_CALLCONV
myWriteProc(void *buffer, unsigned size, unsigned count, fi_handle handle) {
    return (unsigned)fwrite(buffer, size, count, (FILE *)handle);
}
static int DLL_CALLCONV
mySeekProc(fi_handle handle, long offset, int origin) {
    return fseek((FILE *)handle, offset, origin);
}
static long DLL_CALLCONV
myTellProc(fi_handle handle) {
    return ftell((FILE *)handle);
}
BOOL testStreamMultiPageOpen(const char *input, int flags) {
    // initialize your own IO functions
    FreeImageIO io;
    io.read_proc = myReadProc;
    io.write_proc = myWriteProc;
    io.seek_proc = mySeekProc;
    io.tell_proc = myTellProc;
    BOOL bSuccess = FALSE;
    // Open src stream in read-only mode
    FILE *file = fopen(input, "r+b");
    if (file != NULL) {
        // Open the multi-page file
        FREE_IMAGE_FORMAT fif = FreeImage_GetFileTypeFromHandle(&io, (fi_handle)file);
        FIMULTIBITMAP *src = FreeImage_OpenMultiBitmapFromHandle(fif, &io,
            (fi_handle)file, flags);
        if(src) {
            // get the page count
            int count = FreeImage_GetPageCount(src);
            assert(count > 1);
            // delete page 0 (modifications are stored to the cache)
            FreeImage_DeletePage(src, 0);
            // Close src file (nothing is done, the cache is cleared)
            bSuccess = FreeImage_CloseMultiBitmap(src, 0);
            assert(bSuccess);
        }
        // Close the src stream
        fclose(file);
        return bSuccess;
    }

    return bSuccess;
}