示例#1
0
文件: warning.cpp 项目: roxygen/maid2
/*!
    @param	level	[i ]	警告レベル。基本的に任意
*/
void Warning::OnAlert( int level )
{
    static ThreadMutex  s_Douki;
    ThreadMutexLocker Lock(s_Douki);
    std::string text = m_StreamBuf.GetBuffer();

    if( !text.empty() )
    {
        int len = (int)text.length();
        //	末尾に \n がついてたらはずす
        if( text[len-1]=='\n' )
        {
            text.resize(len-1);
        }
    }

    std::string line;
    {
        char buf[256];
        sprintf( buf, "%d", m_Line );
        line = buf;
    }

    const std::string output = text + " " + line + "行目 " + m_FileName + "\n";

    if( !(level<NUMELEMENTS(s_Function)) || !(s_Function[level]) )
    {
        FILE* hFile = ::fopen( "warning.txt", "a" );
        ::fprintf( hFile, "%s", output.c_str() );
        ::fclose( hFile );
    } else
    {
        s_Function[level]( output );
    }
}
示例#2
0
文件: warning.cpp 项目: roxygen/maid2
/*!
    @param	level	[i ]	設定する警告レベル。
    @param	func	[i ]	呼び出す関数。
*/
void Warning::SetAlertFunction( int level, const FUNCTION& func )
{
    if( !(level<NUMELEMENTS(s_Function)) )
    {
        MAID_WARNING( "範囲外です" );
        return ;
    }
    s_Function[level] = func;

}
示例#3
0
void SMsgHeader::SetMsgSize(size_t size)
{
	int count = _snprintf(MsgSize, NUMELEMENTS(MsgSize), "%d", size);
	assert(count >= 0 && count < NUMELEMENTS(MsgSize));
}
示例#4
0
	"DONE",
	"EXEP",
	"GLOB",
	"LOCS",
	"MODS",
	"EXEC",
	"BRPT",
	"BRNW",
	"STEP",
	"LOAD",
	"STOP",
	"EXIT",
};

//check to see that there are the right number of elements in asxMsgIds
CompileTimeAssert(NUMELEMENTS(aszMsgIds) == eMSG_NUMMSGS);




const char* GetMsgString(EMessageType eType)
{
	//check the eType parameter
	assert((eType > eMSG_INVALID) && (eType < eMSG_NUMMSGS));
	//verify the type string is the correct length
	assert(strlen(aszMsgIds[eType]) == sizeof(uint32_t));
	
	return aszMsgIds[eType];
}

uint32_t GetMsgVal(EMessageType eType)
示例#5
0
static void FilterScaleBitmap(CSBitmap* SourceBitmap, CSBitmap* DestBitmap)
{
	const int NumSourceChannels = GetChannels(SourceBitmap);
	int NumSourceSkipChannels = NumSourceChannels;
	const int NumDestChannels = GetChannels(DestBitmap);
	const int kNumFilterChannels = 3;	// Number of channels to filter.
	// Bilinear filtering.
	// Simple floating point code, with precalculated x-locations.
	double YRatio = GetHeight(SourceBitmap) / (double)GetHeight(DestBitmap);
	double XRatio = GetWidth(SourceBitmap) / (double)GetWidth(DestBitmap);

	RGBQUAD	paletteRGBQUAD[256];
	uint8_t	bytePalette[256 * kNumFilterChannels];
	if (NumSourceChannels == 1)
	{
		GetPalette(SourceBitmap, 0, 256, paletteRGBQUAD);
		NumSourceSkipChannels = kNumFilterChannels;
		// After getting the palette, copy it into a layout that is guaranteed to match that
		// of pixels in a bitmap.
		for (int i = 0; i < NUMELEMENTS(paletteRGBQUAD); ++i)
		{
			bytePalette[i * kNumFilterChannels + RED_BITMAP_OFFSET] = paletteRGBQUAD[i].rgbRed;
			bytePalette[i * kNumFilterChannels + GREEN_BITMAP_OFFSET] = paletteRGBQUAD[i].rgbGreen;
			bytePalette[i * kNumFilterChannels + BLUE_BITMAP_OFFSET] = paletteRGBQUAD[i].rgbBlue;
		}
	}
	// Optimized version of filtered scaling.
	// Should probably use new[], but I'm trying to stick to C style code.
	float* SrcXBuffer = (float*)malloc(sizeof(float) * GetWidth(DestBitmap));
	if (!SrcXBuffer)
		return;
	// Precalculate the sourceX values, including left edge clipping them.
	for (int x = 0; x < GetWidth(DestBitmap); ++x)
	{
		double SourceX = (x + 0.5) * XRatio;
		assert(SourceX >= 0 && SourceX < GetWidth(SourceBitmap));
		SourceX -= 0.5;	// Adjust into a more convenient range. Now represents
		// the left edge of the pixel.
		// Deal with the unfortunate border cases. We are clamping the pixels.
		// Other possibilities include wrapping, or using a border colour.
		if (SourceX < 0)
			SourceX = 0;
		if (SourceX >= GetWidth(SourceBitmap) - 1)
			SourceX = GetWidth(SourceBitmap) - 1;
		SrcXBuffer[x] = (float)SourceX;
	}
	for (int y = 0; y < GetHeight(DestBitmap); ++y)
	{
		double SourceY = (y + 0.5) * YRatio;
		assert(SourceY >= 0 && SourceY < GetHeight(SourceBitmap));
		SourceY -= 0.5;	// Adjust into a more convenient range. Now represents
		// the left edge of the pixel.
		// Deal with the unfortunate border cases. We are clamping the pixels.
		// Other possibilities include wrapping, or using a border colour.
		if (SourceY < 0)
			SourceY = 0;
		if (SourceY > GetHeight(SourceBitmap) - 1)
			SourceY = GetHeight(SourceBitmap) - 1;
		// If SourceY might be negative you have to use floor() instead of just casting to int.
		int FirstLine = (int)SourceY;
		double SecondLineWeight = SourceY - FirstLine;

		// We don't need asserts here because GetLinePtr() will check the y-coordinate.
		uint8_t* pDestLine = GetLinePtr(DestBitmap, y);
		uint8_t* pSourceLine1 = GetLinePtr(SourceBitmap, FirstLine);
		// Make sure we don't try getting the address of a non-existent line.
		// Make sure this always gets initialized to something.
		uint8_t* pSourceLine2 = pSourceLine1;
		if (FirstLine + 1 < GetHeight(SourceBitmap))
			pSourceLine2 = GetLinePtr(SourceBitmap, FirstLine + 1);
		uint8_t* pSourcePixel1Left;	// Top line, left pixel.
		uint8_t* pSourcePixel2Left;	// Second line, left pixel.
		for (int x = 0; x < GetWidth(DestBitmap); ++x)
		{
			double SourceX = SrcXBuffer[x];
			int FirstPixel = int(SourceX);
			// Set up pointers into the bitmap or the palette, for the left sample pixels.
			if (NumSourceChannels == 1)
			{
				pSourcePixel1Left = bytePalette + pSourceLine1[FirstPixel] * kNumFilterChannels;
				pSourcePixel2Left = bytePalette + pSourceLine2[FirstPixel] * kNumFilterChannels;
			}
			else
			{
				pSourcePixel1Left = pSourceLine1 + FirstPixel * NumSourceChannels;
				pSourcePixel2Left = pSourceLine2 + FirstPixel * NumSourceChannels;
			}
			uint8_t* pSourcePixel1Right;	// Top line, right pixel.
			uint8_t* pSourcePixel2Right;	// Second line, right pixel.
			// Now setup pointers into the bitmap or the palette, for the right
			// sample pixels. If there are no right sample pixels (right edge)
			// then point at the left sample pixels.
			if (SourceX >= GetWidth(SourceBitmap) - 1)
			{
				pSourcePixel1Right = pSourcePixel1Left;
				pSourcePixel2Right = pSourcePixel2Left;
			}
			else
			{
				if (NumSourceChannels == 1)
				{
					pSourcePixel1Right = bytePalette + pSourceLine1[FirstPixel+1] * kNumFilterChannels;
					pSourcePixel2Right = bytePalette + pSourceLine2[FirstPixel+1] * kNumFilterChannels;
				}
				else
				{
					pSourcePixel1Right = pSourcePixel1Left + NumSourceChannels;
					pSourcePixel2Right = pSourcePixel2Left + NumSourceChannels;
				}
			}
			double SecondPixelWeight = SourceX - FirstPixel;
			for (int channel = 0; channel < kNumFilterChannels; ++channel)
			{
				double FirstLine = pSourcePixel1Left[channel] + (pSourcePixel1Right[channel] - pSourcePixel1Left[channel]) * SecondPixelWeight;
				double SecondLine = pSourcePixel2Left[channel] + (pSourcePixel2Right[channel] - pSourcePixel2Left[channel]) * SecondPixelWeight;
				pDestLine[channel] = (uint8_t)(FirstLine + (SecondLine - FirstLine) * SecondLineWeight);
			}
			pDestLine += NumDestChannels;
		}
	}
	free(SrcXBuffer);
}