Exemplo n.º 1
0
BOOL LoadDIB(const char *filename, HGLOBAL *phDIB, HPALETTE *pPal, int pic_type)
{
	file_error filerr;
	core_file *file = NULL;
	BOOL success = FALSE;
	const char *dir_name;
	const char *zip_name;
	astring *fname;
	void *buffer = NULL;
	if (pPal != NULL ) {
		DeletePalette(pPal);
	}

	switch (pic_type)
	{
		case TAB_SCREENSHOT:
			dir_name = GetImgDir();
			zip_name = "snap";
			break;
		case TAB_FLYER:
			dir_name = GetFlyerDir();
			zip_name = "flyers";
			break;
		case TAB_CABINET:
			dir_name = GetCabinetDir();
			zip_name = "cabinets";
			break;
		case TAB_MARQUEE:
			dir_name = GetMarqueeDir();
			zip_name = "marquees";
			break;
		case TAB_TITLE:
			dir_name = GetTitlesDir();
			zip_name = "titles";
			break;
		case TAB_CONTROL_PANEL:
			dir_name = GetControlPanelDir();
			zip_name = "cpanel";
			break;
        case TAB_PCB :
			dir_name = GetPcbDir();
		    zip_name = "pcb";
			break;
		case BACKGROUND:
			dir_name = GetBgDir();
			zip_name = "bkground";
			break;
		default :
			// in case a non-image tab gets here, which can happen
			return FALSE;
	}
	//Add handling for the displaying of all the different supported snapshot patterntypes
	//%g
	fname = astring_assemble_2(astring_alloc(), filename, ".png");
	filerr = OpenDIBFile(dir_name, zip_name, astring_c(fname), &file, &buffer);
	astring_free(fname);
	if (filerr != FILERR_NONE) {
		//%g/%i
		fname = astring_assemble_3(astring_alloc(), filename, PATH_SEPARATOR, "0000.png");
		filerr = OpenDIBFile(dir_name, zip_name, astring_c(fname), &file, &buffer);
		astring_free(fname);
	}
	if (filerr != FILERR_NONE) {
		//%g%i
		fname = astring_assemble_2(astring_alloc(), filename, "0000.png");
		filerr = OpenDIBFile(dir_name, zip_name, astring_c(fname), &file, &buffer);
		astring_free(fname);
	}
	if (filerr != FILERR_NONE) {
		//%g/%g
		fname = astring_assemble_4(astring_alloc(), filename, PATH_SEPARATOR, filename, ".png");
		filerr = OpenDIBFile(dir_name, zip_name, astring_c(fname), &file, &buffer);
		astring_free(fname);
	}
	if (filerr != FILERR_NONE) {
		//%g/%g%i
		fname = astring_assemble_4(astring_alloc(), filename, PATH_SEPARATOR, filename, "0000.png");
		filerr = OpenDIBFile(dir_name, zip_name, astring_c(fname), &file, &buffer);
		astring_free(fname);
	}

	if (filerr == FILERR_NONE) {
		success = png_read_bitmap_gui(file, phDIB, pPal);
		core_fclose(file);
	}

	// free the buffer if we have to
	if (buffer != NULL) {
		free(buffer);
	}
	return success;
}
Exemplo n.º 2
0
BOOL LoadDIB(const WCHAR *filename, HGLOBAL *phDIB, HPALETTE *pPal, int pic_type)
{
	file_error filerr;
	core_file *file = NULL;
	BOOL success = FALSE;
	const WCHAR *zip_name;
	const WCHAR *dir_name;
	void *buffer = NULL;
	char *utf8filename;
	char *utf8zip_name;
	char *utf8dir_name;
	if (pPal != NULL ) {
		DeletePalette(pPal);
	}

	switch (pic_type)
	{
	case TAB_SCREENSHOT :
		dir_name = GetImgDir();
		zip_name = TEXT("snap");
		break;
	case TAB_FLYER :
		dir_name = GetFlyerDir();
		zip_name = TEXT("flyers");
		break;
	case TAB_CABINET :
		dir_name = GetCabinetDir();
		zip_name = TEXT("cabinets");
		break;
	case TAB_MARQUEE :
		dir_name = GetMarqueeDir();
		zip_name = TEXT( "marquees");
		break;
	case TAB_TITLE :
		dir_name = GetTitlesDir();
		zip_name = TEXT("titles");
		break;
	case TAB_CONTROL_PANEL :
		dir_name = GetControlPanelDir();
		zip_name = TEXT("cpanel");
		break;
        case TAB_PCB :
		dir_name = GetPcbDir();
		zip_name = TEXT("pcb");
		break;
	case BACKGROUND :
		dir_name = GetBgDir();
		zip_name = TEXT("bkground");
		break;
#ifdef USE_IPS
	case TAB_IPS :
		dir_name = GetIPSDir();
		zip_name = TEXT("ips");
		break;
#endif /* USE_IPS */
	default :
		// in case a non-image tab gets here, which can happen
		return FALSE;
	}

	utf8filename = utf8_from_wstring(filename);
	utf8zip_name = utf8_from_wstring(zip_name);
	utf8dir_name = utf8_from_wstring(dir_name);

	//Add handling for the displaying of all the different supported snapshot patterntypes
	//%g
	astring fname(utf8filename, ".png");
	filerr = OpenDIBFile(utf8dir_name, utf8zip_name, fname, &file, &buffer);
	if (filerr != FILERR_NONE)
	{
		//%g/%i
		astring fname(utf8filename, PATH_SEPARATOR, "0000.png");
		filerr = OpenDIBFile(utf8dir_name, utf8zip_name, fname, &file, &buffer);
	}
	if (filerr != FILERR_NONE)
	{
		//%g%i
		astring fname(utf8filename, "0000.png");
		filerr = OpenDIBFile(utf8dir_name, utf8zip_name, fname, &file, &buffer);
	}
	if (filerr != FILERR_NONE)
	{
		//%g/%g
		astring fname(utf8filename, PATH_SEPARATOR, utf8filename, ".png");
		filerr = OpenDIBFile(utf8dir_name, utf8zip_name, fname, &file, &buffer);
	}
	if (filerr != FILERR_NONE)
	{
		//%g/%g%i
		astring fname(utf8filename, PATH_SEPARATOR, utf8filename, ".png");
		filerr = OpenDIBFile(utf8dir_name, utf8zip_name, fname, &file, &buffer);
	}

	if (filerr == FILERR_NONE)
	{
		success = png_read_bitmap_gui(file, phDIB, pPal);
		core_fclose(file);
	}

	// free the buffer if we have to
	if (buffer != NULL)
	{
		free(buffer);
	}

	osd_free(utf8filename);
	osd_free(utf8zip_name);
	osd_free(utf8dir_name);

	return success;
}