コード例 #1
0
ファイル: demoView.cpp プロジェクト: Aliceljm1/CxImageVS2010
bool CDemoView::SetImageRectSelection(CDemoDoc *pDoc,CRect *rect)
{
	if (pDoc==0)
		return false;

	CxImage* ima = pDoc->GetImage();

	if (ima==0)
		return false;

	long x,y;
	RECT rect_img;
	x = rect_img.left = rect->left;
	y = rect_img.top = rect->top;
	GetImageXY(pDoc, ima, &x,&y);
	rect_img.top = ima->GetHeight() - 1 - y;
	rect_img.left = x;

	x = rect_img.right = rect->right;
	y = rect_img.bottom = rect->bottom;
	GetImageXY(pDoc, ima, &x,&y);
	rect_img.bottom = ima->GetHeight() - 1 - y;
	rect_img.right = x;

	ima->SelectionClear();
	ima->SelectionAddRect(rect_img);

	return true;
}
コード例 #2
0
ファイル: DllInterface.cpp プロジェクト: 1ibraheem/xbmc
int ResampleKeepAspect(CxImage &image, unsigned int width, unsigned int height)
{
  bool bResize = false;
  float fAspect = ((float)image.GetWidth()) / ((float)image.GetHeight());
  unsigned int newwidth = image.GetWidth();
  unsigned int newheight = image.GetHeight();
  if (newwidth > width)
  {
    bResize = true;
    newwidth = width;
    newheight = (DWORD)( ( (float)newwidth) / fAspect);
  }
  if (newheight > height)
  {
    bResize = true;
    newheight = height;
    newwidth = (DWORD)( fAspect * ( (float)newheight) );
  }
  if (bResize)
  {
    if (!image.Resample(newwidth, newheight, RESAMPLE_QUALITY) || !image.IsValid())
    {
      printf("PICTURE::SaveThumb: Unable to resample picture: Error:%s\n", image.GetLastError());
      return -1;
    }
  }
  return bResize ? 1 : 0;
}
コード例 #3
0
ファイル: UIHelper.cpp プロジェクト: fffonion/V8
    HBITMAP FrameBitmap(HBITMAP hBmp, COLORREF clrInColor, COLORREF clrOutColor, UINT inLineWidth, UINT outLineWidth)
    {
        CxImage ximage;
        ximage.CreateFromHBITMAP(hBmp);
        ximage.IncreaseBpp(24);

        UINT totalWidth = inLineWidth + outLineWidth;
        if (totalWidth == 0)
            return ximage.MakeBitmap();

        LONG newWidth = ximage.GetWidth() + totalWidth * 2;
        LONG newHeight = ximage.GetHeight() + totalWidth * 2;

        RGBQUAD expandClr;
        expandClr.rgbBlue = GetBValue(clrInColor);
        expandClr.rgbGreen = GetGValue(clrInColor);
        expandClr.rgbRed = GetRValue(clrInColor);
        expandClr.rgbReserved = 0;
        ximage.Expand(newWidth, newHeight, expandClr);

        ximage.DrawLine(1, (newWidth - 1), 1, 1, clrOutColor);
        ximage.DrawLine(1, 1, 1, (newHeight - 1), clrOutColor);
        ximage.DrawLine((newWidth - 1), (newWidth - 1), 1, (newHeight - 1), clrOutColor);
        ximage.DrawLine((newWidth - 1), 1, (newHeight - 1), (newHeight - 1), clrOutColor);

        return ximage.MakeBitmap();
    }
コード例 #4
0
bool IGFrameManager::Cut(LPCWSTR pcwGuid)
{
	IGSmartPtr <IGFrame> spFrame;
	if (!GetFrame(pcwGuid, spFrame))
		return false;
	CxImage *pCxLayer = spFrame->GetWorkingLayer();
	if (!pCxLayer)
		return false;
	RECT rcSel;
	if (pCxLayer->SelectionIsValid())
		pCxLayer->SelectionGetBox (rcSel);
	else{
		rcSel.bottom = 0;
		rcSel.left = 0;
		rcSel.top = pCxLayer->GetHeight();
		rcSel.right = pCxLayer->GetWidth();
	}
	m_spClipboardLayer = new IGLayer(NULL);
	m_spClipboardLayer->Create (rcSel.right - rcSel.left, rcSel.top - rcSel.bottom, 24);
	m_spClipboardLayer->AlphaCreate();
	pCxLayer->AlphaCreate();
	RGBQUAD qGray; qGray.rgbBlue = CXIMAGE_GRAY; qGray.rgbGreen = CXIMAGE_GRAY; qGray.rgbRed = CXIMAGE_GRAY;
	for(long y=rcSel.bottom; y<rcSel.top; y++){
		for(long x=rcSel.left; x<rcSel.right; x++){
			if (pCxLayer->BlindSelectionIsInside(x,y)){
				m_spClipboardLayer->BlindSetPixelColor(x - rcSel.left, y - rcSel.bottom, pCxLayer->BlindGetPixelColor(x,y));
				pCxLayer->BlindSetPixelColor(x, y, qGray);
				pCxLayer->AlphaSet(x, y, 0);
			}
			else
				m_spClipboardLayer->AlphaSet (x - rcSel.left, y - rcSel.bottom, 0);
		}
	}
	return true;
}
コード例 #5
0
ファイル: ximaig.cpp プロジェクト: Bitlsoft/Imagenius_SDK
bool CxImageIG::decodeSubLayer (CxFile& file, IGLibrary::IGLayer *pSubLayerOwner, IGSECTIONHEADER_LAYER *pLayerSection)
{
	CxImage cxSubLayer;
	if (!file.Seek (pLayerSection->commonHeader.nFirstByteOffset, SEEK_SET))
		throw IGEXCEPTION (CxImageIGException, "decodeSubLayer", "file.Seek failed");
	// read sub-layer pixels
	BYTE *pBufImg = new BYTE [pLayerSection->commonHeader.nSizeBuf];
	file.Read (pBufImg, pLayerSection->commonHeader.nSizeBuf, 1);
	if (!cxSubLayer.Decode (pBufImg, pLayerSection->commonHeader.nSizeBuf, CXIMAGEIG_LAYERFORMAT))
		throw IGEXCEPTION (CxImageIGException, "decodeSubLayer", "cxSubLayer.Decode failed");
	delete [] pBufImg;
	// read sub-layer alpha
	cxSubLayer.AlphaCreate (255);
	file.Read (cxSubLayer.pAlpha, cxSubLayer.GetWidth() * cxSubLayer.GetHeight(), 1);
	// decode sub-layer into layer
	BYTE *pLayerBits = NULL;
	BYTE *pSubLayerBits = NULL;
	for (int i = 0; i < pLayerSection->ptSize.y; i++)
	{
		pSubLayerBits = cxSubLayer.GetBits (i);
		pLayerBits = pSubLayerOwner->GetBits (pLayerSection->ptOffset.y + i) + 3 * pLayerSection->ptOffset.x;
		::memcpy (pLayerBits, pSubLayerBits, (pLayerSection->ptSize.x) * 3);			
	}
	BYTE *pLayerAlpha = NULL;
	BYTE *pSubLayerAlpha = NULL;
	for (int i = 0; i < (pLayerSection->ptSize.y); i++)
	{
		pLayerAlpha = pSubLayerOwner->AlphaGetPointer (pLayerSection->ptOffset.x, pLayerSection->ptOffset.y + i);
		pSubLayerAlpha = cxSubLayer.AlphaGetPointer (0, i);	
		::memcpy (pLayerAlpha, pSubLayerAlpha, (pLayerSection->ptSize.x));
	}
	return true;
}
コード例 #6
0
	bool SmtSmfRasLayer::Fetch(eSmtFetchType type)
	{
		if (!IsOpen())
			return false;

		char szImgUrl[MAX_LAYER_FILE_NAME];

		SmtDataSourceInfo info;
		m_pOwnerDs->GetInfo(info);

		sprintf(szImgUrl,"%s",m_szLayerFileName);

		long lCodeType = GetImageTypeByFileExt(m_szLayerFileName);

		CxImage img;

		if (img.Load(szImgUrl,lCodeType))
		{
			BYTE *pImageBuf = NULL;
			long lImageBufSize = 0;
			fRect fLocRect;

			m_pMemLayer->GetRasterRect(fLocRect);
	
			fLocRect.rt.y  = fLocRect.lb.y + fLocRect.Width()*img.GetHeight()/img.GetWidth();

			if (img.Encode(pImageBuf,lImageBufSize,lCodeType))
			{
				return (SMT_ERR_NONE == m_pMemLayer->CreaterRaster((const char *)pImageBuf,lImageBufSize,fLocRect,lCodeType));
			}
		}

		return false;
	}
コード例 #7
0
ファイル: PicShowCtrl.cpp プロジェクト: mengskysama/V8
bool CPicShowCtrl::SaveFile(CString strPath)
{
	int width=180;
	int height=180;

	CPaintDC dc(this);
	CxImage img;
	img.CreateFromHBITMAP(m_hBmp);

	CBitmap bitmapmem;          
	CBitmap *pOldBit;
	CDC m_pMemDC;
	m_pMemDC.CreateCompatibleDC(&dc); 
	bitmapmem.CreateCompatibleBitmap(&dc, width, height);
	pOldBit=m_pMemDC.SelectObject(&bitmapmem);

	CRect rect(0,0,width,height);
	HBRUSH bgBrush = ::CreateSolidBrush(RGB(255,255,255));
	FillRect(m_pMemDC,&rect,bgBrush);
	DeleteObject(bgBrush);
	img.Draw(m_pMemDC,m_iStartx,m_iStarty,img.GetWidth(),img.GetHeight(),&rect);

	CBitmap* pBmp=m_pMemDC.SelectObject(pOldBit);

	CxImage xImagebmp;
	xImagebmp.CreateFromHBITMAP((HBITMAP)bitmapmem.m_hObject);
	xImagebmp.Resample(100,100,0);  
	bitmapmem.DeleteObject();
	m_pMemDC.DeleteDC();
	if(xImagebmp.Save(common::utility::stringhelper::UnicodeToAscii(strPath.GetBuffer()).c_str(), CXIMAGE_FORMAT_JPG))
	{
		return true;
	}
	return false;
}
コード例 #8
0
void CCaptchaGenerator::ReGenerateCaptcha(uint32 nLetterCount)
{
	Clear();
	CxImage* pimgResult = new CxImage(nLetterCount > 1 ? (LETTERSIZE + (nLetterCount-1)*CROWDEDSIZE) : LETTERSIZE, 32, 1, CXIMAGE_FORMAT_BMP);
	pimgResult->SetPaletteColor(0, 255, 255, 255);
	pimgResult->SetPaletteColor(1, 0, 0, 0, 0);
	pimgResult->Clear();
	CxImage imgBlank(LETTERSIZE, LETTERSIZE, 1, CXIMAGE_FORMAT_BMP);	
	imgBlank.SetPaletteColor(0, 255, 255, 255);
	imgBlank.SetPaletteColor(1, 0, 0, 0, 0);
	imgBlank.Clear();
	for (uint32 i = 0; i < nLetterCount; i++) {
		CxImage imgLetter(imgBlank);
		
		CString strLetter(schCaptchaContent[GetRandomUInt16() % ARRSIZE(schCaptchaContent)]);
		m_strCaptchaText += strLetter;
		
		uint16 nRandomSize = GetRandomUInt16() % 10;
		uint16 nRandomOffset = 3 + GetRandomUInt16() % 11;
		imgLetter.DrawString(NULL, nRandomOffset, 32, strLetter, imgLetter.RGBtoRGBQUAD(RGB(0, 0, 0)), _T("Arial"), 40 - nRandomSize, 1000);
		//imgLetter.DrawTextA(NULL, nRandomOffset, 32, strLetter, imgLetter.RGBtoRGBQUAD(RGB(0, 0, 0)), "Arial", 40 - nRandomSize, 1000);
		float fRotate = (float)(35 - (GetRandomUInt16() % 70));
		imgLetter.Rotate2(fRotate, NULL, CxImage::IM_BILINEAR,  CxImage::OM_BACKGROUND, 0, false, true);
		uint32 nOffset = i * CROWDEDSIZE; 
		ASSERT( imgLetter.GetHeight() == pimgResult->GetHeight() && pimgResult->GetWidth() >= nOffset + imgLetter.GetWidth() );
		for (uint32 j = 0; j < imgLetter.GetHeight(); j++)
			for (uint32 k = 0; k < imgLetter.GetWidth(); k++)
				if (pimgResult->GetPixelIndex(nOffset + k, j) != 1)
					pimgResult->SetPixelIndex(nOffset + k, j, imgLetter.GetPixelIndex(k, j));
	}
	pimgResult->Jitter(1);
	//pimgResult->Save("D:\\CaptchaTest.bmp", CXIMAGE_FORMAT_BMP);
	m_pimgCaptcha = pimgResult;
}
コード例 #9
0
ファイル: DllInterface.cpp プロジェクト: abs0/xbmc
  __declspec(dllexport) bool LoadImage(const char *file, unsigned int maxwidth, unsigned int maxheight, ImageInfo *info)
  {
    if (!file || !info) return false;

	if (IsDir(file))
		return false;

	  // load the image
    DWORD dwImageType = GetImageType(file);
    CxImage *image = new CxImage(dwImageType);
    if (!image) return false;

    int actualwidth = maxwidth;
    int actualheight = maxheight;
    try
    {
      if (!image->Load(file, dwImageType, actualwidth, actualheight) || !image->IsValid())
      {
#if !defined(_LINUX) && !defined(__APPLE__)
	    int nErr = GetLastError();
#else
	    int nErr = errno;
#endif
        printf("PICTURE::LoadImage: Unable to open image: %s Error:%s (%d)\n", file, image->GetLastError(),nErr);
        delete image;
        return false;
      }
    }
    catch (...)
    {
      printf("PICTURE::LoadImage: Unable to open image: %s\n", file);
      delete image;
      return false;
    }
    // ok, now resample the image down if necessary
    if (ResampleKeepAspect(*image, maxwidth, maxheight) < 0)
    {
      printf("PICTURE::LoadImage: Unable to resample picture: %s\n", file);
      delete image;
      return false;
    }

    // make sure our image is 24bit minimum
    image->IncreaseBpp(24);

    // fill in our struct
    info->width = image->GetWidth();
    info->height = image->GetHeight();
    info->originalwidth = actualwidth;
    info->originalheight = actualheight;
    memcpy(&info->exifInfo, image->GetExifInfo(), sizeof(EXIFINFO));

    // create our texture
    info->context = image;
    info->texture = image->GetBits();
    info->alpha = image->AlphaGetBits();
    return (info->texture != NULL);
  };
コード例 #10
0
ファイル: DllInterface.cpp プロジェクト: abs0/xbmc
int ResampleKeepAspectArea(CxImage &image, unsigned int area)
{
  float fAspect = ((float)image.GetWidth()) / ((float)image.GetHeight());
  unsigned int width = (unsigned int)sqrt(area * fAspect);
  unsigned int height = (unsigned int)sqrt(area / fAspect);
  if (width > MAX_WIDTH) width = MAX_WIDTH;
  if (height > MAX_HEIGHT) height = MAX_HEIGHT;
  return ResampleKeepAspect(image, width, height, true);
}
コード例 #11
0
ファイル: SonicImage.cpp プロジェクト: kevinzhwl/nxuiengine
BOOL CSonicImage::Load(HGLOBAL hGlobal, DWORD dwSize)
{
	if(m_gif.LoadGif(hGlobal, dwSize) == 1)
	{		
		if(PrepareMemDC(m_gif.GetWidth(), m_gif.GetHeight()) == FALSE)
		{
			m_gif.Clear();
			return FALSE;
		}
		m_gif.Draw(m_Dib.GetSafeHdc());
	}
	else
	{
		BYTE * pData = (BYTE *)GlobalLock(hGlobal);
		CxImage img;
		img.Decode(pData, dwSize, 0);
		GlobalUnlock(hGlobal);
		if(PrepareMemDC(img.GetWidth(), img.GetHeight()) == FALSE)
		{
			img.Clear();
			return FALSE;
		}
		if(!img.AlphaIsValid())
		{
			img.Draw(m_Dib.GetSafeHdc());
			CSSE::DoOr(0xff000000, m_Dib.GetBits(), m_Dib.GetSize());
		}
		else
		{
			if(img.GetBpp() != 24)
			{
				img.Clear();
				return FALSE;
			}
			BYTE * pSrc = img.GetBits();
			BYTE * pAlpha = img.AlphaGetBits();
			BYTE * pMyBits = m_Dib.GetBits();
			int nLineTail = m_nWidth % 4;
			for(int i = 0; i < m_nHeight; i++)
			{
				for(int j = 0; j < m_nWidth; j++)
				{
					*pMyBits++ = *pSrc++;
					*pMyBits++ = *pSrc++;
					*pMyBits++ = *pSrc++;
					*pMyBits++ = *pAlpha++;
				}
				pSrc += nLineTail;
			}
			EnableAlphaChannel();
		}
		img.Clear();
	}	
	return TRUE;
}
コード例 #12
0
STDMETHODIMP CContextMenu::MenuMessageHandler(UINT uMsg, WPARAM wParam, LPARAM lParam, LRESULT *plResult)
{	
	TRACE("CContextMenu::MenuMessageHandler()");
	CRASH_PROTECT_START;

	switch (uMsg)
	{
		case WM_MEASUREITEM:
		{
			LPMEASUREITEMSTRUCT itemInfo = (LPMEASUREITEMSTRUCT)lParam;
			MatroskaAttachmentMenuItem *currentAttachmentStruct = (MatroskaAttachmentMenuItem *)itemInfo->itemData;
			MatroskaAttachmentItem *currentAttachment = currentAttachmentStruct->attachmentSource;
			if (currentAttachment != NULL) {
				// An image attachment
				CxImage *attachedImage = currentAttachment->GetCxImage();
				if (attachedImage != NULL) {
					//TCHAR track_txt[256];					
					//_sntprintf(track_txt, 255, _T("%i x %i, %i bits"), attachedImage->GetWidth(), attachedImage->GetHeight(), attachedImage->GetBpp());
					ModifyMenuA(currentAttachmentStruct->hmAttachmentItem, currentAttachmentStruct->uIDNewItem, MF_STRING|MF_BYCOMMAND, currentAttachmentStruct->uIDNewItem, currentAttachment->GetImageInfo().c_str());

					SIZE correctSize = SmartResize(attachedImage->GetWidth(), attachedImage->GetHeight(), 100, 100);
					attachedImage->Resample(correctSize.cx, correctSize.cy, MatroskaShellExt_GetRegistryValue(_T("ThumbnailResizeMethod"), 0));
					
					itemInfo->itemWidth = correctSize.cx;
					itemInfo->itemHeight = correctSize.cy;
				}
			}
			break;
		}
		case WM_DRAWITEM:
		{
			LPDRAWITEMSTRUCT itemInfo = (LPDRAWITEMSTRUCT)lParam;
			
			MatroskaAttachmentMenuItem *currentAttachmentStruct = (MatroskaAttachmentMenuItem *)itemInfo->itemData;
			
			MatroskaAttachmentItem *currentAttachment = currentAttachmentStruct->attachmentSource;
			if (currentAttachment != NULL) {
				// An image attachment
				CxImage *attachedImage = currentAttachment->GetCxImage();
				if (attachedImage != NULL) {
					long leftPos = (itemInfo->rcItem.right - itemInfo->rcItem.left - attachedImage->GetWidth()) / 2 + itemInfo->rcItem.left;
					long topPos = itemInfo->rcItem.top;
					attachedImage->Draw(itemInfo->hDC, leftPos, topPos);
				}
			}
			break;
		}
	}	
	CRASH_PROTECT_END;

	return S_OK;
};
コード例 #13
0
ファイル: IGFrame.cpp プロジェクト: Bitlsoft/Imagenius_SDK
bool IGFrame::PickColor (POINT ptCoords, RGBQUAD& rgbColor)
{
	// Request thread access
	if (!RequestAccess ())
		return false;
	CxImage *pCurrentLayer = GetWorkingLayer();
	if (!pCurrentLayer)
		return false;
	// convert IG coordinates to Cx coordinates
	IGConvertible::FromIGtoCxCoords (ptCoords, pCurrentLayer->GetHeight());
	rgbColor = pCurrentLayer->GetPixelColor (ptCoords.x, ptCoords.y);
	return true;
}
コード例 #14
0
ファイル: WallOthers.cpp プロジェクト: tsaikd/MagicKD
// if do resample, then return true
bool AutoPicSize(CxImage &img, CSize *pSizeMax/* = NULL*/)
{
	CSize sizeImg(img.GetWidth(), img.GetHeight());
	CScreenSize sizeScreen;
	if (!pSizeMax)
		pSizeMax = &sizeScreen;

	CRect rcWin;
	GetWindowRect(GetDesktopWindow(), rcWin);

	if (CalcPicSize(sizeImg, *pSizeMax)) {
		img.QIShrink(sizeImg.cx, sizeImg.cy);
//		img.Resample2(sizeImg.cx, sizeImg.cy, CxImage::IM_CATROM);
		return true;
	} else {
		return false;
	}
}
コード例 #15
0
ファイル: PicShowCtrl.cpp プロジェクト: mengskysama/V8
void CPicShowCtrl::OnPaint()
{
	CPaintDC dc(this); // device context for painting
	// TODO: 在此处添加消息处理程序代码
	common::ui::CClientRect rcThis(this);
	if (m_hBmp == NULL)
	{
		//还没有选择图片,则绘制白色背景
		HBRUSH bgBrush = ::CreateSolidBrush(RGB(255,255,255));
		CRect rect;
		GetWindowRect(&rcThis);
		ScreenToClient(&rcThis);
		FillRect(dc,&rcThis,bgBrush);
		::DeleteObject(bgBrush);
	}
	else
	{
		int width=180;
		int height=180;

		CxImage img;
		img.CreateFromHBITMAP(m_hBmp);

		CBitmap bitmapmem;          
		CBitmap *pOldBit;
		CDC m_pMemDC;
		m_pMemDC.CreateCompatibleDC(&dc); 
		bitmapmem.CreateCompatibleBitmap(&dc, width, height);
		pOldBit=m_pMemDC.SelectObject(&bitmapmem);

		CRect rect(0,0,width,height);
		HBRUSH bgBrush = ::CreateSolidBrush(RGB(255,255,255));
		FillRect(m_pMemDC,&rect,bgBrush);
		DeleteObject(bgBrush);

		img.Draw(m_pMemDC,m_iStartx,m_iStarty,img.GetWidth(),img.GetHeight(),&rect);
		dc.SetStretchBltMode(HALFTONE);
		dc.StretchBlt(rcThis.left,rcThis.top,rcThis.Width(),rcThis.Height(),&m_pMemDC,0,0,width,height,SRCCOPY);
		m_pMemDC.SelectObject(pOldBit);
		m_pMemDC.DeleteDC();
		bitmapmem.DeleteObject();
	}
}
コード例 #16
0
ファイル: IGFrame.cpp プロジェクト: Bitlsoft/Imagenius_SDK
bool IGFrame::DrawLines (std::list<POINT>& lPts, const IGBrush& brush)
{
	// Request thread access
	if (!RequestAccess ())
		return false;
	CxImage *pCurrentLayer = GetWorkingLayer();
	if (!pCurrentLayer)
		return false;
	if (lPts.size() < 2)
		return false;
	IGConvertible::FromIGtoCxCoords (lPts, pCurrentLayer->GetHeight());
	POINT ptFrom;
	std::list<POINT>::iterator itCurrent = lPts.begin();
	ptFrom = *itCurrent;
	while (++itCurrent != lPts.end())
	{
		pCurrentLayer->DrawLine (ptFrom.x, (*itCurrent).x, ptFrom.y, (*itCurrent).y, brush);
		ptFrom = *itCurrent;
	}
	return true;
}
コード例 #17
0
ファイル: ximaig.cpp プロジェクト: Bitlsoft/Imagenius_SDK
bool CxImageIG::Decode(CxFile *hFile)
{
	IGHEADER igHeader;		
	if (!decodeHeader (hFile, &igHeader))
		throw IGEXCEPTION (CxImageIGException, "Decode", "decodeHeader failed");	

	IGSECTIONHEADER_LAYER *pLayerSections = new IGSECTIONHEADER_LAYER[CXIMAGEIG_MAX_NBLAYERS];
	IGSECTIONHEADER_SELECTION *pSelectionSections = new IGSECTIONHEADER_SELECTION[CXIMAGEIG_MAX_NBSELECTIONS];
	if (!decodeSections (hFile, &igHeader, &pLayerSections[0], &pSelectionSections[0]))
		throw IGEXCEPTION (CxImageIGException, "Decode", "decodeSections failed");	

	if (igHeader.nNbSelections > 1)
		throw IGEXCEPTION (CxImageIGException, "Decode", "igHeader.nNbSelections failed");

	head.biWidth = igHeader.nWidth;
	head.biHeight = igHeader.nHeight;
	info.nNumLayers = 0;

	ProgressSetRange (head.biHeight, 0);
	ProgressSetMessage (L"Decoding IG...");	

	// read layers
	IGLibrary::IGLayer *pLayer;
	int nNbSteps = 0;
	for (int i = 0; i < igHeader.nNbLayers; i++)
	{
		// create a layer on top with no alpha and selection
		LayerCreate (-1, false, false);
		pLayer = GetLayer (i);
		if (!pLayer)
			throw IGEXCEPTION (CxImageIGException, "Decode", "GetLayer failed");
		pLayer->setProgressOwner (info.hProgress);

		// read layer pixels
		BYTE *pBufImg = new BYTE [pLayerSections [i].commonHeader.nSizeBuf];
		hFile->Seek (pLayerSections[i].commonHeader.nFirstByteOffset, SEEK_SET);
		hFile->Read (pBufImg, pLayerSections [i].commonHeader.nSizeBuf, 1);
		if (!pLayer->Decode (pBufImg, pLayerSections [i].commonHeader.nSizeBuf, CXIMAGEIG_LAYERFORMAT))
			throw IGEXCEPTION (CxImageIGException, "Decode", "pLayer->Decode failed");
		delete [] pBufImg;
		// create selection
		//pLayer->SelectionCreate();
		// read layer alpha
		pLayer->AlphaCreate (255);
		hFile->Read (pLayer->pAlpha, pLayer->GetWidth() * pLayer->GetHeight(), 1);

		pLayer->info.xOffset = pLayerSections[i].ptOffset.x; // OffsetX
		pLayer->info.yOffset = pLayerSections[i].ptOffset.y; // OffsetY
		pLayer->setFrameOwner (this);
		pLayer->UpdateImageParameters();
		pLayer->SetId (i);
	}
	AddLayerCache(2);

	if (igHeader.nNbSelections > 0)
	{			
		// read selection
		BYTE *pSelectionZipped = new BYTE[pSelectionSections[0].commonHeader.nSizeBuf];
		hFile->Read (pSelectionZipped, pSelectionSections[0].commonHeader.nSizeBuf, 1);
		
		std::ostrstream strOstream;
		int nSelectionUnzippedSize = 0;
		if (IGPacker::gzipUncompress (pSelectionZipped, pSelectionSections [0].commonHeader.nSizeBuf, strOstream, nSelectionUnzippedSize) != Z_OK)
			throw IGEXCEPTION (CxImageIGException, "Decode", "gzipUncompress failed");
		delete [] pSelectionZipped;

		if (nSelectionUnzippedSize > 0)
		{
			// copy selection to dst selection rect
			BYTE *pFromSelection = (BYTE *)strOstream.str();
			CxImage *pSelectionLayer = GetLayer(igHeader.nPosWorkingLayer);
			RECT rcSel = pSelectionSections[0].rcSelection;
			BYTE *pDstSelection = pSelectionLayer->SelectionGetPointer(rcSel.left, rcSel.bottom);
			if (!pDstSelection)
			{
				pSelectionLayer->SelectionCreate();
				pDstSelection = pSelectionLayer->SelectionGetPointer (rcSel.left, rcSel.bottom);
			}

			int nLayerWidth = pSelectionLayer->GetWidth();
			int nLayerHeight = pSelectionLayer->GetHeight();
			if (((rcSel.right - rcSel.left + 1) == nLayerWidth) &&
				((rcSel.top - rcSel.bottom + 1) == nLayerHeight))
			{
				::memcpy (pDstSelection, pFromSelection, nLayerWidth * nLayerHeight);		
			}
			else
			{
				for (int i = 0; i < rcSel.top - rcSel.bottom; i++)
				{
					::memcpy (pDstSelection, pFromSelection, pSelectionSections [0].rcSelection.right - pSelectionSections [0].rcSelection.left + 1);
					pFromSelection += pSelectionSections [0].rcSelection.right - pSelectionSections [0].rcSelection.left + 1;
					pDstSelection += nLayerWidth;
				}
			}
		}
	}

	delete [] pLayerSections;
	delete [] pSelectionSections;	
	return true;
}
コード例 #18
0
// return number of faces and score
void detectFaces(const CxImage& img, std::list <Face>& lFaces, int nRot)
{
	if (cascade_el == NULL || cascade_er == NULL || cascade_f == NULL || cascade_m == NULL || cascade_n == NULL)
		init();
	CxImage imgRotated (img);
	imgRotated.Rotate180();
	IplImage *pIplImage = cvCreateImageHeader (cvSize (img.GetWidth(), img.GetHeight()), 8, img.GetBpp() / 8);
	pIplImage->imageDataOrigin = (char*)imgRotated.GetDIB();
	pIplImage->imageData = (char*)imgRotated.GetBits();

	CvMemStorage			*storage;

	/* setup memory storage, needed by the object detector */
	storage = cvCreateMemStorage(0);

	assert(cascade_f && cascade_el && cascade_er && cascade_m && cascade_n && storage);

	/* haar detection for faces */
	CvSeq *pFaces = cvHaarDetectObjects(
		pIplImage, cascade_f, storage,
		1.2, 2, CV_HAAR_DO_CANNY_PRUNING, cvSize( 40, 40 ) );
	if (pFaces->total == 0)
		return;

	CvSeq seqFaces (*pFaces);
	list <CvRect> lrFaces;
	for(int idxFace = 0; idxFace < seqFaces.total; idxFace++ ) {
		CvRect *r = (CvRect*)cvGetSeqElem(&seqFaces, idxFace);
		if (r)
			lrFaces.push_back (*r);
	}

	/* haar detection for eyes */
	list<pair <RECT, RECT>> lpairEyes;
	detect_eyes (storage, pIplImage, lpairEyes);
	
	/* haar detection for mouths */
	list<RECT> lMouths;
	detect_mouths (storage, pIplImage, lMouths);
	
	/* haar detection for noses */
	list<RECT> lNoses;
	detect_noses (storage, pIplImage, lNoses);
	
	for(list <CvRect>::iterator itFace = lrFaces.begin(); itFace != lrFaces.end(); ++itFace) {
		CvRect r (*itFace);
		CvRect rFace (*itFace);
		rFace.x = img.GetWidth() - r.x - r.width;
		rFace.y = img.GetHeight() - r.y - r.height;
		RECT rcFace; 
		rcFace.left = img.GetWidth() - r.x - r.width - 10; rcFace.right = img.GetWidth() - r.x + 10;
		rcFace.top = img.GetHeight() - r.y - r.height - 10; rcFace.bottom = img.GetHeight() - r.y + 10;

		/* detect current eyes */
		pair <RECT, RECT> pairEyes;
		match_eyes_with_face (lpairEyes, rFace, pairEyes);

		/* detect current mouth */
		RECT rcMouth;
		match_mouths_with_face (lMouths, rFace, pairEyes, rcMouth);

		/* detect current nose */
		RECT rcNose;
		match_noses_with_face (lNoses, rFace, pairEyes, rcMouth, rcNose);

		lFaces.push_back (Face (rcFace, pairEyes, rcMouth, rcNose, nRot));
	}
	Face::adjustRectFaces(lFaces);

	cvReleaseMemStorage (&storage);

	cvReleaseImageHeader (&pIplImage);
}
コード例 #19
0
ファイル: ximaig.cpp プロジェクト: Bitlsoft/Imagenius_SDK
bool CxImageIG::DecodeLayer (CxFile &file, int nLayerIdx, int nLayerPos, RECT *p_rcSubLayer, bool bUndo, int nSubLayerId)
{	
	// read current header
	IGHEADER igHeader;
	if (!decodeHeader (&file, &igHeader))
		throw IGEXCEPTION (CxImageIGException, "DecodeLayer", "decodeHeader failed");
	if (nLayerIdx < 0)
		throw IGEXCEPTION (CxImageIGException, "DecodeLayer", "nLayerIdx failed");
	if ((nLayerPos < 0) || (nLayerPos >= info.nNumLayers))
		throw IGEXCEPTION (CxImageIGException, "DecodeLayer", "nLayerPos failed");

	IGSECTIONHEADER_LAYER *pLayerSections = new IGSECTIONHEADER_LAYER [CXIMAGEIG_MAX_NBLAYERS];
	IGSECTIONHEADER_SELECTION *pSelectionSections  = new IGSECTIONHEADER_SELECTION [CXIMAGEIG_MAX_NBSELECTIONS];
	if (!decodeSections (&file, &igHeader, &pLayerSections[0], &pSelectionSections[0]))
		throw IGEXCEPTION (CxImageIGException, "DecodeLayer", "decodeSections failed");

	IGLibrary::IGLayer *pLayer = GetLayer (nLayerPos);
	if (!pLayer)
		throw IGEXCEPTION (CxImageIGException, "DecodeLayer", "GetLayer failed");
	CxImage cxSubLayer;
	CxImage *pDecodingLayer = p_rcSubLayer ? &cxSubLayer : pLayer;
	bool bIsSubLayerOwner = bUndo && p_rcSubLayer; // no need to find sub-layer owner in do mode
	int nLayerSectionIndex = findLayerSectionIndex (&igHeader, pLayerSections, nLayerIdx, bIsSubLayerOwner);
	if ((nLayerSectionIndex < 0) || (nLayerSectionIndex >= igHeader.nNbLayers))
		throw IGEXCEPTION (CxImageIGException, "DecodeLayer", "findLayerSectionIndex failed");

	// in undo mode, if a sub-layer owner is found, decode it
	if (bUndo){
		if (bIsSubLayerOwner)
		{
			// decode sub-layer owner
			if (!DecodeLayer (file, pLayerSections [nLayerSectionIndex].commonHeader.nId, nLayerPos))
				throw IGEXCEPTION (CxImageIGException, "DecodeLayer", "DecodeLayer failed");
			// decode sub-layers
			int nSubLayerSectionIndex = findLayerSectionIndex (&igHeader, pLayerSections, nLayerIdx, bIsSubLayerOwner);
			if ((nSubLayerSectionIndex < 0) || (nSubLayerSectionIndex >= igHeader.nNbLayers))
				throw IGEXCEPTION (CxImageIGException, "DecodeLayer", "findLayerSectionIndex failed");
			RECT rcSubLayer;
			rcSubLayer.left = pLayerSections[nSubLayerSectionIndex].ptOffset.x;
			rcSubLayer.right = pLayerSections[nSubLayerSectionIndex].ptOffset.x + pLayerSections[nSubLayerSectionIndex].ptSize.x - 1;
			rcSubLayer.top = pLayerSections[nSubLayerSectionIndex].ptOffset.y;
			rcSubLayer.bottom = pLayerSections[nSubLayerSectionIndex].ptOffset.y + pLayerSections[nSubLayerSectionIndex].ptSize.y - 1;
			return DecodeLayer (file, pLayerSections [nLayerSectionIndex].commonHeader.nId, nLayerPos, &rcSubLayer, true, nLayerIdx);
		}
	}

	if (!file.Seek (pLayerSections [nLayerSectionIndex].commonHeader.nFirstByteOffset, SEEK_SET))
		throw IGEXCEPTION (CxImageIGException, "DecodeLayer", "file.Seek failed");
	// read layer pixels
	BYTE *pBufImg = new BYTE [pLayerSections [nLayerSectionIndex].commonHeader.nSizeBuf];
	file.Read (pBufImg, pLayerSections [nLayerSectionIndex].commonHeader.nSizeBuf, 1);
	if (!pDecodingLayer->Decode (pBufImg, pLayerSections [nLayerSectionIndex].commonHeader.nSizeBuf, CXIMAGEIG_LAYERFORMAT))
		throw IGEXCEPTION (CxImageIGException, "DecodeLayer", "pDecodingLayer->Decode failed");
	delete [] pBufImg;

	// read layer alpha
	pDecodingLayer->AlphaCreate (255);
	file.Read (pDecodingLayer->pAlpha, pDecodingLayer->GetWidth() * pDecodingLayer->GetHeight(), 1);
	
	int nSubLayerWidth = 0;
	int nSubLayerHeight = 0;
	if (p_rcSubLayer)
	{
		// decode sub-layer
		nSubLayerWidth = p_rcSubLayer->right - p_rcSubLayer->left + 1;
		nSubLayerHeight = p_rcSubLayer->bottom - p_rcSubLayer->top + 1;
		BYTE *pLayerBits = NULL;
		BYTE *pSubLayerBits = NULL;
		for (int i = 0; i < nSubLayerHeight; i++)
		{
			// if undo, then sub-layer == original layer
			pSubLayerBits = bUndo ? pDecodingLayer->GetBits (p_rcSubLayer->top + i) + 3 * p_rcSubLayer->left : pDecodingLayer->GetBits (i);
			pLayerBits = pLayer->GetBits (p_rcSubLayer->top + i) + 3 * p_rcSubLayer->left;
			::memcpy (pLayerBits, pSubLayerBits, nSubLayerWidth * 3);			
		}
		BYTE *pLayerAlpha = NULL;
		BYTE *pSubLayerAlpha = NULL;
		for (int i = 0; i < nSubLayerHeight; i++)
		{
			pLayerAlpha = pLayer->AlphaGetPointer (p_rcSubLayer->left, p_rcSubLayer->top + i);
			pSubLayerAlpha = bUndo ? pDecodingLayer->AlphaGetPointer (p_rcSubLayer->left, p_rcSubLayer->top + i) : pDecodingLayer->AlphaGetPointer (0, i);
			::memcpy (pLayerAlpha, pSubLayerAlpha, nSubLayerWidth);
		}
		if (bUndo)
		{
			// original layer is now decoded. decode sub-layers
			bIsSubLayerOwner = false;
			int nMaxSubLayerSectionIndex = findLayerSectionIndex (&igHeader, pLayerSections, nSubLayerId, bIsSubLayerOwner); // we always have bIsSubLayerOwner = false, its used for the reference only
			if (nMaxSubLayerSectionIndex < 0)
				throw IGEXCEPTION (CxImageIGException, "DecodeLayer", "findLayerSectionIndex failed");
			if (nMaxSubLayerSectionIndex <= igHeader.nNbLayers)
			{
				for (int i = 0; i < pLayerSections [nLayerSectionIndex].nSubLayers; i++)
				{
					if (pLayerSections [nLayerSectionIndex].pnSubLayers [i] <= nMaxSubLayerSectionIndex)
					{
						if (!decodeSubLayer (file, pLayer, &pLayerSections [pLayerSections [nLayerSectionIndex].pnSubLayers [i]]))
							throw IGEXCEPTION (CxImageIGException, "DecodeLayer", "decodeSubLayer failed");
					}
				}
			}
		}
	}
	else
	{
		pLayer->info.xOffset = pLayerSections [nLayerSectionIndex].ptOffset.x;
		pLayer->info.yOffset = pLayerSections [nLayerSectionIndex].ptOffset.y;
	}
	pLayer->SetId (nLayerIdx);
	pLayer->UpdateImageParameters();
	delete [] pLayerSections;
	delete [] pSelectionSections;
	return true;
}
コード例 #20
0
ファイル: ximaig.cpp プロジェクト: Bitlsoft/Imagenius_SDK
bool CxImageIG::EncodeLayer (const wchar_t *pcwFilePath, int nLayerIdx, int nLayerPos, RECT *p_rcSubLayer, int nSubLayerOwnerId)
{
	CxIOFile file;
	if (!file.Open (pcwFilePath, L"r+b"))
		throw IGEXCEPTION (CxImageIGException, "EncodeLayer", "file.Open failed");
	// read current header
	IGHEADER igHeader;	
	if (!decodeHeader (&file, &igHeader))
		throw IGEXCEPTION (CxImageIGException, "EncodeLayer", "decodeHeader failed");

	IGSECTIONHEADER_LAYER *pLayerSections = new IGSECTIONHEADER_LAYER[CXIMAGEIG_MAX_NBLAYERS];
	IGSECTIONHEADER_SELECTION *pSelectionSections = new IGSECTIONHEADER_SELECTION[CXIMAGEIG_MAX_NBSELECTIONS];
	if (!decodeSections (&file, &igHeader, &pLayerSections[0], &pSelectionSections[0]))
		throw IGEXCEPTION (CxImageIGException, "EncodeLayer", "decodeSections failed");

	IGLibrary::IGLayer *pLayer = GetLayer (nLayerPos);
	if (!pLayer)
		throw IGEXCEPTION (CxImageIGException, "EncodeLayer", "GetLayer failed");
	_ASSERTE ((int)pLayer->GetId() == nLayerIdx && "CxImageIG::EncodeLayer FAILED");
	bool bIsSubLayerOwner = false;
	int nLayerSectionIndex = findLayerSectionIndex (&igHeader, pLayerSections, nLayerIdx, bIsSubLayerOwner);
	if (nLayerSectionIndex < 0)
		throw IGEXCEPTION (CxImageIGException, "EncodeLayer", "findLayerSectionIndex failed");
	if ((nLayerSectionIndex > igHeader.nNbLayers) || (nLayerSectionIndex >= CXIMAGEIG_MAX_NBLAYERS))
		throw IGEXCEPTION (CxImageIGException, "EncodeLayer", "findLayerSectionIndex failed");
	CxImage cxSubLayer;
	CxImage *pEncodingLayer = pLayer;
	int nSubLayerWidth = 0;
	int nSubLayerHeight = 0;
	if (p_rcSubLayer)
	{
		// Encode sub-layer
		nSubLayerWidth = p_rcSubLayer->right - p_rcSubLayer->left + 1;
		nSubLayerHeight = p_rcSubLayer->bottom - p_rcSubLayer->top + 1;
		cxSubLayer.Create (nSubLayerWidth, nSubLayerHeight, 24);
		cxSubLayer.AlphaCreate (255);
		BYTE *pLayerBits = NULL;
		BYTE *pSubLayerBits = NULL;
		for (int i = 0; i < nSubLayerHeight; i++)
		{
			pSubLayerBits = cxSubLayer.GetBits (i);
			pLayerBits = pLayer->GetBits (p_rcSubLayer->top + i) + 3 * p_rcSubLayer->left;
			::memcpy (pSubLayerBits, pLayerBits, nSubLayerWidth * 3);
		}
		BYTE *pLayerAlpha = NULL;
		BYTE *pSubLayerAlpha = NULL;
		for (int i = 0; i < nSubLayerHeight; i++)
		{
			pLayerAlpha = pLayer->AlphaGetPointer (p_rcSubLayer->left, p_rcSubLayer->top + i);
			pSubLayerAlpha = cxSubLayer.AlphaGetPointer (0, i);		
			::memcpy (pSubLayerAlpha, pLayerAlpha, nSubLayerWidth);
		}
		pEncodingLayer = &cxSubLayer;
		int nSubLayerSectionIndex = findLayerSectionIndex (&igHeader, pLayerSections, nSubLayerOwnerId, bIsSubLayerOwner);
		if (nSubLayerSectionIndex < 0)
			throw IGEXCEPTION (CxImageIGException, "EncodeLayer", "findLayerSectionIndex failed");
		pLayerSections [nSubLayerSectionIndex].pnSubLayers [pLayerSections [nSubLayerSectionIndex].nSubLayers++] = nLayerSectionIndex;
	}
	ProgressSetRange (pLayer->GetHeight(), 0);
	ProgressSetMessage (L"Encoding layer...");	
	// fill layer offset and size
	pLayerSections [nLayerSectionIndex].nSubLayers = 0;
	pLayerSections [nLayerSectionIndex].ptOffset.x = p_rcSubLayer ? p_rcSubLayer->left : pLayer->info.xOffset;
	pLayerSections [nLayerSectionIndex].ptOffset.y = p_rcSubLayer ? p_rcSubLayer->top : pLayer->info.yOffset;
	pLayerSections [nLayerSectionIndex].ptSize.x = p_rcSubLayer ? p_rcSubLayer->right - p_rcSubLayer->left + 1 : pLayer->GetWidth();
	pLayerSections [nLayerSectionIndex].ptSize.y = p_rcSubLayer ? p_rcSubLayer->bottom - p_rcSubLayer->top + 1 : pLayer->GetHeight();
	if (nLayerSectionIndex == igHeader.nNbLayers)
		pLayerSections [nLayerSectionIndex].commonHeader.nSectionId = (BYTE)igHeader.nNbSections;
	pLayerSections [nLayerSectionIndex].commonHeader.nId = nLayerIdx;
	pLayerSections [nLayerSectionIndex].commonHeader.eSectionType = IGSECTION_LAYER;
	// set byte offset
	if (igHeader.nNbSections == 0)
		pLayerSections [nLayerSectionIndex].commonHeader.nFirstByteOffset = sizeof (IGHEADER) + sizeof (IGSECTIONHEADER_LAYER) * CXIMAGEIG_MAX_NBLAYERS + sizeof (IGSECTIONHEADER_SELECTION) * CXIMAGEIG_MAX_NBSELECTIONS;
	else
		pLayerSections [nLayerSectionIndex].commonHeader.nFirstByteOffset = findSectionFirstByteOffset (&igHeader, pLayerSections, pSelectionSections, pLayerSections [nLayerSectionIndex].commonHeader.nSectionId);

	igHeader.nNbLayers = nLayerSectionIndex + 1;
	if (igHeader.nNbSelections == 0)
	{
		igHeader.nNbSections = pLayerSections [nLayerSectionIndex].commonHeader.nSectionId + 1;
		igHeader.nNbSelections = igHeader.nNbSections - igHeader.nNbLayers;
	}
	else
	{
		if (pSelectionSections [igHeader.nNbSelections - 1].commonHeader.nSectionId == pLayerSections [nLayerSectionIndex].commonHeader.nSectionId + 1)
			igHeader.nNbSections = igHeader.nNbSelections + igHeader.nNbLayers;
		else
		{
			igHeader.nNbSections = pLayerSections [nLayerSectionIndex].commonHeader.nSectionId + 1;
			igHeader.nNbSelections = igHeader.nNbSections - igHeader.nNbLayers;
		}
	}

	// write layer pixels
	if (!file.Seek (pLayerSections [nLayerSectionIndex].commonHeader.nFirstByteOffset, SEEK_SET))
		throw IGEXCEPTION (CxImageIGException, "EncodeLayer", "file.Seek failed");

	// set max JPEG quality
	float fCurQuality = pEncodingLayer->GetJpegQualityF();
	pEncodingLayer->SetJpegQualityF (100.0f);
	// JPEG encoding
	BYTE *pBuf = new BYTE [CXIMAGEIG_INIT_LAYERSIZE];
	CxMemFile memFile (pBuf, CXIMAGEIG_INIT_LAYERSIZE);
	if (!pEncodingLayer->Encode (&memFile, CXIMAGEIG_LAYERFORMAT))
		throw IGEXCEPTION (CxImageIGException, "EncodeLayer", "pEncodingLayer->Encode failed");
	BYTE *pBufImg = memFile.GetBuffer();
	long nSizeBufImg = memFile.Tell();
	// reset JPEG quality
	pEncodingLayer->SetJpegQualityF (fCurQuality);
	file.Write (pBufImg, nSizeBufImg, 1);
	delete [] pBufImg;
	pLayerSections [nLayerSectionIndex].commonHeader.nSizeBuf = nSizeBufImg;
	// write layer alpha
	if (!pEncodingLayer->pAlpha)
		pEncodingLayer->AlphaCreate(255);
	int nNbPixels = pEncodingLayer->GetWidth() * pEncodingLayer->GetHeight();
	file.Write (pEncodingLayer->pAlpha, nNbPixels, 1);
	pLayerSections [nLayerSectionIndex].commonHeader.nEndByteOffset = pLayerSections [nLayerSectionIndex].commonHeader.nFirstByteOffset + nSizeBufImg + nNbPixels;

	// write new headers
	if (!encodeHeader (&file, &igHeader))
		throw IGEXCEPTION (CxImageIGException, "EncodeLayer", "encodeHeader failed");
	if (!encodeSections (&file, &igHeader, pLayerSections, pSelectionSections))
		throw IGEXCEPTION (CxImageIGException, "EncodeLayer", "encodeSections failed");
	delete [] pLayerSections;
	delete [] pSelectionSections;
	return true;
}
コード例 #21
0
ファイル: FrameGrabThread.cpp プロジェクト: dalinhuang/dmibox
UINT CFrameGrabThread::GrabFrames(){
	#define TIMEBETWEENFRAMES	50.0 // could be a param later, if needed
	for (int i = 0; i!= nFramesToGrab; i++)
		imgResults[i] = NULL;
	try{
		HRESULT hr;
		CComPtr<IMediaDet> pDet;
		hr = pDet.CoCreateInstance(__uuidof(MediaDet));
		if (!SUCCEEDED(hr))
			return 0;

		// Convert the file name to a BSTR.
		CComBSTR bstrFilename(strFileName);
		hr = pDet->put_Filename(bstrFilename);

		long lStreams;
		bool bFound = false;
		hr = pDet->get_OutputStreams(&lStreams);
		for (long i = 0; i < lStreams; i++)
		{
			GUID major_type;
			hr = pDet->put_CurrentStream(i);
			hr = pDet->get_StreamType(&major_type);
			if (major_type == MEDIATYPE_Video)
			{
				bFound = true;
				break;
			}
		}
		
		if (!bFound)
			return 0;
		
		double dLength = 0;
		pDet->get_StreamLength(&dLength);
		if (dStartTime > dLength)
			dStartTime = 0;

		long width = 0, height = 0; 
		AM_MEDIA_TYPE mt;
		hr = pDet->get_StreamMediaType(&mt);
		if (mt.formattype == FORMAT_VideoInfo) 
		{
			VIDEOINFOHEADER *pVih = (VIDEOINFOHEADER*)(mt.pbFormat);
			width = pVih->bmiHeader.biWidth;
			height = pVih->bmiHeader.biHeight;
			
	        
			// We want the absolute height, don't care about orientation.
			if (height < 0) height *= -1;
		}
		else {
			return 0; // Should not happen, in theory.
		}

		/*FreeMediaType(mt); = */	
		if (mt.cbFormat != 0){
			CoTaskMemFree((PVOID)mt.pbFormat);
			mt.cbFormat = 0;
			mt.pbFormat = NULL;
		}
		if (mt.pUnk != NULL){
			mt.pUnk->Release();
			mt.pUnk = NULL;
		}
		/**/

	    
		long size;
		uint32 nFramesGrabbed;
		for (nFramesGrabbed = 0; nFramesGrabbed != nFramesToGrab; nFramesGrabbed++){
			hr = pDet->GetBitmapBits(dStartTime + (nFramesGrabbed*TIMEBETWEENFRAMES), &size, NULL, width, height);
			if (SUCCEEDED(hr)) 
			{
				// we could also directly create a Bitmap in memory, however this caused problems/failed with *some* movie files
				// when I tried it for the MMPreview, while this method works always - so I'll continue to use this one
				long nFullBufferLen = sizeof( BITMAPFILEHEADER ) + size;
				char* buffer = new char[nFullBufferLen];
				
				BITMAPFILEHEADER bfh;
				memset( &bfh, 0, sizeof( bfh ) );
				bfh.bfType = 'MB';
				bfh.bfSize = nFullBufferLen;
				bfh.bfOffBits = sizeof( BITMAPINFOHEADER ) + sizeof( BITMAPFILEHEADER );
				memcpy(buffer,&bfh,sizeof( bfh ) );

				try {
					hr = pDet->GetBitmapBits(dStartTime+ (nFramesGrabbed*TIMEBETWEENFRAMES), NULL, buffer + sizeof( bfh ), width, height);
				}
				catch (...) {
					ASSERT(0);
					hr = E_FAIL;
				}
				if (SUCCEEDED(hr))
				{
					// decode
					CxImage* imgResult = new CxImage();
					imgResult->Decode((BYTE*)buffer, nFullBufferLen, CXIMAGE_FORMAT_BMP);
					delete[] buffer;
					if (!imgResult->IsValid()){
						delete imgResult;
						break;
					}

					// resize if needed
					if (nMaxWidth > 0 && nMaxWidth < width){
						float scale = (float)nMaxWidth / imgResult->GetWidth();
						int nMaxHeigth = (int)(imgResult->GetHeight() * scale);
						imgResult->Resample(nMaxWidth, nMaxHeigth, 0);
					}
					
					// decrease bpp if needed
					if (bReduceColor){
						RGBQUAD* ppal=(RGBQUAD*)malloc(256*sizeof(RGBQUAD));
						if (ppal) {
							CQuantizer q(256,8);
							q.ProcessImage(imgResult->GetDIB());
							q.SetColorTable(ppal);
							imgResult->DecreaseBpp(8, true, ppal);
							free(ppal);
						}
					}
					
					//CString TestName;
					//TestName.Format("G:\\testframe%i.png",nFramesGrabbed);
					//imgResult->Save(TestName,CXIMAGE_FORMAT_PNG);
					// done
					imgResults[nFramesGrabbed] = imgResult;
				}
				else{
					delete[] buffer;
					break;
				}
			}
		}
		return nFramesGrabbed;
	}
	catch(...){
		ASSERT(0);
		return 0;
	}
}
コード例 #22
0
ファイル: IGFrame.cpp プロジェクト: Bitlsoft/Imagenius_SDK
bool IGFrame::ManageSelection (const IGLibrary::SELECTIONPARAMS& selParams, const std::list<POINT>& lPts)
{
	// Request thread access
	if (!RequestAccess ())
		return false;
	CxImage *pCurrentLayer = GetWorkingLayer();
	if (!pCurrentLayer)
		return false;
	int nCurLayerId = (int)pCurrentLayer->GetId();
	int nCurLayerWidth = (int)pCurrentLayer->GetWidth();
	int nCurLayerHeight = (int)pCurrentLayer->GetHeight();
	_ASSERTE ((nCurLayerId >= 0) && L"Current layer is not identified");
	if (nCurLayerId < 0)
		return false;
	bool bRes = false;
	POINT ptTopLeft = {0, 0};
	POINT ptBottomRight = {-1, -1};
	IGSELECTIONENUM eSelectionType = selParams.eSelectionType;
	if (((eSelectionType & IGSELECTION_SQUARE) == IGSELECTION_SQUARE) ||
		((eSelectionType & IGSELECTION_LASSO) == IGSELECTION_LASSO))
	{
		if (lPts.size() > 0)
		{
			bool bAllEqual = true;
			for (list <POINT>::const_iterator itPt = lPts.cbegin(); itPt != lPts.cend(); ++itPt)
			{
				if (((*itPt).x != lPts.front().x) || ((*itPt).y != lPts.front().y))
					bAllEqual = false;
			}
			if (bAllEqual)
				eSelectionType = IGSELECTION_CLEAR;
		}
	}
	if ((eSelectionType & IGSELECTION_CLEAR) == IGSELECTION_CLEAR)
	{
		if ((eSelectionType & IGSELECTION_INVERT) == IGSELECTION_INVERT)
			bRes = pCurrentLayer->SelectionInvert();
		else
			bRes = pCurrentLayer->SelectionDelete();
	}
	else
	{
		if ((eSelectionType & IGSELECTION_REPLACE) == IGSELECTION_REPLACE)
			pCurrentLayer->SelectionClear();	
		BYTE level = ((eSelectionType & IGSELECTION_REMOVE) == IGSELECTION_REMOVE) ? 0 : 255;

		std::list<POINT> lConvertedPts (lPts); 
		// convert IG coordinates to Cx coordinates
		IGConvertible::FromIGtoCxCoords(lConvertedPts, pCurrentLayer->GetHeight());
	
		// apply selection
		if ((eSelectionType & IGSELECTION_SQUARE) == IGSELECTION_SQUARE)
		{
			if (lPts.size() != 2)
				return false;	
			// read rectangle coordinates
			ptTopLeft = lConvertedPts.front();
			ptBottomRight = lConvertedPts.back();
			int nPosX = ptTopLeft.x;
			int nPosY = ptBottomRight.y;
			RECT rcSel;
			rcSel.left = nPosX; rcSel.top = nPosY;
			nPosX = ptBottomRight.x;
			nPosY = ptTopLeft.y;
			rcSel.right = nPosX; rcSel.bottom = nPosY;
			// adjust rectangle orientation
			int nWidth = rcSel.right - rcSel.left;
			int nHeight = rcSel.top - rcSel.bottom;
			nWidth = (nWidth < 0) ? -1 * nWidth : nWidth;
			nHeight = (nHeight < 0) ? -1 * nHeight : nHeight;
			rcSel.left = (rcSel.left < rcSel.right) ? rcSel.left : rcSel.right;
			rcSel.bottom = (rcSel.bottom < rcSel.top) ? rcSel.bottom : rcSel.top;
			rcSel.right = rcSel.left + nWidth;
			rcSel.top = rcSel.bottom + nHeight;
			// test if rectangle is inside the frame
			if ((rcSel.right < 0) || (rcSel.left >= nCurLayerWidth)
				|| (rcSel.top < 0) || (rcSel.bottom >= nCurLayerHeight))
				return false;	// selection out of bounds
			// adjust bounds
			rcSel.left = (rcSel.left < 0) ? 0 : rcSel.left;
			rcSel.right = (rcSel.right >= nCurLayerWidth) ? nCurLayerWidth - 1 : rcSel.right;
			rcSel.bottom = (rcSel.bottom < 0) ? 0 : rcSel.bottom;
			rcSel.top = (rcSel.top >= nCurLayerHeight) ? nCurLayerHeight - 1 : rcSel.top;
			// add the selection
			bRes = pCurrentLayer->SelectionAddRect (rcSel, level);
		}
		else if ((eSelectionType & IGSELECTION_LASSO) == IGSELECTION_LASSO)
		{
			bRes = pCurrentLayer->SelectionAddPolygon (lConvertedPts, level);
		}
		else if ((eSelectionType & IGSELECTION_MAGIC) == IGSELECTION_MAGIC)
		{
			bRes = pCurrentLayer->SelectionAddMagic (lConvertedPts.front(), level, selParams.nTolerance);
		}
		else if ((eSelectionType & IGSELECTION_FACES) == IGSELECTION_FACES)
		{
			bRes = pCurrentLayer->SelectionAddFaces (level);
		}
		else if ((eSelectionType & IGSELECTION_EYES) == IGSELECTION_EYES)
		{
			bRes = pCurrentLayer->SelectionAddEyes (level);
		}
		else if ((eSelectionType & IGSELECTION_MOUTH) == IGSELECTION_MOUTH)
		{
			bRes = pCurrentLayer->SelectionAddMouth (level);
		}
		else if ((eSelectionType & IGSELECTION_NOZE) == IGSELECTION_NOZE)
		{
			bRes = pCurrentLayer->SelectionAddNoze (level);
		}
		else if ((eSelectionType & IGSELECTION_LPE) == IGSELECTION_LPE)
		{
			bRes = pCurrentLayer->SelectionAddLPE (lConvertedPts, level);
		}
		if (ptBottomRight.x < ptTopLeft.x)
		{
			int nSwap = ptTopLeft.x;
			ptTopLeft.x = ptBottomRight.x;
			ptBottomRight.x = nSwap;
		}
		if (ptBottomRight.y < ptTopLeft.y)
		{
			int nSwap = ptTopLeft.y;
			ptTopLeft.y = ptBottomRight.y;
			ptBottomRight.y = nSwap;
		}
		if (ptTopLeft.x < 0)
			ptTopLeft.x = 0;
		if (ptTopLeft.y < 0)
			ptTopLeft.y = 0;
		if (ptBottomRight.x >= nCurLayerWidth)
			ptBottomRight.x = nCurLayerWidth - 1;
		if (ptBottomRight.y >= nCurLayerHeight)
			ptBottomRight.y = nCurLayerHeight - 1;
	}
	if (!pCurrentLayer->SelectionIsValid())
		pCurrentLayer->SelectionDelete();
	AddNewStep (IGFRAMEHISTORY_STEP_SELECTION, L"Change selection", (int)&selParams, (int)&lPts);
	Redraw (true);
	return bRes;
}
コード例 #23
0
ファイル: DllInterface.cpp プロジェクト: 1ibraheem/xbmc
  __declspec(dllexport) bool LoadImageFromMemory(const BYTE *buffer, unsigned int size, const char *mime, unsigned int maxwidth, unsigned int maxheight, ImageInfo *info)
  {
    if (!buffer || !size || !mime || !info) return false;

    // load the image
    DWORD dwImageType = CXIMAGE_FORMAT_UNKNOWN;
    if (strlen(mime))
      dwImageType = GetImageType(mime);
    if (dwImageType == CXIMAGE_FORMAT_UNKNOWN)
      dwImageType = DetectFileType(buffer, size);
    if (dwImageType == CXIMAGE_FORMAT_UNKNOWN)
    {
      printf("PICTURE::LoadImageFromMemory: Unable to determine image type.");
      return false;
    }

    CxImage *image = new CxImage(dwImageType);
    if (!image)
      return false;

    int actualwidth = maxwidth;
    int actualheight = maxheight;

    try
    {
      bool success = image->Decode((BYTE*)buffer, size, dwImageType, actualwidth, actualheight);
      if (!success && dwImageType != CXIMAGE_FORMAT_UNKNOWN)
      { // try to decode with unknown imagetype
        success = image->Decode((BYTE*)buffer, size, CXIMAGE_FORMAT_UNKNOWN);
      }
      if (!success || !image->IsValid())
      {
        printf("PICTURE::LoadImageFromMemory: Unable to decode image. Error:%s\n", image->GetLastError());
        delete image;
        return false;
      }
    }
    catch (...)
    {
      printf("PICTURE::LoadImageFromMemory: Unable to decode image.");
      delete image;
      return false;
    }

    // ok, now resample the image down if necessary
    if (ResampleKeepAspect(*image, maxwidth, maxheight) < 0)
    {
      printf("PICTURE::LoadImage: Unable to resample picture\n");
      delete image;
      return false;
    }

    // make sure our image is 24bit minimum
    image->IncreaseBpp(24);

    // fill in our struct
    info->width = image->GetWidth();
    info->height = image->GetHeight();
    info->originalwidth = actualwidth;
    info->originalheight = actualheight;
    memcpy(&info->exifInfo, image->GetExifInfo(), sizeof(EXIFINFO));

    // create our texture
    info->context = image;
    info->texture = image->GetBits();
    info->alpha = image->AlphaGetBits();
    return (info->texture != NULL);
  };
コード例 #24
0
ファイル: demoView.cpp プロジェクト: Aliceljm1/CxImageVS2010
//////////////////////////////////////////////////////////////////////////////
// CDemoView message handlers
//////////////////////////////////////////////////////////////////////////////
void CDemoView::OnMouseMove(UINT nFlags, CPoint point) 
{
	CDemoDoc* pDoc = GetDocument();
	CxImage*  ima  = pDoc->GetImage();
	if (!ima)	return;

	// We'll get the RGB values at the point the user selects
	long x = point.x;
	long y = point.y;
	GetImageXY(pDoc, ima, &x,&y);

	TCHAR s[80];
	if (ima->IsInside(x,y))	{

		long yflip = ima->GetHeight() - y - 1;
		_stprintf(s,_T("x: %d y: %d  idx: %d"), x, y, ima->GetPixelIndex(x,yflip));
		RGBQUAD rgb=ima->GetPixelColor(x,yflip);
		if (ima->AlphaIsValid()) rgb.rgbReserved=ima->AlphaGet(x,yflip);
		else rgb.rgbReserved=ima->GetPaletteColor(ima->GetPixelIndex(x,yflip)).rgbReserved;
		_stprintf(&s[_tcslen(s)],_T("  RGBA: (%d, %d, %d, %d)"), rgb.rgbRed, rgb.rgbGreen, rgb.rgbBlue, rgb.rgbReserved);

		//Enable these lines if you want draw over the image	
		//if ((nFlags & MK_LBUTTON)==MK_LBUTTON){
		//	ima->SetPixelColor(x,yflip,RGB(rand()/(RAND_MAX/256),rand()/(RAND_MAX/256),rand()/(RAND_MAX/256)));
		//	Invalidate(0);
		//}
#ifdef VATI_EXTENSIONS
		if (nFlags & MK_RBUTTON && !(nFlags & MK_LBUTTON))
		{
			switch (pDoc->m_tool){
			case 1: // selection
				if ( nFlags & MK_CONTROL ) // CTRL+right button: move selection
				{
					for (int i=0; i<pDoc->m_NumSel; i++)
					{
						pDoc->m_Sel[i].x += (long)(x-m_oldPnt.x);
						pDoc->m_Sel[i].y += (long)(y-m_oldPnt.y);
					}
					m_oldPnt.x = x;
					m_oldPnt.y = y;
					//redraw selection
					CWnd* pFrame=GetParentFrame();
					RECT rClient;
					pFrame->GetClientRect(&rClient);
					pFrame->RedrawWindow( &rClient, NULL, RDW_INVALIDATE | RDW_UPDATENOW);
					DrawSelection();
				}
				else if ( !(nFlags & MK_CONTROL) && pDoc->m_isRectSel && pDoc->m_NumSel==5 )
				{
					// calculate angle difference looking from rectangle center
					double d_angle = 
						atan2( (y - m_orgPnt.y), (x - m_orgPnt.x) )
					  - atan2( (m_oldPnt.y - m_orgPnt.y), (m_oldPnt.x - m_orgPnt.x) );
					m_oldPnt.x = x;
					m_oldPnt.y = y;
					Dpoint2d    p;

                    // rotate corner points around center point
					for(int i=0;i<5;i++)
					{
						p.x = m_dpnt[i].x - m_orgPnt.x;
						p.y = m_dpnt[i].y - m_orgPnt.y;
						m_dpnt[i].x = p.x*cos(d_angle) - p.y*sin(d_angle) + m_orgPnt.x;
						m_dpnt[i].y = p.x*sin(d_angle) + p.y*cos(d_angle) + m_orgPnt.y;
						// write back to selection
						pDoc->m_Sel[i].x = (long)m_dpnt[i].x ;
						pDoc->m_Sel[i].y = (long)m_dpnt[i].y ;

					}
					// redraw the rectangle
					CWnd* pFrame=GetParentFrame();
					RECT rClient;
					pFrame->GetClientRect(&rClient);
					pFrame->RedrawWindow( &rClient, NULL, RDW_INVALIDATE | RDW_UPDATENOW);
					DrawSelection();
				}
			break;			
			} // end switch
		} // end if MK_RBUTTON
#endif	

		if (nFlags & MK_LBUTTON)
			switch (pDoc->m_tool){
			case 0: // move
			{
				SetCursor(LoadCursor(0,IDC_SIZEALL));
				CSize sz(GetTotalSize());
				CWnd* pFrame=GetParentFrame();
				RECT rClient;
				pFrame->GetClientRect(&rClient);
				if (sz.cx>rClient.right) SetScrollPos(SB_HORZ,m_RefScroll.x - point.x + m_RefPoint.x); else SetScrollPos(SB_HORZ,0);
				if (sz.cy>rClient.bottom) SetScrollPos(SB_VERT,m_RefScroll.y - point.y + m_RefPoint.y); else SetScrollPos(SB_VERT,0);
				Invalidate(0);
				break;
			}
			case 1:	//selection
				SetCursor(LoadCursor(0,IDC_CROSS));
#if CXIMAGE_DEMO_SELECT
#ifdef VATI_EXTENSIONS
				if ( nFlags & MK_SHIFT )
				{
					// rectangle selection
					pDoc->m_isRectSel = 1;
					// in rectangle mode, selection array has 0,1 or 5 points
					if (!pDoc->m_NumSel) 
					{
						pDoc->m_Sel[0].x = x;
						pDoc->m_Sel[0].y = y;
						pDoc->m_NumSel = 1;
					}
					else // already has at least one corner
					{
						pDoc->m_Sel[1].x = x;
						pDoc->m_Sel[1].y = pDoc->m_Sel[0].y;
						pDoc->m_Sel[2].x = x;
						pDoc->m_Sel[2].y = y;
						pDoc->m_Sel[3].x = pDoc->m_Sel[0].x;
						pDoc->m_Sel[3].y = y;
						//close the rectangle:
						pDoc->m_Sel[4].x = pDoc->m_Sel[0].x;
						pDoc->m_Sel[4].y = pDoc->m_Sel[0].y;
						pDoc->m_NumSel = 5;
					}
					// delete old rectangle from display:
					CWnd* pFrame=GetParentFrame();
					RECT rClient;
					pFrame->GetClientRect(&rClient);
					pFrame->RedrawWindow( &rClient, NULL, RDW_INVALIDATE | RDW_UPDATENOW);
					// draw the new rectangle
					DrawSelection();
				}
				else
#endif
				{
					//freehand selection (original)
					float zoom=pDoc->GetZoomFactor();
					CPoint pos(GetScrollPosition());
					int i=pDoc->m_NumSel;
					pDoc->m_Sel[i].x = (long)((point.x + pos.x)/zoom);
					pDoc->m_Sel[i].y = (long)((point.y + pos.y)/zoom);
					if (i<(MAX_SEL_POINTS-2)) pDoc->m_NumSel++;
					DrawSelection();
				}
#endif
		} //end switch

	} else _tcscpy(s,_T(" "));
	
	CStatusBar& statusBar = ((CMainFrame *)(AfxGetApp()->m_pMainWnd))->GetStatusBar();
	statusBar.SetPaneText(0, s);
	
	CScrollView::OnMouseMove(nFlags, point);
}
コード例 #25
0
ファイル: DllInterface.cpp プロジェクト: abs0/xbmc
  __declspec(dllexport) bool CreateFolderThumbnail(const char **file, const char *thumb, int maxWidth, int maxHeight)
  {
    if (!file || !file[0] || !file[1] || !file[2] || !file[3] || !thumb) return false;

    CxImage folderimage(maxWidth, maxHeight, 32, CXIMAGE_FORMAT_PNG);
    folderimage.AlphaCreate();
    int iWidth = maxWidth / 2;
    int iHeight = maxHeight / 2;
    for (int i = 0; i < 2; i++)
    {
      for (int j = 0; j < 2; j++)
      {
        int width = iWidth;
        int height = iHeight;
        bool bBlank = false;
        if (strlen(file[i*2 + j]) == 0)
          bBlank = true;
        if (!bBlank)
        {
          CxImage image;
          if (image.Load(file[i*2 + j], CXIMAGE_FORMAT_JPG, width, height))
          {
            // resize image to iWidth
            if (ResampleKeepAspect(image, iWidth - 2, iHeight - 2) >= 0)
            {
              int iOffX = (iWidth - 2 - image.GetWidth()) / 2;
              int iOffY = (iHeight - 2 - image.GetHeight()) / 2;
              for (int x = 0; x < iWidth; x++)
              {
                for (int y = 0; y < iHeight; y++)
                {
                  RGBQUAD rgb;
                  if (x < iOffX || x >= iOffX + (int)image.GetWidth() || y < iOffY || y >= iOffY + (int)image.GetHeight())
                  {
                    rgb.rgbBlue = 0; rgb.rgbGreen = 0; rgb.rgbRed = 0; rgb.rgbReserved = 0;
                  }
                  else
                  {
                    rgb = image.GetPixelColor(x - iOffX, y - iOffY);
                    rgb.rgbReserved = 255;
                  }
                  folderimage.SetPixelColor(x + j*iWidth, y + (1 - i)*iHeight, rgb, true);
                }
              }
            }
            else
              bBlank = true;
          }
          else
            bBlank = true;
        }
        if (bBlank)
        { // no image - just fill with black alpha
          for (int x = 0; x < iWidth; x++)
          {
            for (int y = 0; y < iHeight; y++)
            {
              RGBQUAD rgb;
              rgb.rgbBlue = 0; rgb.rgbGreen = 0; rgb.rgbRed = 0; rgb.rgbReserved = 0;
              folderimage.SetPixelColor(x + j*iWidth, y + (1 - i)*iHeight, rgb, true);
            }
          }
        }
      }
    }
    ::DeleteFile(thumb);
    if (!folderimage.Save(thumb, CXIMAGE_FORMAT_PNG))
    {
      printf("Unable to save thumb file");
      ::DeleteFile(thumb);
      return false;
    }
    return true;
  };
コード例 #26
0
ファイル: demoView.cpp プロジェクト: Aliceljm1/CxImageVS2010
void CDemoView::OnLButtonDown(UINT nFlags, CPoint point) 
{
	CDemoDoc* pDoc = GetDocument();
	if (pDoc) {
		switch(pDoc->m_tool){
		case 0: // select
		case 1:
			{
#ifdef VATI_EXTENSIONS
				if ( nFlags & MK_SHIFT )
					pDoc->m_isRectSel = 1;
				else
					pDoc->m_isRectSel = 0;
#endif
				CxImage* ima = pDoc->GetImage();
				if (ima) {
					m_RefScroll = GetScrollPosition();
					m_RefPoint.x = point.x;
					m_RefPoint.y = point.y;
				}
			}
			break;
		case 2: // zoom
			if (!pDoc->GetWaitingClick()) PostMessage(WM_COMMAND,ID_VIEW_ZOOMIN);
			break;
		case 4: // tracker
			{
				if (m_tracker.HitTest(point) < 0)
				{
					CRectTracker track;
					if (track.TrackRubberBand(this, point, true)) {
						track.m_rect.NormalizeRect();
						m_tracker.m_rect = track.m_rect;
						SetImageRectSelection(pDoc,&(m_tracker.m_rect));
					} else {
						m_tracker.m_rect = CRect(0,0,0,0);
					}
				} else {
					if (m_tracker.Track(this, point, true)){
						m_tracker.m_rect.NormalizeRect();
						SetImageRectSelection(pDoc,&(m_tracker.m_rect));
					} else {
						m_tracker.m_rect = CRect(0,0,0,0);
					}
				}
				OnUpdate(0,0,0);
			}
			break;
		case 3: //text
			{
				//pDoc->m_tool=-1;
				CxImage* ima = pDoc->GetImage();
				if (ima){
					pDoc->SubmitUndo();
					long x = point.x;
					long y = point.y;
					GetImageXY(pDoc, ima, &x,&y);
#ifndef VATI_EXTENSIONS
					RGBQUAD c = ima->RGBtoRGBQUAD(pDoc->m_color);
					c.rgbReserved=255;
					ima->DrawString(0,x,y,pDoc->m_text,c,
								pDoc->m_font.lfFaceName,
								pDoc->m_font.lfHeight,
								pDoc->m_font.lfWeight,
								pDoc->m_font.lfItalic,
								pDoc->m_font.lfUnderline,
								true);
#else
					ima->DrawStringEx(0,x,y,&theApp.m_text );
#endif
				}
				Invalidate(0);
			}
			break;
		case 5: //flood fill
			{
				CxImage* ima = pDoc->GetImage();
				if (ima){
					DlgFloodFill* pDlg = ((CMainFrame *)(AfxGetApp()->m_pMainWnd))->m_pDlgFlood;
					if (pDlg){
						pDlg->UpdateData(1);
						theApp.m_FloodColor = ima->RGBtoRGBQUAD(pDlg->m_color);
						theApp.m_FloodTolerance = pDlg->m_tol;
						theApp.m_FloodOpacity = pDlg->m_opacity;
						theApp.m_FloodSelect = pDlg->m_select;
					}
					pDoc->SubmitUndo();
					long x = point.x;
					long y = point.y;
					GetImageXY(pDoc, ima, &x,&y);
					long yflip = ima->GetHeight() - y - 1;
					ima->FloodFill(x,yflip,theApp.m_FloodColor,theApp.m_FloodTolerance,theApp.m_FloodOpacity,theApp.m_FloodSelect!=0);
					Invalidate(0);
				}
			}
			break;
		}

		if (pDoc->GetWaitingClick()){
			pDoc->SetWaitingClick(0);
			CxImage* ima = pDoc->GetImage();
			if (ima) {
				long x = point.x;
				long y = point.y;
				GetImageXY(pDoc, ima, &x,&y);
				if (ima->IsInside(x,y))	{
					pDoc->SubmitUndo();
					long yflip = ima->GetHeight() - y - 1;
					ima->SetTransIndex(ima->GetPixelIndex(x,yflip));
					// <DP> RGB transparency
					ima->SetTransColor(ima->GetPixelColor(x,yflip));
					pDoc->UpdateAllViews(NULL);
				}
			}
		}
#if CXIMAGE_DEMO_SELECT
		 else {
			KillTimer(1);
			pDoc->m_NumSel=0;
			m_SelShift=0;
		}
#endif
	}
	CScrollView::OnLButtonDown(nFlags, point);
}
コード例 #27
0
ファイル: demoView.cpp プロジェクト: Aliceljm1/CxImageVS2010
void CDemoView::OnUpdate(CView* pSender, LPARAM lHint, CObject* pHint) 
{
	switch (lHint)
	{
	case WM_USER_NEWIMAGE:
		{
			m_tracker.m_rect = CRect(0,0,0,0);

			CDemoDoc* pDoc = GetDocument();
			CxImage*  ima  = pDoc->GetImage();
			if (ima) {
				int px=GetScrollPos(SB_HORZ);
				int py=GetScrollPos(SB_VERT);
				CSize sz(GetTotalSize());
				int x=(int)(ima->GetWidth()*pDoc->GetZoomFactor());
				int y=(int)(ima->GetHeight()*pDoc->GetZoomFactor());
				SetScrollSizes(MM_TEXT,	CSize(x,y));
				CSize sz2(GetTotalSize());

				CWnd* pFrame=GetParentFrame();
				RECT rClient;
				pFrame->GetClientRect(&rClient);

				if (sz.cx!=0 && sz.cy!=0){
					if (x>rClient.right) SetScrollPos(SB_HORZ,sz2.cx*px/sz.cx); else  SetScrollPos(SB_HORZ,0);
					if (y>rClient.bottom) SetScrollPos(SB_VERT,sz2.cy*py/sz.cy); else SetScrollPos(SB_VERT,0);
				}

				if (!(pFrame->IsIconic()||pFrame->IsZoomed())){
					RECT rMainCl,rFrame,rMainFr;
					((CMainFrame *)(AfxGetApp()->m_pMainWnd))->GetClientRect(&rMainCl);
					((CMainFrame *)(AfxGetApp()->m_pMainWnd))->GetWindowRect(&rMainFr);
					pFrame->GetWindowRect(&rFrame);
					pFrame->SetWindowPos(0,0,0,
						(4+rFrame.right-rFrame.left-rClient.right+rClient.left)+
						min(rMainCl.right-(rFrame.left-rMainFr.left+12),x),
						(4+rFrame.bottom-rFrame.top-rClient.bottom+rClient.top)+
						min(rMainCl.bottom-(rFrame.top-rMainFr.top+12),y),
						SWP_NOMOVE|SWP_NOZORDER);
					//ResizeParentToFit(1);
				}

				if (!ima->SelectionIsValid()) KillTimer(1);

#ifdef VATI_EXTENSIONS
				ima->SetJpegQualityF(theApp.m_optJpegQuality);
  #if CXIMAGE_SUPPORT_JPG
				ima->SetCodecOption(theApp.m_optJpegOptions,CXIMAGE_FORMAT_JPG);
  #endif
  #if CXIMAGE_SUPPORT_RAW
				ima->SetCodecOption(theApp.m_optRawOptions,CXIMAGE_FORMAT_RAW);
  #endif
#endif

				CMainFrame* pMain = (CMainFrame*) AfxGetMainWnd();
				if (pMain->m_HistoBar.IsWindowVisible()){
					pDoc->m_hmax=ima->Histogram(pDoc->m_hr,pDoc->m_hg,pDoc->m_hb,pDoc->m_hgray);
					pMain->m_HistoBar.Invalidate();
				} else {
					pDoc->m_hmax = 0;
				}
			}

			break;
		}
	default:
		{
			CDemoDoc* pDoc = GetDocument();
			if (pDoc){
				CxImage*  ima  = pDoc->GetImage();
				if (ima){
					if (pDoc->GetStretchMode()) SetScrollSizes(MM_TEXT,	CSize(0,0));
					else SetScrollSizes(MM_TEXT,CSize((int)(ima->GetWidth()*pDoc->GetZoomFactor()),
													  (int)(ima->GetHeight()*pDoc->GetZoomFactor())));
				}
			}
		}
	}
	CScrollView::OnUpdate(pSender, lHint, pHint);
}
コード例 #28
0
ファイル: ToolBarCtrlZ.cpp プロジェクト: techpub/archive-code
void CToolBarCtrlZ::DrawItem(CDC *pDC, int iIndex, const CRect &rtItem, BOOL bHover)
{
	UINT			uItemId;
	UINT			uItemState;
	TBBUTTON		tbb;


	TCHAR			szText[1024];
	TBBUTTONINFO	tbi;
	CArray<CxImage*, CxImage*>	*parrImgs = NULL;
	CxImage			*pIconImg = NULL;		
	int				iIconTop;
	CRect			rtDraw;
	CRect			rtText;
	COLORREF		clrText;
	
	CClientRect		rtClient(this);
	rtDraw = rtItem;
	rtDraw.top = rtClient.top;
	rtDraw.bottom = rtClient.bottom;

	if (!GetButton(iIndex, &tbb))
		return;

	uItemId = tbb.idCommand;
	uItemState = GetState(uItemId);

	parrImgs = &m_arrImgs;
	if ( !IsButtonEnabled(uItemId) )
	{
		clrText = RGB(204, 128, 128);
		if (0 != m_arrDisableImgs.GetCount())
			parrImgs = &m_arrDisableImgs;
	}
	else
	{
		clrText = RGB(255, 254, 253);

		if (TBSTATE_PRESSED & uItemState/*IsButtonPressed(uItemId)*/)
			rtDraw.OffsetRect(1, 1);
		else if (bHover/*iIndex == GetHotItem()*/)
			rtDraw.OffsetRect(-1, -2);
	}


	ZeroMemory(&tbi, sizeof(TBBUTTONINFO));
	tbi.cbSize = sizeof(TBBUTTONINFO);
	tbi.dwMask = TBIF_TEXT | TBIF_IMAGE;
	tbi.pszText = szText;
	tbi.cchText = 1024;
	//if (GetButtonInfo(p->nmcd.dwItemSpec, &tbi))
	GetButtonInfo(uItemId, &tbi);
	{

		rtText = rtDraw;

		if (tbi.iImage < parrImgs->GetCount())
		{
			pIconImg = parrImgs->GetAt(tbi.iImage);
			if (NULL != pIconImg)
			{
				iIconTop = rtDraw.Height() - pIconImg->GetHeight();
				iIconTop /= 2;
				iIconTop += rtDraw.top;
				pIconImg->Draw(pDC->GetSafeHdc(), rtDraw.left, iIconTop);
				rtText.left += pIconImg->GetWidth() + 4;
			}
		}


		{
			CWndFontDC	fontDC(pDC->GetSafeHdc(), GetSafeHwnd());
			CTextDC		textDC(pDC->GetSafeHdc(), clrText);
			
			pDC->DrawText(tbi.pszText, -1, &rtText, DT_LEFT | DT_VCENTER | DT_SINGLELINE);
		}
	}

}
コード例 #29
0
ファイル: IGIPFilter.cpp プロジェクト: JBetser/Imagenius_SDK
bool IGIPFilter::OnImageProcessing (CxImage& image, IGImageProcMessage& message)
{
	IGIPFilterMessage *pIGThreadMessage = dynamic_cast <IGIPFilterMessage *> (&message);
	_ASSERTE (pIGThreadMessage && L"Wrong IGThread message, image processing aborted");
	if (!pIGThreadMessage || !m_pFrame)
		return false;
	IGLayer *pLayer = m_pFrame->GetLayer (m_pFrame->GetLayerPos (image.GetWorkingLayer()));
	if (!pLayer)
		return false;

	switch (pIGThreadMessage->m_eFilterType)
	{
	case IGIPFILTER_BLUR:
		return pLayer->GaussianBlur (5.0f);
	case IGIPFILTER_GRADIENT:
		{
			long tKernel [9];
			pLayer->GrayScale();
			CxImage g1(*pLayer), g2(*pLayer), g3(*pLayer), g4(*pLayer);
			tKernel[0] = 0;tKernel[1] = 1;tKernel[2] = -1;
			tKernel[3] = 0;tKernel[4] = 1;tKernel[5] = -1;
			tKernel[6] = 0;tKernel[7] = 1;tKernel[8] = -1;
			g1.Filter (tKernel, 3, 4, 0);
			tKernel[0] = -1;tKernel[1] = 1;tKernel[2] = 0;
			tKernel[3] = -1;tKernel[4] = 1;tKernel[5] = 0;
			tKernel[6] = -1;tKernel[7] = 1;tKernel[8] = 0;
			g2.Filter (tKernel, 3, 4, 0);
			tKernel[0] = -1;tKernel[1] = -1;tKernel[2] = -1;
			tKernel[3] = 1;tKernel[4] = 1;tKernel[5] = 1;
			tKernel[6] = 0;tKernel[7] = 0;tKernel[8] = 0;
			g3.Filter (tKernel, 3, 4, 0);
			tKernel[0] = 0;tKernel[1] = 0;tKernel[2] = 0;
			tKernel[3] = 1;tKernel[4] = 1;tKernel[5] = 1;
			tKernel[6] = -1;tKernel[7] = -1;tKernel[8] = -1;
			g4.Filter (tKernel, 3, 4, 0);
			pLayer->Copy (g1, true, false, false, false);
			*pLayer += g2;
			*pLayer += g3;
			*pLayer += g4;
			return true;
		}
	case IGIPFILTER_GRADIENT_MORPHO:
		return pLayer->ComputeGradient (true);
	case IGIPFILTER_GRAY:
		return pLayer->GrayScale();
	case IGIPFILTER_SKIN:
		return pLayer->FilterSkin();
	case IGIPFILTER_SKIN_UNNOISED:
		return pLayer->FilterSkinUnnoised();
	case IGIPFILTER_EYES:
		{
			RECT rcNo = {-1,-1,-1,-1};
			return pLayer->RedEyeRemove (rcNo, rcNo, 0.5f);
		}
	case IGIPFILTER_EYES_COLOR:
		{
			RECT rcNo = {-1,-1,-1,-1};
			RGBQUAD rgbq;
			IGTexture texture;
			if (!m_pFrame->GetProperty (IGProperties::IGPROPERTY_CURTEXTURE, texture))
				return false;
			COLORREF col = (COLORREF)texture;
			rgbq.rgbRed = GetRValue (col);
			rgbq.rgbBlue = GetBValue (col);
			rgbq.rgbGreen = GetGValue (col);
			rgbq.rgbReserved = 0x00;
			rgbq = pLayer->RGBtoHSL (rgbq);
			return pLayer->ChangeEyeColor (rcNo, rcNo, rgbq.rgbRed, rgbq.rgbGreen, 50.0f);
		}
	case IGIPFILTER_FFT:
		{
			CxImage copy (*pLayer);
			copy.GrayScale();
			CxImage res;
			if (!pLayer->FFT2 (&copy, NULL, &res, NULL))
				return false;
			pLayer->Copy (res);
			return true;
		}
	case IGIPFILTER_FACE_EFFECT:
		{
			IGIPFaceEffectMessage *pIGIPFaceEffectMessage = dynamic_cast <IGIPFaceEffectMessage *> (pIGThreadMessage);
			_ASSERTE (pIGIPFaceEffectMessage && L"Wrong IGThread message, face effect image processing aborted");
			if (!pIGIPFaceEffectMessage)
				return false;
			return pLayer->ProcessFaceEffect (pIGIPFaceEffectMessage);
		}
	case IGIPFILTER_COLORIZE:
		{
			RGBQUAD rgbq;
			IGTexture texture;
			if (!m_pFrame->GetProperty (IGProperties::IGPROPERTY_CURTEXTURE, texture))
				return false;
			COLORREF col = (COLORREF)texture;
			rgbq.rgbRed = GetRValue (col);
			rgbq.rgbBlue = GetBValue (col);
			rgbq.rgbGreen = GetGValue (col);
			rgbq.rgbReserved = 0x00;
			rgbq = pLayer->RGBtoHSL (rgbq);
			return pLayer->Colorize (rgbq.rgbRed, rgbq.rgbGreen, rgbq.rgbBlue, (float)texture.GetTransparency() / 255.0f);
		}
	case IGIPFILTER_BRIGHTNESS:
		{
			int nStrength = -1;
			if (!m_pFrame->GetRequestProperty(IGIPFILTER_PARAM_STRENGTH, nStrength) || (nStrength == -1))
				return false;
			return pLayer->Light ((long)((float)nStrength * 2.55f));
		}
	case IGIPFILTER_CONTRAST:
		{
			int nStrength = -1;
			if (!m_pFrame->GetRequestProperty(IGIPFILTER_PARAM_STRENGTH, nStrength) || (nStrength == -1))
				return false;
			return pLayer->Light (0, nStrength);
		}
	case IGIPFILTER_SATURATE:
		{
			int nStrength = -1;
			if (!m_pFrame->GetRequestProperty(IGIPFILTER_PARAM_STRENGTH, nStrength) || (nStrength == -1))
				return false;
			return pLayer->Saturate (nStrength);
		}
	case IGIPFILTER_VIBRANCE:
		{
			int nStrength = -1;
			if (!m_pFrame->GetRequestProperty(IGIPFILTER_PARAM_STRENGTH, nStrength) || (nStrength == -1))
				return false;
			return pLayer->Vibrance ((long)((float)nStrength * 2.55f));
		}
	case IGIPFILTER_MORPHING:
		{
			int nRadius = -1, nType = -1, nPosX = -1, nPosY = -1, nDirectionX = 0, nDirectionY = 0;
			if (!m_pFrame->GetRequestProperty(IGIPFILTER_PARAM_STRENGTH, nRadius) || (nRadius == -1))
				return false;
			if (!m_pFrame->GetRequestProperty(IGIPFILTER_PARAM_TYPE, nType) || (nType == -1))
				return false;
			if (!m_pFrame->GetRequestProperty(IGIPFILTER_PARAM_POSX, nPosX) || (nPosX == -1))
				return false;
			if (!m_pFrame->GetRequestProperty(IGIPFILTER_PARAM_POSY, nPosY) || (nPosY == -1))
				return false;
			if (!m_pFrame->GetRequestProperty(IGIPFILTER_PARAM_DIRECTIONX, nDirectionX))
				return false;
			if (!m_pFrame->GetRequestProperty(IGIPFILTER_PARAM_DIRECTIONY, nDirectionY))
				return false;
			// convert DZ coords to IG
			double dSeadragonToPixelRatioX, dSeadragonToPixelRatioY;
			IGConvertible::FromDZtoIGRatios (image.GetWidth(), image.GetHeight(), dSeadragonToPixelRatioX, dSeadragonToPixelRatioY);
			POINT ptPos; ptPos.x = (int)((double)nPosX * dSeadragonToPixelRatioX); ptPos.y = (int)((double)nPosY * dSeadragonToPixelRatioY);
			POINT ptDir; ptDir.x = (int)((double)nDirectionX * dSeadragonToPixelRatioX); ptDir.y = (int)((double)nDirectionY * dSeadragonToPixelRatioY);
			// convert IG coords to CX
			IGConvertible::FromIGtoCxCoords(ptPos, image.GetHeight());
			ptDir.y *= -1;
			// apply morphing
			return pLayer->Morphing (ptPos.x, ptPos.y, (float)ptDir.x, (float)ptDir.y, (float)nRadius, nType);
		}
	case IGIPFILTER_NEGATIVE:
			return pLayer->Negative();
	case IGIPFILTER_TRANSPARENCY:
		{
			int nAlpha = 0;
			if (!m_pFrame->GetRequestProperty(IGIPFILTER_PARAM_STRENGTH, nAlpha))
				return false;
			pLayer->AlphaDelete();
			return pLayer->AlphaCreate ((BYTE)((float)nAlpha * 2.55f));
		}
	case IGIPFILTER_PAINT:
		{
			int nPosX = -1, nPosY = -1;
			if (!m_pFrame->GetRequestProperty(IGIPFILTER_PARAM_POSX, nPosX) || (nPosX == -1))
				return false;
			if (!m_pFrame->GetRequestProperty(IGIPFILTER_PARAM_POSY, nPosY) || (nPosY == -1))
				return false;
			int nTolerance = 0;
			if (!m_pFrame->GetRequestProperty(IGIPFILTER_PARAM_TOLERANCE, nTolerance))
				return false;
			RGBQUAD rgbq;
			IGTexture texture;
			if (!m_pFrame->GetProperty (IGProperties::IGPROPERTY_CURTEXTURE, texture))
				return false;
			// convert DZ coords to IG
			double dSeadragonToPixelRatioX, dSeadragonToPixelRatioY;
			IGConvertible::FromDZtoIGRatios (image.GetWidth(), image.GetHeight(), dSeadragonToPixelRatioX, dSeadragonToPixelRatioY);
			POINT ptPos; ptPos.x = (int)((double)nPosX * dSeadragonToPixelRatioX); ptPos.y = (int)((double)nPosY * dSeadragonToPixelRatioY);
			// convert IG coords to CX
			IGConvertible::FromIGtoCxCoords(ptPos, image.GetHeight());
			COLORREF col = (COLORREF)texture;
			rgbq.rgbRed = GetRValue (col);
			rgbq.rgbBlue = GetBValue (col);
			rgbq.rgbGreen = GetGValue (col);
			rgbq.rgbReserved = 0x00;			
			return pLayer->FloodFill (ptPos.x, ptPos.y, rgbq, nTolerance);
		}
	case IGIPFILTER_PAINTGRADIENT:
		{
			int nPosX = -1, nPosY = -1, nDirectionX = 0, nDirectionY = 0;
			if (!m_pFrame->GetRequestProperty(IGIPFILTER_PARAM_POSX, nPosX) || (nPosX == -1))
				return false;
			if (!m_pFrame->GetRequestProperty(IGIPFILTER_PARAM_POSY, nPosY) || (nPosY == -1))
				return false;
			if (!m_pFrame->GetRequestProperty(IGIPFILTER_PARAM_DIRECTIONX, nDirectionX))
				return false;
			if (!m_pFrame->GetRequestProperty(IGIPFILTER_PARAM_DIRECTIONY, nDirectionY))
				return false;
			RGBQUAD rgbq, rgbqBkgnd;
			IGTexture texture, bkgndTexture;
			if (!m_pFrame->GetProperty (IGProperties::IGPROPERTY_CURTEXTURE, texture))
				return false;
			COLORREF col = (COLORREF)texture;
			rgbq.rgbRed = GetRValue (col);
			rgbq.rgbBlue = GetBValue (col);
			rgbq.rgbGreen = GetGValue (col);
			rgbq.rgbReserved = 0x00;	
			if (!m_pFrame->GetProperty (IGProperties::IGPROPERTY_BKGNDTEXTURE, bkgndTexture))
				return false;
			// convert DZ coords to IG
			double dSeadragonToPixelRatioX, dSeadragonToPixelRatioY;
			IGConvertible::FromDZtoIGRatios (image.GetWidth(), image.GetHeight(), dSeadragonToPixelRatioX, dSeadragonToPixelRatioY);
			POINT ptPos; ptPos.x = (int)((double)nPosX * dSeadragonToPixelRatioX); ptPos.y = (int)((double)nPosY * dSeadragonToPixelRatioY);
			POINT ptDir; ptDir.x = (int)((double)nDirectionX * dSeadragonToPixelRatioX); ptDir.y = (int)((double)nDirectionY * dSeadragonToPixelRatioY);
			// convert IG coords to CX
			IGConvertible::FromIGtoCxCoords(ptPos, image.GetHeight());
			ptDir.y *= -1;
			COLORREF colBkgnd = (COLORREF)bkgndTexture;
			rgbqBkgnd.rgbRed = GetRValue (colBkgnd);
			rgbqBkgnd.rgbBlue = GetBValue (colBkgnd);
			rgbqBkgnd.rgbGreen = GetGValue (colBkgnd);
			rgbqBkgnd.rgbReserved = 0x00;	
			return pLayer->FillGradient (ptPos.x, ptPos.y, ptDir.x, ptDir.y, rgbq, rgbqBkgnd);
		}
	case IGIPFILTER_REPAIR:
		return pLayer->Repair (0.25f, 3, 0);
	case IGIPFILTER_SHARPEN:
		return pLayer->UnsharpMask (5.0f, 0.5f, 0);	
	case IGIPFILTER_MATIFY:
		{
			COLORREF col = IGIPFACE_EFFECT_MATIFY_COLORCODE;
			RGBQUAD rgbq;
			rgbq.rgbRed = GetRValue (col);
			rgbq.rgbBlue = GetBValue (col);
			rgbq.rgbGreen = GetGValue (col);
			rgbq.rgbReserved = 0x00;
			rgbq = pLayer->RGBtoHSL (rgbq);
			return pLayer->Colorize (rgbq.rgbRed, rgbq.rgbGreen, rgbq.rgbBlue, 1.0f);
		}
	case IGIPFILTER_THRESHOLD:
		return pLayer->AdaptiveThreshold(0);
	case IGIPFILTER_AUTOROTATE:
		return pLayer->AutoRotate();
	case IGIPFILTER_SKETCH:
		return pLayer->Sketch();
	case IGIPFILTER_CARTOON:
		return pLayer->Cartoon();
	case IGIPFILTER_OILPAINTING:
		return pLayer->OilPainting();
	case IGIPFILTER_WATERPAINTING:
		return pLayer->WaterPainting();
	case IGIPFILTER_SEPIA:
		{
			RGBQUAD rgbq;
			rgbq.rgbRed = 112;
			rgbq.rgbBlue = 20;
			rgbq.rgbGreen = 66;
			rgbq.rgbReserved = 0x00;
			rgbq = pLayer->RGBtoHSL (rgbq);
			return pLayer->Colorize (rgbq.rgbRed, rgbq.rgbGreen, rgbq.rgbBlue, 1.0f);
		}
	case IGIPFILTER_VINTAGE:
		{
			pLayer->UnsharpMask (5.0f, 0.5f, 0);	
			pLayer->UnsharpMask (5.0f, 0.5f, 0);	
			pLayer->UnsharpMask (5.0f, 0.5f, 0);	
			RGBQUAD rgbq;
			rgbq.rgbRed = 112;
			rgbq.rgbBlue = 20;
			rgbq.rgbGreen = 66;
			rgbq.rgbReserved = 0x00;
			rgbq = pLayer->RGBtoHSL (rgbq);
			return pLayer->Colorize (rgbq.rgbRed, rgbq.rgbGreen, rgbq.rgbBlue, 0.25f);
		}
	case IGIPFILTER_DITHER:
		return pLayer->Dither();
	case IGIPFILTER_CLAY:
		return pLayer->Clay();
	case IGIPFILTER_PYTHON:
		{
			wstring wsPythonScript;
			if (!m_pFrame->GetRequestProperty(IGIPFILTER_PARAM_SCRIPT, wsPythonScript))
				return false;
			return pLayer->ExecutePythonScript (wsPythonScript);
		}
	case IGIPFILTER_FILTER1:
		{
			CxImage *layer1 (*pLayer);
			CxImage *layer2 (*pLayer);
			CxImage *layer3 (*pLayer);
			int nAlpha = 0;

			// Contrast the image using the curve: out 116, in 139
			long contrast_in = 139, contrast_out = 116;
			CxImage *contrast_IN (*pLayer);
			CxImage *contrast_OUT (*pLayer);
			contrast_IN->Mix(*contrast_OUT); 

			contrast_IN->Light(0, contrast_in);
			contrast_OUT->Light(0, contrast_out);

			// Add contrast IN & OUT images
			// Apply layer 2 as screen with opacity 48
			nAlpha = 48;
			layer2->AlphaDelete();
			layer2->AlphaCreate ((BYTE)((float)nAlpha * 2.55f));

			// Apply layer 3 as overlay with opacity 35
			nAlpha = 35;
			layer3->AlphaDelete();
			layer3->AlphaCreate ((BYTE)((float)nAlpha * 2.55f));

			// Adding the three layers 
			layer1->Mix(*layer2);
			layer1->Mix(*layer3);

			return true;
		}

	case IGIPFILTER_PAPER:
		return pLayer->Paper();

	case IGIPFILTER_HALOSEPIA:
		return pLayer->Sepia();		

	case IGIPFILTER_BW:
		return pLayer->BlackAndWhite();
	}

	return false;
}
コード例 #30
0
ファイル: demoView.cpp プロジェクト: Aliceljm1/CxImageVS2010
//////////////////////////////////////////////////////////////////////////////
// CDemoView drawing
void CDemoView::OnDraw(CDC* pDC)
{
	CDemoDoc* pDoc = GetDocument();
	ASSERT_VALID(pDoc);

	BOOL bPrinting = pDC->IsPrinting();

	CMemDC* pMemDC = NULL;
	if (!bPrinting) pDC = pMemDC = new CMemDC(pDC);

	if (!bPrinting && m_brHatch.m_hObject){
		CRect rect;
		GetClientRect(&rect);
		rect.right  = max(rect.right , m_totalDev.cx);
		rect.bottom = max(rect.bottom, m_totalDev.cy);
		m_brHatch.UnrealizeObject();
		CPoint pt(0, 0);
		pDC->LPtoDP(&pt);
		pt = pDC->SetBrushOrg(pt.x % 8, pt.y % 8);
		CBrush* old = pDC->SelectObject(&m_brHatch);
		pDC->FillRect(&rect, &m_brHatch);
		pDC->SelectObject(old);
	}

	CxImage* ima = pDoc->GetImage(); 
	if (ima) {
		if (bPrinting) {
			// get size of printer page (in pixels)
			int cxPage = pDC->GetDeviceCaps(HORZRES);
			int cyPage = pDC->GetDeviceCaps(VERTRES);
			//int dcbpp = pDC->GetDeviceCaps(BITSPIXEL);
			//int dcnc = pDC->GetDeviceCaps(NUMCOLORS);
			//int dcp = pDC->GetDeviceCaps(PLANES);
			// get printer pixels per inch
			int cxInch = pDC->GetDeviceCaps(LOGPIXELSX);
			int cyInch = pDC->GetDeviceCaps(LOGPIXELSY);
			// Best Fit case: create a rectangle which preserves the aspect ratio
			int cx = ima->GetXDPI() ? (ima->GetWidth()*cxInch)/ima->GetXDPI():ima->GetWidth()*cxInch/96;
			int cy = ima->GetYDPI() ? (ima->GetHeight()*cyInch)/ima->GetYDPI():ima->GetHeight()*cyInch/96;
			// print it!
			/*HDC TmpDC=CreateCompatibleDC(pDC->GetSafeHdc());
			HBITMAP bm =::CreateCompatibleBitmap(pDC->GetSafeHdc(), cx, cy);
			HBITMAP oldbm = (HBITMAP)::SelectObject(TmpDC,bm);
			BitBlt(TmpDC,0,0,cx,cy,0,0,0,WHITENESS);
			ima->Draw(TmpDC,CRect(0,0,cx,cy));
			BitBlt(pDC->GetSafeHdc(),100,100,cx,cy,TmpDC,0,0,SRCCOPY);
			DeleteObject(SelectObject(TmpDC,oldbm));
			DeleteDC(TmpDC);*/
			CxImage tmp;
			tmp.Copy(*ima);
			RGBQUAD c={255,255,255,0};
			if (tmp.GetTransIndex()>=0) tmp.SetPaletteColor((BYTE)tmp.GetTransIndex(),c);
			tmp.SetTransColor(c);
			tmp.AlphaStrip();
			tmp.Stretch(pDC->GetSafeHdc(), CRect(100,100,cx,cy));
		} else {
			if (pDoc->GetStretchMode()) {
				CRect rect;
				GetClientRect(&rect);
				ima->Draw(pDC->GetSafeHdc(), rect,0,pDoc->GetSmoothMode()!=0);
			} else {
				float zoom=pDoc->GetZoomFactor();
				if (zoom==1)
					ima->Draw(pDC->GetSafeHdc());
				else
					ima->Draw(pDC->GetSafeHdc(),
						CRect(0,0,(int)(ima->GetWidth()*zoom),(int)(ima->GetHeight()*zoom)),
						0,pDoc->GetSmoothMode()!=0);
			}

			if ( m_tracker.m_rect.Width()>0 && m_tracker.m_rect.Height()>0 )
				m_tracker.Draw(pDC);
		}
	}

	delete pMemDC;
}