ReactOS Fundraising Campaign 2012
 
€ 4,410 / € 30,000

Information | Donate

Home | Info | Community | Development | myReactOS | Contact Us

  1. Home
  2. Community
  3. Development
  4. myReactOS
  5. Fundraiser 2012

  1. Main Page
  2. Alphabetical List
  3. Data Structures
  4. Directories
  5. File List
  6. Data Fields
  7. Globals
  8. Related Pages

ReactOS Development > Doxygen

dibitmap.c
Go to the documentation of this file.
00001 /* $Id: dibitmap.c 54535 2011-11-29 14:55:58Z dgorbachev $
00002  *
00003  * COPYRIGHT:       See COPYING in the top level directory
00004  * PROJECT:         ReactOS Display Control Panel
00005  * FILE:            dll/cpl/desk/dibitmap.c
00006  * PURPOSE:         DIB loading
00007  *
00008  * PROGRAMMERS:     Trevor McCort (lycan359@gmail.com)
00009  */
00010 
00011 #include "desk.h"
00012 
00013 PDIBITMAP
00014 DibLoadImage(LPTSTR lpFilename)
00015 {
00016     BOOL     bSuccess;
00017     DWORD    dwFileSize, dwHighSize, dwBytesRead;
00018     HANDLE   hFile;
00019     PDIBITMAP lpBitmap;
00020 
00021     hFile = CreateFile(lpFilename,
00022                        GENERIC_READ,
00023                        FILE_SHARE_READ,
00024                        NULL,
00025                        OPEN_EXISTING,
00026                        FILE_FLAG_SEQUENTIAL_SCAN,
00027                        NULL);
00028     if (hFile == INVALID_HANDLE_VALUE)
00029         return NULL;
00030 
00031     dwFileSize = GetFileSize(hFile, &dwHighSize);
00032 
00033     if (dwHighSize)
00034     {
00035         CloseHandle(hFile);
00036         return NULL;
00037     }
00038 
00039     lpBitmap = HeapAlloc(GetProcessHeap(), 0, sizeof(DIBITMAP));
00040     if (lpBitmap == NULL)
00041     {
00042         CloseHandle(hFile);
00043         return NULL;
00044     }
00045 
00046     lpBitmap->header = HeapAlloc(GetProcessHeap(), 0, dwFileSize);
00047     if (lpBitmap->header == NULL)
00048     {
00049         HeapFree(GetProcessHeap(), 0, lpBitmap);
00050         CloseHandle(hFile);
00051         return NULL;
00052     }
00053 
00054     bSuccess = ReadFile(hFile, lpBitmap->header, dwFileSize, &dwBytesRead, NULL);
00055     CloseHandle(hFile);
00056 
00057     if (!bSuccess ||
00058         (dwBytesRead != dwFileSize) ||
00059         (lpBitmap->header->bfType != * (WORD *) "BM") ||
00060         (lpBitmap->header->bfSize != dwFileSize))
00061     {
00062         HeapFree(GetProcessHeap(), 0, lpBitmap->header);
00063         HeapFree(GetProcessHeap(), 0, lpBitmap);
00064         return NULL;
00065     }
00066 
00067     lpBitmap->info = (BITMAPINFO *)(lpBitmap->header + 1);
00068     lpBitmap->bits = (BYTE *)lpBitmap->header + lpBitmap->header->bfOffBits;
00069 
00070     /* Get the DIB width and height */
00071     if (lpBitmap->info->bmiHeader.biSize == sizeof(BITMAPCOREHEADER))
00072     {
00073         lpBitmap->width  = ((BITMAPCOREHEADER *)lpBitmap->info)->bcWidth;
00074         lpBitmap->height = ((BITMAPCOREHEADER *)lpBitmap->info)->bcHeight;
00075     }
00076     else
00077     {
00078         lpBitmap->width   =     lpBitmap->info->bmiHeader.biWidth;
00079         lpBitmap->height  = abs(lpBitmap->info->bmiHeader.biHeight);
00080     }
00081 
00082     return lpBitmap;
00083 }
00084 
00085 
00086 VOID
00087 DibFreeImage(PDIBITMAP lpBitmap)
00088 {
00089     if (lpBitmap == NULL)
00090         return;
00091 
00092     /* Free the header */
00093     if (lpBitmap->header != NULL)
00094         HeapFree(GetProcessHeap(), 0, lpBitmap->header);
00095 
00096     /* Free the bitmap structure */
00097     if (lpBitmap != NULL)
00098         HeapFree(GetProcessHeap(), 0, lpBitmap);
00099 }

Generated on Thu May 24 2012 04:21:17 for ReactOS by doxygen 1.7.6.1

ReactOS is a registered trademark or a trademark of ReactOS Foundation in the United States and other countries.