home *** CD-ROM | disk | FTP | other *** search
- /*
- * This is some stuff I was writing to try to detect duplicate images. It
- * works for ICON/ICON and SICN/SICN tests. It doesn't work when trying to
- * detect whether any regular ICON is the same as the B/W image in a cicn.
- * I don't know why. Anyway, this code isn't part of the application, so
- * it's necessary to make sure there aren't any duplicate images in the resource
- * fork.
- */
-
- # include "TransSkel.h"
- # if ENABLE_DEBUG
- # include "Debug.h"
- # endif
-
- # include "Concentration.h"
-
-
-
- static void
- GetCIconInfo (Handle h, Ptr *p, short *len)
- {
- CIconHandle c = (CIconHandle) h;
- short ht, maskSize;
-
- ht = (**c).iconPMap.bounds.bottom - (**c).iconPMap.bounds.top;
- maskSize = (**c).iconMask.rowBytes * ht;
- *p = (Ptr) (&(**c).iconMaskData + maskSize);
- *len = (**c).iconBMap.rowBytes * ht;
- }
-
-
- static Boolean
- PtrCompare (Ptr p1, Ptr p2, short size)
- {
- short i;
-
- for (i = 0; i < size; i++)
- {
- if (p1[i] != p2[i])
- return (false);
- }
- return (true);
- }
-
-
- static Boolean
- HandleCompare (Handle h1, Handle h2, short size)
- {
- return (PtrCompare (*h1, *h2, size)); /* PtrCompare doesn't move memory */
- }
-
-
- /*
- * Compare a new ICON or cicn hunk of data to see if its equivalent is already
- * in the large piece array. If a given piece has a data handle that's the same
- * size as the new data, compare the bytes directly. This takes case of ICON/ICON
- * and cicn/cicn test. For ICON/cicn comparisons, compare the ICON against the
- * B/W bitmap from the cicn. (It's necessary to do this because a cicn B/W bitmap
- * may look identical to an ICON on a B/W monitor.
- */
-
- Boolean
- UniqueIcon (Piece pieceArray[], short nPieces, Handle h, short type)
- {
- Piece *p;
- Handle h2;
- short size;
- short i;
- Ptr cPtr;
- short cSize;
-
- size = GetHandleSize (h);
- for (i = 0; i < nPieces; i++)
- {
- p = &pieceArray[i];
- h2 = p->pieceData;
- if (size == GetHandleSize (h2))
- {
- if (HandleCompare (h, h2, size))
- return (false);
- }
- if (type == iconType && p->pieceType == cicnType) /* ICON vs. cicn */
- {
- GetCIconInfo (p->pieceData, &cPtr, &cSize);
- if (size == cSize && PtrCompare (*h, cPtr, size))
- {
- # if ENABLE_DEBUG
- DisplayCString ("cicn/ICON duplicate found.\r");
- # endif
- return (false);
- }
- }
- else if (type == cicnType && p->pieceType == iconType) /* cicn vs. ICON */
- {
- GetCIconInfo (h, &cPtr, &cSize);
- if (size == cSize && PtrCompare (cPtr, *(p->pieceData), size))
- {
- # if ENABLE_DEBUG
- DisplayCString ("cicn/ICON duplicate found.\r");
- # endif
- return (false);
- }
- }
- }
- return (true);
- }
-
-
- Boolean
- UniqueSicn (Piece pieceArray[], short nPieces, Handle h, short type)
- {
- Handle h2;
- short size;
- short i;
-
- size = GetHandleSize (h);
- for (i = 0; i < nPieces; i++)
- {
- h2 = pieceArray[i].pieceData;
- if (size == GetHandleSize (h2))
- {
- if (HandleCompare (h, h2, size))
- return (false);
- }
- }
- return (true);
- }
-