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

util.c
Go to the documentation of this file.
00001 /*
00002  * Copyright (C) 2009 Tony Wasserka
00003  *
00004  * This library is free software; you can redistribute it and/or
00005  * modify it under the terms of the GNU Lesser General Public
00006  * License as published by the Free Software Foundation; either
00007  * version 2.1 of the License, or (at your option) any later version.
00008  *
00009  * This library is distributed in the hope that it will be useful,
00010  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00011  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00012  * Lesser General Public License for more details.
00013  *
00014  * You should have received a copy of the GNU Lesser General Public
00015  * License along with this library; if not, write to the Free Software
00016  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
00017  *
00018  */
00019 
00020 #include "wine/debug.h"
00021 #include "d3dx9_36_private.h"
00022 
00023 
00024 /************************************************************
00025  * pixel format table providing info about number of bytes per pixel,
00026  * number of bits per channel and format type.
00027  *
00028  * Call get_format_info to request information about a specific format.
00029  */
00030 static const PixelFormatDesc formats[] =
00031 {
00032    /* format                    bits per channel        shifts per channel   bpp   type        */
00033     { D3DFMT_R8G8B8,          {  0,   8,   8,   8 },  {  0,  16,   8,   0 },   3,  FORMAT_ARGB },
00034     { D3DFMT_A8R8G8B8,        {  8,   8,   8,   8 },  { 24,  16,   8,   0 },   4,  FORMAT_ARGB },
00035     { D3DFMT_X8R8G8B8,        {  0,   8,   8,   8 },  {  0,  16,   8,   0 },   4,  FORMAT_ARGB },
00036     { D3DFMT_A8B8G8R8,        {  8,   8,   8,   8 },  { 24,   0,   8,  16 },   4,  FORMAT_ARGB },
00037     { D3DFMT_X8B8G8R8,        {  0,   8,   8,   8 },  {  0,   0,   8,  16 },   4,  FORMAT_ARGB },
00038     { D3DFMT_R5G6B5,          {  0,   5,   6,   5 },  {  0,  11,   5,   0 },   2,  FORMAT_ARGB },
00039     { D3DFMT_X1R5G5B5,        {  0,   5,   5,   5 },  {  0,  10,   5,   0 },   2,  FORMAT_ARGB },
00040     { D3DFMT_A1R5G5B5,        {  1,   5,   5,   5 },  { 15,  10,   5,   0 },   2,  FORMAT_ARGB },
00041     { D3DFMT_R3G3B2,          {  0,   3,   3,   2 },  {  0,   5,   2,   0 },   1,  FORMAT_ARGB },
00042     { D3DFMT_A8R3G3B2,        {  8,   3,   3,   2 },  {  8,   5,   2,   0 },   2,  FORMAT_ARGB },
00043     { D3DFMT_A4R4G4B4,        {  4,   4,   4,   4 },  { 12,   8,   4,   0 },   2,  FORMAT_ARGB },
00044     { D3DFMT_X4R4G4B4,        {  0,   4,   4,   4 },  {  0,   8,   4,   0 },   2,  FORMAT_ARGB },
00045     { D3DFMT_A2R10G10B10,     {  2,  10,  10,  10 },  { 30,  20,  10,   0 },   4,  FORMAT_ARGB },
00046     { D3DFMT_A2B10G10R10,     {  2,  10,  10,  10 },  { 30,   0,  10,  20 },   4,  FORMAT_ARGB },
00047     { D3DFMT_G16R16,          {  0,  16,  16,   0 },  {  0,   0,  16,   0 },   4,  FORMAT_ARGB },
00048     { D3DFMT_A8,              {  8,   0,   0,   0 },  {  0,   0,   0,   0 },   1,  FORMAT_ARGB },
00049 
00050     { D3DFMT_UNKNOWN,         {  0,   0,   0,   0 },  {  0,   0,   0,   0 },   0,  FORMAT_UNKNOWN }, /* marks last element */
00051 };
00052 
00053 
00054 /************************************************************
00055  * map_view_of_file
00056  *
00057  * Loads a file into buffer and stores the number of read bytes in length.
00058  *
00059  * PARAMS
00060  *   filename [I] name of the file to be loaded
00061  *   buffer   [O] pointer to destination buffer
00062  *   length   [O] size of the obtained data
00063  *
00064  * RETURNS
00065  *   Success: D3D_OK
00066  *   Failure:
00067  *     see error codes for CreateFileW, GetFileSize, CreateFileMapping and MapViewOfFile
00068  *
00069  * NOTES
00070  *   The caller must UnmapViewOfFile when it doesn't need the data anymore
00071  *
00072  */
00073 HRESULT map_view_of_file(LPCWSTR filename, LPVOID *buffer, DWORD *length)
00074 {
00075     HANDLE hfile, hmapping = NULL;
00076 
00077     hfile = CreateFileW(filename, GENERIC_READ, FILE_SHARE_READ, 0, OPEN_EXISTING, 0, 0);
00078     if(hfile == INVALID_HANDLE_VALUE) goto error;
00079 
00080     *length = GetFileSize(hfile, NULL);
00081     if(*length == INVALID_FILE_SIZE) goto error;
00082 
00083     hmapping = CreateFileMappingW(hfile, NULL, PAGE_READONLY, 0, 0, NULL);
00084     if(!hmapping) goto error;
00085 
00086     *buffer = MapViewOfFile(hmapping, FILE_MAP_READ, 0, 0, 0);
00087     if(*buffer == NULL) goto error;
00088 
00089     CloseHandle(hmapping);
00090     CloseHandle(hfile);
00091 
00092     return S_OK;
00093 
00094 error:
00095     CloseHandle(hmapping);
00096     CloseHandle(hfile);
00097     return HRESULT_FROM_WIN32(GetLastError());
00098 }
00099 
00100 /************************************************************
00101  * load_resource_into_memory
00102  *
00103  * Loads a resource into buffer and stores the number of
00104  * read bytes in length.
00105  *
00106  * PARAMS
00107  *   module  [I] handle to the module
00108  *   resinfo [I] handle to the resource's information block
00109  *   buffer  [O] pointer to destination buffer
00110  *   length  [O] size of the obtained data
00111  *
00112  * RETURNS
00113  *   Success: D3D_OK
00114  *   Failure:
00115  *     See error codes for SizeofResource, LoadResource and LockResource
00116  *
00117  * NOTES
00118  *   The memory doesn't need to be freed by the caller manually
00119  *
00120  */
00121 HRESULT load_resource_into_memory(HMODULE module, HRSRC resinfo, LPVOID *buffer, DWORD *length)
00122 {
00123     HGLOBAL resource;
00124 
00125     *length = SizeofResource(module, resinfo);
00126     if(*length == 0) return HRESULT_FROM_WIN32(GetLastError());
00127 
00128     resource = LoadResource(module, resinfo);
00129     if( !resource ) return HRESULT_FROM_WIN32(GetLastError());
00130 
00131     *buffer = LockResource(resource);
00132     if(*buffer == NULL) return HRESULT_FROM_WIN32(GetLastError());
00133 
00134     return S_OK;
00135 }
00136 
00137 
00138 /************************************************************
00139  * get_format_info
00140  *
00141  * Returns information about the specified format.
00142  * If the format is unsupported, it's filled with the D3DFMT_UNKNOWN desc.
00143  *
00144  * PARAMS
00145  *   format [I] format whose description is queried
00146  *   desc   [O] pointer to a StaticPixelFormatDesc structure
00147  *
00148  */
00149 const PixelFormatDesc *get_format_info(D3DFORMAT format)
00150 {
00151     unsigned int i = 0;
00152     while(formats[i].format != format && formats[i].format != D3DFMT_UNKNOWN) i++;
00153     return &formats[i];
00154 }

Generated on Sun May 27 2012 04:22:12 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.