Example #1
0
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;
}
Example #2
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 #3
0
//////////////////////////////////////////////////////////////////////////////
// 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);
}
Example #4
0
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);
}
Example #5
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));
		}
	}

}