home *** CD-ROM | disk | FTP | other *** search
Text File | 1995-11-13 | 6.3 KB | 117 lines | [TEXT/CWIE] |
- /*
- Crop a PICT resource
- ...allowing one to crop a PICS file or a series of PICT files
- */
-
- #include <QDOffscreen.h>
- #include "CropPICTs.h"
- #include "PICS_Types.h"
- #include "SavePicture.h"
- #include "assert_mac.h"
- #include "QDUtils.h" // For CenterRect
- #include "FileRegistry.h"
-
- // ---------------------------------------------------------------------------
-
- /*
- The <picBuffer> is assumed to be at least the same or larger
- dimensions than that of <inputPic>. If you pass the address of
- an empty PicHandle to <croppedPic>, CropPICT will record the
- cropped <inputPic> as a picture to <croppedPic>. If you pass NULL
- instead, no picture will be saved.
-
- <destBuffer> may be the same as <picBuffer>
- <srcCropRect> may be the same as <destCropRect>
- */
-
- Boolean CropPICT(
- const PicHandle inputPic,
- const GraphicsBufferPtr picBuffer,
- const GraphicsBufferPtr destBuffer,
- const Rect *srcCropRect,
- const Rect *destCropRect,
- PicHandle *croppedPic) {
-
- GWorldPtr saveWorld;
- GDHandle saveDev;
- Rect picRect;
- Boolean result;
-
- ASSERT(inputPic != NULL);
- ASSERT(picBuffer != NULL);
- ASSERT(destBuffer != NULL);
- ASSERT(srcCropRect != NULL);
- ASSERT(destCropRect != NULL);
-
- GetGWorld(&saveWorld, &saveDev);
- SetGraphicsBuffer(picBuffer);
- picRect = (**inputPic).picFrame;
- FlushRectTopLeft(&picRect);
- DrawPicture(inputPic, &picRect);
-
- result = CapturePICT(picBuffer, destBuffer, srcCropRect, destCropRect, croppedPic);
-
- SetGWorld(saveWorld, saveDev);
- return(result);
- } // END CropPICT
-
- // ---------------------------------------------------------------------------
-
- Boolean CapturePICT(
- const GraphicsBufferPtr srcBuffer,
- const GraphicsBufferPtr destBuffer,
- const Rect *srcRect,
- const Rect *destRect,
- PicHandle *croppedPic) {
-
- GWorldPtr saveWorld;
- GDHandle saveDev;
- Rect clipRect;
- RgnHandle saveClip;
-
- ASSERT(srcBuffer != NULL);
- ASSERT(destBuffer != NULL);
- ASSERT(srcRect != NULL);
- ASSERT(destRect != NULL);
-
- GetGWorld(&saveWorld, &saveDev);
- SetGraphicsBuffer(destBuffer);
-
- if (croppedPic != NULL) {
- saveClip = NewRgn();
- ASSERT(saveClip != NULL);
- GetClip(saveClip);
- GetGraphicsBufferBounds(destBuffer, (CP_Rect*)&clipRect);
- // It's in global coords so we have to adjust it
- FlushRectTopLeft(&clipRect);
- ClipRect(&clipRect);
-
- *croppedPic = OpenPicture(destRect);
- ASSERT(*croppedPic != NULL);
- }
-
- CopyGraphicsBuffer(srcBuffer, destBuffer,
- (CP_Rect*)srcRect, (CP_Rect*)destRect);
-
- if (croppedPic != NULL) {
- ClosePicture();
- ASSERT(*croppedPic != NULL);
-
- SetClip(saveClip);
- DisposeRgn(saveClip);
- SetGWorld(saveWorld, saveDev);
- }
-
- return(true);
- } // END CapturePICT
-
- // ---------------------------------------------------------------------------
-
- /*
- This routine assumes you already have picked the input <picsFile> and
- created the output <outputFile>. It also assumes that you have set the
- depth of monitor <outputDevice> appropriately, prior to calling the routine.
- (CropPICSFile uses the depth of <outputDevice> to determine the depth
- of the output PICS frames).
-
- Technically, the order of the frames in