Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions PhotoshopAPI/src/Core/FileIO/Read.h
Original file line number Diff line number Diff line change
Expand Up @@ -252,8 +252,7 @@ void ReadBinaryArray(ByteStream& stream, std::span<T> buffer, uint64_t offset, u
size, sizeof(T));
}

std::vector<T> data(size / sizeof(T));
stream.read(Util::toWritableBytes(data), offset);
stream.read(Util::toWritableBytes(buffer), offset);
endianDecodeBEArray<T>(buffer);
}

Expand Down
20 changes: 20 additions & 0 deletions PhotoshopAPI/src/PhotoshopFile/LayerAndMaskInformation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -828,6 +828,20 @@ void ChannelImageData::read(ByteStream& stream, const FileHeader& header, const
maxHeight = static_cast<uint32_t>(lrMask.height);
}
}
else if (layerRecord.m_LayerMaskData.value().m_VectorMask.has_value())
{
const LayerRecords::LayerMask mask = layerRecord.m_LayerMaskData.value().m_VectorMask.value();
// Generate our coordinates from the mask extents instead
ChannelCoordinates lrMask = generateChannelCoordinates(ChannelExtents(mask.m_Top, mask.m_Left, mask.m_Bottom, mask.m_Right));
if (static_cast<uint32_t>(lrMask.width) > maxWidth)
{
maxWidth = static_cast<uint32_t>(lrMask.width);
}
if (static_cast<uint32_t>(lrMask.height) > maxHeight)
{
maxHeight = static_cast<uint32_t>(lrMask.height);
}
}
}
std::vector<uint8_t> buffer;
if (header.m_Depth == Enum::BitDepth::BD_8)
Expand Down Expand Up @@ -867,6 +881,12 @@ void ChannelImageData::read(ByteStream& stream, const FileHeader& header, const
// Generate our coordinates from the mask extents instead
coordinates = generateChannelCoordinates(ChannelExtents(mask.m_Top, mask.m_Left, mask.m_Bottom, mask.m_Right));
}
else if (layerRecord.m_LayerMaskData.has_value() && layerRecord.m_LayerMaskData->m_VectorMask.has_value())
{
const LayerRecords::LayerMask mask = layerRecord.m_LayerMaskData.value().m_VectorMask.value();
// Generate our coordinates from the mask extents instead
coordinates = generateChannelCoordinates(ChannelExtents(mask.m_Top, mask.m_Left, mask.m_Bottom, mask.m_Right));
}
}
// Get the compression of the channel. We must read it this way as the offset has to be correct before parsing
Enum::Compression channelCompression = Enum::Compression::ZipPrediction;
Expand Down
16 changes: 16 additions & 0 deletions PhotoshopAPI/src/Util/FileUtil.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,4 +48,20 @@ namespace Util
return std::span<const uint8_t>(reinterpret_cast<const uint8_t*>(vec.data()), vec.size() * sizeof(T));
}

template <typename T>
std::span<uint8_t> toWritableBytes(std::span<T> span)
{
// Ensure the vector is not empty and the type is trivially copyable
static_assert(std::is_trivially_copyable_v<T>, "Type must be trivially copyable");
return std::span<uint8_t>(reinterpret_cast<uint8_t*>(span.data()), span.size() * sizeof(T));
}

template <typename T>
std::span<const uint8_t> toBytes(const std::span<const T> span)
{
// Ensure the vector is not empty and the type is trivially copyable
static_assert(std::is_trivially_copyable_v<T>, "Type must be trivially copyable");
return std::span<const uint8_t>(reinterpret_cast<const uint8_t*>(span.data()), span.size() * sizeof(T));
}

}
Loading