Beispiel #1
0
void DtxUtil::QuantizeAllhandler(const char* inputfile, const char* outputfile, char* command)
{
	uint8	alpha	 = 0;
	char buffer[1024];
	// determine the number of distinct colors with alpha
	int	 numAlpha = NumColorsWithAlphaInDTX(inputfile,&alpha);

	DEBUG_EXEC(printf("\nnumAlpha = %d", numAlpha));
	CString tgaFile = "tmp.tga";
	CString tmpFile = inputfile;  tmpFile += ".tmp";

	// DTX->TGA
	if( DTX2TGAhandler(inputfile, LPCTSTR(tgaFile)) )
	{
		// TGA 32bit -> TGA256
		if( numAlpha == 1 ) sprintf( buffer,"imgconvert -colors 256 -colorspace Transparent %s %s", LPCTSTR(tgaFile), LPCTSTR(tgaFile) );
		else   				sprintf( buffer,"imgconvert -colors 240 -colorspace Transparent %s %s", LPCTSTR(tgaFile), LPCTSTR(tgaFile) );

		DEBUG_EXEC(printf("\n%s", buffer));
		system( buffer );
		// TGA->DTX
		TGA2DTXhandler(LPCTSTR(tgaFile), LPCTSTR(tmpFile));
		// DTX->BPP32P
		DTX2BPP_32Phandler(LPCTSTR(tmpFile), outputfile);

		DELETE_FILE(LPCTSTR(tgaFile));
		DELETE_FILE(LPCTSTR(tmpFile));
	}
	else
	{
		DELETE_FILE(LPCTSTR(tgaFile));
	}
}
Beispiel #2
0
/* Called at the end of the program. Frees up all memory allocated for
 * variables.
 */
void End(void) {
    DEBUG_EXEC("Closing Saturn environment\n");

    /* Freeing the constants created in Init() */
    for (int i = 0; i < 4; i++) {
        DEBUG_ENV("Freeing \"%s\" at %p\n", env->vars[i]->label, env->vars + i);
        free(env->vars[i]);
    }

    /* Freeing the variables declared by the user */
    for (int i = 4; i < env->varcount; i++) {
        DEBUG_ENV("Freeing \"%s\" at %p\n", env->vars[i]->label, env->vars + i)
        free(env->vars[i]->label);
        if (env->vars[i]->type == _STR) {
            free(env->vars[i]->val.STR);
        }
        if (env->vars[i]->type == _FIL) {
            free(env->vars[i]->val.FIL.path);
        }
        free(env->vars[i]);
    }
    free(env->vars);
    free(env);

    exit(EXIT_SUCCESS);
}
Beispiel #3
0
/* Initialize the environment
 *    Allocate room for 10 variables
 *    Set the global constants
 */
void Init(void) {
    DEBUG_EXEC("Initializing Saturn environment\n");

    /* Allocate room for 10 variables to begin with */
    env = malloc(sizeof(Environment));
    env->vars = malloc(10 * sizeof(Var *));
    env->memsize = 10;
    env->varcount = 4;

    /* Create global constants */
    env->vars[0] = malloc(sizeof(Var));
    env->vars[0]->label = "stdin";
    env->vars[0]->type = _FIL;
    env->vars[0]->val.FIL.pntr = stdin;
    env->vars[0]->val.FIL.isopen = true;

    env->vars[1] = malloc(sizeof(Var));
    env->vars[1]->val.FIL.pntr = stdout;
    env->vars[1]->type = _FIL;
    env->vars[1]->label = "stdout";
    env->vars[1]->val.FIL.isopen = true;

    env->vars[2] = malloc(sizeof(Var));
    env->vars[2]->label = "stderr";
    env->vars[2]->type = _FIL;
    env->vars[2]->val.FIL.pntr = stderr;
    env->vars[2]->val.FIL.isopen = true;

    env->vars[3] = malloc(sizeof(Var));
    env->vars[3]->label = "newline";
    env->vars[3]->type = _STR;
    env->vars[3]->val.STR = "\n";
}
Beispiel #4
0
void DtxUtil::DTX2BPP_32Phandler(const char* inputfile, const char* outputfile)
{
	CMoFileIO	outFile;
	DStream		*pStream;

	if(!outFile.Open(outputfile, "wb"))
	{
		printf("\nError: can't open %s", outputfile);
		return;
	}

	if(!(pStream = streamsim_Open((LPCTSTR)inputfile, "rb")))
	{
		printf("\nError: can't open %s", inputfile);
		outFile.Close();
		return;
	}
	DEBUG_EXEC(printf("\nDTX2BPP_32P"));
	CString dtxfilename = outputfile;
	// _asm int 3;
	if(!SaveDtxAs8Bit(pStream, outFile, &dtxfilename ))
	{
		printf("\nError: operation unsuccessful");
	}
	pStream->Release();
}
Beispiel #5
0
BOOL DtxUtil::DTX2TGAhandler(const char* inputfile, const char* outputfile)
{
	CMoFileIO	outFile;
	DStream		*pStream;

	if(!outFile.Open(outputfile, "wb"))
	{
		printf("\nError: can't open %s", outputfile);
		return FALSE;
	}

	if(!(pStream = streamsim_Open((LPCTSTR)inputfile, "rb")))
	{
		printf("\nError: can't open %s", inputfile);
		outFile.Close();
		return FALSE;
	}

	DEBUG_EXEC(printf("\nDTX2TGA"));
	if(!SaveDtxAsTga(pStream, outFile ))
	{
		printf("\nError: operation unsuccessful");
		return FALSE;
	}
	pStream->Release();
	return TRUE;
}
Beispiel #6
0
/* Searches the environment for variables that are named token, and returns
 * a variable if found, null otherwise
 */
Var * Env(char *token) {
    DEBUG_PARS("Environment contains %d variables\n", env->varcount);

    for (int i = 0; i < env->varcount; i++) {
        DEBUG_PARS("\t%s variable: \"%s\"\n", TypeLabel(env->vars[i]->type),
                   env->vars[i]->label);
        if (strcmp(env->vars[i]->label, token) == 0) {
            DEBUG_EXEC("Found %s in environment at %d\n", env->vars[i]->label, i);
            return env->vars[i];
        }
    }

    return NULL;
}
Beispiel #7
0
void DtxUtil::RecursiveHandlerWrapper(const char* startdir, const char* outputdir, char* command, int option)
{
	char buffer[1024];
	if (option != R_DTX2TGA)
	{
		sprintf(buffer,"rmdir /S /Q %s", outputdir);
		DEBUG_EXEC(printf("\nsystem(%s)", buffer));
		system(buffer);
		_mkdir(outputdir);
		sprintf(buffer,"%s//%s", outputdir, startdir);
		_mkdir(buffer);
	}

	RecursiveHandler(startdir, outputdir, command, option);
}
Beispiel #8
0
void DtxUtil::TGA2DTXhandler( const char* inputfile, const char* outputfile)
{
	DEBUG_EXEC(printf("\nTGA2DTX"));
	LoadedBitmap bitmap;
	CString str;
	DStream *pStream, *pInFile;


	if( pInFile = streamsim_Open(inputfile, "rb") )
	{
		tga_Create2(pInFile, &bitmap);
		if( dtx_IsTextureSizeValid(bitmap.m_Width) && dtx_IsTextureSizeValid(bitmap.m_Height) )
		{
			pStream = streamsim_Open(outputfile, "wb");
			if(pStream)
			{
				SavePcxAsTexture(&bitmap, pStream, 0);
				pStream->Release();
			}
		}
	}
}
Beispiel #9
0
acpi_status
acpi_ns_init_one_device (
	acpi_handle             obj_handle,
	u32                     nesting_level,
	void                    *context,
	void                    **return_value)
{
	acpi_status             status;
	acpi_namespace_node    *node;
	u32                     flags;
	acpi_device_walk_info  *info = (acpi_device_walk_info *) context;


	FUNCTION_TRACE ("Ns_init_one_device");


	if (!(acpi_dbg_level & ACPI_LV_INIT)) {
		ACPI_DEBUG_PRINT_RAW ((ACPI_DB_OK, "."));
	}

	info->device_count++;

	acpi_ut_acquire_mutex (ACPI_MTX_NAMESPACE);

	node = acpi_ns_map_handle_to_node (obj_handle);
	if (!node) {
		acpi_ut_release_mutex (ACPI_MTX_NAMESPACE);
		return (AE_BAD_PARAMETER);
	}

	acpi_ut_release_mutex (ACPI_MTX_NAMESPACE);

	/*
	 * Run _STA to determine if we can run _INI on the device.
	 */
	DEBUG_EXEC (acpi_ut_display_init_pathname (node, "_STA [Method]"));
	status = acpi_ut_execute_STA (node, &flags);
	if (ACPI_FAILURE (status)) {
		/* Ignore error and move on to next device */

		return_ACPI_STATUS (AE_OK);
	}

	info->num_STA++;

	if (!(flags & 0x01)) {
		/* don't look at children of a not present device */

		return_ACPI_STATUS(AE_CTRL_DEPTH);
	}


	/*
	 * The device is present. Run _INI.
	 */
	DEBUG_EXEC (acpi_ut_display_init_pathname (obj_handle, "_INI [Method]"));
	status = acpi_ns_evaluate_relative (obj_handle, "_INI", NULL, NULL);
	if (AE_NOT_FOUND == status) {
		/* No _INI means device requires no initialization */

		status = AE_OK;
	}

	else if (ACPI_FAILURE (status)) {
		/* Ignore error and move on to next device */

#ifdef ACPI_DEBUG
		NATIVE_CHAR *scope_name = acpi_ns_get_table_pathname (obj_handle);

		ACPI_DEBUG_PRINT ((ACPI_DB_WARN, "%s._INI failed: %s\n",
				scope_name, acpi_format_exception (status)));

		ACPI_MEM_FREE (scope_name);
#endif
	}

	else {
		/* Count of successful INIs */

		info->num_INI++;
	}

	return_ACPI_STATUS (AE_OK);
}
Beispiel #10
0
void RecursiveHandler(const char* startdir, const char* outputdir, char* command, int option )
{
	WIN32_FIND_DATA	findData;
	HANDLE			findHandle;
	CString			startdirDyn;

	startdirDyn		= startdir;
	startdirDyn		+= "\\*.*";
	findHandle		= FindFirstFile(LPCTSTR(startdirDyn), &findData );

	DEBUG_EXEC(printf("\ndir: %s", LPCTSTR(startdirDyn)));
	if( INVALID_HANDLE_VALUE != findHandle )
	{
		int count = 0;
		do
		{
			if( count > 1 )
			{
				CString	 subDirDyn;
				subDirDyn = startdir;
				subDirDyn += "\\";
				subDirDyn += findData.cFileName;
				CString	 outputDirDyn;
				outputDirDyn  = outputdir;
				outputDirDyn += "\\";
				outputDirDyn += subDirDyn;

				if( findData.dwFileAttributes == FILE_ATTRIBUTE_DIRECTORY )
				{
					DEBUG_EXEC(printf("\ndir:	"));
					DEBUG_EXEC(printf("(%s)", findData.cFileName ));
					_mkdir(LPCTSTR(outputDirDyn)); DEBUG_EXEC(printf("\nmkdir: %s", LPCTSTR(outputDirDyn)));
					RecursiveHandler(LPCTSTR(subDirDyn), outputdir, command, option);

				}
				else
				{
					DEBUG_EXEC(printf("\nprocess: "));
					CString	 fileNameDyn;
					fileNameDyn = startdir;
					fileNameDyn += "\\";
					fileNameDyn += findData.cFileName;
					DEBUG_EXEC(printf("%s -> %s", LPCTSTR(fileNameDyn), LPCTSTR(outputDirDyn) ));
					char buffer[1024];
					switch(option)
					{
					case R_QUANTIZE:
						sprintf(buffer, "%s -q %s %s", command, LPCTSTR(fileNameDyn), LPCTSTR(outputDirDyn)  );
						DEBUG_EXEC(printf("\n%s",buffer));
						system(buffer);
						break;
					case R_QUANTIZE_ALL:
						sprintf(buffer, "%s -qa %s %s", command, LPCTSTR(fileNameDyn), LPCTSTR(outputDirDyn)  );
						DEBUG_EXEC(printf("\n%s",buffer));
						system(buffer);
						break;
					case R_DTX2TGA:
						char tempBuf[256], tempBuf2[256];
						memset(tempBuf, '\0', 256);
						memset(tempBuf2, '\0', 256);
						strncpy(tempBuf, fileNameDyn, strlen(fileNameDyn)-3);
						// printf("\n\n\n%s\n\n", tempBuf);
						sprintf(tempBuf2, "%stga", tempBuf);
						// printf("\n\n%s\n\n\n", tempBuf2);
						sprintf(buffer, "%s -dtx2tga %s %s", command, LPCTSTR(fileNameDyn), LPCTSTR(tempBuf2));
						DEBUG_EXEC(printf("\n%s",buffer));
						system(buffer);
						break;
					};
					// QuantizeAllhandler(LPCTSTR(fileNameDyn), LPCTSTR(outputDirDyn) );
				}
			}
			count++;
		} while( FindNextFile(findHandle,&findData ) );

		FindClose(findHandle);
	}
}
Beispiel #11
0
void DtxUtil::Quantizehandler(const char* inputfile, const char* outputfile, char* command )
{
	// determine the number of distinct colors with alpha
	// 1         -> just do normal quantization to 256 colors
	// 2         -> chromakey, quantize to 255, transparent to (0,0,0,0)
	// n <= 255  -> quant to 256 - n
	// n >  256  -> true 32 bit

	uint8	alpha	 = 0;
	// determine the number of distinct colors with alpha
	int		numAlpha = NumColorsWithAlphaInDTX(inputfile,&alpha);

	DEBUG_EXEC(printf("\nnumAlpha = %d alpha = %d", numAlpha, alpha));

	char buffer[1024];
	// 1         -> just do normal quantization to 256 colors
	if( 1 == numAlpha )
	{
		CString tgaFile = "tmp.tga";//inputfile;  tgaFile += ".tga";
		CString tmpFile = inputfile;  tmpFile += ".dtx";
		// DTX->TGA
		if( DTX2TGAhandler(inputfile, LPCTSTR(tgaFile)) )
		{
			// TGA 32bit -> TGA256
			sprintf( buffer,"imgconvert -colors 256 -colorspace Transparent %s %s", LPCTSTR(tgaFile), LPCTSTR(tgaFile) );
			system( buffer );
			// TGA->DTX
			TGA2DTXhandler(LPCTSTR(tgaFile), LPCTSTR(tmpFile));
			// DTX->BPP32P
			DTX2BPP_32Phandler(LPCTSTR(tmpFile), outputfile);

			DELETE_FILE(LPCTSTR(tgaFile));
			DELETE_FILE(LPCTSTR(tmpFile));
		}
		else
		{
			DELETE_FILE(LPCTSTR(tgaFile));
		}
		// sprintf( buffer,"echo %cCONVERT\%c", '%', '%' );
		// system( buffer );
	}
	// 2         -> chromakey, quantize to 255, transparent to (0,0,0,0)
	else if( 2 == numAlpha)
	{
		CString tgaFile = inputfile;  tgaFile += ".tga";
		CString tmpFile = inputfile;  tmpFile += ".dtx";
		// DTX->TGA
		if( DTX2TGAhandler(inputfile, LPCTSTR(tgaFile)) )
		{
			// TGA 32bit -> TGA256
			sprintf( buffer,"imgconvert -colors 255 -colorspace Transparent %s %s", LPCTSTR(tgaFile), LPCTSTR(tgaFile) );
			system( buffer );
			// TGA->DTX
			TGA2DTXhandler(LPCTSTR(tgaFile), LPCTSTR(tmpFile));
			// DTX->BPP32P
			DTX2BPP_32Phandler(LPCTSTR(tmpFile), outputfile);
			DELETE_FILE(LPCTSTR(tgaFile));
			DELETE_FILE(LPCTSTR(tmpFile));
		}
		else
		{
			DELETE_FILE(LPCTSTR(tgaFile));
		}
	}
	// n >  256  -> true 32 bit
	else
	{
		CString tgaFile = inputfile;  tgaFile += ".tga";
		CString tmpFile = inputfile;  tmpFile += ".dtx";
		// DTX->TGA
		if( DTX2TGAhandler(inputfile, LPCTSTR(tgaFile)) )
		{
			printf("\nwarning: %s has too many gradients of alpha, forcing 32 bit", inputfile );
			sprintf( buffer,"\ncopy /Y %s %s", inputfile, outputfile );
			printf(buffer);
			system( buffer );
		}
		else
		{
			DELETE_FILE(LPCTSTR(tgaFile));
		}
	}
}