ciderpress/reformat/SuperHiRes.h

310 lines
9.5 KiB
C
Raw Normal View History

2007-03-27 17:47:10 +00:00
/*
* CiderPress
* Copyright (C) 2007 by faddenSoft, LLC. All Rights Reserved.
* See the file LICENSE for distribution terms.
*/
/*
* Convert the various Super HiRes formats.
*/
Large set of changes to restore CiderPress build. CiderPress and MDC now compile, and execute far enough to open their respective "about" boxes, but I doubt they'll do much more than that. * Switch from MBCS to UNICODE APIs Microsoft switched to UTF-16 (by way of UCS-2) a long time ago, and the support for MBCS seems to be getting phased out. So it's time to switch to wide strings. This is a bit awkward for CiderPress because it works with disk and file archives with 8-bit filenames, and I want NufxLib and DiskImgLib to continue to work on Linux (which has largely taken the UTF-8 approach to Unicode). The libraries will continue to work with 8-bit filenames, with CiderPress/MDC doing the conversion at the appropriate point. There were a couple of places where strings from a structure handed back by one of the libraries were used directly in the UI, or vice-versa, which is a problem because we have nowhere to store the result of the conversion. These currently have fixed place-holder "xyzzy" strings. All UI strings are now wide. Various format strings now use "%ls" and "%hs" to explicitly specify wide and narrow. This doesn't play well with gcc, so only the Windows-specific parts use those. * Various updates to vcxproj files The project-file conversion had some cruft that is now largely gone. The build now has a common output directory for the EXEs and libraries, avoiding the old post-build copy steps. * Added zlib 1.2.8 and nufxlib 2.2.2 source snapshots The old "prebuilts" directory is now gone. The libraries are now built as part of building the apps. I added a minimal set of files for zlib, and a full set for nufxlib. The Linux-specific nufxlib goodies are included for the benefit of the Linux utilities, which are currently broken (don't build). * Replace symbols used for include guards Symbols with a leading "__" are reserved.
2014-11-10 23:32:55 +00:00
#ifndef REFORMAT_SUPERHIRES_H
#define REFORMAT_SUPERHIRES_H
2007-03-27 17:47:10 +00:00
#include "ReformatBase.h"
/*
* Reformat SHR images (abstract base class).
*
* THOUGHT: add a "convert single line" function that copies to bytes or
* RGBTRIPLEs or whatever. Use it in the usual functions and for converting
* odd-sized APF-format images. Args are the bits for the line, 320/640 mode
* for source-pixel interpretation, and the color palette for that line. We
* need to orient less on the format we're converting *to* (e.g. 320/640x200)
* and more on what we're converting *from* (arbitrary sized image with
* certain GS-specific characteristics).
*/
class ReformatSHR : public ReformatGraphics {
public:
enum {
kNumLines = 200,
kPixelBytesPerLine = 160,
kNumColorTables = 16,
kNumEntriesPerColorTable = 16,
kColorTableEntrySize = 2,
kOutputWidth = 640, // use pixel-doubling so we can get both
kOutputHeight = 400, // 320 and 640 modes
kTotalSize = 32768,
kMaxPixelsPerScan = 1280, // allow up to 1280x1024
kMaxScanLines = 1024, // in APF images
kSCBColorTableMask = 0x0f,
kSCBFillMode = 0x20,
kSCBInterrupts = 0x40,
kSCBNumPixels = 0x80, // 0=320, 1=640
};
/*
* This holds one SHR screen; the size must be 32768 bytes.
*/
typedef struct SHRScreen {
uint8_t pixels[kNumLines * kPixelBytesPerLine];
uint8_t scb[kNumLines];
uint8_t reserved[256 - kNumLines];
uint8_t colorTable[kNumColorTables * kNumEntriesPerColorTable *
kColorTableEntrySize];
} SHRScreen;
/* convert 0RGB into (R,G,B) */
void GSColor(int color, RGBTRIPLE* pTriple) {
pTriple->rgbtRed = ((color >> 8) & 0x0f) * 17;
pTriple->rgbtGreen = ((color >> 4) & 0x0f) * 17;
pTriple->rgbtBlue = (color & 0x0f) * 17;
}
void GSColor(int color, RGBQUAD* pQuad) {
pQuad->rgbRed = ((color >> 8) & 0x0f) * 17;
pQuad->rgbGreen = ((color >> 4) & 0x0f) * 17;
pQuad->rgbBlue = (color & 0x0f) * 17;
pQuad->rgbReserved = 0;
}
/* 16 palettes of 16 colors */
RGBQUAD fColorTables[kNumColorTables][kNumEntriesPerColorTable];
MyDIBitmap* SHRScreenToBitmap8(const SHRScreen* pScreen);
MyDIBitmap* SHRDataToBitmap8(const uint8_t* pPixels,
const uint8_t* pSCB, const uint8_t* pColorTable,
int pixelBytesPerLine, int numScanLines,
int outputWidth, int outputHeight);
2007-03-27 17:47:10 +00:00
};
/*
* Reformat an unpacked SHR graphic into a bitmap.
*/
class ReformatUnpackedSHR : public ReformatSHR {
public:
ReformatUnpackedSHR(void) {}
virtual ~ReformatUnpackedSHR(void) {}
2007-03-27 17:47:10 +00:00
virtual void Examine(ReformatHolder* pHolder) override;
virtual int Process(const ReformatHolder* pHolder,
ReformatHolder::ReformatID id, ReformatHolder::ReformatPart part,
ReformatOutput* pOutput) override;
2007-03-27 17:47:10 +00:00
private:
SHRScreen fScreen;
2007-03-27 17:47:10 +00:00
};
/*
* Reformat an unpacked ".APP" SHR graphic from John Elway Quarterback GS
* into a bitmap. (Implementing this was trivial if slightly silly.)
*/
class ReformatJEQSHR : public ReformatSHR {
public:
ReformatJEQSHR(void) {}
virtual ~ReformatJEQSHR(void) {}
2007-03-27 17:47:10 +00:00
virtual void Examine(ReformatHolder* pHolder) override;
virtual int Process(const ReformatHolder* pHolder,
ReformatHolder::ReformatID id, ReformatHolder::ReformatPart part,
ReformatOutput* pOutput) override;
2007-03-27 17:47:10 +00:00
private:
enum { kExpectedLen = 32288 };
SHRScreen fScreen;
2007-03-27 17:47:10 +00:00
};
/*
* Reformat a Paintworks SHR graphic ($c0/0000) into a bitmap.
*/
class ReformatPaintworksSHR : public ReformatSHR {
public:
ReformatPaintworksSHR(void) {}
virtual ~ReformatPaintworksSHR(void) {}
2007-03-27 17:47:10 +00:00
virtual void Examine(ReformatHolder* pHolder) override;
virtual int Process(const ReformatHolder* pHolder,
ReformatHolder::ReformatID id, ReformatHolder::ReformatPart part,
ReformatOutput* pOutput) override;
2007-03-27 17:47:10 +00:00
private:
enum { kMinSize = 223 };
//SHRScreen fScreen;
2007-03-27 17:47:10 +00:00
};
/*
* Reformat a packed SHR graphic ($c0/0001) into a bitmap.
*/
class ReformatPackedSHR : public ReformatSHR {
public:
ReformatPackedSHR(void) {}
virtual ~ReformatPackedSHR(void) {}
2007-03-27 17:47:10 +00:00
virtual void Examine(ReformatHolder* pHolder) override;
virtual int Process(const ReformatHolder* pHolder,
ReformatHolder::ReformatID id, ReformatHolder::ReformatPart part,
ReformatOutput* pOutput) override;
2007-03-27 17:47:10 +00:00
private:
SHRScreen fScreen;
2007-03-27 17:47:10 +00:00
};
/*
* Reformat an Apple-Preferred Format SHR graphic ($c0/0002) into a bitmap.
*
* The graphic could be a standard SHR image, a larger or smaller than normal
* SHR image, or a 3200-color image.
*/
class ReformatAPFSHR : public ReformatSHR {
public:
2014-11-18 05:13:13 +00:00
ReformatAPFSHR(void) : fNonStandard(false), fPixelStore(NULL),
fSCBStore(NULL) {}
virtual ~ReformatAPFSHR(void) {
2014-11-18 05:13:13 +00:00
if (fPixelStore != NULL && fPixelStore != fScreen.pixels)
delete[] fPixelStore;
2014-11-18 05:13:13 +00:00
if (fSCBStore != NULL && fSCBStore != fScreen.scb)
delete[] fSCBStore;
}
virtual void Examine(ReformatHolder* pHolder) override;
virtual int Process(const ReformatHolder* pHolder,
ReformatHolder::ReformatID id, ReformatHolder::ReformatPart part,
ReformatOutput* pOutput) override;
2007-03-27 17:47:10 +00:00
private:
int UnpackMain(const uint8_t* srcPtr, long srcLen);
int UnpackMultipal(uint8_t* dstPtr, const uint8_t* srcPtr, long srcLen);
void UnpackNote(const uint8_t* srcPtr, long srcLen);
/* use this for standard-sized images */
SHRScreen fScreen;
/* set for non-standard images */
bool fNonStandard;
/* use this for non-standard-sized images */
uint8_t* fPixelStore;
uint8_t* fSCBStore;
int fNumScanLines; // #of scan lines in image
int fPixelsPerScanLine;
int fPixelBytesPerLine;
int fOutputWidth;
int fOutputHeight; // scan lines * 2
2007-03-27 17:47:10 +00:00
};
/*
* Reformat a 3200-color SHR graphic into a bitmap.
*/
class Reformat3200SHR : public ReformatSHR {
public:
Reformat3200SHR(void) {}
virtual ~Reformat3200SHR(void) {}
2007-03-27 17:47:10 +00:00
// alternate construction, used by APFSHR
Reformat3200SHR(SHRScreen* pScreen, uint8_t* multiPal) {
memcpy(&fScreen, pScreen, sizeof(fScreen));
memcpy(fExtColorTable, multiPal, sizeof(fExtColorTable));
}
2007-03-27 17:47:10 +00:00
virtual void Examine(ReformatHolder* pHolder) override;
virtual int Process(const ReformatHolder* pHolder,
ReformatHolder::ReformatID id, ReformatHolder::ReformatPart part,
ReformatOutput* pOutput) override;
2007-03-27 17:47:10 +00:00
MyDIBitmap* SHR3200ToBitmap24(void);
2007-03-27 17:47:10 +00:00
protected:
enum {
kExtNumColorTables = kNumLines,
kExtTotalSize = 38400,
};
2007-03-27 17:47:10 +00:00
SHRScreen fScreen; // only "pixels" is valid
2007-03-27 17:47:10 +00:00
/* this holds the 200 color tables, with the entries switched to normal */
uint8_t fExtColorTable[kExtNumColorTables *
kNumEntriesPerColorTable * kColorTableEntrySize];
2007-03-27 17:47:10 +00:00
};
/*
* Reformat a packed 3200-color SHR graphic.
*/
class Reformat3201SHR : public Reformat3200SHR {
public:
Reformat3201SHR(void) {}
virtual ~Reformat3201SHR(void) {}
2007-03-27 17:47:10 +00:00
virtual void Examine(ReformatHolder* pHolder) override;
virtual int Process(const ReformatHolder* pHolder,
ReformatHolder::ReformatID id, ReformatHolder::ReformatPart part,
ReformatOutput* pOutput) override;
2007-03-27 17:47:10 +00:00
};
/*
* Generic DreamGrafix code.
*/
class DreamGrafix {
public:
DreamGrafix(void) : fWidth(0), fHeight(0), fNumColors(0) {}
~DreamGrafix(void) {}
2007-03-27 17:47:10 +00:00
/*
* Scan the file. If it's a DreamGrafix image, extract values from the
* header fields and return "true".
*/
bool ScanDreamGrafix(ReformatHolder* pHolder);
2007-03-27 17:47:10 +00:00
/*
* Unpack a DreamGrafix SHR image compressed with LZW.
*/
bool UnpackDG(const uint8_t* srcBuf, long srcLen,
ReformatSHR::SHRScreen* pScreen, uint8_t* extColorTable);
2007-03-27 17:47:10 +00:00
int fWidth;
int fHeight;
int fNumColors;
2007-03-27 17:47:10 +00:00
private:
static int UnpackLZW(const uint8_t* srcBuf, long srcLen,
uint8_t* dstBuf, long dstLen);
enum { kHeaderOffset = 17 };
2007-03-27 17:47:10 +00:00
};
/*
* Reformat a DreamGrafix 256-color SHR graphic.
*/
class ReformatDG256SHR : public ReformatSHR {
public:
ReformatDG256SHR(void) {}
virtual ~ReformatDG256SHR(void) {}
2007-03-27 17:47:10 +00:00
virtual void Examine(ReformatHolder* pHolder) override;
virtual int Process(const ReformatHolder* pHolder,
ReformatHolder::ReformatID id, ReformatHolder::ReformatPart part,
ReformatOutput* pOutput) override;
2007-03-27 17:47:10 +00:00
private:
DreamGrafix fDG;
SHRScreen fScreen;
2007-03-27 17:47:10 +00:00
};
/*
* Reformat a DreamGrafix 3200-color SHR graphic.
*/
class ReformatDG3200SHR : public Reformat3200SHR {
public:
ReformatDG3200SHR(void) {}
virtual ~ReformatDG3200SHR(void) {}
2007-03-27 17:47:10 +00:00
virtual void Examine(ReformatHolder* pHolder) override;
virtual int Process(const ReformatHolder* pHolder,
ReformatHolder::ReformatID id, ReformatHolder::ReformatPart part,
ReformatOutput* pOutput) override;
2007-03-27 17:47:10 +00:00
private:
DreamGrafix fDG;
2007-03-27 17:47:10 +00:00
};
Large set of changes to restore CiderPress build. CiderPress and MDC now compile, and execute far enough to open their respective "about" boxes, but I doubt they'll do much more than that. * Switch from MBCS to UNICODE APIs Microsoft switched to UTF-16 (by way of UCS-2) a long time ago, and the support for MBCS seems to be getting phased out. So it's time to switch to wide strings. This is a bit awkward for CiderPress because it works with disk and file archives with 8-bit filenames, and I want NufxLib and DiskImgLib to continue to work on Linux (which has largely taken the UTF-8 approach to Unicode). The libraries will continue to work with 8-bit filenames, with CiderPress/MDC doing the conversion at the appropriate point. There were a couple of places where strings from a structure handed back by one of the libraries were used directly in the UI, or vice-versa, which is a problem because we have nowhere to store the result of the conversion. These currently have fixed place-holder "xyzzy" strings. All UI strings are now wide. Various format strings now use "%ls" and "%hs" to explicitly specify wide and narrow. This doesn't play well with gcc, so only the Windows-specific parts use those. * Various updates to vcxproj files The project-file conversion had some cruft that is now largely gone. The build now has a common output directory for the EXEs and libraries, avoiding the old post-build copy steps. * Added zlib 1.2.8 and nufxlib 2.2.2 source snapshots The old "prebuilts" directory is now gone. The libraries are now built as part of building the apps. I added a minimal set of files for zlib, and a full set for nufxlib. The Linux-specific nufxlib goodies are included for the benefit of the Linux utilities, which are currently broken (don't build). * Replace symbols used for include guards Symbols with a leading "__" are reserved.
2014-11-10 23:32:55 +00:00
#endif /*REFORMAT_SUPERHIRES_H*/