home *** CD-ROM | disk | FTP | other *** search
Text File | 1995-10-09 | 6.1 KB | 229 lines | [TEXT/PJMM] |
- (****************************************************************************)
- (* *)
- (* Application: CollectPictColors *)
- (* *)
- (* Description: This application uses the Picture Utilities package *)
- (* and Jon Zap's KnowsPict application to demonstrate *)
- (* two methods of collecting colors used by Pict *)
- (* resources. In this program, you'll see different *)
- (* results for each method. With the Pict Util package, *)
- (* the routine, GetPictInfo, returns a colortable with *)
- (* the number of colors requested, but only the colors *)
- (* used in the picture or it's pixmap(s) image data are *)
- (* stored in the requested colors. As for the *)
- (* remaining requested colors not used by the picture *)
- (* but stored in the picture's pixmap(s) colortable, *)
- (* they are set to black. In Jon's application this *)
- (* doesn't occur. All the colors used by the picture, *)
- (* including those stored in the picture's pixmap(s) *)
- (* colortable are returned. To use Jon's routines, *)
- (* simply call CollectColors with the appropriate *)
- (* parameters. *)
- (* *)
- (* Files: CollectPictColors.π *)
- (* CollectPictColors.c *)
- (* CollectPictColors.π.rsrc *)
- (* CLUTBuilder.c (written by Jon Zap) *)
- (* *)
- (* Programmer: Edgar Lee *)
- (* Organization: Apple Computer, Inc. *)
- (* Department: Developer Technical Support, DTS *)
- (* Date Created: 02-20-92 *)
- (* *)
- (* Converted to Pascal 1995 *)
- (* Language: Pascal (Think Pascal version 4.0.2 / *)
- (* Metrowerks Pascal CW6) *)
- (* *)
- (**********************************************)
-
-
- {Converted to Pascal 1995 by… bah, what do you care?}
-
-
- program CollectPictColors;
-
- uses
- Palettes,
- {$IFC UNDEFINED THINK_PASCAL}
- Types, QuickDraw, Memory, Events, Menus, Windows, TextEdit, Dialogs,{}
- Fonts, Resources, ToolUtils, PictUtils,
- {$ELSEC}
- PictUtil,
- {$ENDC}
- CLUTBuilder;
-
- (* Constant Declarations *)
-
- const
- kWWidth = 470;
- kWHeight = 330;
-
- procedure InitMac;
- begin
- {$IFC UNDEFINED THINK_PASCAL}
- MaxApplZone;
-
- InitGraf(@qd.thePort);
- InitFonts;
- InitWindows;
- InitMenus;
- TEInit;
- InitDialogs(nil);
- {$ENDC}
- InitCursor;
- FlushEvents(0, everyEvent);
- end; {InitMac}
-
- procedure CreateWindow;
- var
- theRect: Rect;
- window: WindowPtr;
- wLeft, wTop: Integer;
- begin
- {$IFC UNDEFINED THINK_PASCAL}
- wLeft := (qd.screenBits.bounds.right - qd.screenBits.bounds.left - kWWidth) div 2;
- wTop := (qd.screenBits.bounds.bottom - qd.screenBits.bounds.top - kWHeight) div 2;
- {$ELSEC}
- wLeft := (screenBits.bounds.right - screenBits.bounds.left - kWWidth) div 2;
- wTop := (screenBits.bounds.bottom - screenBits.bounds.top - kWHeight) div 2;
- {$ELSEC}
- SetRect(theRect, wLeft, wTop, wLeft + kWWidth, wTop + kWHeight);
- window := NewCWindow(nil, theRect, 'Collect Pict Colors', true, documentProc, WindowPtr(-1), true, 0);
- SetPort(window);
-
- TextFont(geneva);
- TextSize(9);
- TextMode(srcCopy);
- end; {CreateWindow}
-
- procedure DrawColors (ctable: CTabHandle; offset: Integer; theString: Str255);
- var
- i: Integer;
- col, row: Integer;
- theRect: Rect;
- begin
- ForeColor(whiteColor);
- BackColor(blackColor);
-
- MoveTo(offset, 20);
- DrawString(theString);
-
- if (ctable <> nil) then
- begin
- for i := 0 to 255 do
- begin
- col := offset + ((i mod 8) * 16);
- row := 30 + ((i div 8) * 9);
-
- SetRect(theRect, col, row, col + 10, row + 3);
- RGBForeColor(ctable^^.ctTable[i].rgb);
- PaintRect(theRect);
-
- ForeColor(whiteColor);
- InsetRect(theRect, -2, -2);
- FrameRect(theRect);
- end;
- end
- else
- begin
- MoveTo(12, offset);
- DrawString('-Sorry could not load PICT resource.');
- end;
- end;
-
- procedure DrawPictureColors;
- var
- theRect: Rect;
- pict: PicHandle;
- ctable: CTabHandle;
- depth: Integer;
- directFlag: Boolean;
- thePictInfo: PictInfo;
- begin
-
- (* Load the pict resource. *)
- pict := GetPicture(128);
-
- (* Make sure it's not purgeable. *)
- HNoPurge(Handle(pict));
-
- (* Set a black background. *)
- SetRect(theRect, 0, 0, kWWidth, kWHeight);
- ForeColor(blackColor);
- PaintRect(theRect);
-
- (* See what CollectColors returns. *)
- ctable := CollectColors(pict, depth, directFlag);
- DrawColors(ctable, 20, 'COLLECTCOLORS Colortable');
-
- (* Draw the picture. *)
- theRect := pict^^.picFrame;
- OffsetRect(theRect, -theRect.left + 160, -theRect.top + 70);
- DrawPicture(pict, theRect);
-
- (* Frame the picture. *)
- InsetRect(theRect, -2, -2);
- FrameRect(theRect);
-
- (* Now see what GetPictInfo returns. *)
- if noErr = GetPictInfo(pict, thePictInfo, returnColorTable, 256, medianMethod, 0) then
- ;
- DrawColors(thePictInfo.theColorTable, theRect.right + 15, 'GETPICTINFO Colortable');
-
- (* Release the resource. *)
- ReleaseResource(Handle(pict));
-
- (* Release the colortable. *)
- DisposeCTable(ctable);
- end; {DrawPictureColors}
-
- procedure DoEventLoop;
- var
- event: EventRecord;
- window: WindowPtr;
- clickArea: Integer;
- screenRect: Rect;
- begin
- while true do
- begin
- if (WaitNextEvent(everyEvent, event, 0, nil)) then
- begin
- if (event.what = mouseDown) then
- begin
- clickArea := FindWindow(event.where, window);
- if (clickArea = inDrag) then
- begin
- screenRect := GetGrayRgn^^.rgnBBox;
- DragWindow(window, event.where, screenRect);
- end
- else if (clickArea = inContent) then
- begin
- if (window <> FrontWindow) then
- SelectWindow(window);
- end
- else if (clickArea = inGoAway) then
- if (TrackGoAway(window, event.where)) then
- exit(DoEventLoop);
- end
- else if (event.what = updateEvt) then
- begin
- window := WindowPtr(event.message);
- SetPort(window);
-
- BeginUpdate(window);
- DrawPictureColors;
- EndUpdate(window);
- end;
- end;
- end;
- end; {DoEventLoop}
-
- {main program}
-
- begin
- InitMac;
-
- CreateWindow;
-
- DoEventLoop;
- end.