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;
};
Example #2
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;
	}
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;
}
Example #4
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;
}
Example #5
0
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;
}
Example #6
0
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;
}
Example #7
0
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;
}
Example #8
0
    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();
    }
Example #9
0
  __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);
  };
Example #10
0
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);
}
Example #11
0
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;
}
Example #12
0
bool CxImageIG::writeSelection (CxFile& file, IGSECTIONHEADER_SELECTION& selectionSection, CxImage& layer, bool bOneMemoryBlock)
{
	// write selection data
	if (!file.Seek (selectionSection.commonHeader.nFirstByteOffset, SEEK_SET))
		throw IGEXCEPTION (CxImageIGException, "writeSelection", "file.Seek failed");
	// extracting rect selection
	BYTE *pFromSelection = layer.SelectionGetPointer(selectionSection.rcSelection.left,
													selectionSection.rcSelection.bottom);
	BYTE *pSelection = new BYTE [(selectionSection.rcSelection.right - selectionSection.rcSelection.left + 1) *
		(selectionSection.rcSelection.top - selectionSection.rcSelection.bottom + 1)];
	if (!pFromSelection)
	{
		::ZeroMemory (pSelection, (selectionSection.rcSelection.right - selectionSection.rcSelection.left + 1) *
			(selectionSection.rcSelection.top - selectionSection.rcSelection.bottom + 1));
	}	
	else
	{
		BYTE *pDstSelection = pSelection;
		if (bOneMemoryBlock)
		{
			::memcpy (pDstSelection, pFromSelection, (selectionSection.rcSelection.right - selectionSection.rcSelection.left + 1) *
										selectionSection.rcSelection.top - selectionSection.rcSelection.bottom + 1);		
		}
		else
		{
			for (int i = 0; i < selectionSection.rcSelection.top - selectionSection.rcSelection.bottom + 1; i++)
			{
				::memcpy (pDstSelection, pFromSelection, selectionSection.rcSelection.right - selectionSection.rcSelection.left + 1);
				pFromSelection += layer.GetWidth();
				pDstSelection += selectionSection.rcSelection.right - selectionSection.rcSelection.left + 1;		
			}
		}
	}
	// compressing data
	BYTE *pSelectionZipped = NULL;
	unsigned long ulSelectionZippedSize = IGPacker::gzipCompress (pSelection, (selectionSection.rcSelection.right - selectionSection.rcSelection.left + 1) *
																	(selectionSection.rcSelection.top - selectionSection.rcSelection.bottom + 1), &pSelectionZipped);
	delete [] pSelection;
	file.Write (pSelectionZipped, ulSelectionZippedSize, 1);
	delete [] pSelectionZipped;

	selectionSection.commonHeader.nSizeBuf = ulSelectionZippedSize;
	selectionSection.commonHeader.nEndByteOffset = selectionSection.commonHeader.nFirstByteOffset + ulSelectionZippedSize;
	return true;
}
Example #13
0
// 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;
	}
}
Example #14
0
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();
	}
}
Example #15
0
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;
}
Example #16
0
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;
}
Example #17
0
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;
	}
}
Example #18
0
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;
}
Example #19
0
void CExport::GenerateImages()
{
	// 25-80% progress
	BYTE* tempBuffer = NULL;
	long theSize;
	int index = 0;

	CString oldAppPath = main_frame->m_INI.GetString("General", "ImageCacheApp");
	CString newAppPath = application->file_information.file_path;

	CPath path;
	path.SetToCurrentDirectory();
	CString cachePath = path.GetFullPath();
	cachePath += "Data\\imagecache.bin";

	// Check if there is a cached image block we can use
	if (application == pLastAppCachedImageBlock && !application->resources.images_changed && fileexists(cachePath) && oldAppPath == newAppPath) {
		imageBlock.load(cachePath);
		return;
	}

	// Write the app path to the INI so the cache doesnt get used with the wrong application
	main_frame->m_INI.WriteString("General", "ImageCacheApp", newAppPath);

	// Write image count
	imageBlock<<(int)application->resources.images.size();

	// Loop and add resources.images
	for (list<CImageResource>::iterator i = application->resources.images.begin(); i != application->resources.images.end(); i++, index++)
	{
		CxImage& im = i->bitmap;
		
		if (application->runtime == CApplication::rt_application)
			im.Encode(tempBuffer, theSize, CXIMAGE_FORMAT_BMP);
		else
			im.Encode(tempBuffer, theSize, CXIMAGE_FORMAT_PNG);

		// Write image ID
		imageBlock<<(int)i->m_FixedID;

		// Write image hotspot
		imageBlock << i->m_Hotspot.x;
		imageBlock << i->m_Hotspot.y;

		// Write image action points
		int apointsize = i->m_Action.size();
		imageBlock << apointsize;
		for(map<CString, CPoint>::iterator it = i->m_Action.begin(); it!= i->m_Action.end(); it++)
		{
			imageBlock << it->second.x << it->second.y << it->first;
		}

		// Write image data size
		imageBlock<<(int)theSize;

		// Write image data code
		imageBlock.append(tempBuffer, theSize);	
		
		// Free memory using CxImage (for malloc/new compatibility)
		im.FreeMemory(tempBuffer);

		// Generate a collision mask
		BYTE* bits;
		int pitch;
		CxImage* pCol = &im;
		if(i->m_Collision.IsValid())
		{
			pCol = & i->m_Collision;
		}

		CreateCollisionMask(*pCol, bits, pitch);

		imageBlock<< pCol->GetWidth();
		imageBlock<< pCol->GetHeight();
		imageBlock<< pitch;
		imageBlock.append(bits, pitch * pCol->GetHeight());

		// CreateCollisionMask allocated bits so free it
		delete[] bits;

		// CxImage requires the tempBuffer parameter be NULL (for some reason)
		tempBuffer = NULL;

		// Progress 25-80% for this function
		ProgressDlg.SetProgress(25 + (index * 55) / application->resources.images.size());
	}

	// Dump the image block to file
	imageBlock.save(cachePath);

	pLastAppCachedImageBlock = application;
	application->resources.images_changed = false;
}
Example #20
0
  __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;
  };
Example #21
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);
}
Example #22
0
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);
		}
	}

}
Example #23
0
  __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);
  };
Example #24
0
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;
}
Example #25
0
void TextureManager::LoadBLP(GLuint id, Texture *tex)
{
	// Vars
	int offsets[16], sizes[16], w=0, h=0, type=0;
	GLint format = 0;
	char attr[4];

	if (useLocalFiles) {
		wxString texName(tex->name.c_str(), wxConvUTF8);
		BYTE *buffer = NULL;
		CxImage *image = NULL;

		if ((TryLoadLocalTexture(texName, CXIMAGE_FORMAT_PNG, &image) || 
			 TryLoadLocalTexture(texName, CXIMAGE_FORMAT_TGA, &image)) 
			 && image) {
			long size = image->GetWidth() * image->GetHeight() * 4;
			if (image->Encode2RGBA(buffer, size, true)) {
				tex->w = image->GetWidth();
				tex->h = image->GetHeight();
				tex->compressed = true;

				GLuint texFormat = GL_TEXTURE_2D;
				glBindTexture(texFormat, id);

				glTexImage2D(texFormat, 0, GL_RGBA8, image->GetWidth(), image->GetHeight(), 0, GL_RGBA, GL_UNSIGNED_BYTE, buffer);

				glTexParameteri(texFormat, GL_TEXTURE_MIN_FILTER, GL_LINEAR);	// Linear Filtering
				glTexParameteri(texFormat, GL_TEXTURE_MAG_FILTER, GL_LINEAR);	// Linear Filtering

				wxDELETE(image);
				wxDELETE(buffer);
				return;
			}
		}

	}

	// bind the texture
	glBindTexture(GL_TEXTURE_2D, id);
	
	MPQFile f(tex->name);
	if (g_modelViewer) {
		g_modelViewer->modelOpened->Add(wxString(tex->name.c_str(), wxConvUTF8));
	}
	if (f.isEof()) {
		tex->id = 0;
		wxLogMessage(wxT("Error: Could not load the texture '%s'"), wxString(tex->name.c_str(), wxConvUTF8).c_str());
		f.close();
		return;
	} else {
		//tex->id = id; // I don't see the id being set anywhere,  should I set it now?
		wxLogMessage(wxT("Loading texture: %s"), wxString(tex->name.c_str(), wxConvUTF8).c_str());
	}

	f.seek(4);
	f.read(&type,4);
	f.read(attr,4);
	f.read(&w,4);
	f.read(&h,4);
	f.read(offsets,4*16);
	f.read(sizes,4*16);

	tex->w = w;
	tex->h = h;

	bool hasmipmaps = (attr[3]>0);
	int mipmax = hasmipmaps ? 16 : 1;

	/*
	reference: http://en.wikipedia.org/wiki/.BLP
	*/
	//wxLogMessage(wxT("[BLP]: type: %d, encoding: %d, alphadepth: %d, alphaencoding: %d, mipmap: %d, %d*%d"), type, attr[0], attr[1], attr[2], attr[3], w, h);
	if (type == 0) { // JPEG compression
		/*
		 * DWORD JpegHeaderSize;
		 * BYTE[JpegHeaderSize] JpegHeader;
		 * struct MipMap[16]
		 * {
		 *     BYTE[???] JpegData;
		 * }
		 */
		wxLogMessage(wxT("Error: %s:%s#%d type=%d"), __FILE__, __FUNCTION__, __LINE__, type);

		BYTE *buffer = NULL;
		CxImage *image = NULL;
		unsigned char *buf = new unsigned char[sizes[0]];

		f.seek(offsets[0]);
		f.read(buf,sizes[0]);
		image = new CxImage(buf, sizes[0], CXIMAGE_FORMAT_JPG);

		if (image == NULL)
			return;

		long size = image->GetWidth() * image->GetHeight() * 4;
		image->Encode2RGBA(buffer, size);

		glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, image->GetWidth(), image->GetHeight(), 0, GL_RGBA, GL_UNSIGNED_BYTE, buffer);

		wxDELETE(image);
		wxDELETE(buffer);
		wxDELETE(buf);
	} else if (type == 1) {
		if (attr[0] == 2) {
			/*
			Type 1 Encoding 2 AlphaDepth 0 (DXT1 no alpha)
			The image data is formatted using DXT1 compression with no alpha channel.

			Type 1 Encoding 2 AlphaDepth 1 (DXT1 one bit alpha)
			The image data is formatted using DXT1 compression with a one-bit alpha channel.

			Type 1 Encoding 2 AlphaDepth 8 (DXT3)
			The image data is formatted using DXT3 compression.

			Type 1 Encoding 2 AlphaDepth 8 AlphaEncoding 7 (DXT5)
			The image data are formatted using DXT5 compression.
			*/
			// encoding 2, directx compressed
			unsigned char *ucbuf = NULL;
			if (!video.supportCompression) 
				ucbuf = new unsigned char[w*h*4];
		
			format = GL_COMPRESSED_RGBA_S3TC_DXT1_EXT;
			int blocksize = 8;
			
			// guesswork here :(
			// new alpha bit depth == 4 for DXT3, alfred 2008/10/11
			if (attr[1]==8 || attr[1]==4) {
				format = GL_COMPRESSED_RGBA_S3TC_DXT3_EXT;
				blocksize = 16;
			}

			// Fix to the BLP2 format required in WoW 2.0 thanks to Linghuye (creator of MyWarCraftStudio)
			if (attr[1]==8 && attr[2]==7) {
				format = GL_COMPRESSED_RGBA_S3TC_DXT5_EXT;
				blocksize = 16;
			}

			tex->compressed = true;

			unsigned char *buf = new unsigned char[sizes[0]];

			// do every mipmap level
			for (size_t i=0; i<mipmax; i++) {
				if (w==0) w = 1;
				if (h==0) h = 1;
				if (offsets[i] && sizes[i]) {
					f.seek(offsets[i]);
					f.read(buf,sizes[i]);

					int size = ((w+3)/4) * ((h+3)/4) * blocksize;

					if (video.supportCompression) {
						glCompressedTexImage2DARB(GL_TEXTURE_2D, (GLint)i, format, w, h, 0, size, buf);
					} else {
						decompressDXTC(format, w, h, size, buf, ucbuf);					
						glTexImage2D(GL_TEXTURE_2D, (GLint)i, GL_RGBA8, w, h, 0, GL_RGBA, GL_UNSIGNED_BYTE, ucbuf);
					}
					
				} else break;
				w >>= 1;
				h >>= 1;
			}

			wxDELETEA(buf);
			if (!video.supportCompression) 
				wxDELETEA(ucbuf);

		} else if (attr[0]==1) {
Example #26
0
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);
}
Example #27
0
//////////////////////////////////////////////////////////////////////////////
// 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;
}
Example #28
0
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;
}
Example #29
0
void CExport::CreateCollisionMask(CxImage& image, BYTE*& bits, int& pitch)
{
	// Determine size of our buffer.  All buffers are rounded up to 128 bit pitch, just in case SSE can be used.
	const int align_pitch_bits = 64;
	const int align_pitch_bytes = align_pitch_bits / 8;

	pitch = image.GetWidth() / 8;
	if (image.GetWidth() % 8 != 0)
		pitch++;		// 11 pixel width needs 2 bytes not 1 rounded

	// Eg. a 20 byte pitch must round up to 32 (+12, 16 - 4)
	if (pitch % align_pitch_bytes != 0)
		pitch += align_pitch_bytes - (pitch % align_pitch_bytes);

	// If the pitch does not leave at least a 64 pixel gutter, increase it by 64 pixels.
	// This prevents false positives when a 64 pixel check from the far right edge can wrap around to the next line.
	if ((pitch * 8) - image.GetWidth() < align_pitch_bits)
		pitch += align_pitch_bytes;

	// Allocate and zero the memory
	bits = new BYTE[image.GetHeight() * pitch];
	memset(bits, 0, image.GetHeight() * pitch);

/*	// Set as per a DWORD pointer to prevent endian corruption

	DWORD* ptr = (DWORD*)bits;
	int ipitch = pitch / sizeof(DWORD);

	// Loop each pixel and set the bit in the bitmask
	for (int x = 0; x < image.GetWidth(); x++) {
		for (int y = 0; y < image.GetHeight(); y++) {

			// Set the bit (check alpha component)
			int bit = image.GetPixelColor(x, y).rgbReserved > 0 ? 1 : 0;

			// Invert Y (CxImage stupidness)
			ptr[(image.GetHeight() - y - 1) * ipitch + (x/32)] |= bit << (31 - (x % 32));
		}
	}
	*/ 
	// sorry tigs trying byte method
	BYTE* ptr = (BYTE*)bits;
	int ipitch = pitch / sizeof(BYTE);
	

	// Loop each pixel and set the bit in the bitmask
	for (int x = 0; x < image.GetWidth(); x++) {
		for (int y = 0; y < image.GetHeight(); y++) {

			// What is this for??? Commented out 22/11/08 since it has no effect anyway -AG
			//if(x == 0)
			//	ptr[(image.GetHeight() - y - 1) * ipitch] = 0; //first byte must be 0

			// Set the bit (check alpha component)
			int bit = image.GetPixelColor(x, y).rgbReserved > 0 ? 1 : 0;

			// Invert Y (CxImage stupidness)
			ptr[(image.GetHeight() - y - 1) * ipitch + (x/8)] |= bit << (7 - (x % 8));
		}
	}

}