EmilDohne / PhotoshopAPI

A modern and performant C++20 read/write parser of Photoshop Files (*.psd and *.psb) with fully fledged Python bindings hosted on PyPi
https://photoshopapi.readthedocs.io/en/latest/
BSD 3-Clause "New" or "Revised" License
103 stars 11 forks source link

Writing uneven files fails to decompress #24

Closed EmilDohne closed 8 months ago

EmilDohne commented 9 months ago

When writing uneven files likely due to how we go from bbox coords to center coords (division) It writes out the extents incorrectly. e.g. when using the following code:


using namespace NAMESPACE_PSAPI;

std::filesystem::path psb_path = std::filesystem::current_path();
psb_path += "\\Document.psb";

const uint32_t width = 63;
const uint32_t height = 32;
LayeredFile<bpp32_t> document = { Enum::ColorMode::RGB, width, height };

std::unordered_map <Enum::ChannelID, std::vector<bpp32_t>> channelMap;
channelMap[Enum::ChannelID::Red] = std::vector<bpp32_t>(width * height, .25f);
channelMap[Enum::ChannelID::Green] = std::vector<bpp32_t>(width * height, .25f);
channelMap[Enum::ChannelID::Blue] = std::vector<bpp32_t>(width * height, .25f);

ImageLayer<bpp32_t>::Params layerParams = {};
layerParams.layerName = "Layer";
layerParams.width = width;
layerParams.height = height;

auto layer = std::make_shared<ImageLayer<bpp32_t>>(
    std::move(channelMap),
    layerParams
);
document.addLayer(layer);

File::FileParams params = { .doRead = false, .forceOverwrite = true };
auto outputFile = File(psb_path, params);
auto psdDocumentPtr = LayeredToPhotoshopFile(std::move(document));
psdDocumentPtr->write(outputFile);

It writes out the bbox as [0, 0, 32, 62] which is incorrect as it should be [0, 0, 32, 63] Please investigate