From ad669a3fd4ee469155a6d48a2b648943ba9252dc Mon Sep 17 00:00:00 2001 From: Iliyas Jorio Date: Tue, 16 Feb 2021 21:41:08 +0100 Subject: [PATCH] Add GetPictureFromFile (extension) --- src/Graphics/Graphics.cpp | 36 +++++++++++++++++++++++++++++------- src/Pomme.h | 5 +++++ 2 files changed, 34 insertions(+), 7 deletions(-) diff --git a/src/Graphics/Graphics.cpp b/src/Graphics/Graphics.cpp index dd312b2..39202c9 100644 --- a/src/Graphics/Graphics.cpp +++ b/src/Graphics/Graphics.cpp @@ -7,6 +7,7 @@ #include #include #include +#include using namespace Pomme; using namespace Pomme::Graphics; @@ -123,14 +124,9 @@ static UInt32 GetEightColorPaletteValue(long color) // ---------------------------------------------------------------------------- - // PICT resources -PicHandle GetPicture(short PICTresourceID) +static PicHandle GetPictureFromStream(std::istream& stream, bool skip512) { - Handle rawResource = GetResource('PICT', PICTresourceID); - if (rawResource == nil) - return nil; - memstream substream(*rawResource, GetHandleSize(rawResource)); - ARGBPixmap pm = ReadPICT(substream, false); - ReleaseResource(rawResource); + ARGBPixmap pm = ReadPICT(stream, skip512); // Tack the data onto the end of the Picture struct, // so that DisposeHandle frees both the Picture and the data. @@ -148,6 +144,32 @@ PicHandle GetPicture(short PICTresourceID) return ph; } +PicHandle GetPicture(short PICTresourceID) +{ + Handle rawResource = GetResource('PICT', PICTresourceID); + if (rawResource == nil) + return nil; + + memstream stream(*rawResource, GetHandleSize(rawResource)); + PicHandle ph = GetPictureFromStream(stream, false); + ReleaseResource(rawResource); + return ph; +} + +PicHandle GetPictureFromFile(const FSSpec* spec) +{ + short refNum; + + OSErr error = FSpOpenDF(spec, fsRdPerm, &refNum); + if (error != noErr) + return nil; + + auto& stream = Pomme::Files::GetStream(refNum); + PicHandle ph = GetPictureFromStream(stream, true); + FSClose(refNum); + return ph; +} + // ---------------------------------------------------------------------------- - // Rect diff --git a/src/Pomme.h b/src/Pomme.h index d36466e..41c9a2d 100644 --- a/src/Pomme.h +++ b/src/Pomme.h @@ -114,8 +114,13 @@ void OffsetRect(Rect* r, short dh, short dv); // ---------------------------------------------------------------------------- // QuickDraw 2D: PICT +// Read picture from 'PICT' resource. PicHandle GetPicture(short PICTresourceID); +// Read a picture from a PICT file on disk. +// Pomme extension (not part of the original Toolbox API). +PicHandle GetPictureFromFile(const FSSpec* spec); + // ---------------------------------------------------------------------------- // QuickDraw 2D: GWorld