Exemple #1
0
CSimulatorIn::~CSimulatorIn()
{
	if(DumpFile != NULL) fclose(DumpFile);

	// Free all allocated memory
	DeleteAllData();

	if(WorkQueueMap != NULL) delete WorkQueueMap;
	if(PeerInfoMap != NULL) delete PeerInfoMap;
	if(ContentInfoMap != NULL) delete ContentInfoMap;
}
Exemple #2
0
void CSimulatorIn::Reset(unsigned long RandomSeed)
{
	// Free all allocated memory
	DeleteAllData();

	if(WorkQueueMap != NULL) delete WorkQueueMap;
	WorkQueueMap = new CAtlMap<unsigned int, CWorkQueue*>();
	if(PeerInfoMap != NULL) delete PeerInfoMap;
	PeerInfoMap = new CAtlMap<unsigned int, CPeerInfo*>();
	if(ContentInfoMap != NULL) delete ContentInfoMap;
	ContentInfoMap = new CAtlMap<unsigned int, CContentInfo*>();

	CacheMode = MODE_CACHE_OFF;
	GroupMode = MODE_GROUPING_OFF;

	Log = "";

	Step = 0;

	NewPeerID = 0;
	
	InitRandomSeed = RandomSeed;
	wRand.SetSeed(RandomSeed);

	StatisticsTotalSearchContentCount = 0;
	StatisticsTotalSearchContentSuccessCount = 0;
	StatisticsTotalSearchContentHopCount = 0;
	StatisticsTotalMessageCount = 0;
	memset(StatisticsTotalMessageCountEach, 0, sizeof(StatisticsTotalMessageCountEach));

	// Set environment to default 
	SetEnvironmentDefault();

	/*JIN*/
	GroupMaxNumber = 0;
}
Exemple #3
0
int CRaster::CreateRaster(DWORD width, DWORD height, int bitPerPixel)
{
    DWORD               numColor;
    LOGPALETTE          *logPal;
    switch(bitPerPixel) {
    case 1:
        shiftPixel  = (width + 7) / 8;
        break;
    case 4:
        shiftPixel  = (width + 1) / 2;
        break;
    case 8:
        shiftPixel  = width;
        break;
    case 24:
        shiftPixel  = width * 3;
        break;
    default:
        return -1;
    }/* switch */

    if(flag) {
        DeleteAllData();
    }/* if */

    numColor = 1 << bitPerPixel;

    if(	bitPerPixel == 1 ||
        bitPerPixel == 4 ||
        bitPerPixel == 8) { // type of bitmap

        imgInfo = (BITMAPINFO*)malloc(  sizeof(BITMAPINFO) 
                                        + sizeof(RGBQUAD) * numColor);
    // Create Palette for 1<<bitCount colors
        pal     = new CPalette();
        logPal  = (LOGPALETTE*)calloc(  1, sizeof(LOGPALETTE) 
                                        + sizeof(PALETTEENTRY) * numColor);
        logPal->palVersion      = 0x300;
        logPal->palNumEntries   = (WORD)numColor;

        for(DWORD Index = 0; Index < numColor; Index++) {
            logPal->palPalEntry[Index].peRed    = (BYTE)Index;
            logPal->palPalEntry[Index].peGreen  = (BYTE)Index;
            logPal->palPalEntry[Index].peBlue   = (BYTE)Index;
        }/* for */

        pal->CreatePalette(logPal);
        free(logPal);
    } else
        if( bitPerPixel == 24 ) {
            imgInfo = (BITMAPINFO*)malloc(  sizeof(BITMAPINFO) 
                                            + sizeof(RGBQUAD));
    }/* if */

    sizeString  = (shiftPixel + 3) / 4 * 4; // Attention !!! divided 4 !!!;

    imgInfo = (BITMAPINFO*)calloc(  sizeof(BITMAPINFO) + sizeof(RGBQUAD), 1);
    imgInfo->bmiHeader.biSize           = sizeof(BITMAPINFOHEADER);
    imgInfo->bmiHeader.biWidth          = width;
    imgInfo->bmiHeader.biHeight         = -(int)(height);
    imgInfo->bmiHeader.biPlanes         = 1;
    imgInfo->bmiHeader.biBitCount       = WORD(bitPerPixel);
    imgInfo->bmiHeader.biCompression    = BI_RGB;
    imgInfo->bmiHeader.biSizeImage      = sizeString*height;

    imgDataSave     = new BYTE[sizeString*height];
    imgData         = new BYTE[sizeString*height];

    return 1;
}/* CRaster::CreateRaster */
Exemple #4
0
CRaster::~CRaster()
{
    DeleteAllData();
}/* CRaster::~CRaster */
Exemple #5
0
int CRaster::LoadBMP(const char* cfileName)
{
    CFile   file;
    BITMAPFILEHEADER    fileHeader;
    BITMAPINFOHEADER    infoHeader;
    DWORD               width, height;

    LOGPALETTE          *logPal;

    DWORD               Index;
    WORD                bitCount;
    BYTE*               tempImage;

    if(flag) {
        DeleteAllData();
    }/* if */

    if(file.Open(cfileName, CFile::modeRead, NULL) == 0)
        return -1;

    fileName    = cfileName; 

    file.Read(&fileHeader, sizeof(BITMAPFILEHEADER));
    if(fileHeader.bfType != 0x4d42) {
        file.Close();
        return -1;
    } /* if... it's not BMP */

// Load bitmap info
    file.Read(&infoHeader, sizeof(BITMAPINFOHEADER));
    bitCount    = infoHeader.biBitCount;
    if(infoHeader.biCompression != BI_RGB ) {
        file.Close();
        return -2;
    }/* if */
    if( bitCount == 1 ||
        bitCount == 4 ||
        bitCount == 8) { // type of bitmap

        DWORD numColor = infoHeader.biClrUsed;
        if(numColor == 0) {
            numColor = 1<<bitCount;
        }

        imgInfo = (BITMAPINFO*)malloc(  sizeof(BITMAPINFO) 
                                        + sizeof(RGBQUAD) * (1<<bitCount));
        file.Read(imgInfo->bmiColors, sizeof(RGBQUAD) * numColor);

    // Create Palette for 1<<bitCount colors
        pal     = new CPalette();
        logPal  = (LOGPALETTE*)
                    calloc( 1,  sizeof(LOGPALETTE) 
                                    + sizeof(PALETTEENTRY) * (1<<bitCount));

        logPal->palVersion      = 0x300;
        logPal->palNumEntries   = BYTE(1<<bitCount);

        for(Index = 0; Index < numColor; Index++) {

            logPal->palPalEntry[Index].peRed    =
                imgInfo->bmiColors[Index].rgbRed;

            logPal->palPalEntry[Index].peGreen	=
                imgInfo->bmiColors[Index].rgbGreen;

            logPal->palPalEntry[Index].peBlue   =
                imgInfo->bmiColors[Index].rgbBlue;
        }/* for */

        pal->CreatePalette(logPal);
        free(logPal);
    } else if(  bitCount == 24 ) {
        imgInfo = (BITMAPINFO*)malloc(  sizeof(BITMAPINFO) 
                                        + sizeof(RGBQUAD));
    } else {
        file.Close();
        return -2;
    } /* if... not support BMP */

    imgInfo->bmiHeader	= infoHeader;

// Load image data
    width   = imgInfo->bmiHeader.biWidth;
    height  = abs(imgInfo->bmiHeader.biHeight);

    switch(bitCount) {
    case 1:
        shiftPixel  = (width + 7) / 8;
        break;
    case 4:
        shiftPixel  = (width + 1) / 2;
        break;
    case 8:
        shiftPixel  = width;
        break;
    case 24:
        shiftPixel  = width * 3;
        break;
    }/* switch */

    DestWidth   = width;
    DestHeight  = height;
    SrcWidth    = width;
    SrcHeight   = height;

    sizeString  = (shiftPixel + 3) / 4 * 4;	// Attention !!! divided 4 !!!;

    tempImage       = new BYTE[sizeString*height];
    imgData         = new BYTE[sizeString*height];
    imgDataSave     = tempImage;

    for(Index = 0; Index < height; Index++) {
        file.Read(tempImage, sizeString);
        tempImage+=sizeString;
    }/* for */

    imgInfo->bmiHeader.biHeight = -abs(imgInfo->bmiHeader.biHeight);

    UpdateImage(0);
    flag    = 1;
    file.Close();
    return 1;
}/* CRaster::LoadBMP */