Skip to content

Commit f1cc294

Browse files
author
Bim Overbohm
committed
Support converting 1- and 2-bit data to tiles
1 parent f135121 commit f1cc294

File tree

2 files changed

+11
-2
lines changed

2 files changed

+11
-2
lines changed

src/img2h.cpp

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -401,7 +401,16 @@ int main(int argc, const char *argv[])
401401
imgSize = Magick::Geometry(8, 8);
402402
}
403403
}
404-
nrOfBytesPerImageOrSprite = imgType == Magick::ImageType::PaletteType ? (maxColorMapColors <= 16 ? (nrOfBytesPerImageOrSprite / 2) : nrOfBytesPerImageOrSprite) : (nrOfBytesPerImageOrSprite * 2);
404+
if (imgType == Magick::ImageType::PaletteType)
405+
{
406+
nrOfBytesPerImageOrSprite = maxColorMapColors <= 16 ? (nrOfBytesPerImageOrSprite / 2) : nrOfBytesPerImageOrSprite;
407+
nrOfBytesPerImageOrSprite = maxColorMapColors <= 4 ? (nrOfBytesPerImageOrSprite / 2) : nrOfBytesPerImageOrSprite;
408+
nrOfBytesPerImageOrSprite = maxColorMapColors <= 2 ? (nrOfBytesPerImageOrSprite / 2) : nrOfBytesPerImageOrSprite;
409+
}
410+
else
411+
{
412+
nrOfBytesPerImageOrSprite *= 2;
413+
}
405414
// convert image data to uint32_ts and palette to BGR555 uint16_ts
406415
auto [imageData32, imageOrSpriteStartIndices] = Image::Processing::combineImageData<uint32_t>(images, options.interleavePixels);
407416
// make sure we have the correct number of images. sprites and tiles will have no start indices, thus we need to use nrOfImagesOrSprites

src/processing/spritehelpers.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ std::vector<uint8_t> convertToWidth(const std::vector<uint8_t> &src, uint32_t wi
3232
std::vector<uint8_t> convertToTiles(const std::vector<uint8_t> &src, uint32_t width, uint32_t height, uint32_t bitsPerPixel, uint32_t tileWidth, uint32_t tileHeight)
3333
{
3434
bitsPerPixel = bitsPerPixel == 15 ? 16 : bitsPerPixel;
35-
REQUIRE(bitsPerPixel == 4 || bitsPerPixel == 8 || bitsPerPixel == 16, std::runtime_error, "Bits per pixel must be in [4, 8, 15, 16]");
35+
REQUIRE(bitsPerPixel == 1 || bitsPerPixel == 2 || bitsPerPixel == 4 || bitsPerPixel == 8 || bitsPerPixel == 16, std::runtime_error, "Bits per pixel must be in [1, 2, 4, 8, 15, 16]");
3636
REQUIRE(tileWidth % 8 == 0 && tileHeight % 8 == 0, std::runtime_error, "Tile width and height must be divisible by 8");
3737
REQUIRE(width % 8 == 0 && height % 8 == 0, std::runtime_error, "Width and height must be divisible by 8");
3838
std::vector<uint8_t> dst(src.size());

0 commit comments

Comments
 (0)