Skip to content

Commit 14a3ee2

Browse files
committed
sync rewrite mixins and add code for bbox retrieval etc.
1 parent c6bb616 commit 14a3ee2

33 files changed

+2280
-1453
lines changed

.github/workflows/build-wheels.yml

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -76,15 +76,6 @@ jobs:
7676
brew install libtool
7777
brew install automake
7878
79-
- name: Setup Python
80-
uses: actions/setup-python@v4
81-
with:
82-
python-version: '3.12'
83-
84-
- name: Install CMake using pip
85-
run: |
86-
python -m pip install cmake
87-
8879
- name: Initialize vcpkg
8980
uses: lukka/run-vcpkg@v11
9081
with:
@@ -96,6 +87,7 @@ jobs:
9687
CXX: g++-13
9788
CIBW_ARCHS: auto64
9889
MACOSX_DEPLOYMENT_TARGET: 14.0
90+
CIBW_BEFORE_BUILD: pip install cmake
9991
CIBW_MANYLINUX_X86_64_IMAGE: quay.io/pypa/manylinux_2_34_x86_64:latest
10092
CIBW_BUILD: "${{ matrix.os_dist.dist }}"
10193
# Test not only by running the test suite but also by executing every example we provide. This is to ensure

PhotoshopAPI/src/Core/Geometry/BoundingBox.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,10 @@ namespace Geometry
2626
struct BoundingBox
2727
{
2828
/// The minimum (bottom-left) corner of the bounding box.
29-
Point2D<T> minimum;
29+
Point2D<T> minimum{};
3030

3131
/// The maximum (top-right) corner of the bounding box.
32-
Point2D<T> maximum;
32+
Point2D<T> maximum{};
3333

3434
/// Default constructor.
3535
/// Initializes the bounding box with default `Point2D` values.
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
#include "Macros.h"
2+
3+
#include "Mesh.h"
4+
5+
PSAPI_NAMESPACE_BEGIN
6+
7+
8+
template struct Face<double, 4>;
9+
template struct OctreeNode<double, 128>;
10+
template class Octree<double, 128>;
11+
template struct QuadMesh<double>;
12+
13+
14+
PSAPI_NAMESPACE_END

PhotoshopAPI/src/Core/Geometry/Mesh.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -567,6 +567,14 @@ namespace Geometry
567567
}
568568
}
569569
};
570+
571+
572+
// In most cases we will deal with doubles so we get advantages by explicitly instantiating them
573+
extern template struct Face<double, 4>;
574+
extern template struct OctreeNode<double, 128>;
575+
extern template class Octree<double, 128>;
576+
extern template struct QuadMesh<double>;
577+
570578
}
571579

572580
PSAPI_NAMESPACE_END

PhotoshopAPI/src/Core/Geometry/Point.h

Lines changed: 39 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,8 @@ namespace Geometry
2929
{
3030
using value_type = T;
3131

32-
T x{};
33-
T y{};
32+
T x = static_cast<T>(0);
33+
T y = static_cast<T>(0);
3434

3535
Point2D() = default;
3636
constexpr Point2D(T x_val, T y_val) : x(x_val), y(y_val) {}
@@ -134,8 +134,32 @@ namespace Geometry
134134
// Use a simple hash combination method
135135
return std::hash<T>()(x) ^ (std::hash<T>()(y) << 1); // XOR combined with left shift for distribution
136136
}
137-
};
138137

138+
// Provide a get<I> function for structured bindings
139+
template <std::size_t I>
140+
constexpr auto& get(Point2D<T>& point)
141+
{
142+
if constexpr (I == 0) return point.x;
143+
else if constexpr (I == 1) return point.y;
144+
}
145+
146+
// Provide a get<I> function for structured bindings
147+
template <std::size_t I>
148+
constexpr const auto& get(const Point2D<T>& point)
149+
{
150+
if constexpr (I == 0) return point.x;
151+
else if constexpr (I == 1) return point.y;
152+
}
153+
154+
// Provide a get<I> function for structured bindings
155+
template <std::size_t I>
156+
constexpr auto&& get(Point2D<T>&& point)
157+
{
158+
if constexpr (I == 0) return std::move(point.x);
159+
else if constexpr (I == 1) return std::move(point.y);
160+
}
161+
162+
};
139163

140164
/// Extension of a Point2D to additionally describe the UV coordinate of a given point.
141165
template <typename T>
@@ -180,4 +204,16 @@ namespace std
180204
return point.hash();
181205
}
182206
};
207+
}
208+
209+
// Enable structured bindings
210+
namespace std {
211+
template <typename T>
212+
struct tuple_size<NAMESPACE_PSAPI::Geometry::Point2D<T>> : std::integral_constant<std::size_t, 2> {};
213+
214+
template <typename T, std::size_t I>
215+
struct tuple_element<I, NAMESPACE_PSAPI::Geometry::Point2D<T>> {
216+
static_assert(I < 2, "Index out of bounds for Point2D");
217+
using type = T;
218+
};
183219
}

PhotoshopAPI/src/Core/Struct/ImageChannel.h

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,10 +41,10 @@ struct ImageChannel
4141
{
4242
/// The size of each sub-chunk in the super-chunk. For more information about what a chunk and super-chunk is
4343
/// please refer to the c-blosc2 documentation. Defaults to 8MB
44-
static const uint64_t m_ChunkSize = 1024 * 1024 * 8;
44+
static constexpr uint64_t m_ChunkSize = 1024 * 1024 * 8;
4545
/// This does not indicate the compression method of the channel in memory
4646
/// but rather the compression method it writes the PhotoshopFile with
47-
Enum::Compression m_Compression = Enum::Compression::Raw;
47+
Enum::Compression m_Compression = Enum::Compression::ZipPrediction;
4848
/// Information about what channel this actually is
4949
Enum::ChannelIDInfo m_ChannelID = { Enum::ChannelID::Red, 1 };
5050
/// The size of the original (uncompressed) data in bytes
@@ -57,8 +57,10 @@ struct ImageChannel
5757
int32_t getHeight() const { return m_Height; };
5858
/// Get the x-coordinate of the uncompressed ImageChannel
5959
float getCenterX() const { return m_XCoord; };
60+
void setCenterX(float value) { m_XCoord = value; }
6061
/// Get the y-coordinate of the uncompressed ImageChannel
6162
float getCenterY() const { return m_YCoord; };
63+
void setCenterY(float value) { m_YCoord = value; }
6264
/// Get the total number of chunks held in the ImageChannel
6365
uint64_t getNumChunks() const { return m_NumChunks; };
6466

@@ -117,7 +119,7 @@ struct ImageChannel
117119
// ---------------------------------------------------------------------------------------------------------------------
118120
// ---------------------------------------------------------------------------------------------------------------------
119121
template <typename T>
120-
void getData(std::span<T> buffer, size_t numThreads = 0)
122+
void getData(std::span<T> buffer, size_t numThreads = 0) const
121123
{
122124
PSAPI_PROFILE_FUNCTION();
123125

@@ -203,7 +205,7 @@ struct ImageChannel
203205
// ---------------------------------------------------------------------------------------------------------------------
204206
// ---------------------------------------------------------------------------------------------------------------------
205207
template <typename T>
206-
std::vector<T> getData(size_t numThreads = 0)
208+
std::vector<T> getData(size_t numThreads = 0) const
207209
{
208210
std::vector<T> buffer(m_OrigByteSize / sizeof(T));
209211
getData(std::span<T>(buffer), numThreads);
@@ -318,7 +320,9 @@ struct ImageChannel
318320
~ImageChannel()
319321
{
320322
if (!m_wasFreed)
323+
{
321324
blosc2_schunk_free(m_Data);
325+
}
322326
m_wasFreed = true;
323327
}
324328
ImageChannel() = default;

PhotoshopAPI/src/LayeredFile/LayerTypes/AdjustmentLayer.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,4 +15,8 @@ struct AdjustmentLayer : Layer<T>
1515

1616
};
1717

18+
extern template struct AdjustmentLayer<bpp8_t>;
19+
extern template struct AdjustmentLayer<bpp16_t>;
20+
extern template struct AdjustmentLayer<bpp32_t>;
21+
1822
PSAPI_NAMESPACE_END

PhotoshopAPI/src/LayeredFile/LayerTypes/ArtboardLayer.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,4 +15,8 @@ struct ArtboardLayer : Layer<T>
1515
ArtboardLayer() = default;
1616
};
1717

18+
extern template struct ArtboardLayer<bpp8_t>;
19+
extern template struct ArtboardLayer<bpp16_t>;
20+
extern template struct ArtboardLayer<bpp32_t>;
21+
1822
PSAPI_NAMESPACE_END

PhotoshopAPI/src/LayeredFile/LayerTypes/GroupLayer.h

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ struct LayeredFile;
3232
/// \tparam T The data type for pixel values in layers (e.g., uint8_t, uint16_t, float32_t).
3333
///
3434
template <typename T>
35-
struct GroupLayer : public Layer<T>
35+
struct GroupLayer final: public Layer<T>
3636
{
3737
/// \defgroup layer The groups' child layers
3838
/// @{
@@ -151,13 +151,13 @@ struct GroupLayer : public Layer<T>
151151
/// \param colorMode The color mode for the conversion.
152152
/// \param header The file header for the conversion.
153153
/// \return A tuple containing layerRecords and imageData.
154-
std::tuple<LayerRecord, ChannelImageData> to_photoshop(const Enum::ColorMode colorMode, const FileHeader& header) override
154+
std::tuple<LayerRecord, ChannelImageData> to_photoshop() override
155155
{
156156
PascalString lrName = Layer<T>::generate_name();
157-
ChannelExtents extents = generate_extents(ChannelCoordinates(Layer<T>::m_Width, Layer<T>::m_Height, Layer<T>::m_CenterX, Layer<T>::m_CenterY), header);
157+
ChannelExtents extents = generate_extents(ChannelCoordinates(Layer<T>::m_Width, Layer<T>::m_Height, Layer<T>::m_CenterX, Layer<T>::m_CenterY));
158158
uint8_t clipping = 0u; // No clipping mask for now
159159
LayerRecords::BitFlags bitFlags = LayerRecords::BitFlags(Layer<T>::m_IsLocked, !Layer<T>::m_IsVisible, false);
160-
std::optional<LayerRecords::LayerMaskData> lrMaskData = Layer<T>::generate_mask(header);
160+
std::optional<LayerRecords::LayerMaskData> lrMaskData = Layer<T>::generate_mask();
161161
LayerRecords::LayerBlendingRanges blendingRanges = Layer<T>::generate_blending_ranges();
162162

163163

@@ -299,5 +299,9 @@ struct GroupLayer : public Layer<T>
299299
};
300300

301301

302+
extern template struct GroupLayer<bpp8_t>;
303+
extern template struct GroupLayer<bpp16_t>;
304+
extern template struct GroupLayer<bpp32_t>;
305+
302306

303307
PSAPI_NAMESPACE_END

0 commit comments

Comments
 (0)