int CNotification::CalculateWidth(int defaultSize)
{
	CString s;
	GetWindowText(s);
	
	CDIB dib;
	dib.Resize(1, 1);
	if(!dib.Ready())
	{
		return defaultSize;
	}
	Graphics g(dib.dc);
	g.SetCompositingMode(CompositingModeSourceOver);
	g.SetSmoothingMode(SmoothingModeAntiAlias);

	RectF rf(0, 0, 0, 0);

	Font font(L"Arial", defaultSize * 0.6f, FontStyleRegular, UnitPixel);
	StringFormat *stringFormat = new StringFormat();
	stringFormat->SetAlignment(StringAlignmentCenter);
	stringFormat->SetLineAlignment(StringAlignmentCenter);
	stringFormat->SetFormatFlags(StringFormatFlagsLineLimit);
	stringFormat->SetTrimming(StringTrimmingEllipsisCharacter);

	g.MeasureString(s.GetBuffer(), s.GetLength(), &font, rf, stringFormat, &rf);

	delete stringFormat;

	defaultSize += (int)rf.Width - defaultSize / 2;
	return defaultSize;
}
Example #2
0
void CShowPalDoc::Serialize(CArchive& ar)
{
    if (ar.IsStoring()) {
        ASSERT(1); // We don't do this.
    } else {
        // Get the file from the archive.
        CFile* fp = ar.GetFile();
        ASSERT(fp);
        ar.Flush();
        // Load the DIB from the file.
        CDIB dib;
        if (!dib.Load(fp)) {
            AfxMessageBox("Failed to load DIB file");
            return;
        }
        // Create the palette from the DIB.
        if (m_pPal) delete m_pPal;
        m_pPal = new CDIBPal;
        ASSERT(m_pPal);
        if (!m_pPal->Create(&dib)) {
            AfxMessageBox("Failed to create palette from DIB file");
            delete m_pPal;
            m_pPal = NULL;
        }
    }
}
Example #3
0
File: Dib.cpp Project: F5000/spree
BOOL CDIB::DrawText(CDC *pDC, LPCTSTR szString, COLORREF fontcolor )
{
	CFont		pfont;	
	LOGFONT		lf;
	
	lf.lfHeight=16;
	lf.lfWidth=0;
	lf.lfEscapement=0;
	lf.lfOrientation=0;
	lf.lfWeight=FW_NORMAL;
	lf.lfItalic=0;
	lf.lfUnderline=0;
	lf.lfStrikeOut=0;
	lf.lfCharSet=DEFAULT_CHARSET; //ANSI_CHARSET;
	lf.lfOutPrecision=OUT_DEFAULT_PRECIS;
	lf.lfClipPrecision=CLIP_DEFAULT_PRECIS;
	lf.lfQuality=PROOF_QUALITY;
	lf.lfPitchAndFamily=VARIABLE_PITCH | FF_ROMAN;
	wcscpy(lf.lfFaceName, _T("MS Sans Serif") );
	
	pfont.CreateFontIndirect( &lf );		
	
	CDC BufferDC;
	CBitmap BufferBitmap, *OldBitmap;
	
	BufferDC.CreateCompatibleDC ( pDC );
	CFont *pOldFont = BufferDC.SelectObject(&pfont);
	
	SIZE  size;
	GetTextExtentPoint32( BufferDC.GetSafeHdc(), szString, wcslen(szString), &size );
	
	size.cx += 16;
	
	BufferBitmap.CreateCompatibleBitmap ( pDC, size.cx, size.cy );
	OldBitmap=BufferDC.SelectObject ( &BufferBitmap );
	
	BufferDC.FillSolidRect ( 0, 0, size.cx, size.cy, 0 );		
	
	RECT rect;
	rect.left = 2;
	rect.top  = 0;
	rect.right = size.cx-1;
	rect.bottom = size.cy-1;
	
	BufferDC.SetTextColor(fontcolor);	
	BufferDC.DrawText(szString,&rect,DT_LEFT|DT_VCENTER|DT_SINGLELINE);
	
	BufferDC.SelectObject ( OldBitmap );
	
	CDIB tempDIB;
	tempDIB.Create ( size.cx, size.cy );
	GetDIBits ( pDC->m_hDC, HBITMAP(BufferBitmap), 0, size.cy, tempDIB.m_Bits, &(tempDIB.m_Info), DIB_RGB_COLORS ); 	
	BufferDC.SelectObject(pOldFont);
	pfont.DeleteObject();

	BlendRect( &tempDIB, 0, 0 );
	
	return TRUE;
}
void CSkinList::OnPaint()
{	
	CPaintDC dc(this);
	CDIB tmp;
	Draw(tmp);
	if(!tmp.Ready())
	{
		return;
	}
	BitBlt(dc.m_hDC, 0, 0, tmp.Width(), tmp.Height(), tmp.dc, 0, 0, SRCCOPY);
}
Example #5
0
void QTwain::Create24Bit(CDIB& source,CDIB& dest)
{
	int pal;
	dest.Create(source.Width(),source.Height(),24);
	pal = source.GetPaletteSize();
	BYTE palet[768];

	for(int i=0; i < pal; i++)
	{
		COLORREF col = source.PaletteColor(i);
		palet[i*3+2] = GetRValue(col);
		palet[i*3+1] = GetGValue(col);
		palet[i*3+0] = GetBValue(col);
	}

	int j;
	int i;
	BYTE *src,*dst,*ptr;

	for(i=0; i < source.Height(); i++)
	{
		src = source.GetLinePtr(i);
		dst = dest.GetLinePtr(i);
		ptr = dst;
		int index;
		for(j=0; j < source.Width(); j++,ptr+=3)
		{
			switch(pal)
			{
			case 2:
				if(src[j>>3] & masktable[j&7])
				{
					index = 1;
				}
				else
				{
					index = 0;
				}
				break;
			case 16:
				if(j & 1)
				{
					index = src[j>>1] & 0x0f;
				}
				else
				{
					index = (src[j>>1] >> 4) & 0x0f;
				}
				break;
			case 256:
				index = src[j];
				break;
			}
Example #6
0
void EVOpenDlg::CopyImage( HANDLE hBitmap,TW_IMAGEINFO& info )
{//处理扫描仪数据
	if ( info.SamplesPerPixel!=3 )
	{
		MessageBox("请使用彩色扫描");
		return;
	}
	CDIB dib;
	dib.CreateFromHandle(hBitmap,info.BitsPerPixel);
	CString tmpName=_T("tmp.bmp");
	TCHAR    tmpPath[_MAX_PATH+1];
	GetTempPath(_MAX_PATH,tmpPath);
	tmpName.Insert(0,tmpPath);
	dib.SaveDIB(tmpName,CDIB::BMP);
	IplImage* pImage = cvLoadImage(tmpName.GetBuffer());
	UpdateScan(pImage);
	cvReleaseImage(&pImage);//*/
	return;
}
void CSkinList::Draw(CDIB &tmp)
{
	CRect r;
	GetClientRect(&r);

	tmp.Resize(r.Width(), r.Height());
	if(!tmp.Ready())
	{
		return;
	}

	RectF rf(0, 0, (REAL)tmp.Width(), (REAL)tmp.Height());
	RectF rx;

	Graphics g(tmp.dc);
	g.SetCompositingMode(CompositingModeSourceOver);

	if(bckg->Ready())
	{
		tmp.Draw(tmp.Rect(), 0, 0, bckg, DrawFlagsReflectDest);
	}

	if(dib->Ready())
	{
		g.DrawImage(dib->bmp, 0.0f, r.Height() * 0.36f);

		Font font(L"Arial", 9.0f);
		StringFormat *stringFormat = new StringFormat();
		stringFormat->SetAlignment(StringAlignmentCenter);
		stringFormat->SetLineAlignment(StringAlignmentCenter);
		stringFormat->SetTrimming(StringTrimmingEllipsisCharacter);

		CString s;
		s.Format(L"%s\n%s", skin->name.GetBuffer(), skin->description.GetBuffer());
		
		RectF rx(0, 0, (REAL)dib->Width(), r.Height() * 0.36f);

		rx.Y++;
		SolidBrush brush(0xfff0f0f0);
		g.DrawString(s.GetBuffer(), s.GetLength(), &font, rx, stringFormat, &brush);

		rx.Y--;
		brush.SetColor(0xff000000);
		g.DrawString(s.GetBuffer(), s.GetLength(), &font, rx, stringFormat, &brush);

		delete stringFormat;
	}
}
CDIB* CRenderThread::Render(GP<DjVuImage> pImage, const CSize& size,
		const CDisplaySettings& displaySettings, int nDisplayMode,
		int nRotate, bool bThumbnail)
{
	if (size.cx <= 0 || size.cy <= 0)
		return NULL;

	CSize szImage(pImage->get_width(), pImage->get_height());
	int nTotalRotate = GetTotalRotate(pImage, nRotate);

	CSize szScaled(size);
	if (nTotalRotate % 2 != 0)
		swap(szScaled.cx, szScaled.cy);

	GRect rect(0, 0, szScaled.cx, szScaled.cy);

	bool bScalePnmFixed = displaySettings.bScaleColorPnm;

	// Use fast scaling for thumbnails.
	if (bThumbnail)
		bScalePnmFixed = false;

	// Use default faster scaling when zoom factor is >= 1.0.
	// Additionally, use the default scaling when requested
	// image size is small, since quality does not matter at this
	// scale. NOTE: this also deals with the special case of size (1, 1),
	// which can force PnmScaleFixed into an infinite loop.
	if ((szScaled.cx < 150 || szScaled.cy < 150)
			|| (szScaled.cx >= szImage.cx || szScaled.cy >= szImage.cy))
		bScalePnmFixed = false;

	// Disable PnmFixed scaling if we perform an integer reduction of the image.
	/*
	for (int nReduction = 1; nReduction <= 15; ++nReduction)
	{
		if (szScaled.cx*nReduction > szImage.cx - nReduction
				&& szScaled.cx*nReduction < szImage.cx + nReduction
				&& szScaled.cy*nReduction > szImage.cy - nReduction
				&& szScaled.cy*nReduction < szImage.cy + nReduction)
		{
			bScalePnmFixed = false;
			break;
		}
	}
	*/

	// Disable PnmFixed scaling for color images according to settings
	GP<IW44Image> bg44 = pImage->get_bg44();
	GP<GPixmap> bgpm = pImage->get_bgpm();
	GP<GPixmap> fgpm = pImage->get_fgpm();
	if (!displaySettings.bScaleColorPnm && (bg44 != NULL || bgpm != NULL || fgpm != NULL)
			&& nDisplayMode != CDjVuView::BlackAndWhite)
		bScalePnmFixed = false;

	if (bScalePnmFixed)
		rect = GRect(0, 0, szImage.cx, szImage.cy);

	GP<GBitmap> pGBitmap;
	GP<GPixmap> pGPixmap;

	try
	{
		switch (nDisplayMode)
		{
		case CDjVuView::BlackAndWhite:
			pGBitmap = pImage->get_bitmap(rect, rect, 4);
			break;

		case CDjVuView::Foreground:
			pGPixmap = pImage->get_fg_pixmap(rect, rect);
			if (pGPixmap == NULL)
				pGBitmap = pImage->get_bitmap(rect, rect, 4);
			break;

		case CDjVuView::Background:
			pGPixmap = pImage->get_bg_pixmap(rect, rect);
			break;

		case CDjVuView::Color:
		default:
			pGPixmap = pImage->get_pixmap(rect, rect);
			if (pGPixmap == NULL)
				pGBitmap = pImage->get_bitmap(rect, rect, 4);
		}
	}
	catch (GException&)
	{
		return NULL;
	}
	catch (CMemoryException*)
	{
		return NULL;
	}
	catch (...)
	{
		theApp.ReportFatalError();
	}

	CDIB* pBitmap = NULL;

	if (pGPixmap != NULL)
	{
		if (nTotalRotate != 0)
			pGPixmap = pGPixmap->rotate(nTotalRotate);

		if (bScalePnmFixed)
			pGPixmap = RescalePixmap_subpix(pGPixmap, size.cx, size.cy);

		pBitmap = RenderPixmap(*pGPixmap, displaySettings);
	}
	else if (pGBitmap != NULL)
	{
		if (nTotalRotate != 0)
			pGBitmap = pGBitmap->rotate(nTotalRotate);

		if (bScalePnmFixed)
		{
			pGPixmap = RescaleBitmap_subpix(pGBitmap, size.cx, size.cy);
			pBitmap = RenderPixmap(*pGPixmap, displaySettings);
		}
		else
		{
			pBitmap = RenderBitmap(*pGBitmap, displaySettings);
		}
	}
	else
	{
		pBitmap = RenderEmpty(size, displaySettings);
	}

	if (pBitmap != NULL)
		pBitmap->SetDPI(pImage->get_dpi());

	return pBitmap;
}
void CTabsControl::DrawItem(CTabControl *item, Gdiplus::Graphics &g)
{
	CRect rect = ItemRect(item);

	g.ResetTransform();
	g.TranslateTransform((REAL)rect.left, (REAL)rect.top);

	RectF rf(0.0f, 0.0f, (REAL)rect.Width(), (REAL)rect.Height());
	RectF rx;

	if(item->selected)
	{
		#define shadowb 10

		CDIB tmp;
		tmp.Resize(rect.Width() + shadowb * 2, rect.Height() + shadowb * 2);
		if(tmp.Ready())
		{
			Graphics gt(tmp.bmp);
			RectF rx(0, 0, (REAL)tmp.Width(), (REAL)tmp.Height());
			
			GraphicsPath *path = new GraphicsPath();
			path->AddLine(rx.X + shadowb, rx.Y + rx.Height - shadowb, rx.X + rx.Width - 2 - shadowb, rx.Y + rx.Height - shadowb);
			path->AddLine(rx.X + rx.Width - 2 - shadowb, rx.Y + rx.Height - shadowb, rx.X + rx.Width - 2, rx.Y);
			path->AddLine(rx.X + rx.Width - 2, rx.Y, rx.X + rx.Width, rx.Y + rx.Height);
			path->AddLine(rx.X + rx.Width, rx.Y + rx.Height, rx.X, rx.Y + rx.Height);
			path->AddLine(rx.X, rx.Y, rx.X + shadowb, rx.Y + rx.Height - shadowb);
			path->CloseFigure();

			SolidBrush brush(0xff000000);
			gt.FillPath(&brush, path);

			tmp.Blur(tmp.Rect(), CRect(0, 0, 0, 0), shadowb);

			g.DrawImage(tmp.bmp, rf, shadowb, shadowb, rf.Width, rf.Height, UnitPixel);

			delete path;
		}
	}

	Font font(L"Arial", item->selected ? 8.0f : 8.0f);
	StringFormat *stringFormat = new StringFormat();
	stringFormat->SetAlignment(StringAlignmentCenter);
	stringFormat->SetLineAlignment(StringAlignmentCenter);
	stringFormat->SetTrimming(StringTrimmingEllipsisCharacter);
	stringFormat->SetFormatFlags(StringFormatFlagsLineLimit);

	if(item->icon->Ready())
	{
		g.SetInterpolationMode(InterpolationModeBicubic);
		rx = rf;
		rx.Y += 6;
		rx.Height -= (20 + rx.Y);
		rx.Width = rx.Height;
		rx.X += (rf.Width - rx.Width) / 2;

		if(item->selected)
		{
			rx.Y++;

			#define shadow 5
			CDIB tmp;
			tmp.Resize(item->icon->Width(), item->icon->Height());
			if(tmp.Ready())
			{
				tmp.Draw(CRect(shadow, shadow, 
					item->icon->Width() - shadow, 
					item->icon->Height() - shadow), 
					item->icon->Rect(), item->icon);
				DIB_ARGB *p = tmp.scan0;
				int size = tmp.Width() * tmp.Height();
				for(int i = 0; i < size; i++, p++)
				{
					p->r = 0;
					p->g = 0;
					p->b = 0;
				}
				tmp.Blur(tmp.Rect(), CRect(0, 0, 0, 0), shadow);
				g.DrawImage(tmp.bmp, RectF(rx.X, rx.Y + shadow, rx.Width, rx.Height));
			}
			tmp.Assign(item->icon);
			/*if(tmp.Ready())
			{
				DIB_ARGB *p = tmp.scan0;
				int size = tmp.Width() * tmp.Height();
				for(int i = 0; i < size; i++, p++)
				{
					p->r = 0x6f;
					p->g = 0xa6;
					p->b = 0xde;
				} 
			}*/
			g.DrawImage(tmp.bmp, rx);
		}
		else
		{
			g.DrawImage(item->icon->bmp, rx);
		}
	}

	SolidBrush brush(0xff000000);
	rx = rf;
	rx.Height = 20;
	rx.Y = rf.Height - rx.Height;

	rx.Y++;
	g.DrawString(item->text.GetBuffer(), item->text.GetLength(), &font, rx, stringFormat, &brush);

	brush.SetColor(item->selected && false ? 0xff6fa6de : 0xfff0f0f0);
	rx.Y--;
	g.DrawString(item->text.GetBuffer(), item->text.GetLength(), &font, rx, stringFormat, &brush);

	delete stringFormat;

	//POSITION p = items.Find(item);
	//items.GetNext(p);
	//if(p)
	{
		RectF rx = rf;
		rx.X += rx.Width - 1;
		rx.Width = 1;
		LinearGradientBrush brush(rx, Color(140, 0x69, 0x69, 0x69), Color(0x69, 0x69, 0x69), LinearGradientModeVertical);
		g.FillRectangle(&brush, rx);
	}
}
bool Dock3D::DrawImage(CDIB *dst, CRect rect, int offsetX, CDIB *src)
{
	const int scale = 2;

	CDIB tmp;
	tmp.Resize(rect.Width() * scale, rect.Height() * scale);
	if (!tmp.Ready())
	{
		return false;
	}

	DrawDockD3Image(&tmp, tmp.Rect(), offsetX * scale, src);

	rect.left++;
	//rect.right--;

	dst->Draw(rect, tmp.Rect(), &tmp);

	/*int x, y, index, x1, x2;
	float y_ratio = (float)(src->Height() - 1) / rect.Height();
	float x_ratio, x_diff, y_diff;
	DIB_ARGB *pd, *psa, *psb, *psc, *psd;

	for(int i = 0; i < rect.Height(); i++)
	{
		x1 = (int)(rect.left + 1 + offsetX * (1 - (1.0f + i) / rect.Height()));
		x2 = (int)(rect.right - 1 - offsetX * (1 - (1.0f + i) / rect.Height()));

		x_ratio = (float)src->Width() / (x2 - x1);
		pd = (DIB_ARGB*)((int)dst->scan0 + ((rect.bottom - 1 - i) * dst->Width() + x1) * 4);

		for(int j = 0; j < x2 - x1; j++, pd++)
		{
			x = (int)(x_ratio * j);
			y = (int)(y_ratio * i);
			x_diff = (x_ratio * j) - x;
			y_diff = (y_ratio * i) - y;
			index = y * src->Width() + x;
			psa = (DIB_ARGB*)((int)src->scan0 + (index) * 4);
			psb = (DIB_ARGB*)((int)src->scan0 + (index + 1) * 4);
			psc = (DIB_ARGB*)((int)src->scan0 + (index + src->Width()) * 4);
			psd = (DIB_ARGB*)((int)src->scan0 + (index + src->Width() + 1) * 4);

			pd->a = (unsigned char)(
				psa->a * (1 - x_diff) * (1 - y_diff) +
				psb->a * x_diff * (1 - y_diff) +
				psc->a * y_diff * (1 - x_diff) +
				psd->a * x_diff * y_diff);

			pd->b = (unsigned char)(
				psa->b * (1 - x_diff) * (1 - y_diff) +
				psb->b * x_diff * (1 - y_diff) +
				psc->b * y_diff * (1 - x_diff) +
				psd->b * x_diff * y_diff) * pd->a / 255;

			pd->g = (unsigned char)(
				psa->g * (1 - x_diff) * (1 - y_diff) +
				psb->g * x_diff * (1 - y_diff) +
				psc->g * y_diff * (1 - x_diff) +
				psd->g * x_diff * y_diff) * pd->a / 255;

			pd->r = (unsigned char)(
				psa->r * (1 - x_diff) * (1 - y_diff) +
				psb->r * x_diff * (1 - y_diff) +
				psc->r * y_diff * (1 - x_diff) +
				psd->r * x_diff * y_diff) * pd->a / 255;
		}
	}

	// Border's antialiasing
	DIB_ARGB *pd1, *pd2;
	int px2 = 0, py2 = 0, px1 = 0, py1 = 0;

	for(int i = 0; i <= rect.Height(); i++)
	{
		if(i == 0)
		{
			px1 = (int)(rect.left + 1 + offsetX * (1 - (1.0f + i) / rect.Height()));
			py1 = i;
			px2 = (int)(rect.right - 1 - offsetX * (1 - (1.0f + i) / rect.Height()));
			py2 = i;
		}
		else
		{
			x1 = (int)(rect.left + 1 + offsetX * (1 - (1.0f + i) / rect.Height()));
			if(x1 < px1)
			{
				pd1 = (DIB_ARGB*)((int)dst->scan0 + ((rect.bottom - 1 - py1) * dst->Width() + px1 + 1) * 4);
				pd2 = (DIB_ARGB*)((int)dst->scan0 + ((rect.bottom - 1 - py1 + 1) * dst->Width() + px1) * 4);
				pd = (DIB_ARGB*)((int)dst->scan0 + ((rect.bottom - 1 - py1) * dst->Width() + px1) * 4);

				for(int y = py1; y < i; y++, pd1 -= dst->Width(), pd2 -= dst->Width(), pd -= dst->Width())
				{
					pd->a = (unsigned char)((pd1->a + pd2->a) / 2 * (1 + y - py1) / (i - py1));
					pd->r = (pd1->r * 255 / max(pd1->a, 1) + pd2->r * 255 / max(pd2->a, 1)) / 2 * pd->a / 255;
					pd->g = (pd1->g * 255 / max(pd1->a, 1) + pd2->g * 255 / max(pd2->a, 1)) / 2 * pd->a / 255;
					pd->b = (pd1->b * 255 / max(pd1->a, 1) + pd2->b * 255 / max(pd2->a, 1)) / 2 * pd->a / 255;
				}
				px1 = x1;
				py1 = i;
			}

			x2 = (int)(rect.right - 1 - offsetX * (1 - (1.0f + i) / rect.Height()));
			if(x2 > px2)
			{
				pd1 = (DIB_ARGB*)((int)dst->scan0 + ((rect.bottom - 1 - py2) * dst->Width() + px2 - 1) * 4);
				pd2 = (DIB_ARGB*)((int)dst->scan0 + ((rect.bottom - 1 - py2 + 1) * dst->Width() + px2) * 4);
				pd = (DIB_ARGB*)((int)dst->scan0 + ((rect.bottom - 1 - py2) * dst->Width() + px2) * 4);

				for(int y = py2; y < i; y++, pd1 -= dst->Width(), pd2 -= dst->Width(), pd -= dst->Width())
				{
					pd->a = (unsigned char)((pd1->a + pd2->a) / 2 * (1 + y - py2) / (i - py2));
					pd->r = (pd1->r * 255 / max(pd1->a, 1) + pd2->r * 255 / max(pd2->a, 1)) / 2 * pd->a / 255;
					pd->g = (pd1->g * 255 / max(pd1->a, 1) + pd2->g * 255 / max(pd2->a, 1)) / 2 * pd->a / 255;
					pd->b = (pd1->b * 255 / max(pd1->a, 1) + pd2->b * 255 / max(pd2->a, 1)) / 2 * pd->a / 255;
				}
				px2 = x2;
				py2 = i;
			}
		}
	}*/

	return true;
}