Example #1
0
void StencilComp::Read (istream& in) {
    GraphicComp::Read(in);
    Bitmap* image = ReadBitmap(in);
    Bitmap* mask = nil;

    Skip(in);
    int m;
    in >> m;

    if (m == valid_mask) {
        mask = ReadBitmap(in);
    } else if (m == mask_equals_image) {
        mask = image;
    }

    UStencil* stencil = new UStencil(image, mask);
    stencil->FillBg(ReadBgFilled(in));
    PSColor* fg = ReadColor(in);
    PSColor* bg = ReadColor(in);
    stencil->SetColors(fg, bg);

    Transformer* t = ReadTransformer(in);
    stencil->SetTransformer(t);
    Unref(t);

    SetGraphic(stencil);
    _filename = ReadString(in);
}
Example #2
0
int32
Controller::CaptureThread()
{
	Settings settings;
	BScreen screen;
	BRect bounds = settings.CaptureArea();
	bigtime_t captureDelay = (bigtime_t)settings.CaptureFrameDelay() * 1000;
	
	// TODO: Validate captureDelay with some limits
	
	_DumpSettings();
	_TestWaitForRetrace();
	
	const int32 windowBorder = settings.WindowFrameBorderSize();
	int32 token = GetWindowTokenForFrame(bounds, windowBorder);
	bigtime_t waitTime = 0;
	status_t error = B_ERROR;
	while (!fKillThread) {
		if (!fPaused) {		
			if (token != -1) {
				BRect windowBounds = GetWindowFrameForToken(token, windowBorder);
				if (windowBounds.IsValid())
					bounds.OffsetTo(windowBounds.LeftTop());
			}
				
			_WaitForRetrace(captureDelay); // Wait for Vsync
			BBitmap *bitmap = new BBitmap(bounds, screen.ColorSpace());
			error = ReadBitmap(bitmap, true, bounds);
			bigtime_t currentTime = system_time();
			// Takes ownership of the bitmap
	    	if (error == B_OK && fFileList->AddItem(bitmap, currentTime))
				atomic_add(&fNumFrames, 1);
			else {
				delete bitmap;
				break;
			}
		} else
			snooze(500000);
	}
	
	fCaptureThread = -1;
	fKillThread = true;
	
	if (error != B_OK) {
		BMessage message(kMsgControllerCaptureStopped);
		message.AddInt32("status", (int32)error);
		SendNotices(kMsgControllerCaptureStopped, &message);
		
		delete fFileList;
		fFileList = NULL;
	}
		
	return B_OK;
}
Example #3
0
void CExampleDemoDlg::OnBnClickedBtnNext()
{
	SAFE_DELETE(m_pOrignImage);
//当要按下个按钮的时候,保存上一张图片的选择结果到相应的文件夹中,移动新的图片,需要等到delete后,才能移动,否则无法访问

	if (m_classifyid>=0)
	{
		CString classify_file;
		classify_file.Format("%d", m_classifyid);
		classify_file =classify_file+"\\"+ CString(m_imagefilename.back().c_str());
		CString imgpath = m_imagefilepathname.back().c_str();
		MoveFile(imgpath, classify_file);
		//MoveFile("0.jpg", "t.jpg");
		m_imagefilepathname.pop_back();
		m_imagefilename.pop_back();
		((CButton *)GetDlgItem(IDC_GROUP_BUTTON+ m_classifyid))->SetCheck(FALSE);
		m_classifyid = -1;
	}


	if (m_imagefilepathname.empty())
	{
		AfxMessageBox("当前文件已挑选完毕,请重新选择新的文件夹");
		m_classifyid = -1;
		return;
	}
	string strFoo = m_imagefilepathname.back();
	m_pOrignImage = ReadBitmap(strFoo);
	if (!GetFaceRect(m_pOrignImage))
	{	
		m_classifyid = 19;
		SAFE_DELETE(m_pOrignImage);
		OnBnClickedBtnNext();
		//remove(szName);

		//m_imagefilepathname.pop_back();
		//m_imagefilename.pop_back();

	}



	//SAFE_DELETE(pInImage);
	this->Invalidate(FALSE);
}
Example #4
0
// ************************************************************
//		ProcessResults()
// ************************************************************
CMemoryBitmap* BaseProvider::ProcessHttpRequest(void* secureHttpClient, CString url, CString shortUrl, bool success)
{
	SecureHttpClient* client = reinterpret_cast<SecureHttpClient*>(secureHttpClient);

	if (_isStopped)  return NULL;

	if (!success) client->LogHttpError();

	TileHttpContentType contentType = client->get_ContentType(Id);

	char* body = NULL;
	int length = 0;

	if (success && client->GetStatus() == 200)
	{
		client->ReadBody(&body, length);
	}

	client->LogRequest(length, shortUrl, url);

	CMemoryBitmap* bmp = NULL;
	switch (contentType)
	{
	case httpImage:
		bmp = ReadBitmap(body, length);
		break;
	case httpXml:
		if (IsWms())
		{
			CString s(body);
			ParseServerException(s);
		}
		break;
	default:
		break;
	}

	if (body) {
		delete[] body;
	}

	return bmp;
}
int main (int argc, char *argv[])
{
   FILE *fpin, *fpout, *fptxt;
   BITMAP img;

   if (argc != 4)
   {                                                         
      printf ("ARGOMENTI: <file in> <file out> <textfile>\n");
      exit (EXIT_FAILURE);
   }

   if ((fpin = fopen (argv[1], "rb")) == NULL)
   {
      printf ("Error opening input file\n");
      exit (EXIT_FAILURE);
   }

   if ((fpout = fopen (argv[2], "wb")) == NULL)
   {
      printf ("Error opening output file\n");
      exit (EXIT_FAILURE);
   }

   if ((fptxt = fopen (argv[3], "r")) == NULL)
   {
      printf ("Error opening text file\n");
      exit (EXIT_FAILURE);
   }

   img = ReadBitmap (fpin);
   fclose (fpin);

   encode (img, fptxt);
   fclose (fptxt);

   WriteBitmap (img, fpout);
   fclose (fpout);

   ReleaseBitmapData (&img);

   return EXIT_SUCCESS;
}
Example #6
0
/*--------------------------------------------------
  read settings
----------------------------------------------------*/
void InitStartMenuSetting(HWND hwndClock)
{
	char fname[MAX_PATH], s[MAX_PATH];
	
	m_bStartMenu = GetMyRegLong(NULL, "StartMenu", FALSE);
	m_bStartMenu = GetMyRegLong(m_section, "StartMenu", m_bStartMenu);
	
	m_alpha = GetMyRegLong(NULL, "AlphaStartMenu", 0);
	m_alpha = GetMyRegLong(m_section, "Alpha", m_alpha);
	m_alpha = 255 - (m_alpha * 255 / 100);
	if(m_alpha < 8) m_alpha = 8;
	else if(m_alpha > 255) m_alpha = 255;
	
	if(m_bStartMenu || m_alpha < 255) m_bSubclass = TRUE;
	
	if(!m_bStartMenu) return;
	
	m_colMenu = GetMyRegLong(NULL, "StartMenuCol",
		RGB(128, 128, 128));
	m_colMenu = GetMyRegLong(m_section, "Color", m_colMenu);
	
	m_bTile = GetMyRegLong(NULL, "StartMenuTile", FALSE);
	m_bTile = GetMyRegLong(m_section, "Tile", m_bTile);
	
	GetMyRegStr(NULL, "StartMenuBmp", s, MAX_PATH, "");
	GetMyRegStr(m_section, "Bitmap", fname, MAX_PATH, s);
	
	if(fname[0]) // load bitmap
	{
		char fname2[MAX_PATH];
		RelToAbs(fname2, fname);
		m_hbmpMenu = ReadBitmap(hwndClock, fname2, FALSE);
		if(m_hbmpMenu)
		{
			HDC hdc;
			hdc = GetDC(hwndClock);
			m_hdcMemMenu = CreateCompatibleDC(hdc);
			SelectObject(m_hdcMemMenu, m_hbmpMenu);
			ReleaseDC(hwndClock, hdc);
		}
	}
}
Example #7
0
int _tmain(int argc, _TCHAR* argv[])
{
	if( argc < 2 )
	{
		_tprintf(_T("converts a picture to a tank skin\n"));
		_tprintf(_T("only 24-bit windows bitmaps supports\n"));
		_tprintf(_T("using: mkskin input_file.bmp [output_file.bmp]\n"));
		return 0;
	}

	_tprintf(_T("input file: \n  %s\n"), argv[1]);

	BITMAPFILEHEADER bmfh	= {0};
	BITMAPINFOHEADER bmih	= {0};

	RGBTRIPLE *pInputBits = NULL;
	if( !ReadBitmap(argv[1], &bmfh, &bmih, &pInputBits) )
		return -1;

	RGBTRIPLE *pOutputBits = new RGBTRIPLE[FRAME_WIDTH * FRAME_HEIGHT * FRAME_COUNT];
    MakeSkin(pOutputBits, pInputBits, &bmih);

	bmih.biSizeImage = FRAME_WIDTH * FRAME_HEIGHT * FRAME_COUNT * sizeof(RGBTRIPLE);
	bmfh.bfSize      = bmih.biSizeImage + bmfh.bfOffBits;
	bmih.biWidth     = FRAME_WIDTH * X_FRAMES;
	bmih.biHeight    = FRAME_HEIGHT * Y_FRAMES;

	_TCHAR outfn[MAX_PATH];
	if( argc > 2 ) _tcscpy(outfn, argv[2]);
	else _stprintf(outfn, _T("%s-skin.bmp"), argv[1]);

	_tprintf(_T("output file: \n  %s\n"), outfn);
	if( WriteBitmap(outfn, &bmfh, &bmih, pOutputBits) )
		_tprintf(_T("OK.\n"));
	else
		Sleep(1000);

	delete[] pOutputBits;
	delete[] pInputBits;
	return 0;
}
Example #8
0
void LoadReplacementBitmaps (const char *pszLevelName)
{
	char		szFilename [SHORT_FILENAME_LEN];
	CFile		cf;
	int		i, j;
	CBitmap	bm;

//first, free up data allocated for old bitmaps
PrintLog ("   loading replacement textures\n");
CFile::ChangeFilenameExtension (szFilename, pszLevelName, ".pog");
if (cf.Open (szFilename, gameFolders.szDataDir, "rb", 0)) {
	int					id, version, nBitmapNum, bTGA;
	int					bmDataSize, bmDataOffset, bmOffset;
	ushort				*indices;
	tPIGBitmapHeader	*bmh;

	id = cf.ReadInt ();
	version = cf.ReadInt ();
	if (id != MAKE_SIG ('G','O','P','D') || version != 1) {
		cf.Close ();
		return;
		}
	nBitmapNum = cf.ReadInt ();
	indices = new ushort [nBitmapNum];
	bmh = new tPIGBitmapHeader [nBitmapNum];
#if 0
	cf.Read (indices, nBitmapNum * sizeof (ushort), 1);
	cf.Read (bmh, nBitmapNum * sizeof (tPIGBitmapHeader), 1);
#else
	for (i = 0; i < nBitmapNum; i++)
		indices [i] = cf.ReadShort ();
	for (i = 0; i < nBitmapNum; i++)
		PIGBitmapHeaderRead (bmh + i, cf);
#endif
	bmDataOffset = cf.Tell ();
	bmDataSize = cf.Length () - bmDataOffset;

	for (i = 0; i < nBitmapNum; i++) {
		bmOffset = bmh [i].offset;
		memset (&bm, 0, sizeof (CBitmap));
		bm.AddFlags (bmh [i].flags & (BM_FLAGS_TO_COPY | BM_FLAG_TGA));
		bm.SetWidth (bmh [i].width + ((short) (bmh [i].wh_extra & 0x0f) << 8));
		bm.SetRowSize (bm.Width ());
		if ((bTGA = (bm.Flags () & BM_FLAG_TGA)) && (bm.Width () > 256))
			bm.SetHeight (bm.Width () * bmh [i].height);
		else
			bm.SetHeight (bmh [i].height + ((short) (bmh [i].wh_extra & 0xf0) << 4));
		bm.SetBPP (bTGA ? 4 : 1);
		if (!(bm.Width () * bm.Width ()))
			continue;
		bm.SetAvgColorIndex (bmh [i].avgColor);
		bm.SetType (BM_TYPE_ALT);
		if (!bm.CreateBuffer ())
			break;
		cf.Seek (bmDataOffset + bmOffset, SEEK_SET);
#if DBG
		if (indices [i] == nDbgTexture)
			nDbgTexture = nDbgTexture;
#endif
		if (bTGA) {
			int			nFrames = bm.Height () / bm.Width ();
			tTgaHeader	h;

			h.width = bm.Width ();
			h.height = bm.Width ();
			h.bits = 32;
			if (!ReadTGAImage (cf, &h, &bm, -1, 1.0, 0, 1)) {
				bm.DestroyBuffer ();
				break;
				}
			bm.SetFrameCount ((ubyte) nFrames);
			if (nFrames > 1) {
				tEffectClip	*ecP = NULL;
				tWallClip *wcP;
				tVideoClip *vcP;
				while ((ecP = FindEffect (ecP, indices [i]))) {
					//e->vc.nFrameCount = nFrames;
					ecP->flags |= EF_ALTFMT | EF_FROMPOG;
					}
				if (!ecP) {
					if ((wcP = FindWallAnim (indices [i]))) {
						//w->nFrameCount = nFrames;
						wcP->flags |= WCF_ALTFMT | WCF_FROMPOG;
						}
					else if ((vcP = FindVClip (i))) {
						//v->nFrameCount = nFrames;
						vcP->flags |= WCF_ALTFMT | WCF_FROMPOG;
						}
					}
				}
			j = indices [i];
			bm.SetId (j);
			}
		else {
#if DBG
			if (j == nDbgTexture)
				nDbgTexture = nDbgTexture;
#endif
			ReadBitmap (&bm, int (bm.Width ()) * int (bm.Height ()), &cf, true, false);
			j = indices [i];
			bm.SetId (j);
			bm.RLEExpand (NULL, 0);
			*bm.Props () = *gameData.pig.tex.bitmapP [j].Props ();
			bm.Remap (paletteManager.Game (), TRANSPARENCY_COLOR, SUPER_TRANSP_COLOR);
			}
#if DBG
		if (j == nDbgTexture)
			nDbgTexture = nDbgTexture;
#endif
		gameData.pig.tex.bitmapP [j].Unload (j, 0);
		bm.SetFromPog (1);
		char szName [20];
		if (*gameData.pig.tex.bitmapP [j].Name ())
			sprintf (szName, "[%s]", gameData.pig.tex.bitmapP [j].Name ());
		else
			sprintf (szName, "POG#%04d", j);
		bm.SetName (szName);
		gameData.pig.tex.altBitmapP [j] = bm;
		gameData.pig.tex.altBitmapP [j].SetBuffer (bm.Buffer (), 0, bm.Length ());
		bm.SetBuffer (NULL);
		gameData.pig.tex.bitmapP [j].SetOverride (gameData.pig.tex.altBitmapP + j);
		CBitmap* bmP = gameData.pig.tex.altBitmapP + j;
		tRgbColorf color;
		if (0 <= bmP->AvgColor (&color))
			bmP->SetAvgColorIndex (bmP->Palette ()->ClosestColor (&color));
		UseBitmapCache (gameData.pig.tex.altBitmapP + j, (int) bm.Width () * (int) bm.RowSize ());
		}
	delete[] indices;
	delete[] bmh;
	cf.Close ();
	paletteManager.SetLastPig ("");
	TexMergeFlush ();       //for re-merging with new textures
	}
}
Example #9
0
int PageInBitmap (CBitmap *bmP, const char *bmName, int nIndex, int bD1, bool bHires)
{
	CBitmap			*altBmP = NULL;
	int				nFile, nSize, nOffset, nFrames, nShrinkFactor, nBestShrinkFactor,
						bRedone = 0, bTGA;
	sbyte				nFlags;
	bool				bDefault = false;
	CFile				cf, *cfP = &cf;
	char				fn [6][FILENAME_LEN];

#if DBG
if (!bmName)
	return 0;
if ((nDbgTexture > 0) && (nIndex == nDbgTexture))
	nDbgTexture = nDbgTexture;
#endif
if (bmP->Buffer ())
	return 1;

StopTime ();
nShrinkFactor = 8 >> min (gameOpts->render.textures.nQuality, gameStates.render.nMaxTextureQuality);
if (nShrinkFactor < 4) {
	if (nShrinkFactor == 1)
		nShrinkFactor = 2;	// cap texture quality at 256x256 (x frame#)
	else if (IsPowerup (bmName) || IsWeapon (bmName))	// force downscaling of powerup hires textures
		nShrinkFactor <<= 1;
	}
nSize = (int) bmP->FrameSize ();
if (nIndex >= 0)
	GetFlagData (bmName, nIndex);
#if DBG
if (strstr (bmName, "metl139"))
	bmName = bmName;
#endif
if (gameStates.app.bNostalgia)
	gameOpts->render.textures.bUseHires [0] = 0;

bTGA = 0;
nFlags = (nIndex < 0) ? 0 : gameData.pig.tex.bitmapFlags [bD1][nIndex];
if (bmP->Texture ())
	bmP->Texture ()->Release ();
bmP->SetBPP (1);

if ((*bmName && /*!gameStates.app.bDemoData &&*/ ((nIndex < 0) || IsCockpit (bmName) || bHires || gameOpts->render.textures.bUseHires [0])) &&
	 !(gameOpts->render.powerups.b3D && IsWeapon (bmName) && !gameStates.app.bHaveMod)) {
#if 0
	if ((nIndex >= 0) && ReadS3TC (gameData.pig.tex.altBitmaps [bD1] + nIndex, gameFolders.szTextureCacheDir [bD1], bmName)) {
		altBmP = gameData.pig.tex.altBitmaps [bD1] + nIndex;
		altBmP->nType = BM_TYPE_ALT;
		bmP->SetOverride (altBmP);
		BM_FRAMECOUNT (altBmP) = 1;
		nFlags &= ~BM_FLAG_RLE;
		nFlags |= BM_FLAG_TGA;
		bmP = altBmP;
		altBmP = NULL;
		}
	else
#endif
	if (*gameFolders.szTextureDir [2]) {
		char szLevelFolder [FILENAME_LEN];
		if (gameData.missions.nCurrentLevel < 0)
			sprintf (szLevelFolder, "slevel%02d", -gameData.missions.nCurrentLevel);
		else
			sprintf (szLevelFolder, "level%02d", gameData.missions.nCurrentLevel);
		sprintf (gameFolders.szTextureDir [3], "%s/%s", gameFolders.szTextureDir [2], szLevelFolder);
		sprintf (gameFolders.szTextureCacheDir [3], "%s/%s", gameFolders.szTextureCacheDir [2], szLevelFolder);
		}
	else
		*gameFolders.szTextureDir [3] =
		*gameFolders.szTextureCacheDir [3] = '\0';
	MakeBitmapFilenames (bmName, gameFolders.szTextureDir [3], gameFolders.szTextureCacheDir [3], fn [1], fn [0], nShrinkFactor);
	MakeBitmapFilenames (bmName, gameFolders.szTextureDir [2], gameFolders.szTextureCacheDir [2], fn [3], fn [2], nShrinkFactor);
	MakeBitmapFilenames (bmName, gameFolders.szTextureDir [bD1], gameFolders.szTextureCacheDir [bD1], fn [5], fn [4], nShrinkFactor);

	if (0 <= (nFile = OpenBitmapFile (fn, cfP))) {
		cfP->Close ();
		PrintLog ("loading hires texture '%s' (quality: %d)\n", fn [nFile], min (gameOpts->render.textures.nQuality, gameStates.render.nMaxTextureQuality));
		if (nFile < 2)	//was level specific mod folder
			MakeTexSubFolders (gameFolders.szTextureCacheDir [3]);
		if (nIndex < 0)
			altBmP = &gameData.pig.tex.addonBitmaps [-nIndex - 1];
		else
			altBmP = &gameData.pig.tex.altBitmaps [bD1][nIndex];
		if (!ReadTGA (fn [nFile], "", altBmP)) {
			altBmP = NULL;
			if (!bDefault)
				cfP->Close ();
			throw (EX_OUT_OF_MEMORY);
			}
		else {
			bTGA = 1;
			if (strstr (fn [nFile], "omegblob#") && strstr (fn [nFile], "/mods/"))
				gameStates.render.bOmegaModded = 1;
			altBmP->SetType (BM_TYPE_ALT);
			bmP->SetOverride (altBmP);
			bmP = altBmP;
			bmP->DelFlags (BM_FLAG_RLE);
			nSize = bmP->Size ();
			nFrames = (bmP->Height () % bmP->Width ()) ? 1 : bmP->Height () / bmP->Width ();
			bmP->SetFrameCount (ubyte (nFrames));
			nOffset = -1;
			if (nIndex >= 0) {
				nFlags = bmP->Flags ();
				if (bmP->Height () > bmP->Width ()) {
					tEffectClip	*ecP = NULL;
					tWallClip *wcP;
					tVideoClip *vcP;
					while ((ecP = FindEffect (ecP, nIndex))) {
						//e->vc.nFrameCount = nFrames;
						ecP->flags |= EF_ALTFMT;
						//ecP->vClipInfo.flags |= WCF_ALTFMT;
						}
					if (!ecP) {
						if ((wcP = FindWallAnim (nIndex))) {
						//w->nFrameCount = nFrames;
							wcP->flags |= WCF_ALTFMT;
							}
						else if ((vcP = FindVClip (nIndex))) {
							//v->nFrameCount = nFrames;
							vcP->flags |= WCF_ALTFMT;
							}
						else {
							PrintLog ("   couldn't find animation for '%s'\n", bmName);
							}
						}
					}
				}
			}
		}
	}

if (!altBmP) {
	if (nIndex < 0) {
		StartTime (0);
		return 0;
		}
	cfP = cfPiggy + bD1;
	if (!cfP->File ())
		PiggyInitPigFile (NULL);
	nOffset = bitmapOffsets [bD1][nIndex];
	bDefault = true;
	}

bRedone = 1;
if ((nOffset >= 0) && cfP->Seek (nOffset, SEEK_SET)) {
	if (!bDefault)
		cfP->Close ();
	throw (EX_IO_ERROR);
	}
#if 1//DBG
bmP->SetName (bmName);
#endif
#if TEXTURE_COMPRESSION
if (bmP->Compressed ())
	UseBitmapCache (bmP, bmP->CompressedSize ());
else
#endif
	{
	if (bTGA || bmP->CreateBuffer ())
		UseBitmapCache (bmP, nSize);
	}
if (!bmP->Buffer () || (bitmapCacheUsed > bitmapCacheSize)) {
	if (!bDefault)
		cfP->Close ();
	throw (EX_OUT_OF_MEMORY);
	}
if (!bTGA && (nIndex >= 0))
	bmP->SetFlags (nFlags);
bmP->SetId (nIndex);
#if DBG
if (nIndex == nDbgTexture)
	nDbgTexture = nDbgTexture;
#endif
int i = ReadBitmap (bmP, nSize, cfP, bDefault, bD1 != 0, bHires);
if (i) {
	if (i < 0) {
		if (!bDefault)
			cfP->Close ();
		throw (EX_IO_ERROR);
		}
	}
else
#if TEXTURE_COMPRESSION
if (!bmP->Compressed ())
#endif
	{
	bmP->SetType (BM_TYPE_ALT);
	bmP->SetTranspType (-1);
	if (IsOpaqueDoor (nIndex)) {
		bmP->DelFlags (BM_FLAG_TRANSPARENT);
		bmP->TransparentFrames () [0] &= ~1;
		}
#if TEXTURE_COMPRESSION
	if (CompressTGA (bmP))
		bmP->SaveS3TC (gameFolders.szTextureCacheDir [(nFile < 2) ? 3 : (nFile < 4) ? 2 : bD1], bmName);
	else {
#endif
		nBestShrinkFactor = BestShrinkFactor (bmP, nShrinkFactor);
		if ((nBestShrinkFactor > 1) && ShrinkTGA (bmP, nBestShrinkFactor, nBestShrinkFactor, 1)) {
			nSize /= (nBestShrinkFactor * nBestShrinkFactor);
			if (gameStates.app.bCacheTextures) {
				tTgaHeader	h;

				memset (&h, 0, sizeof (h));
				h.bits = bmP->BPP () * 8;
				h.width = bmP->Width ();
				h.height = bmP->Height ();
				h.imageType = 2;
				// nFile < 2: mod level texture folder
				// nFile < 4: mod texture folder
				// otherwise standard D1 or D2 texture folder
				SaveTGA (bmName, gameFolders.szTextureCacheDir [(nFile < 2) ? 3 : (nFile < 4) ? 2 : bD1], &h, bmP);
				}
			}
		}
#if TEXTURE_COMPRESSION
	}
#endif

#if DBG
nPrevIndex = nIndex;
strcpy (szPrevBm, bmName);
#endif
tRgbColorf color;
if (0 <= (bmP->AvgColor (&color)))
	bmP->SetAvgColorIndex (ubyte (bmP->Palette ()->ClosestColor (&color)));
StartTime (0);
if (!bDefault)
	cfP->Close ();
return 1;
}
Example #10
0
/*-----------------------------------------------------------------------------
   This routine is the image resolve function any html widget. It is 
   adapted from Mosaic-2.0 (img.c)
   Written by HRL. Modified by COMET.
   
------------------------------------------------------------------------------*/
ImageInfo
*html_ImageResolve ( Widget w, char *src, int noload )
{
	int		i, cnt;
	unsigned char	*data;
	unsigned char	*bg_map;
	unsigned char	*bgptr;
	unsigned char	*ptr;
	int		Used[256];
	XColor		colrs[256];
	ImageInfo	*img_data;
	char		*txt;
	int		widthbyheight = 0;
	char		*fnam;
	int		rc;
	int		bg, bg_red, bg_green, bg_blue;
	char		*file, *dpath;
	int		width,height;
	int		Rdata_colors_per_inlined_image = 50;
	int		verbose;
    
         
	verbose = GetVerboseLevel();
	if( verbose > VERBOSE_0 )
	    printf ( "html_ImageResolve\n" );

	dpath = GetConfigValue ("GarpHTML");
	if (src[0] == '~')
	    file = builddirpath ( dpath, home_html );
	else
	    file = builddirpath ( dpath, src );
   
	bg = -1;
	bg_map = NULL;
	data = ReadBitmap ( file, &width, &height, colrs, &bg );

	Free ( dpath );
	Free ( file );
   
   /* if we have a transparent background, prepare for it */
   if ((bg >= 0)&&(data != NULL)) {
      bg_red = colrs[bg].red;
      bg_green = colrs[bg].green;
      bg_blue = colrs[bg].blue;
      bg_map = (unsigned char *)malloc(width * height);
   }
      
   if (data == NULL)
      return NULL;
   else {
      img_data = (ImageInfo *) XtMalloc(sizeof(ImageInfo));
      img_data->width = width;
      img_data->height = height;
      img_data->image_data = data;
      img_data->image = NULL;
      img_data->internal = 0;
   }
       
  widthbyheight = img_data->width * img_data->height;

  /* Fill out used array. */
  for (i=0; i < 256; i++)
    {
      Used[i] = 0;
    }
  cnt = 1;
  bgptr = bg_map;
  ptr = img_data->image_data;
  for (i=0; i < widthbyheight; i++)
    {
      if (Used[(int)*ptr] == 0)
        {
          Used[(int)*ptr] = cnt;
          cnt++;
        }
      if (bg >= 0)
        {
		if (*ptr == bg)
		{
			*bgptr = (unsigned char)1;
		}
		else
		{
			*bgptr = (unsigned char)0;
		}
		bgptr++;
        }
      ptr++;
    }
  cnt--;
  
  /*
   * If the image has too many colors, apply a median cut algorithm to
   * reduce the color usage, and then reprocess it.
   * Don't cut colors for direct mapped visuals like TrueColor.
   */
  if ((cnt > Rdata_colors_per_inlined_image)/* SD &&(SWS_Vclass != TrueColor)*/)
    {
       /*printf("doing a Median Cut\n");*/
/* SD
      MedianCut(img_data->image_data, &img_data->width, 
                &img_data->height, colrs, cnt, 
                Rdata_colors_per_inlined_image);
*/
      /*printf("after Median Cut\n");*/
      
      for (i=0; i < 256; i++)
        Used[i] = 0;
      cnt = 1;
      ptr = img_data->image_data;
      for (i=0; i < widthbyheight; i++)
        {
          if (Used[(int)*ptr] == 0)
            {
              Used[(int)*ptr] = cnt;
              cnt++;
            }
          ptr++;
        }
      cnt--;

      /* if we had a transparent bg, MedianCut used it.  Get a new one */
      if (bg >= 0)
      {
	cnt++;
	bg = 256;
      }
   }

  img_data->num_colors = cnt;

  img_data->reds = (int *)malloc(sizeof(int) * cnt);
  img_data->greens = (int *)malloc(sizeof(int) * cnt);
  img_data->blues = (int *)malloc(sizeof(int) * cnt);

  for (i=0; i < 256; i++)
    {
      int indx;
      
      if (Used[i] != 0)
        {
          indx = Used[i] - 1;
          img_data->reds[indx] = colrs[i].red;
          img_data->greens[indx] = colrs[i].green;
          img_data->blues[indx] = colrs[i].blue;
	  /* squeegee in the background color */
	  if ((bg >= 0)&&(i == bg))
            {
              img_data->reds[indx] = bg_red;
              img_data->greens[indx] = bg_green;
              img_data->blues[indx] = bg_blue;
            }
        }
    }

    /* if MedianCut ate our background, add the new one now. */
    if (bg == 256)
      {
	img_data->reds[cnt - 1] = bg_red;
	img_data->greens[cnt - 1] = bg_green;
	img_data->blues[cnt - 1] = bg_blue;
      }
  
  bgptr = bg_map;
  ptr = img_data->image_data;
  for (i=0; i < widthbyheight; i++)
    {
      *ptr = (unsigned char)(Used[(int)*ptr] - 1);
      /* if MedianCut ate the background, enforce it here */
      if (bg == 256)
        {
          if ((int)*bgptr == 1)
            {
              *ptr = (unsigned char)(cnt - 1);
            }
          bgptr++;
        }
      ptr++;
    }

  /* free the background map if we have one */
    Free (bg_map);

  Free (src);
  return img_data;

}