DecodeMMRImage

#include "BITIFF.H"

 

BOOL CALLBACK DecodeMMRImage( int                 nFile,
LONG          lOffset,
UINT           wWidth,
DWORD      dwCompression,
int                 nFillOrder,
UINT           wByteOrder,
UINT           wHeight,
LONG          lParam,
FILLPROC  lpLineFn)

Description

Decompresses a MMR monochrome image from an offset location from a file. The user can set byte order for Intel or Motorola chips, and the byte fill order. The decoded image data can be retrieved through the user defined callback function line by line.

Parameters

int

nFile

Image file handle.

UINT

wWidth

Width of the image in pixels.

UINT

wHeight

Height of the image in pixels.

DWORD

dwCompression

Compression type.

int

nFillOrder

The byte fill order.

UINT

wByteOrder

The byte order.

LONG

lParam

User defined info. It is passed to the callback function as a third parameter unchanged.

FILLPROC

lpLineFn

Callback function that will get the decoded DIB lines.

Return values

TRUE on success, FALSE if failed.

Programming notes

The only compression type is supported in this version is IBMMMR.

The wByteOrder field may be either LH_BYTE_ORDER or HL_BYTE_ORDER. LH_BYTE_ORDER means that byte order is always from least significant to most significant, for both 16-bit and 32-bit integers. HL_BYTE_ORDER means that byte order is always from most significant to least significant. LH_BYTE_ORDER is used by computers with Intel processors (IBM compatible computers). HL_BYTE_ORDER is used with computers with Motorola processors (Macintosh computers).

Bit order defines in the "BITIFF.H" file:        NORM_BIT_ORDER // default

                                                                        REV_BIT_ORDER

 

Byte order defines in the "BITIFF.H" file:     LH_BYTE_ORDER              // default

                                                                        HL_BYTE_ORDER

Requirements

Header :     Declared in BiTiff.h; include BiTiff.h.

Library :    Use BiTiff.lib.

DLLs :       BiTiff.dll.

References to related functions

See EncodeMMRImage().

Code example

#include "BITIFF.H"

 

BOOL CALLBACK LoadMMRImage(LPSTR lpszFileName, UINT wFormat)

{

    int                   nFile;

    BOOL            bSuccess;

    HWND          hWnd;

    DWORD        dwCommpress = 0;

    IOCA             Ioca;

 

    hWnd = GetActiveWindow();

 

    // Displays an hourglass-cursor and saves the original one.

    hOldCur = SetCursor(LoadCursor(NULL,IDC_WAIT));

 

    // Erases previous bitmap if any.

    // It is necessary to free the memory it occupies.

    hBitmap = NULL;

 

    // Opens the image file.

    nFile = _lopen(lpszFileName,READ);

    if (nFile > 0)                             // Opening OK.

    {    // Gets a DC to be used later in the call back function.

       switch (wFormat)

       {

          case IBM_MMR_IOCA_FORMAT:

          if (ReadIOCAHeader(nFile,&Ioca) == FALSE) {

              return(FALSE);

          }

          BmInfo.bmiHeader.biWidth = Ioca.wHSize;

          BmInfo.bmiHeader.biHeight = Ioca.wVSize;

          // the file pointer already at the beginning of image

          lOffset = Ioca.lFirstImgOffset;

 

          break;

           case IBM_MMR_FORMAT:

          // Calls a dialog box to ask for image dimensions.

          bSuccess = DialogBox(hInst,"AskDimsDlg",hWnd, AskDimsDlg);

          if(!bSuccess)

          {   return(FALSE);

          }

          break;

       }

 

       hDC = GetDC(hWnd);

       if (hDC != NULL)

       {

          hBitmap = CreateBitmap((int)BmInfo.bmiHeader.biWidth,

                          (int)BmInfo.bmiHeader.biHeight,1,1,(LPSTR)NULL);

          if (hBitmap != NULL)

          {

             ERASEBITMAP(hBitmap,hDC,BmInfo.bmiHeader.biWidth,

                         BmInfo.bmiHeader.biHeight);

 

             // Fills the image in the bitmap.

             if (!DecodeMMRImage(nFile, lOffset,

                         (UINT)BmInfo.bmiHeader.biWidth,

                         (UINT)BmInfo.bmiHeader.biHeight,dwCommpress,

                         Ioca.wFirstImgSize, nFillOrder, wByteOrder,

                         0L, FlushMMRLine))

             {

                DeleteObject(hBitmap);

                hBitmap = NULL;

             }

             lOffset = 0L;

          }  // Endif bitmap creation OK.

          ReleaseDC(hWnd,hDC);

       }  // Endif retrieving DC OK.

       // Closes image file.

       _lclose(nFile);

    }

    // Restores original cursor from hourglass-cursor.

    SetCursor(hOldCur);

    if (hBitmap == NULL) // Error occurred.

    {

       MessageBox(NULL,(LPSTR)"Unable to access data. Loading has failed.",

                 (LPSTR)"TIFF error",MB_OK|MB_ICONEXCLAMATION);

    }

    return(hBitmap != NULL);

}

 

int CALLBACK FlushMMRLine(LPSTR lpLineBuff, int nLine, LONG lParam)

{

    // Saves last processed line index.

    nActLine = nLine;

 

    // Writes data into bitmap.

    SetDIBits(hDC,hBitmap,(int)BmInfo.bmiHeader.biHeight - nLine,1,

                            lpLineBuff,(LPBITMAPINFO)&BmInfo,DIB_RGB_COLORS);

 

    return(TOK);

}