Пример #1
0
/** \fn     GalleryDatabaseHelper::InsertData(ImageMetadata *)
 *  \brief  Inserts either a new directory or file in the database
 *  \param  im Information of the given item
 *  \return void
 */
void GalleryDatabaseHelper::InsertData(ImageMetadata *im)
{
    if (!im)
        return;

    if (im->m_type == kSubDirectory || im->m_type == kUpDirectory)
        InsertDirectory(im);

    if (im->m_type == kImageFile || im->m_type == kVideoFile)
        InsertFile(im);
}
Пример #2
0
void ExtractValuesFromImageFile(CHAR * szImageFile, void ** ppData,
	DWORD dwStride, DWORD * pdwImageWidth, DWORD * pdwImageHeight)
{
	CHAR file[MAX_PATH];
	InsertDirectory(g_szFileDir, szImageFile, file);

	D3DX10_IMAGE_INFO imageInfo;
	D3DX10GetImageInfoFromFileA(file, 0, &imageInfo, 0);
	DWORD width = imageInfo.Width; 
	if (pdwImageWidth) *pdwImageWidth = width;
	DWORD height = imageInfo.Height;
	if (pdwImageHeight) *pdwImageHeight = height;

	D3DX10_IMAGE_LOAD_INFO loadInfo;
	loadInfo.Width  = width;
	loadInfo.Height = height;
	loadInfo.Depth  = imageInfo.Depth;
	loadInfo.FirstMipLevel = 0;
	loadInfo.MipLevels = imageInfo.MipLevels;
	loadInfo.Usage = D3D10_USAGE_STAGING;
	loadInfo.BindFlags = 0;
	loadInfo.CpuAccessFlags = D3D10_CPU_ACCESS_READ;
	loadInfo.MiscFlags = 0;
	loadInfo.Format = imageInfo.Format;
	loadInfo.Filter = D3DX10_FILTER_NONE;
	loadInfo.MipFilter = D3DX10_FILTER_NONE;
	loadInfo.pSrcInfo  = 0;

	ID3D10Texture2D * tex;
	if (FAILED(D3DX10CreateTextureFromFileA(g_pD3DDevice, file, &loadInfo, 0, (ID3D10Resource**)&tex, NULL))) {
		DxUtSendErrorEx("ExtractValuesFromImageFile could not load the image file.", file);
	}

	*ppData = new CHAR[dwStride*width*height];
	D3D10_MAPPED_TEXTURE2D map;
	tex->Map(0, D3D10_MAP_READ, 0, &map);
	BYTE * ar = (BYTE*)map.pData;
	for (DWORD i=0; i<height; i++) {
		DWORD rowStart1 = i*dwStride*width;
		DWORD rowStart2 = i*dwStride*map.RowPitch/4;
		for (DWORD j=0; j<dwStride*width; j++) {
			((BYTE*)(*ppData))[rowStart1 + j] = ar[rowStart2 + j];
		}
	}
	tex->Unmap(0);
	ReleaseX(tex);
}