From b2b3a3f6689cff4dbf719138d824045f32041d6d Mon Sep 17 00:00:00 2001 From: Christian Gmeiner Date: Tue, 22 Sep 2009 10:39:41 +0200 Subject: use section method to get a pointer to a valid sSection or NULL --- spuencoder.c | 20 ++++++++++---------- spuencoder.h | 2 +- spuregion.c | 9 +++++++++ spuregion.h | 4 +++- 4 files changed, 23 insertions(+), 12 deletions(-) diff --git a/spuencoder.c b/spuencoder.c index 18749f9..811422f 100644 --- a/spuencoder.c +++ b/spuencoder.c @@ -142,19 +142,19 @@ void cSpuEncoder::writeNibble(uint8_t val) } } -void cSpuEncoder::writeColorAndAlpha(sSection &sec, bool withCMD) +void cSpuEncoder::writeColorAndAlpha(sSection *sec, bool withCMD) { if (withCMD) { spu[written++] = CMD_SET_COLOR; } - spu[written++] = (sec.colIndex[0] << 4) | (sec.colIndex[1] & 0x0f); - spu[written++] = (sec.colIndex[2] << 4) | (sec.colIndex[3] & 0x0f); + spu[written++] = (sec->colIndex[0] << 4) | (sec->colIndex[1] & 0x0f); + spu[written++] = (sec->colIndex[2] << 4) | (sec->colIndex[3] & 0x0f); if (withCMD) { spu[written++] = CMD_SET_ALPHA; } - spu[written++] = (opacity[sec.colIndex[0]] << 4) | (opacity[sec.colIndex[1]] & 0x0f); - spu[written++] = (opacity[sec.colIndex[2]] << 4) | (opacity[sec.colIndex[3]] & 0x0f); + spu[written++] = (opacity[sec->colIndex[0]] << 4) | (opacity[sec->colIndex[1]] & 0x0f); + spu[written++] = (opacity[sec->colIndex[2]] << 4) | (opacity[sec->colIndex[3]] & 0x0f); } void cSpuEncoder::writeRegionInformation() @@ -177,13 +177,13 @@ void cSpuEncoder::writeRegionInformation() spu[written++] = (((reg->openSections() & 0x0f) << 4)| ((reg->endLine >> 8) & 0x0f)); spu[written++] = reg->endLine & 0xff; - for (size_t j = 0; j <= reg->openSections(); j++) { + for (size_t j = 0; j < reg->openSections(); j++) { - sSection sec = reg->sections[i]; + sSection *sec = reg->section(i); // define section (PXCTLI) - spu[written++] = (sec.startColumn >> 8) & 0x0f; - spu[written++] = sec.startColumn & 0xff; + spu[written++] = (sec->startColumn >> 8) & 0x0f; + spu[written++] = sec->startColumn & 0xff; // write color and alpha writeColorAndAlpha(sec, false); @@ -290,7 +290,7 @@ void cSpuEncoder::generateSpuData(bool topAndBottom) throw (char const* ) spu[written++] = bottomStart & 0xff; // write color-> palette index and alpha data for the first region - writeColorAndAlpha(regions.front()->sections[0], true); + writeColorAndAlpha(regions.front()->section(0), true); // write informations for other regions if (regions.size() > 1) { diff --git a/spuencoder.h b/spuencoder.h index 149ee5c..c48863d 100644 --- a/spuencoder.h +++ b/spuencoder.h @@ -66,7 +66,7 @@ private: tColor palcolors[16]; void writeNibble(uint8_t val); - void writeColorAndAlpha(sSection &sec, bool withCMD); + void writeColorAndAlpha(sSection *sec, bool withCMD); void writeRegionInformation(); void generateColorPalette(); void generateSpuData(bool topAndBottom) throw (char const* ); diff --git a/spuregion.c b/spuregion.c index 6055ec3..973b787 100644 --- a/spuregion.c +++ b/spuregion.c @@ -39,6 +39,15 @@ uint8_t cSpuRegion::openSections() return usedSections + 1; } +sSection *cSpuRegion::section(uint8_t num) +{ + if (usedSections == MAX_SECTIONS) { + return NULL; + } + + return §ions[num]; +} + bool cSpuRegion::addColIndex(tIndex idx) { sSection *sec = §ions[usedSections]; diff --git a/spuregion.h b/spuregion.h index 0af9996..8fa0e3d 100644 --- a/spuregion.h +++ b/spuregion.h @@ -30,6 +30,7 @@ #include const static int MAX_COLORS = 4; +const static int MAX_SECTIONS = 15; // we can support up to 15 sections per region struct sSection { uint16_t startColumn; @@ -45,15 +46,16 @@ public: uint16_t startLine; uint16_t endLine; - sSection sections[15]; // sections per region uint8_t openSections(); + sSection *section(uint8_t num); bool addColIndex(tIndex idx); bool containsColIndex(tIndex idx); private: uint8_t usedSections; + sSection sections[MAX_SECTIONS]; }; #endif // SPUREGION_H -- cgit v1.2.3