BOOL CNtMagickView::DoReadImage() { // Release image object memory m_Image.isValid(FALSE); // Read the image and handle any exceptions try { m_Image.read(ws2s(m_szFile.GetBuffer(MAX_PATH+1))); } catch(Exception e) { m_Image.isValid(FALSE); DoDisplayError("Read",e.what()); return FALSE; } catch(exception e) { m_Image.isValid(FALSE); DoDisplayError("Read",e.what()); return FALSE; } return TRUE; }
void CIMDisplayView::OnCrop() { CIMDisplayDoc* pDoc = GetDocument(); ASSERT_VALID(pDoc); SetupUndo(); BeginWaitCursor(); try { CRect trackRect; m_tracker.GetTrueRect(trackRect); Geometry newGeo( trackRect.Width(), trackRect.Height(), trackRect.left, trackRect.top ); pDoc->GetImage().crop( newGeo ); } catch(Exception e) { DoDisplayError("OnCrop",e.what()); } EndWaitCursor(); UpdateTheView(); }
void CIMDisplayView::OnRoll() { CRollDialog dlg; dlg.HPixels( 25 ); // good default as any... dlg.VPixels( 25 ); // good default as any... if ( dlg.DoModal() == IDOK ) { CIMDisplayDoc* pDoc = GetDocument(); ASSERT_VALID(pDoc); SetupUndo(); BeginWaitCursor(); try { pDoc->GetImage().roll( dlg.HPixels(), dlg.VPixels() ); } catch(Exception e) { DoDisplayError("OnRoll",e.what()); } EndWaitCursor(); UpdateTheView(); } }
void CNtMagickView::OnImageRotate90() { try { m_Image.rotate(90); } catch(Exception e) { DoDisplayError("Rotate 90",e.what()); return; } catch(exception e) { DoDisplayError("Rotate 90",e.what()); return; } DoDisplayImage(); }
void CNtMagickView::OnImageFlipVertical() { try { m_Image.flip(); } catch(Exception e) { DoDisplayError("Flip",e.what()); return; } catch(exception e) { DoDisplayError("Flip",e.what()); return; } DoDisplayImage(); }
BOOL CIMDisplayDoc::DoReadImage( void ) { BeginWaitCursor(); // Read the image and handle any exceptions try { m_pImage.read(m_szFile.GetBuffer(MAX_PATH+1)); } // Image may still be usable if there is a warning catch(Magick::Warning &warning) { DoDisplayWarning("DoReadImage",warning.what()); } // Image is not usable catch(Magick::Error &error) { DoDisplayError("DoReadImage",error.what()); m_pImage.isValid(false); return FALSE; } catch(std::exception &e) { DoDisplayError("DoReadImage",e.what()); m_pImage.isValid(false); return FALSE; } // Ensure that image is in sRGB space m_pImage.colorSpace(sRGBColorspace); EndWaitCursor(); return TRUE; }
void CIMDisplayView::RotateImage( double inDegrees ) { CIMDisplayDoc* pDoc = GetDocument(); ASSERT_VALID(pDoc); SetupUndo(); BeginWaitCursor(); try { pDoc->GetImage().rotate( inDegrees ); } catch(Exception e) { DoDisplayError("RotateImage",e.what()); } EndWaitCursor(); UpdateTheView(); }
void CIMDisplayView::MinifyImage( void ) { CIMDisplayDoc* pDoc = GetDocument(); ASSERT_VALID(pDoc); SetupUndo(); BeginWaitCursor(); try { pDoc->GetImage().minify( ); } catch(Exception e) { DoDisplayError("MinifyImage",e.what()); } EndWaitCursor(); UpdateTheView(); }
void CIMDisplayView::ResizeImage( Geometry& inGeometry ) { CIMDisplayDoc* pDoc = GetDocument(); ASSERT_VALID(pDoc); SetupUndo(); BeginWaitCursor(); try { pDoc->GetImage().zoom( inGeometry ); } catch(Exception e) { DoDisplayError("ResizeImage",e.what()); } EndWaitCursor(); UpdateTheView(); }
void CIMDisplayView::OnTrimedges() { CIMDisplayDoc* pDoc = GetDocument(); ASSERT_VALID(pDoc); SetupUndo(); BeginWaitCursor(); try { pDoc->GetImage().trim( ); } catch(Exception e) { DoDisplayError("onTrimEdges",e.what()); } EndWaitCursor(); UpdateTheView(); }
void CIMDisplayView::ScaleImage( Geometry& inGeometry ) { CIMDisplayDoc* pDoc = GetDocument(); ASSERT_VALID(pDoc); SetupUndo(); BeginWaitCursor(); try { // NOTE: should this be scale or sample? pDoc->GetImage().scale( inGeometry ); } catch(Exception e) { DoDisplayError("ScaleImage",e.what()); } EndWaitCursor(); UpdateTheView(); }
void CIMDisplayView::DoDisplayImage( Image &inImage, CDC* pDC ) { // make sure we're getting a valid image! if (!inImage.isValid()) { return; } // if the view is dirty, dispose the old offscreen! if ( mViewDirty == true ) { delete mOffscreenDC; mOffscreenDC = NULL; } // make sure we have a valid destination DC if (pDC != NULL) { // if we don't already have a ready offscreen, then prepare one if ( !mOffscreenDC ) { // // Set up the Windows bitmap header // BITMAPINFOHEADER bmi; bmi.biSize = sizeof(BITMAPINFOHEADER); // Size of structure bmi.biWidth = inImage.columns(); // Bitmaps width in pixels bmi.biHeight = (-1)*inImage.rows(); // Bitmaps height n pixels bmi.biPlanes = 1; // Number of planes in the image bmi.biBitCount = 32; // The number of bits per pixel bmi.biCompression = BI_RGB; // The type of compression used bmi.biSizeImage = 0; // The size of the image in bytes bmi.biXPelsPerMeter = 0; // Horizontal resolution bmi.biYPelsPerMeter = 0; // Veritical resolution bmi.biClrUsed = 0; // Number of colors actually used bmi.biClrImportant = 0; // Colors most important mBMI = bmi; // keep it for clipboard use... RGBQUAD *prgbaDIB = 0; HBITMAP hBitmap = CreateDIBSection ( pDC->m_hDC, // handle to device context (BITMAPINFO *)&bmi, // pointer to structure containing bitmap size, format, and color data DIB_RGB_COLORS, // color data type indicator: RGB values or palette indices (void**)&prgbaDIB, // pointer to variable to receive a pointer to the bitmap's bit values NULL, // optional handle to a file mapping object 0 // offset to the bitmap bit values within the file mapping object ); if ( !hBitmap ) { CString message; message.FormatMessage("Windows failed to allocate bitmap of size %1!d!x%2!d!!", inImage.rows(), inImage.columns()); DoDisplayError("DoDisplayImage",message); return; } // // If image is non-opaque, apply a pattern background so // non-opaque regions become evident. // Magick::Image image=inImage; if (inImage.matte()) { Magick::Image texture; texture.read("image:checkerboard"); image.texture(texture); image.matte(false); } // // Extract the pixels from Magick++ image object and convert to a DIB section // const unsigned int columns = image.columns(); const unsigned int rows = image.rows(); RGBQUAD *pDestPixel = prgbaDIB; for( unsigned int row = 0 ; row < rows ; row++ ) { const PixelPacket *pPixels = image.getConstPixels(0,row,columns,1); #if QuantumDepth == 8 // Form of PixelPacket is identical to RGBQUAD when QuantumDepth==8 memcpy((void*)pDestPixel,(const void*)pPixels,sizeof(PixelPacket)*columns); pDestPixel += columns; #else // 16 or 32 bit Quantum // Transfer pixels, scaling to Quantum for( unsigned long nPixelCount = columns; nPixelCount ; nPixelCount-- ) { pDestPixel->rgbRed = ScaleQuantumToChar(pPixels->red); pDestPixel->rgbGreen = ScaleQuantumToChar(pPixels->green); pDestPixel->rgbBlue = ScaleQuantumToChar(pPixels->blue); pDestPixel->rgbReserved = 0; ++pDestPixel; ++pPixels; } #endif } // Create a display surface mOffscreenDC = new CDC(); mOffscreenDC->CreateCompatibleDC( pDC ); // Clear the background (Is this really necessary?) //CRect rectClient; //GetClientRect(rectClient); //mOffscreenDC->FillSolidRect(rectClient,mOffscreenDC->GetBkColor()); // Now copy the bitmap to device mOffscreenDC->SelectObject( hBitmap ); } pDC->BitBlt( 0, 0, inImage.columns(), inImage.rows(), mOffscreenDC, 0, 0, SRCCOPY ); mViewDirty = false; // not any more! // draw the marching ants, if any bool isPrinting = pDC->IsPrinting(); if ( !isPrinting && m_tracker.m_rect.Width() && m_tracker.m_rect.Height() ) m_tracker.Draw( pDC ); } }
void CIMDisplayView::OnEditCopy() { CIMDisplayDoc* pDoc = GetDocument(); ASSERT_VALID(pDoc); OpenClipboard(); EmptyClipboard(); unsigned long nPixels = m_tracker.m_rect.Width() * m_tracker.m_rect.Height(); /* CClientDC cdc(this); BITMAP bitmap; CBitmap * junk = new CBitmap(); #if 0 junk->CreateCompatibleBitmap(&cdc,m_tracker.m_rect.Width(),m_tracker.m_rect.Height()); junk->GetBitmap(&bitmap); #else bitmap.bmType = 0; bitmap.bmWidth = m_tracker.m_rect.Width(); bitmap.bmHeight = m_tracker.m_rect.Height(); bitmap.bmWidthBytes = bitmap.bmWidth * 4; bitmap.bmPlanes = 1; bitmap.bmBitsPixel = 32; bitmap.bmBits = NULL; junk->CreateBitmapIndirect( &bitmap ); #endif CDC dc; dc.CreateCompatibleDC( &cdc ); dc.SelectObject(junk); */ BITMAP bitmap; bitmap.bmType = 0; bitmap.bmWidth = m_tracker.m_rect.Width(); bitmap.bmHeight = m_tracker.m_rect.Height(); bitmap.bmWidthBytes = bitmap.bmWidth * 4; bitmap.bmPlanes = 1; bitmap.bmBitsPixel = 32; bitmap.bmBits = NULL; long memSize = nPixels * bitmap.bmBitsPixel; HANDLE theBitsH = (HANDLE) ::GlobalAlloc (GMEM_MOVEABLE | GMEM_DDESHARE, memSize); if (theBitsH == NULL) DoDisplayError( "OnEditCopy", GetLastError() ); else { PixelPacket *pPixels = pDoc->GetImage().getPixels(m_tracker.m_rect.left, m_tracker.m_rect.top, m_tracker.m_rect.Width(), m_tracker.m_rect.Height()); RGBQUAD * theBits = (RGBQUAD *) ::GlobalLock((HGLOBAL) theBitsH); RGBQUAD *pDestPixel = theBits; if ( bitmap.bmBits == NULL ) bitmap.bmBits = theBits; for( unsigned long nPixelCount = nPixels; nPixelCount ; nPixelCount-- ) { pDestPixel->rgbRed = ScaleQuantumToChar(pPixels->red); pDestPixel->rgbGreen = ScaleQuantumToChar(pPixels->green); pDestPixel->rgbBlue = ScaleQuantumToChar(pPixels->blue); pDestPixel->rgbReserved = 0; ++pDestPixel; ++pPixels; } #if 0 DWORD result = junk->SetBitmapBits( memSize, theBits ); if ( result == 0 ) DoDisplayError( "OnEditCopy", GetLastError() ); #else bitmap.bmBits = theBits; CBitmap * junk = new CBitmap(); junk->CreateBitmapIndirect( &bitmap ); #endif ::GlobalUnlock((HGLOBAL) theBitsH); SetClipboardData(CF_BITMAP, junk->m_hObject); CloseClipboard(); delete junk; } }