diff --git a/include/OP2Utility.h b/include/OP2Utility.h index 7d0b3a49..51de8e1d 100644 --- a/include/OP2Utility.h +++ b/include/OP2Utility.h @@ -18,8 +18,9 @@ #include "../src/Map/Map.h" -#include "../src/Sprite/ArtFile.h" #include "../src/Bitmap/BitmapFile.h" +#include "../src/Sprite/ArtFile.h" +#include "../src/Sprite/OP2BmpLoader.h" #include "../src/Stream/FileReader.h" #include "../src/Stream/SliceReader.h" diff --git a/src/Bitmap/BitmapFile.cpp b/src/Bitmap/BitmapFile.cpp index 485a8a0d..1bf64a3e 100644 --- a/src/Bitmap/BitmapFile.cpp +++ b/src/Bitmap/BitmapFile.cpp @@ -7,7 +7,7 @@ BitmapFile BitmapFile::CreateDefaultIndexed(uint16_t bitCount, uint32_t width, u BitmapFile bitmapFile; bitmapFile.imageHeader = ImageHeader::Create(width, height, bitCount); bitmapFile.palette.resize(bitmapFile.imageHeader.CalcMaxIndexedPaletteSize()); - bitmapFile.pixels.resize(bitmapFile.imageHeader.CalculatePitch() * height); + bitmapFile.pixels.resize(bitmapFile.imageHeader.CalculateDefaultPitch() * height); const std::size_t pixelOffset = sizeof(BmpHeader) + sizeof(ImageHeader) + bitmapFile.palette.size() * sizeof(Color); const std::size_t bitmapFileSize = pixelOffset + bitmapFile.pixels.size() * sizeof(uint8_t); @@ -35,16 +35,36 @@ void BitmapFile::VerifyIndexedPaletteSizeDoesNotExceedBitCount(uint16_t bitCount void BitmapFile::VerifyPixelSizeMatchesImageDimensionsWithPitch() const { - BitmapFile::VerifyPixelSizeMatchesImageDimensionsWithPitch(imageHeader.bitCount, imageHeader.width, imageHeader.height, pixels.size()); + VerifyPixelSizeMatchesImageDimensionsWithPitch(imageHeader.bitCount, FindPitch(), imageHeader.height, pixels.size()); } -void BitmapFile::VerifyPixelSizeMatchesImageDimensionsWithPitch(uint16_t bitCount, int32_t width, int32_t height, std::size_t pixelsWithPitchSize) +void BitmapFile::VerifyPixelSizeMatchesImageDimensionsWithPitch(uint16_t bitCount, std::size_t pitch, int32_t height, std::size_t pixelsWithPitchSize) { - if (pixelsWithPitchSize != ImageHeader::CalculatePitch(bitCount, width) * std::abs(height)) { + if (pixelsWithPitchSize != pitch * std::abs(height)) { throw std::runtime_error("The size of pixels does not match the image's height time pitch"); } } +std::size_t BitmapFile::FindPitch() const +{ + return FindPitch(imageHeader.width, imageHeader.height, pixels.size()); +} + +std::size_t BitmapFile::FindPitch(std::size_t width, std::size_t height, std::size_t pixelCount) +{ + if (pixelCount % height != 0) { + throw std::runtime_error("Unable to calculate a valid pitch based on height and pixel count"); + } + + const std::size_t pitch = pixelCount / height; + + if (pitch < width) { + throw std::runtime_error("Calculated pitch would be smaller than image pixel width"); + } + + return pitch; +} + void BitmapFile::VerifyIndexedImageForSerialization(uint16_t bitCount) { if (!ImageHeader::IsIndexedImage(bitCount)) { diff --git a/src/Bitmap/BitmapFile.h b/src/Bitmap/BitmapFile.h index ed67d17c..e37ac1d9 100644 --- a/src/Bitmap/BitmapFile.h +++ b/src/Bitmap/BitmapFile.h @@ -20,28 +20,31 @@ class BitmapFile BmpHeader bmpHeader; ImageHeader imageHeader; std::vector palette; - std::vector pixels; + std::vector pixels; // Includes pitch + // Uses a default 4 byte pitch static BitmapFile CreateDefaultIndexed(uint16_t bitCount, uint32_t width, uint32_t height); - // BMP Reader only supports Indexed Color palettes (1, 2, and 8 bit BMPs). + // BMP Reader only supports indexed color palettes (1, 2, and 8 bit BMPs). static BitmapFile ReadIndexed(const std::string& filename); static BitmapFile ReadIndexed(Stream::BidirectionalSeekableReader& seekableReader); - // BMP Writer only supporting Indexed Color palettes (1, 2, and 8 bit BMPs). - // @indexedPixels: Must include padding to fill each image row out to the next 4 byte memory border (pitch). - static void WriteIndexed(std::string filename, uint16_t bitCount, int32_t width, int32_t height, std::vector palette, const std::vector& indexedPixels); - static void WriteIndexed(Stream::BidirectionalSeekableWriter& seekableWriter, uint16_t bitCount, int32_t width, int32_t height, std::vector palette, const std::vector& indexedPixels); + // BMP Writer only supports indexed color palettes (1, 2, and 8 bit BMPs). + // @indexedPixels: Size must be padded to a multiple of pitch. (4 byte pitch is typical) + static void WriteIndexed(std::string filename, uint16_t bitCount, int32_t width, int32_t height, std::size_t pitch, std::vector palette, const std::vector& indexedPixels); + static void WriteIndexed(Stream::BidirectionalSeekableWriter& seekableWriter, uint16_t bitCount, int32_t width, int32_t height, std::size_t pitch, std::vector palette, const std::vector& indexedPixels); static void WriteIndexed(std::string filename, const BitmapFile& bitmapFile); void VerifyIndexedPaletteSizeDoesNotExceedBitCount() const; static void VerifyIndexedPaletteSizeDoesNotExceedBitCount(uint16_t bitCount, std::size_t paletteSize); - // Check the pixel count is correct and already includes dummy pixels out to next 4 byte boundary. - // @width: Width in pixels. Do not include the pitch in width. - // @pixelsWithPitchSize: Number of pixels including padding pixels to next 4 byte boundary. + // Check the pixel count is correct and already includes dummy pixels out to pitch boundary. void VerifyPixelSizeMatchesImageDimensionsWithPitch() const; - static void VerifyPixelSizeMatchesImageDimensionsWithPitch(uint16_t bitCount, int32_t width, int32_t height, std::size_t pixelsWithPitchSize); + // @pixelsWithPitchSize: Number of pixels including padding pixels to next pitch boundary. + static void VerifyPixelSizeMatchesImageDimensionsWithPitch(uint16_t bitCount, std::size_t pitch, int32_t height, std::size_t pixelsWithPitchSize); + + std::size_t FindPitch() const; + static std::size_t FindPitch(std::size_t width, std::size_t height, std::size_t pixelCount); void Validate() const; @@ -55,8 +58,8 @@ class BitmapFile static void ReadPixels(Stream::BidirectionalSeekableReader& seekableReader, BitmapFile& bitmapFile); // Write - static void WriteHeaders(Stream::BidirectionalSeekableWriter& seekableWriter, uint16_t bitCount, int width, int height, const std::vector& palette); - static void WritePixels(Stream::BidirectionalSeekableWriter& seekableWriter, const std::vector& pixels, int32_t width, uint16_t bitCount); + static void WriteHeaders(Stream::BidirectionalSeekableWriter& seekableWriter, uint16_t bitCount, int width, int height, std::size_t pitch, const std::vector& palette); + static void WritePixels(Stream::BidirectionalSeekableWriter& seekableWriter, const std::vector& pixels, int32_t width, uint16_t bitCount, std::size_t pitch); }; bool operator==(const BitmapFile& lhs, const BitmapFile& rhs); diff --git a/src/Bitmap/Color.h b/src/Bitmap/Color.h index 41558bab..c4fa3552 100644 --- a/src/Bitmap/Color.h +++ b/src/Bitmap/Color.h @@ -19,7 +19,7 @@ static_assert(4 == sizeof(Color), "Color is an unexpected size"); bool operator==(const Color& lhs, const Color& rhs); bool operator!=(const Color& lhs, const Color& rhs); -using Palette = std::array; +using Palette8Bit = std::array; namespace DiscreteColor { diff --git a/src/Bitmap/ImageHeader.cpp b/src/Bitmap/ImageHeader.cpp index 4c412313..fbbe9044 100644 --- a/src/Bitmap/ImageHeader.cpp +++ b/src/Bitmap/ImageHeader.cpp @@ -63,12 +63,12 @@ void ImageHeader::VerifyValidBitCount(uint16_t bitCount) } } -std::size_t ImageHeader::CalculatePitch() const +std::size_t ImageHeader::CalculateDefaultPitch() const { - return ImageHeader::CalculatePitch(bitCount, width); + return ImageHeader::CalculateDefaultPitch(bitCount, width); } -std::size_t ImageHeader::CalculatePitch(uint16_t bitCount, int32_t width) +std::size_t ImageHeader::CalculateDefaultPitch(uint16_t bitCount, int32_t width) { const auto bytesOfPixelsPerRow = CalcPixelByteWidth(bitCount, width); return (bytesOfPixelsPerRow + 3) & ~3; diff --git a/src/Bitmap/ImageHeader.h b/src/Bitmap/ImageHeader.h index 939d8355..1371e91b 100644 --- a/src/Bitmap/ImageHeader.h +++ b/src/Bitmap/ImageHeader.h @@ -42,8 +42,9 @@ struct ImageHeader void VerifyValidBitCount() const; static void VerifyValidBitCount(uint16_t bitCount); - std::size_t CalculatePitch() const; - static std::size_t CalculatePitch(uint16_t bitCount, int32_t width); + // Default pitch granularity is 4 bytes + std::size_t CalculateDefaultPitch() const; + static std::size_t CalculateDefaultPitch(uint16_t bitCount, int32_t width); // Does not include padding std::size_t CalcPixelByteWidth() const; diff --git a/src/Bitmap/IndexedBmpReader.cpp b/src/Bitmap/IndexedBmpReader.cpp index 2c263cc2..4e68ff36 100644 --- a/src/Bitmap/IndexedBmpReader.cpp +++ b/src/Bitmap/IndexedBmpReader.cpp @@ -62,8 +62,9 @@ void BitmapFile::ReadPalette(Stream::BidirectionalSeekableReader& seekableReader void BitmapFile::ReadPixels(Stream::BidirectionalSeekableReader& seekableReader, BitmapFile& bitmapFile) { - std::size_t pixelContainerSize = bitmapFile.bmpHeader.size - bitmapFile.bmpHeader.pixelOffset; - BitmapFile::VerifyPixelSizeMatchesImageDimensionsWithPitch(bitmapFile.imageHeader.bitCount, bitmapFile.imageHeader.width, bitmapFile.imageHeader.height, pixelContainerSize); + const std::size_t pixelContainerSize = bitmapFile.bmpHeader.size - bitmapFile.bmpHeader.pixelOffset; + const std::size_t pitch = FindPitch(bitmapFile.imageHeader.width, bitmapFile.imageHeader.height, pixelContainerSize); + BitmapFile::VerifyPixelSizeMatchesImageDimensionsWithPitch(bitmapFile.imageHeader.bitCount, pitch, bitmapFile.imageHeader.height, pixelContainerSize); bitmapFile.pixels.clear(); bitmapFile.pixels.resize(pixelContainerSize); diff --git a/src/Bitmap/IndexedBmpWriter.cpp b/src/Bitmap/IndexedBmpWriter.cpp index df9fe8d1..020b125b 100644 --- a/src/Bitmap/IndexedBmpWriter.cpp +++ b/src/Bitmap/IndexedBmpWriter.cpp @@ -11,34 +11,35 @@ void BitmapFile::WriteIndexed(std::string filename, const BitmapFile& bitmapFile } bitmapFile.Validate(); + const auto pitch = FindPitch(bitmapFile.imageHeader.width, bitmapFile.imageHeader.height, bitmapFile.pixels.size()); - WriteIndexed(filename, bitmapFile.imageHeader.bitCount, bitmapFile.imageHeader.width, bitmapFile.imageHeader.height, bitmapFile.palette, bitmapFile.pixels); + WriteIndexed(filename, bitmapFile.imageHeader.bitCount, bitmapFile.imageHeader.width, bitmapFile.imageHeader.height, pitch, bitmapFile.palette, bitmapFile.pixels); } -void BitmapFile::WriteIndexed(std::string filename, uint16_t bitCount, int32_t width, int32_t height, std::vector palette, const std::vector& indexedPixels) +void BitmapFile::WriteIndexed(std::string filename, uint16_t bitCount, int32_t width, int32_t height, std::size_t pitch, std::vector palette, const std::vector& indexedPixels) { Stream::FileWriter fileWriter(filename); - WriteIndexed(fileWriter, bitCount, width, height, palette, indexedPixels); + WriteIndexed(fileWriter, bitCount, width, height, pitch, palette, indexedPixels); } -void BitmapFile::WriteIndexed(Stream::BidirectionalSeekableWriter& seekableWriter, uint16_t bitCount, int32_t width, int32_t height, std::vector palette, const std::vector& indexedPixels) +void BitmapFile::WriteIndexed(Stream::BidirectionalSeekableWriter& seekableWriter, uint16_t bitCount, int32_t width, int32_t height, std::size_t pitch, std::vector palette, const std::vector& indexedPixels) { VerifyIndexedImageForSerialization(bitCount); VerifyIndexedPaletteSizeDoesNotExceedBitCount(bitCount, palette.size()); - VerifyPixelSizeMatchesImageDimensionsWithPitch(bitCount, width, height, indexedPixels.size()); + VerifyPixelSizeMatchesImageDimensionsWithPitch(bitCount, pitch, height, indexedPixels.size()); palette.resize(ImageHeader::CalcMaxIndexedPaletteSize(bitCount), DiscreteColor::Black); - WriteHeaders(seekableWriter, bitCount, width, height, palette); + WriteHeaders(seekableWriter, bitCount, width, height, pitch, palette); seekableWriter.Write(palette); - WritePixels(seekableWriter, indexedPixels, width, bitCount); + WritePixels(seekableWriter, indexedPixels, width, bitCount, pitch); } -void BitmapFile::WriteHeaders(Stream::BidirectionalSeekableWriter& seekableWriter, uint16_t bitCount, int width, int height, const std::vector& palette) +void BitmapFile::WriteHeaders(Stream::BidirectionalSeekableWriter& seekableWriter, uint16_t bitCount, int width, int height, std::size_t pitch, const std::vector& palette) { std::size_t pixelOffset = sizeof(BmpHeader) + sizeof(ImageHeader) + palette.size() * sizeof(Color); - std::size_t fileSize = pixelOffset + ImageHeader::CalculatePitch(bitCount, width) * std::abs(height); + std::size_t fileSize = pixelOffset + pitch * std::abs(height); if (fileSize > UINT32_MAX) { throw std::runtime_error("Bitmap size is too large to save to disk."); @@ -51,9 +52,8 @@ void BitmapFile::WriteHeaders(Stream::BidirectionalSeekableWriter& seekableWrite seekableWriter.Write(imageHeader); } -void BitmapFile::WritePixels(Stream::BidirectionalSeekableWriter& seekableWriter, const std::vector& pixels, int32_t width, uint16_t bitCount) +void BitmapFile::WritePixels(Stream::BidirectionalSeekableWriter& seekableWriter, const std::vector& pixels, int32_t width, uint16_t bitCount, std::size_t pitch) { - const auto pitch = ImageHeader::CalculatePitch(bitCount, width); const auto bytesOfPixelsPerRow = ImageHeader::CalcPixelByteWidth(bitCount, width); const std::vector padding(pitch - bytesOfPixelsPerRow, 0); diff --git a/src/Sprite/ArtFile.h b/src/Sprite/ArtFile.h index 1daa8f88..f563c954 100644 --- a/src/Sprite/ArtFile.h +++ b/src/Sprite/ArtFile.h @@ -17,7 +17,7 @@ namespace Stream { struct ArtFile { public: - std::vector palettes; + std::vector palettes; std::vector imageMetas; std::vector animations; uint32_t unknownAnimationCount; diff --git a/src/Sprite/ImageMeta.h b/src/Sprite/ImageMeta.h index cdb5765a..ca79b1f4 100644 --- a/src/Sprite/ImageMeta.h +++ b/src/Sprite/ImageMeta.h @@ -23,7 +23,7 @@ struct ImageMeta { static_assert(2 == sizeof(ImageType), "ImageMeta::ImageType is an unexpected size"); - uint32_t scanLineByteWidth; //number of bytes in each scan line of image (this should be the width of the image rounded up to a 32 bit boundary) + uint32_t scanLineByteWidth; //number of bytes in each scan line of image (this should be the width of the image rounded up to a 4 byte boundary) uint32_t pixelDataOffset; // Offset of the pixel data in the .bmp file uint32_t height; // Height of image in pixels uint32_t width; // Width of image in pixels diff --git a/src/Sprite/OP2BmpLoader.cpp b/src/Sprite/OP2BmpLoader.cpp index 96a4062a..37bac521 100644 --- a/src/Sprite/OP2BmpLoader.cpp +++ b/src/Sprite/OP2BmpLoader.cpp @@ -5,21 +5,25 @@ #include #include +const std::vector OP2BmpLoader::DefaultMonochromePalette{ Color{0, 0, 0}, Color{255, 255, 255} }; + OP2BmpLoader::OP2BmpLoader(std::string bmpFilename, std::string artFilename) : bmpReader(bmpFilename), artFile(ArtFile::Read(artFilename)) { } +OP2BmpLoader::OP2BmpLoader(std::string bmpFilename, Stream::BidirectionalSeekableReader& artFileStream) : + bmpReader(bmpFilename), artFile(ArtFile::Read(artFileStream)) { } + void OP2BmpLoader::ExtractImage(std::size_t index, const std::string& filenameOut) { artFile.VerifyImageIndexInBounds(index); - ImageMeta& imageMeta = artFile.imageMetas[index]; + const ImageMeta& imageMeta = artFile.imageMetas[index]; - std::vector palette(artFile.palettes[imageMeta.paletteIndex].size()); - std::copy(artFile.palettes[imageMeta.paletteIndex].begin(), artFile.palettes[imageMeta.paletteIndex].end(), palette.begin()); + const auto palette = CreatePalette(imageMeta); - std::size_t pixelOffset = imageMeta.pixelDataOffset + 14 + sizeof(ImageHeader) + palette.size() * sizeof(Color); + const std::size_t pixelOffset = imageMeta.pixelDataOffset + 14 + sizeof(ImageHeader) + palette.size() * sizeof(Color); - auto pixels = GetPixels(pixelOffset, imageMeta.scanLineByteWidth * imageMeta.height); + const auto pixels = GetPixels(pixelOffset, imageMeta.scanLineByteWidth * imageMeta.height); std::vector pixelContainer(imageMeta.scanLineByteWidth * imageMeta.height); (*pixels).Read(pixelContainer); @@ -29,7 +33,30 @@ void OP2BmpLoader::ExtractImage(std::size_t index, const std::string& filenameOu throw std::runtime_error("Image height is too large to fit in standard bitmap file format."); } - BitmapFile::WriteIndexed(filenameOut, imageMeta.GetBitCount(), imageMeta.width, -static_cast(imageMeta.height), palette, pixelContainer); + BitmapFile::WriteIndexed(filenameOut, imageMeta.GetBitCount(), imageMeta.width, -static_cast(imageMeta.height), imageMeta.scanLineByteWidth, palette, pixelContainer); +} + +std::size_t OP2BmpLoader::FrameCount(std::size_t animationIndex) const { + return artFile.animations[animationIndex].frames.size(); +} + +std::size_t OP2BmpLoader::LayerCount(std::size_t animationIndex, std::size_t frameIndex) const { + return artFile.animations[animationIndex].frames[frameIndex].layers.size(); +} + +std::vector OP2BmpLoader::CreatePalette(const ImageMeta& imageMeta) const +{ + std::vector palette; + + if (imageMeta.GetBitCount() == 1) { + return DefaultMonochromePalette; + } + else { + palette.resize(artFile.palettes[imageMeta.paletteIndex].size()); + std::copy(artFile.palettes[imageMeta.paletteIndex].begin(), artFile.palettes[imageMeta.paletteIndex].end(), palette.begin()); + } + + return palette; } std::unique_ptr OP2BmpLoader::GetPixels(std::size_t startingIndex, std::size_t length) diff --git a/src/Sprite/OP2BmpLoader.h b/src/Sprite/OP2BmpLoader.h index a17a9276..beaab2b1 100644 --- a/src/Sprite/OP2BmpLoader.h +++ b/src/Sprite/OP2BmpLoader.h @@ -10,8 +10,14 @@ class OP2BmpLoader { public: OP2BmpLoader(std::string bmpFilename, std::string artFilename); + OP2BmpLoader(std::string bmpFilename, Stream::BidirectionalSeekableReader& artFileStream); void ExtractImage(std::size_t index, const std::string& filenameOut); + + inline std::size_t ImageCount() const { return artFile.imageMetas.size(); } + inline std::size_t AnimationCount() const { return artFile.animations.size(); } + std::size_t FrameCount(std::size_t animationIndex) const; + std::size_t LayerCount(std::size_t animationIndex, std::size_t frameIndex) const; private: // Bmp loader for Outpost 2 specific BMP file @@ -19,6 +25,8 @@ class OP2BmpLoader // Actual palette data and range of pixels to form each image is contained in the .prt file. Stream::FileReader bmpReader; ArtFile artFile; + static const std::vector DefaultMonochromePalette; + std::vector CreatePalette(const ImageMeta& imageMeta) const; std::unique_ptr GetPixels(std::size_t startingIndex, std::size_t length); }; diff --git a/src/Sprite/PaletteHeader.cpp b/src/Sprite/PaletteHeader.cpp index 06919460..a35e65e4 100644 --- a/src/Sprite/PaletteHeader.cpp +++ b/src/Sprite/PaletteHeader.cpp @@ -10,7 +10,7 @@ PaletteHeader::PaletteHeader() : remainingTagCount(0) {} PaletteHeader::PaletteHeader(const ArtFile& artFile) : remainingTagCount(1) { - uint64_t dataSize = sizeof(Palette); + uint64_t dataSize = sizeof(Palette8Bit); uint64_t overallSize = 4 + sizeof(overallHeader) + sizeof(sectionHeader) + sizeof(remainingTagCount) + dataSize; diff --git a/test/Bitmap/BitmapFile.test.cpp b/test/Bitmap/BitmapFile.test.cpp index bbc2c7df..aa0ccb01 100644 --- a/test/Bitmap/BitmapFile.test.cpp +++ b/test/Bitmap/BitmapFile.test.cpp @@ -62,13 +62,13 @@ TEST(BitmapFile, VerifyIndexedPaletteSizeDoesNotExceedBitCount) TEST(BitmapFile, VerifyPixelSizeMatchesImageDimensionsWithPitch) { - EXPECT_NO_THROW(BitmapFile::VerifyPixelSizeMatchesImageDimensionsWithPitch(1, 1, 1, 4)); - EXPECT_THROW(BitmapFile::VerifyPixelSizeMatchesImageDimensionsWithPitch(1, 1, 1, 1), std::runtime_error); + EXPECT_NO_THROW(BitmapFile::VerifyPixelSizeMatchesImageDimensionsWithPitch(1, 4, 1, 4)); + EXPECT_THROW(BitmapFile::VerifyPixelSizeMatchesImageDimensionsWithPitch(1, 4, 1, 1), std::runtime_error); // Test non-static version of function - BitmapFile bitmapFile = BitmapFile::CreateDefaultIndexed(1, 1, 1);; + BitmapFile bitmapFile = BitmapFile::CreateDefaultIndexed(1, 1, 2);; EXPECT_NO_THROW(bitmapFile.VerifyPixelSizeMatchesImageDimensionsWithPitch()); - bitmapFile.pixels.resize(1, 0); + bitmapFile.pixels.resize(3, 0); // Cannot calculate a valid pitch EXPECT_THROW(bitmapFile.VerifyPixelSizeMatchesImageDimensionsWithPitch(), std::runtime_error); } diff --git a/test/Bitmap/ImageHeader.test.cpp b/test/Bitmap/ImageHeader.test.cpp index b1fdf75a..49c9718e 100644 --- a/test/Bitmap/ImageHeader.test.cpp +++ b/test/Bitmap/ImageHeader.test.cpp @@ -77,23 +77,23 @@ TEST(ImageHeader, VerifyValidBitCount) TEST(ImageHeader, CalculatePitch) { - EXPECT_EQ(4, ImageHeader::CalculatePitch(1, 1)); - EXPECT_EQ(4, ImageHeader::CalculatePitch(1, 32)); - EXPECT_EQ(8, ImageHeader::CalculatePitch(1, 33)); + EXPECT_EQ(4, ImageHeader::CalculateDefaultPitch(1, 1)); + EXPECT_EQ(4, ImageHeader::CalculateDefaultPitch(1, 32)); + EXPECT_EQ(8, ImageHeader::CalculateDefaultPitch(1, 33)); - EXPECT_EQ(4, ImageHeader::CalculatePitch(4, 1)); - EXPECT_EQ(4, ImageHeader::CalculatePitch(4, 8)); - EXPECT_EQ(8, ImageHeader::CalculatePitch(4, 9)); + EXPECT_EQ(4, ImageHeader::CalculateDefaultPitch(4, 1)); + EXPECT_EQ(4, ImageHeader::CalculateDefaultPitch(4, 8)); + EXPECT_EQ(8, ImageHeader::CalculateDefaultPitch(4, 9)); - EXPECT_EQ(4, ImageHeader::CalculatePitch(8, 1)); - EXPECT_EQ(4, ImageHeader::CalculatePitch(8, 4)); - EXPECT_EQ(8, ImageHeader::CalculatePitch(8, 5)); + EXPECT_EQ(4, ImageHeader::CalculateDefaultPitch(8, 1)); + EXPECT_EQ(4, ImageHeader::CalculateDefaultPitch(8, 4)); + EXPECT_EQ(8, ImageHeader::CalculateDefaultPitch(8, 5)); // Test non-static version of function ImageHeader imageHeader; imageHeader.bitCount = 1; imageHeader.width = 1; - EXPECT_EQ(4, imageHeader.CalculatePitch()); + EXPECT_EQ(4, imageHeader.CalculateDefaultPitch()); } TEST(ImageHeader, CalcByteWidth) diff --git a/test/Bitmap/IndexedBmpWriter.test.cpp b/test/Bitmap/IndexedBmpWriter.test.cpp index 2d434801..6f82b9c4 100644 --- a/test/Bitmap/IndexedBmpWriter.test.cpp +++ b/test/Bitmap/IndexedBmpWriter.test.cpp @@ -12,8 +12,8 @@ TEST(BitmapFile, InvalidBitCountThrows) const std::vector pixels(4, 0); const std::string filename = "Sprite/data/MonochromeTest.bmp"; - EXPECT_THROW(BitmapFile::WriteIndexed(filename, 3, 1, 1, palette, pixels), std::runtime_error); - EXPECT_THROW(BitmapFile::WriteIndexed(filename, 32, 1, 1, palette, pixels), std::runtime_error); + EXPECT_THROW(BitmapFile::WriteIndexed(filename, 3, 1, 1, 4, palette, pixels), std::runtime_error); + EXPECT_THROW(BitmapFile::WriteIndexed(filename, 32, 1, 1, 4, palette, pixels), std::runtime_error); XFile::DeletePath(filename); } @@ -24,7 +24,7 @@ TEST(BitmapFile, TooManyPaletteEntriesThrows) const std::vector pixels(4, 0); const std::string filename("Sprite/data/PaletteRangeTest.bmp"); - EXPECT_THROW(BitmapFile::WriteIndexed(filename, 1, 1, 1, palette, pixels), std::runtime_error); + EXPECT_THROW(BitmapFile::WriteIndexed(filename, 1, 1, 1, 4, palette, pixels), std::runtime_error); XFile::DeletePath(filename); } @@ -35,7 +35,7 @@ TEST(BitmapFile, WritePartiallyFilledPalette) const std::vector pixels(4, 0); const std::string filename("Sprite/data/PaletteRangeTest.bmp"); - EXPECT_NO_THROW(BitmapFile::WriteIndexed(filename, 1, 1, 1, palette, pixels)); + EXPECT_NO_THROW(BitmapFile::WriteIndexed(filename, 1, 1, 1, 4, palette, pixels)); XFile::DeletePath(filename); } @@ -46,10 +46,10 @@ TEST(BitmapFile, IncorrectPixelPaddingThrows) const std::string filename("Sprite/data/IncorrectPixelPaddingTest.bmp"); std::vector pixels(3, 0); - EXPECT_THROW(BitmapFile::WriteIndexed(filename, 1, 1, 1, palette, pixels), std::runtime_error); + EXPECT_THROW(BitmapFile::WriteIndexed(filename, 1, 1, 1, 4, palette, pixels), std::runtime_error); pixels.resize(5, 0); - EXPECT_THROW(BitmapFile::WriteIndexed(filename, 1, 1, 1, palette, pixels), std::runtime_error); + EXPECT_THROW(BitmapFile::WriteIndexed(filename, 1, 1, 1, 4, palette, pixels), std::runtime_error); XFile::DeletePath(filename); } diff --git a/test/Sprite/ArtWriter.test.cpp b/test/Sprite/ArtWriter.test.cpp index 0cfe83f9..8c316db9 100644 --- a/test/Sprite/ArtWriter.test.cpp +++ b/test/Sprite/ArtWriter.test.cpp @@ -27,7 +27,7 @@ TEST(ArtWriter, BlankFilename) class SimpleArtFile : public ::testing::Test { public: inline SimpleArtFile() { - artFile.palettes.push_back(Palette()); + artFile.palettes.push_back(Palette8Bit()); ImageMeta imageMeta; imageMeta.width = 10;