summaryrefslogtreecommitdiffstats
path: root/third_party/jpeg-xl/lib/jxl/test_image.h
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-19 00:47:55 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-19 00:47:55 +0000
commit26a029d407be480d791972afb5975cf62c9360a6 (patch)
treef435a8308119effd964b339f76abb83a57c29483 /third_party/jpeg-xl/lib/jxl/test_image.h
parentInitial commit. (diff)
downloadfirefox-26a029d407be480d791972afb5975cf62c9360a6.tar.xz
firefox-26a029d407be480d791972afb5975cf62c9360a6.zip
Adding upstream version 124.0.1.upstream/124.0.1
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'third_party/jpeg-xl/lib/jxl/test_image.h')
-rw-r--r--third_party/jpeg-xl/lib/jxl/test_image.h96
1 files changed, 96 insertions, 0 deletions
diff --git a/third_party/jpeg-xl/lib/jxl/test_image.h b/third_party/jpeg-xl/lib/jxl/test_image.h
new file mode 100644
index 0000000000..13d0806ec8
--- /dev/null
+++ b/third_party/jpeg-xl/lib/jxl/test_image.h
@@ -0,0 +1,96 @@
+// Copyright (c) the JPEG XL Project Authors. All rights reserved.
+//
+// Use of this source code is governed by a BSD-style
+// license that can be found in the LICENSE file.
+
+#ifndef LIB_JXL_TEST_IMAGE_H_
+#define LIB_JXL_TEST_IMAGE_H_
+
+#include <jxl/codestream_header.h>
+#include <jxl/types.h>
+#include <stddef.h>
+
+#include <cstdint>
+#include <string>
+#include <vector>
+
+#include "lib/extras/packed_image.h"
+#include "lib/jxl/base/span.h"
+
+namespace jxl {
+namespace test {
+
+// Returns a test image with some autogenerated pixel content, using 16 bits per
+// channel, big endian order, 1 to 4 channels
+// The seed parameter allows to create images with different pixel content.
+std::vector<uint8_t> GetSomeTestImage(size_t xsize, size_t ysize,
+ size_t num_channels, uint16_t seed);
+
+class TestImage {
+ public:
+ TestImage();
+
+ extras::PackedPixelFile& ppf() { return ppf_; }
+
+ TestImage& DecodeFromBytes(const std::vector<uint8_t>& bytes);
+
+ TestImage& ClearMetadata();
+
+ TestImage& SetDimensions(size_t xsize, size_t ysize);
+
+ TestImage& SetChannels(size_t num_channels);
+
+ // Sets the same bit depth on color, alpha and all extra channels.
+ TestImage& SetAllBitDepths(uint32_t bits_per_sample,
+ uint32_t exponent_bits_per_sample = 0);
+
+ TestImage& SetDataType(JxlDataType data_type);
+
+ TestImage& SetEndianness(JxlEndianness endianness);
+
+ TestImage& SetRowAlignment(size_t align);
+
+ TestImage& SetColorEncoding(const std::string& description);
+
+ TestImage& CoalesceGIFAnimationWithAlpha();
+
+ class Frame {
+ public:
+ Frame(TestImage* parent, bool is_preview, size_t index);
+
+ void ZeroFill();
+ void RandomFill(uint16_t seed = 177);
+
+ void SetValue(size_t y, size_t x, size_t c, float val);
+
+ private:
+ extras::PackedPixelFile& ppf() const { return parent_->ppf(); }
+
+ extras::PackedFrame& frame() {
+ return is_preview_ ? *ppf().preview_frame : ppf().frames[index_];
+ }
+
+ TestImage* parent_;
+ bool is_preview_;
+ size_t index_;
+ };
+
+ Frame AddFrame();
+
+ Frame AddPreview(size_t xsize, size_t ysize);
+
+ private:
+ extras::PackedPixelFile ppf_;
+ JxlPixelFormat format_ = {3, JXL_TYPE_UINT8, JXL_LITTLE_ENDIAN, 0};
+
+ static void CropLayerInfo(size_t xsize, size_t ysize, JxlLayerInfo* info);
+
+ static void CropImage(size_t xsize, size_t ysize, extras::PackedImage* image);
+
+ static JxlDataType DefaultDataType(const JxlBasicInfo& info);
+};
+
+} // namespace test
+} // namespace jxl
+
+#endif // LIB_JXL_TEST_IMAGE_H_