bool NameGuid(GUID guid, CString &str, bool alsoAddGuid) { bool found = false; for (int i=0; i<KnownGuidCount; i++) { // lookup known GUIDS if (KnownGuidList[i].guid == guid) { str = CString(KnownGuidList[i].name); if(!alsoAddGuid) return true; found = true; break; } } if (!found) { // interpret as fourcc GUID const FOURCCMap fourccZeroed; GUID guidZeroed = guid; guidZeroed.Data1 = 0x0; CString fourccString; if (fourccZeroed == guidZeroed && 0==GetFourCC(guid.Data1, fourccString)) { str = _T("MEDIASUBTYPE_"); str += fourccString; if(!alsoAddGuid) return true; found = true; } } if (found) str.Append(_T(" ")); LPOLESTR str2; HRESULT hr = StringFromCLSID(guid, &str2); if (SUCCEEDED(hr) && str2) { if (found) str.Append(CString(str2)); else str = CString(str2); CoTaskMemFree(str2); } return found; }
/* 010309 Carl Corcoran */ HRESULT WAVReader::Open(CCString FileName, BOOL bCircular, CCLog* pLog) { this->bCircular = bCircular; DWORD idRiff = 0; DWORD idWave = 0; DWORD br = 0; DWORD dwSize; this->Close(); this->hFile = CreateFile(FileName, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, NULL, NULL); if(this->hFile == INVALID_HANDLE_VALUE || this->hFile == 0) { pLog->AddEntry(L"Could not open \"%s\" for reading.", (PCWSTR)FileName); pLog->AddEntry(GetLastError(), L"CreateFile returned"); return E_FAIL; } //RIFF ReadFile(this->hFile, &idRiff, 4, &br, NULL); if(br != 4) { pLog->AddEntry(L"Could not read from WAV file."); pLog->AddEntry(GetLastError(), L"ReadFile returned"); return E_FAIL; } if(idRiff != mmioFOURCC('R', 'I', 'F', 'F')) { pLog->AddEntry(L"The WAV file is invalid or corrupt."); pLog->AddEntry(L"File does not contain a valid RIFF chunk."); return E_FAIL; } //Size of riff chunk ReadFile(this->hFile, &idRiff, 4, &br, NULL); //WAVE ReadFile(this->hFile, &idWave, 4, &br, NULL); if(br != 4) { pLog->AddEntry(L"Could not read from WAV file."); pLog->AddEntry(GetLastError(), L"ReadFile returned"); return E_FAIL; } if(idWave != mmioFOURCC('W', 'A', 'V', 'E')) { pLog->AddEntry(L"The WAV file is invalid or corrupt."); pLog->AddEntry(L"File does not contain a valid WAVE chunk."); return E_FAIL; } //Search for the fmt chunk. if(CC_FindChunk(GetFourCC("fmt "), this->hFile, pLog) != S_OK) { return E_FAIL; } ReadFile(this->hFile, &dwSize, 4, &br, NULL); if(br != 4) { pLog->AddEntry(L"Could not read from WAV file."); pLog->AddEntry(GetLastError(), L"ReadFile returned"); return E_FAIL; } DWORD dwWFX = sizeof(WAVEFORMATEX); DWORD dwWF = sizeof(WAVEFORMAT); DWORD dwBR = 0; //Let's read in the format. if((dwSize < sizeof(WAVEFORMAT)) || (dwSize > sizeof(WAVEFORMATEX))) { pLog->AddEntry(L"The WAV file is invalid or corrupt."); pLog->AddEntry(L"The 'fmt ' chunk is the wrong size."); return E_FAIL; } ReadFile(this->hFile, &this->Format, dwSize, &br, NULL); //We now should have the format. //Find the data chunk. if(CC_FindChunk(GetFourCC("data"), this->hFile, pLog) != S_OK) { return E_FAIL; } //Get the size of the data chunk. ReadFile(this->hFile, &this->dwSize, sizeof(DWORD), &br, NULL); if(br != sizeof(DWORD)) { pLog->AddEntry(L"Could not read from WAV file."); pLog->AddEntry(GetLastError(), L"ReadFile returned"); return E_FAIL; } //We're all set. this->dwDataPos = SetFilePointer(this->hFile, 0, 0, FILE_CURRENT); return S_OK; }
void SaveDDSFile(TCHAR* pszFile, AMD_TC_Texture& texture) { FILE* pFile = _tfopen(pszFile, _T("wb")); if(!pFile) return; fwrite(&DDS_HEADER, sizeof(DWORD), 1, pFile); DDSD2 ddsd; memset(&ddsd, 0, sizeof(DDSD2)); ddsd.dwSize = sizeof(DDSD2); ddsd.dwFlags = DDSD_CAPS|DDSD_WIDTH|DDSD_HEIGHT|DDSD_PIXELFORMAT|DDSD_MIPMAPCOUNT|DDSD_LINEARSIZE; ddsd.dwWidth = texture.dwWidth; ddsd.dwHeight = texture.dwHeight; ddsd.dwMipMapCount = 1; ddsd.ddpfPixelFormat.dwSize = sizeof(DDPIXELFORMAT); ddsd.ddsCaps.dwCaps = DDSCAPS_TEXTURE|DDSCAPS_COMPLEX|DDSCAPS_MIPMAP; ddsd.ddpfPixelFormat.dwFourCC = GetFourCC(texture.format); if(ddsd.ddpfPixelFormat.dwFourCC) { ddsd.dwLinearSize = texture.dwDataSize; ddsd.ddpfPixelFormat.dwFlags = DDPF_FOURCC; if(IsDXT5SwizzledFormat(texture.format)) { ddsd.ddpfPixelFormat.dwPrivateFormatBitCount = ddsd.ddpfPixelFormat.dwFourCC; ddsd.ddpfPixelFormat.dwFourCC = FOURCC_DXT5; } } else { switch(texture.format) { case AMD_TC_FORMAT_ARGB_8888: ddsd.ddpfPixelFormat.dwRBitMask = 0x00ff0000; ddsd.ddpfPixelFormat.dwGBitMask = 0x0000ff00; ddsd.ddpfPixelFormat.dwBBitMask = 0x000000ff; ddsd.lPitch = texture.dwPitch; ddsd.ddpfPixelFormat.dwRGBBitCount = 32; ddsd.ddpfPixelFormat.dwFlags=DDPF_ALPHAPIXELS|DDPF_RGB; ddsd.ddpfPixelFormat.dwRGBAlphaBitMask = 0xff000000; break; case AMD_TC_FORMAT_RGB_888: ddsd.ddpfPixelFormat.dwRBitMask = 0x00ff0000; ddsd.ddpfPixelFormat.dwGBitMask = 0x0000ff00; ddsd.ddpfPixelFormat.dwBBitMask = 0x000000ff; ddsd.lPitch = texture.dwPitch; ddsd.ddpfPixelFormat.dwRGBBitCount = 24; ddsd.ddpfPixelFormat.dwFlags=DDPF_RGB; break; case AMD_TC_FORMAT_RG_8: ddsd.ddpfPixelFormat.dwRBitMask = 0x0000ff00; ddsd.ddpfPixelFormat.dwGBitMask = 0x000000ff; ddsd.lPitch = texture.dwPitch; ddsd.ddpfPixelFormat.dwRGBBitCount = 16; ddsd.ddpfPixelFormat.dwFlags=DDPF_ALPHAPIXELS|DDPF_LUMINANCE; ddsd.ddpfPixelFormat.dwRGBAlphaBitMask = 0xff000000; break; case AMD_TC_FORMAT_R_8: ddsd.ddpfPixelFormat.dwRBitMask = 0x000000ff; ddsd.lPitch = texture.dwPitch; ddsd.ddpfPixelFormat.dwRGBBitCount = 8; ddsd.ddpfPixelFormat.dwFlags= DDPF_LUMINANCE; break; case AMD_TC_FORMAT_ARGB_2101010: ddsd.ddpfPixelFormat.dwRBitMask = 0x000003ff; ddsd.ddpfPixelFormat.dwGBitMask = 0x000ffc00; ddsd.ddpfPixelFormat.dwBBitMask = 0x3ff00000; ddsd.ddpfPixelFormat.dwRGBAlphaBitMask = 0xc0000000; ddsd.lPitch = texture.dwPitch; ddsd.ddpfPixelFormat.dwRGBBitCount = 32; ddsd.ddpfPixelFormat.dwFlags=DDPF_ALPHAPIXELS|DDPF_RGB; break; case AMD_TC_FORMAT_ARGB_16: ddsd.dwLinearSize = texture.dwDataSize; ddsd.ddpfPixelFormat.dwFlags = DDPF_FOURCC|DDPF_ALPHAPIXELS; ddsd.ddpfPixelFormat.dwFourCC = D3DFMT_A16B16G16R16; break; case AMD_TC_FORMAT_RG_16: ddsd.dwLinearSize = texture.dwDataSize; ddsd.ddpfPixelFormat.dwFlags = DDPF_FOURCC; ddsd.ddpfPixelFormat.dwFourCC = D3DFMT_G16R16; break; case AMD_TC_FORMAT_R_16: ddsd.dwLinearSize = texture.dwDataSize; ddsd.ddpfPixelFormat.dwFlags = DDPF_FOURCC; ddsd.ddpfPixelFormat.dwFourCC = D3DFMT_L16; break; case AMD_TC_FORMAT_ARGB_16F: ddsd.dwLinearSize = texture.dwDataSize; ddsd.ddpfPixelFormat.dwFlags = DDPF_FOURCC|DDPF_ALPHAPIXELS; ddsd.ddpfPixelFormat.dwFourCC = D3DFMT_A16B16G16R16F; break; case AMD_TC_FORMAT_RG_16F: ddsd.dwLinearSize = texture.dwDataSize; ddsd.ddpfPixelFormat.dwFlags = DDPF_FOURCC; ddsd.ddpfPixelFormat.dwFourCC = D3DFMT_G16R16F; break; case AMD_TC_FORMAT_R_16F: ddsd.dwLinearSize = texture.dwDataSize; ddsd.ddpfPixelFormat.dwFlags = DDPF_FOURCC; ddsd.ddpfPixelFormat.dwFourCC = D3DFMT_R16F; break; case AMD_TC_FORMAT_ARGB_32F: ddsd.dwLinearSize = texture.dwDataSize; ddsd.ddpfPixelFormat.dwFlags = DDPF_FOURCC|DDPF_ALPHAPIXELS; ddsd.ddpfPixelFormat.dwFourCC = D3DFMT_A32B32G32R32F; break; case AMD_TC_FORMAT_RG_32F: ddsd.dwLinearSize = texture.dwDataSize; ddsd.ddpfPixelFormat.dwFlags = DDPF_FOURCC; ddsd.ddpfPixelFormat.dwFourCC = D3DFMT_G32R32F; break; case AMD_TC_FORMAT_R_32F: ddsd.dwLinearSize = texture.dwDataSize; ddsd.ddpfPixelFormat.dwFlags = DDPF_FOURCC; ddsd.ddpfPixelFormat.dwFourCC = D3DFMT_R32F; break; default: assert(0); break; } } fwrite(&ddsd, sizeof(DDSD2), 1, pFile); fwrite(texture.pData, texture.dwDataSize, 1, pFile); fclose(pFile); }