void CEnvelopeWizard::SetImageSize(CAGSymImage* pImage, POINT* pCenterPoint) { if (!pImage) return; // The image symbol should be at (0,0) and have a unity matrix CRect DestRect = pImage->GetDestRect(); DestRect.MoveToXY(0,0); pImage->SetDestRect(DestRect); // Maintain a maximum image size using the symbol's matrix CAGMatrix NewMatrix; if (DestRect.Width() > m_nMaxImageSize || DestRect.Height() > m_nMaxImageSize) { int dx = m_nMaxImageSize; int dy = m_nMaxImageSize; double fScale = ScaleToFit(&dx, &dy, DestRect.Width(), DestRect.Height(), true/*bUseSmallerFactor*/); NewMatrix.Scale(fScale, fScale); NewMatrix.Transform(DestRect); } if (pCenterPoint) NewMatrix.Translate(pCenterPoint->x - DestRect.Width()/2, pCenterPoint->y - DestRect.Height()/2); pImage->SetMatrix(NewMatrix); }
void IndieLibManager::ScaleToFit(IND_Entity2d* entity, IND_Surface* originsurface,int finalx, int finaly) { //Get original surface dimensions int originx = originsurface->GetWidth(); int originy = originsurface->GetHeight(); //Call subfunction ScaleToFit(entity, originx, originy, finalx, finaly); }
bool CDocCommands::CropSetAspect(int iValue) { CImageObject* pObject = m_DocWindow.GetSelectedObject(); if (!pObject) return false; // Constrain the DestRect to the Aspect ratio and set it as the new CropRect CSize Aspect(LOWORD(iValue), HIWORD(iValue)); CRect DestRect = pObject->GetDestRect(); int dx = DestRect.Width(); int dy = DestRect.Height(); ScaleToFit(&dx, &dy, Aspect.cx, Aspect.cy, true/*bUseSmallerFactor*/); DestRect.left -= ((dx - DestRect.Width()) / 2); DestRect.top -= ((dy - DestRect.Height()) / 2); DestRect.right = DestRect.left + dx; DestRect.bottom = DestRect.top + dy; pObject->SetCropRect(DestRect); return true; }
////////////////////////////////////////////////////////////////////// // Constrain the selection to the AspectX & AspectY. // If bCenter then it will try to keep the center constant. // Otherwise it will keep the upper left corner constant. ////////////////////////////////////////////////////////////////////// void CSelection::ConstrainSelection(RECT* pRect, long AspectX, long AspectY, bool bCenter) { if (!AspectX || !AspectY) return; int x = WIDTH(*pRect); int y = HEIGHT(*pRect); int sx = (x >= 0 ? 1 : -1); int sy = (y >= 0 ? 1 : -1); x = abs(x); y = abs(y); ScaleToFit(&x, &y, (int)AspectX, (int)AspectY, true/*bUseSmallerFactor*/); x *= sx; y *= sy; if (bCenter) { pRect->left -= ((x - WIDTH(*pRect)) / 2); pRect->top -= ((y - HEIGHT(*pRect)) / 2); } pRect->right = pRect->left + x; pRect->bottom = pRect->top + y; }
BOOL CanZoom( HWND hWnd, LFIXED FileRate, LPRECT lpFileRect, LPRECT lpDispRect ) /************************************************************************/ { LFIXED DispRate; long lFileWidth, lFileHeight; int iDispWidth, iDispHeight; LPIMAGE lpImage; lpImage = GetImagePtr(hWnd); if (FileRate != 0) // FileRate passed in DispRate = FGET(FUNITY, FileRate); else // Displaying a FileRect { // calculate DispRate using this FileRect and // DispRect. iDispWidth = RectWidth(lpDispRect); iDispHeight = RectHeight(lpDispRect); DispRate = ScaleToFit(&iDispWidth, &iDispHeight, RectWidth(lpFileRect), RectHeight(lpFileRect)); } // Calculate eventual size in File coordinates using // this DispRate. This calculation is done by most // of the viewing routines and has the possibility // of overflow. Usually in these routines when the // calculation is made it is too late to turn back // so those routines call CanZoom() before doing // anything that is unreversible. lFileWidth = FMUL(lpImage->npix, DispRate); lFileHeight = FMUL(lpImage->nlin, DispRate); // Although MAXINT is 32767, I decided to use 30000 just // for some slop and my own paranoia return(lFileWidth > 0L && lFileWidth <= MAX_IMAGE_WIDTH && lFileHeight > 0L && lFileHeight <= MAX_IMAGE_HEIGHT); }
void IndieLibManager::ScaleToFit(IND_Entity2d* entity, IND_Animation* originalanimation,int finalx, int finaly) { //An animation can have many sequences, and can have many heights-widths //as default, scaling is done to BIGGER frame of ALL SEQUENCES int sequences = originalanimation->GetNumSequences(); int biggerx = 0; int biggery = 0; //LOOP Find bigger x and y to scale for(int i = 0;i<sequences;i++) { assert(i-1 < sequences); int animwidth = originalanimation->GetHighWidth(i); //Bigger width of this sequence int animheight = originalanimation->GetHighHeight(i); //Bigger heigth of this sequence //Assignment if it is bigger if(animwidth > biggerx) biggerx = animwidth; if(animheight > biggery) biggery = animheight; }//LOOP END //Call subfunction ScaleToFit(entity, biggerx, biggery, finalx, finaly); }
void ComputeDispRect(HWND hWnd) /************************************************************************/ { int w, h, dx, dy; int iWidth, iHeight, iImageWidth, iImageHeight; LFIXED DispRate; RECT DispRect; BOOL bZoomed, bIconic; LPIMAGE lpImage; LPDISPLAY lpDisplay; lpImage = GetImagePtr(hWnd); lpDisplay = GetDisplayPtr(hWnd); BOOL bInPlaceFrameType = FALSE; HWND hMDIWindow = hWnd; CWnd *pWnd = CWnd::FromHandle(hMDIWindow); if (pWnd->IsKindOf(RUNTIME_CLASS(CServerView))) { hMDIWindow = pWnd->GetParentFrame()->GetSafeHwnd(); bInPlaceFrameType = ((CServerView*)pWnd)->GetDocument()->IsInPlaceActive(); } // get max size of client area with no scrollbars GetDispRect(hWnd, &DispRect, 1, 1); w = RectWidth(&DispRect); h = RectHeight(&DispRect); // If we have no FileRate to this point, it means somebody wants // to display a specific FileRect. Calculate a FileRate so that // we can calculate a DispRect. This is necessary because it is // possible (when the window is maximized for example) that the // FileRect requested will not fill up the window, so it would // need to be recalculated. It is assumed that scrollbars would // not be needrf and should not be needed if the calculation is // done correctly, which hopefully it is. if (!lpDisplay->FileRate) { iWidth = w; iHeight = h; DispRate = ScaleToFit(&iWidth, &iHeight, RectWidth(&lpDisplay->FileRect), RectHeight(&lpDisplay->FileRect)); lpDisplay->FileRate = FGET(FUNITY, DispRate); } if (lpDisplay->FileRate == TINYRATE) // Iconic { iWidth = w; iHeight = h; iImageWidth = lpImage->npix; iImageHeight = lpImage->nlin; DispRate = ScaleToFit(&iWidth, &iHeight, iImageWidth, iImageHeight); //--------------------------------------------------------------------- // NOTE!! added bInPlaceFrameType here because Insitu needs to be able // to scale over 100%. //--------------------------------------------------------------------- if (!bInPlaceFrameType && (DispRate > FGET(1, 1))) { DispRate = FGET(1, 1); iWidth = FMUL(iImageWidth, DispRate); iHeight = FMUL(iImageHeight, DispRate); } } else // if (lpDisplay->FileRate) // Specific FileRate { // Calulate how much space is needed at this FileRate DispRate = FGET(FUNITY, lpDisplay->FileRate); iImageWidth = FMUL(lpImage->npix, DispRate); iImageHeight = FMUL(lpImage->nlin, DispRate); // See if scrollbars will be necessary and get the // appropriate DispRect if so if (iImageWidth > w && iImageHeight > h) { GetDispRect(hWnd, &DispRect, 2, 2); } else if (iImageWidth > w) { GetDispRect(hWnd, &DispRect, 2, 1); h = RectHeight(&DispRect); if (iImageHeight > h) { GetDispRect(hWnd, &DispRect, 2, 2); } } else if (iImageHeight > h) { GetDispRect(hWnd, &DispRect, 1, 2); w = RectWidth(&DispRect); if (iImageWidth > w) { GetDispRect(hWnd, &DispRect, 2, 2); } } w = RectWidth(&DispRect); h = RectHeight(&DispRect); iWidth = w; iHeight = h; // Clip the DispRect size to the amount needed for image if (iImageWidth < iWidth) iWidth = iImageWidth; if (iImageHeight < iHeight) iHeight = iImageHeight; } bIconic = IsIconic(hMDIWindow); bZoomed = IsZoomed(hMDIWindow); if (bZoomed || bIconic) { dy = RectHeight(&DispRect) - iHeight; dy /= 2; dx = RectWidth(&DispRect) - iWidth; dx /= 2; lpDisplay->DispRect.top = DispRect.top + dy; lpDisplay->DispRect.left = DispRect.left + dx; } else { lpDisplay->DispRect.top = DispRect.top; lpDisplay->DispRect.left = DispRect.left; } lpDisplay->DispRect.bottom = lpDisplay->DispRect.top + iHeight - 1; lpDisplay->DispRect.right = lpDisplay->DispRect.left + iWidth - 1; }
void CalcFullViewWindowSize( LPRECT lpWindowRect, LPRECT lpFileRect, LFIXED FileRate, int npix, int nlin, int x, int y, BOOL fHasRulers, BOOL fClipToImage ) /************************************************************************/ { int dx, dy, sx, sy, rs, iImageWidth, iImageHeight, iWidth, iHeight; LFIXED DispRate; int minsize; // normal window - to goal is to size the window to fit the view // If FileRate == 0 or 1, then we make the window as big as possible // for the FileRect provided. If FileRate != 0, then we make the // the window as big as possible to fit the image at that FileRate. // If the fClipToImage flag and FileRate == 0, then we do not let // the FileRate go over 100%. This is used for a caller who wants // to display the image pixel for pixel, if possible. if (x < 0 || y < 0) GetDocumentPosition(&x, &y); dx = 2 * GetSystemMetrics(SM_CXFRAME); dy = GetSystemMetrics(SM_CYCAPTION) + (2*GetSystemMetrics(SM_CYFRAME)) - 1; // get size of scrollbars and rulers for use later GetScrollBarSize(&sx, &sy); rs = GetRulerSize(); // determine maximum area for window to occupy if (IsIconic(PictPubApp.Get_hWndAstral())) *lpWindowRect = rClient; else GetClientRect(PictPubApp.Get_hClientAstral(), lpWindowRect); lpWindowRect->top = y; lpWindowRect->left = x; lpWindowRect->right -= dx; lpWindowRect->bottom -= (dy + GetSystemMetrics(SM_CYFRAME)); // start with this maximum Client Area size minsize = MIN_WINDOW_SIZE+rs; iWidth = RectWidth(lpWindowRect); if ( iWidth < minsize ) iWidth = minsize; iHeight = RectHeight(lpWindowRect); if ( iHeight < minsize ) iHeight = minsize; // If we already have a FileRate, calculate new size of window // based on the image size if (FileRate > TINYRATE) { // calculate size of area for total image at this // FileRate DispRate = FGET(FUNITY, FileRate); iImageWidth = FMUL(npix, DispRate); iImageHeight = FMUL(nlin, DispRate); // add in additional space for rulers if necessary if (fHasRulers) { iImageWidth += rs; iImageHeight += rs; } if (iImageWidth > iWidth && iImageHeight < iHeight) iImageHeight += sy; if (iImageHeight > iHeight && iImageWidth < iWidth) iImageWidth += sx; // see if we don't need the total width // otherwise, use the maximum if (iImageWidth < iWidth) iWidth = iImageWidth; // see if we don't need the total height // otherwise, use the maximum if (iImageHeight < iHeight) iHeight = iImageHeight; } // if we have no FileRate, then somebody wants a specific // FileRect, figure out how big the window needs to be and // whether we need rulers else { // get width and height of area to be displayed iImageWidth = RectWidth(lpFileRect); iImageHeight = RectHeight(lpFileRect); // reduce the maximum area if we have rulers if (fHasRulers) { iWidth -= rs; iHeight -= rs; } // reduce the maximum area if we need scrollbars if (lpFileRect->left != 0 || lpFileRect->right != npix-1 || lpFileRect->top != 0 || lpFileRect->bottom != nlin-1) { iWidth -= sx; iHeight -= sy; } // scale maximum client area size (not including rulers and // scrollbars) to fit aspect ratio of FileRect DispRate = ScaleToFit(&iWidth, &iHeight, iImageWidth, iImageHeight); // if caller wants to clip to hires to achieve 100% view, // clip. But only if hires is smaller if (iImageWidth <= iWidth && iImageHeight <= iHeight && fClipToImage) { iWidth = iImageWidth; iHeight = iImageHeight; } // add ruler size back into client area if (fHasRulers) { iWidth += rs; iHeight += rs; } // add scrollbar size back into client area if (lpFileRect->left != 0 || lpFileRect->right != npix-1 || lpFileRect->top != 0 || lpFileRect->bottom != nlin-1) { iWidth += sx; iHeight += sy; } } // Calculate new window size based on iWidth and iHeight */ lpWindowRect->right = lpWindowRect->left + iWidth + dx - 1; lpWindowRect->bottom = lpWindowRect->top + iHeight + dy - 1; }
LOCAL BOOL FullScreenView_OnInitDialog(HWND hDlg, HWND hWndFocus, LPARAM lParam) { CPPMDIChildWnd *pMDIChild; HWND hMDIWnd; RECT ClientRect; int npix, nlin, cx, cy, dx, dy; HWND hControl, hMDIChild, hView; LPOBJECT lpBase; LPFRAME lpFrame; // Make the window as big as the screen dx = GetSystemMetrics( SM_CXSCREEN ); dy = GetSystemMetrics( SM_CYSCREEN ); MoveWindow( hDlg, 0, 0, dx, dy, NO ); // Compute the center of the window GetClientRect( hDlg, &ClientRect ); cx = ( ClientRect.right + ClientRect.left ) / 2; cy = ( ClientRect.bottom + ClientRect.top ) / 2; // Link all of the images to image controls hControl = GetDlgItem( hDlg, IDC_VIEWFULL ); CServerView *pView = PictPubApp.GetActiveView(); BOOL bInplaceActive = (pView && pView->GetDocument()->IsInPlaceActive()); if (bInplaceActive) { hMDIChild = pView->GetParentFrame()->GetSafeHwnd(); hView = pView->GetSafeHwnd(); } else { pMDIChild = (CPPMDIChildWnd*)((CMDIFrame*)PictPubApp.m_pMainWnd)->MDIGetActive(); hMDIWnd = pMDIChild->GetSafeHwnd(); if (hMDIWnd) hView = pMDIChild->GetActiveView()->GetSafeHwnd(); else hView = NULL; } while ( hView ) { lpBase = ImgGetBase((LPIMAGE)GetImagePtr(hView)); if ( !lpBase || !hControl ) break; lpFrame = ObjGetEditFrame(lpBase); // Link the frame to the image control SetWindowLong( hControl, GWL_IMAGE, (long)lpBase ); // The destination size can be no bigger the the screen npix = FrameXSize(lpFrame); nlin = FrameYSize(lpFrame); if ( npix > dx || nlin > dy ) { npix = dx; nlin = dy; ScaleToFit( &npix, &nlin, FrameXSize(lpFrame), FrameYSize(lpFrame)); } // Position the control in the center of the window ClientRect.left = cx - npix/2; ClientRect.right = ClientRect.left + npix; ClientRect.top = cy - nlin/2; ClientRect.bottom = ClientRect.top + nlin; MoveWindow( hControl, ClientRect.left, ClientRect.top, // New position RectWidth( &ClientRect ), RectHeight( &ClientRect ), // New size NO /* No repaint*/ ); if (bInplaceActive) break; // Check to see if these get destroyed when the window does do { hView = NULL; if (hMDIWnd = GetWindow( hMDIWnd, GW_HWNDNEXT )) { if ((CWnd::FromHandle(hMDIWnd))-> IsKindOf(RUNTIME_CLASS(CPPMDIChildWnd))) hView = ((CPPMDIChildWnd*)CWnd::FromHandle(hMDIWnd))-> GetActiveView()->GetSafeHwnd(); } } while (hMDIWnd && !hView); if (!hView) break; // Get another image control hControl = CopyWindow( hControl ); } return TRUE; }
HICON CXTPIconHandle::ScaleToFit(CSize desiredExtent) const { return ScaleToFit(m_hIcon, desiredExtent); }
void CPictureListView::DrawListViewThumbnails() { // Set the length of the space between thumbnails // You can also calculate and set it based on the length of your list control // Hold the window update to avoid flicking SetRedraw(FALSE); // Reset the image list for (int i=0; i<m_ImageList.GetImageCount(); i++) m_ImageList.Remove(i); // Remove all items from list view if (GetItemCount()) DeleteAllItems(); // Draw the thumbnails i = 0; for (int nIndex = 0; nIndex < MAX_NUM_PICTURES; nIndex++) { CAGSymImage* pImage = m_pParent->GetEnvelopeWizard()->m_pGraphics[nIndex]; if (!pImage) continue; BITMAPINFOHEADER* pDib = pImage->GetDib(); if (!pDib) continue; // Borrow our dib header to create our thumbnail bitmap int nWidth = pDib->biWidth; int nHeight = pDib->biHeight; pDib->biWidth = m_nThumbnailSize; pDib->biHeight = m_nThumbnailSize; // Create thumbnail bitmap section HBITMAP hBitmap = ::CreateDIBSection(NULL, (BITMAPINFO*)pDib, DIB_RGB_COLORS, NULL, NULL, 0); // Restore the dib header pDib->biWidth = nWidth; pDib->biHeight = nHeight; // Select the thumbnail bitmap into screen dc HDC hMemDC = ::CreateCompatibleDC(NULL); HGDIOBJ hOldObj = ::SelectObject(hMemDC, hBitmap); // Set stretch mode ::SetStretchBltMode(hMemDC, COLORONCOLOR); int dx = m_nThumbnailSize; int dy = m_nThumbnailSize; ScaleToFit(&dx, &dy, nWidth, nHeight, true/*bUseSmallerFactor*/); // Populate the thumbnail bitmap bits RECT rect = {0, 0, m_nThumbnailSize, m_nThumbnailSize}; ::FillRect(hMemDC, &rect, CAGBrush(RGB(255,255,255))); ::StretchDIBits(hMemDC, (m_nThumbnailSize - dx)/2, (m_nThumbnailSize - dy)/2, dx, dy, 0, 0, nWidth, nHeight, DibPtr(pDib), (BITMAPINFO*)pDib, DIB_RGB_COLORS, SRCCOPY); // Restore DC object ::SelectObject(hMemDC, hOldObj); // Clean up ::DeleteObject(hMemDC); // Add the bitmap to our image list m_ImageList.Add(hBitmap); // Set the image file name as item text InsertItem(i, "", i); // Get the current item position POINT pt; GetItemPosition(i, &pt); // Shift the thumbnail to desired position pt.x = 0; pt.y = i * m_nThumbnailSize; SetItemPosition(i, pt); i++; } // Show the new thumbnails //j Arrange(LVA_ALIGNLEFT); SetRedraw(TRUE); }
void CPhotoManager::Callback(IDispatch* pDisp1, IDispatch* pDisp2, DISPID id, VARIANT* pVarResult) { if (!pDisp1) return; HRESULT hr = S_OK; if (id == DISPID_MOUSEOVER) { CComQIPtr<IHTMLElement2> spElem2(pDisp1); if (!spElem2) return; hr = spElem2->focus(); } else if (id == DISPID_MOUSEDOWN) { CComQIPtr<IHTMLElement> spElem(pDisp1); if (!spElem) return; CComPtr<IDispatch> spDisp; spElem->get_document(&spDisp); CComQIPtr<IHTMLDocument2> spDoc(spDisp); if (FAILED(hr) || !spDoc) return; CComPtr<IHTMLWindow2> spWnd; HRESULT hr = spDoc->get_parentWindow(&spWnd); if (FAILED(hr) || !spWnd) return; CComPtr<IHTMLEventObj> spEventObj; hr = spWnd->get_event(&spEventObj); if (FAILED(hr) || !spEventObj) return; long lVal; spEventObj->get_button(&lVal); if ( lVal == 1) // 1 = left button is pressed hr = spElem->click(); } else if (id == DISPID_MYCLICK) { CComQIPtr<IHTMLElement> spElem(pDisp1); if (!spElem) return; CComQIPtr<IHTMLImgElement> spImgElem(pDisp1); if (!spImgElem) return; CComPtr<IDispatch> spDisp; hr = spElem->get_document(&spDisp); if (FAILED(hr) || !spDisp) return; CComQIPtr<IHTMLDocument2> spDoc(spDisp); if (!spDoc) return; CString strFileName; bool bOK = AddAPhoto((IHTMLDocument2*)spDoc, strFileName); if (!bOK) return; CComQIPtr<IMarkupServices2> spMarkup2 = spDoc; if (spMarkup2) hr = spMarkup2->BeginUndoUnit(L"Add a Photo"); long lElemWidth = 0; long lElemHeight = 0; GetElemSize(spElem, lElemWidth, lElemHeight); if (!lElemWidth && !lElemHeight) { GetImgElemSize(spImgElem, lElemWidth, lElemHeight); SetElemSize(spElem, lElemWidth, lElemHeight); } long lImageWidth = 0; long lImageHeight = 0; CImage Image(strFileName); Image.GetNativeImageSize(lImageWidth, lImageHeight); #define SHIFT (GetAsyncKeyState(VK_SHIFT) < 0) if (SHIFT) ::MessageBox(NULL, "The photo will be embedded in the email message.", g_szAppName, MB_OK); else { CString strURL = m_strHost + "/cgi-bin/flashalbum/cmaddaphoto.pl"; // strFormDataPairs is a string of name/value pairs as follows "name1:value1|\nname2:value2|\n" CString strFormDataPairs; strFormDataPairs += "inputfile:~" + strFileName + "|\n"; CUploadImages Upload(ULI_NOUPSIZE /*| ULI_LEAVETEMP | ULI_DEBUG*/); CString strResult; Upload.UploadImages(strURL, strFormDataPairs, lElemWidth, lElemHeight, 70/*nQuality*/, strResult); if (strResult.Find("error") < 0 && strResult.Find("http") >= 0) { GetImageHost(strResult); strFileName = strResult; //::MessageBox(NULL, String("The photo was uploaded first to %s.", strFileName), g_szAppName, MB_OK); } else { CString szMsg; szMsg.LoadString(IDS_ADDAPHOTO_ERROR); ::MessageBox(NULL, szMsg, g_szAppName, MB_OK); if (spMarkup2) hr = spMarkup2->EndUndoUnit(); return; } } if (lImageWidth && lImageHeight) { ScaleToFit(&lElemWidth, &lElemHeight, lImageWidth, lImageHeight, true/*bUseSmallerFactor*/); SetImgElemSize(spImgElem, lElemWidth, lElemHeight); SetElemStyle(spElem, lElemWidth, lElemHeight); } hr = spImgElem->put_src(CComBSTR(strFileName)); if (spMarkup2) { hr = spMarkup2->EndUndoUnit(); CComQIPtr<IMarkupContainer2> spMarkupCont2 = spMarkup2; if (spMarkupCont2) { long l = spMarkupCont2->GetVersionNumber(); l += 0; } } if (FAILED(hr)) return; } }
BOOL ReadObjData( LPSTR lpFileName, LPOBJECTLIST lpObjList, int outDepth, LPINT lpDataType, LPRECT lpScaleRect, LPINT lpFullFileX, LPINT lpFullFileY, LPINT lpFullResolution) /************************************************************************/ { LPFRAME lpFrame; LPOBJECT lpObject; int ifh; LPLONG lngptr; LPWORD shtptr; int nObjects, i, idFileType, nPasses; WORD wBytes, wByteOrder, wVersion; long lObjSize, lObjStart; LPOBJOFFSETS lpOffsets; OBJECT Obj; LFIXED xrate, yrate; int opix, olin, baseW, baseH; LPRECT lpLoadRect; xrate = yrate = UNITY; lpOffsets = NULL; if ( !lpObjList ) return( FALSE ); lpObjList->lpHead = lpObjList->lpTail = NULL; if ( (ifh = _lopen(lpFileName, OF_READ)) < 0) { Message( IDS_EOPEN, lpFileName ); return( FALSE ); } // Read in header info wBytes = OBJ_HDR_SIZE; if ( _lread(ifh, LineBuffer[0], wBytes) != wBytes ) goto BadRead; shtptr = (LPWORD)LineBuffer[0]; wByteOrder = GetNextWord(&shtptr); /* byte order is LSB,MSB */ if (wByteOrder != TIF_II && wByteOrder != TIF_MM) goto BadRead; wVersion = GetNextWord(&shtptr); /* Version Number */ nObjects = GetNextWord(&shtptr); /* Number of Objects */ lngptr = (LPLONG)shtptr; lObjSize = GetNextLong(&lngptr); /* size of object data */ lObjStart = GetNextLong(&lngptr); /* start of object data */ if (!(lpOffsets = (LPOBJOFFSETS)Alloc(sizeof(OBJOFFSETS)*nObjects))) { Message(IDS_EMEMALLOC); return(FALSE); } _llseek (ifh, lObjStart, 0); wBytes = (WORD)lObjSize; nPasses = 0; for (i = 0; i < nObjects; ++i) { if ( _lread(ifh, LineBuffer[0], wBytes) != wBytes ) goto BadRead; shtptr = (LPWORD)LineBuffer[0]; Obj.ObjectType = (OBJECT_TYPE)GetNextWord(&shtptr); Obj.rObject.left = GetNextWord(&shtptr); Obj.rObject.top = GetNextWord(&shtptr); Obj.rObject.right = GetNextWord(&shtptr); Obj.rObject.bottom = GetNextWord(&shtptr); Obj.Opacity = GetNextWord(&shtptr); Obj.MergeMode = (MERGE_MODE)GetNextWord(&shtptr); Obj.wGroupID = GetNextWord(&shtptr); if (i==0 && lpScaleRect) { opix = RectWidth(lpScaleRect); olin = RectHeight(lpScaleRect); baseW = RectWidth(&Obj.rObject); baseH = RectHeight(&Obj.rObject); xrate = ScaleToFit(&opix, &olin, baseW, baseH); if (opix > baseW || olin > baseH) { // No upsizing allowed opix = baseW; olin = baseH; } xrate = FGET( opix, baseW ); yrate = FGET( olin, baseH ); } // scale the object rect Obj.rObject.left = FMUL(Obj.rObject.left, xrate); Obj.rObject.top = FMUL(Obj.rObject.top, yrate); Obj.rObject.right = FMUL(Obj.rObject.right, xrate); Obj.rObject.bottom = FMUL(Obj.rObject.bottom, yrate); if (!(lpObject = ObjCreateFromFrame(ST_PERMANENT, NULL, NULL, &Obj.rObject, Control.NoUndo))) { Message(IDS_EMEMALLOC); goto BadRead; } idFileType = GetNextWord(&shtptr); lpOffsets[i].bInvert = GetNextWord(&shtptr); lpOffsets[i].rMask.left = GetNextWord(&shtptr); lpOffsets[i].rMask.top = GetNextWord(&shtptr); lpOffsets[i].rMask.right = GetNextWord(&shtptr); lpOffsets[i].rMask.bottom = GetNextWord(&shtptr); // scale the mask rect lpOffsets[i].rMask.left = FMUL(lpOffsets[i].rMask.left, xrate); lpOffsets[i].rMask.top = FMUL(lpOffsets[i].rMask.top, yrate); lpOffsets[i].rMask.right = FMUL(lpOffsets[i].rMask.right, xrate); lpOffsets[i].rMask.bottom = FMUL(lpOffsets[i].rMask.bottom, yrate); lngptr = (LPLONG)shtptr; lpOffsets[i].lDataOffset = GetNextLong(&lngptr); lpOffsets[i].lAlphaOffset = GetNextLong(&lngptr); shtptr = (LPWORD)lngptr; // versions after 1.1 saved selected state if (wVersion == 0x0101) Obj.fSelected = NO; else Obj.fSelected = GetNextWord(&shtptr); if (wVersion < 0x0103 || lObjSize == 41) { Obj.ObjectDataID = OBJECT_DATA_NONE; Obj.dwObjectData = 0; } else { Obj.ObjectDataID = GetNextWord(&shtptr); Obj.dwObjectData = *(LPDWORD)shtptr; shtptr += 2; } lpObject->ObjectType = Obj.ObjectType; lpObject->Opacity = Obj.Opacity; lpObject->MergeMode = Obj.MergeMode; lpObject->wGroupID = Obj.wGroupID; lpObject->fSelected = Obj.fSelected; lpObject->ObjectDataID = Obj.ObjectDataID; lpObject->dwObjectData = Obj.dwObjectData; ObjAddTail(lpObjList, (LPPRIMOBJECT)lpObject); ++nPasses; if (lpOffsets[i].lAlphaOffset) ++nPasses; } ProgressBegin(nPasses, 0); lpObject = NULL; i = 0; while (lpObject = (LPOBJECT)ObjGetNextObject(lpObjList, (LPPRIMOBJECT)lpObject, YES)) { if (lpScaleRect && i!=0) { lpLoadRect = &lpObject->rObject; } else lpLoadRect = lpScaleRect; _llseek (ifh, lpOffsets[i].lDataOffset, 0); lpFrame = ReadTiffData(ifh, lpFileName, outDepth, lpDataType, NO/*bReadOnly*/, lpLoadRect, NO, lpFullFileX, lpFullFileY, lpFullResolution); if (i == 0) { lpDataType = NULL; lpFullFileX = NULL; lpFullFileY = NULL; lpFullResolution = NULL; } if (!lpFrame) goto BadRead; PixmapSetup(&lpObject->Pixmap, lpFrame, Control.NoUndo); if (!lpOffsets[i].lAlphaOffset) { ++i; continue; } _llseek (ifh, lpOffsets[i].lAlphaOffset, 0); lpFrame = ReadTiffData(ifh, lpFileName, outDepth, lpDataType, NO/*bReadOnly*/, lpLoadRect, NO, NULL, NULL, NULL); if (!lpFrame) goto BadRead; lpObject->lpAlpha = MaskCreate(lpFrame, 0, 0, OFF, Control.NoUndo); if (!lpObject->lpAlpha) { Message(IDS_EMEMALLOC); goto BadRead; } lpObject->lpAlpha->bInvert = lpOffsets[i].bInvert; lpObject->lpAlpha->rMask = lpOffsets[i].rMask; ++i; } if ( lpOffsets ) FreeUp( (LPTR)lpOffsets ); _lclose(ifh); ProgressEnd(); return( TRUE ); BadRead: while (lpObject = (LPOBJECT)ObjGetNextObject(lpObjList, NULL, YES)) { ObjUnlinkObject(lpObjList, (LPPRIMOBJECT)lpObject); ObjFreeUp(lpObject); } _lclose(ifh); if ( lpOffsets ) FreeUp( (LPTR)lpOffsets ); if (nPasses) ProgressEnd(); Message( IDS_EREAD, lpFileName ); return( FALSE ); }