/src/libjxl/lib/jxl/test_image.h
Line | Count | Source (jump to first uncovered line) |
1 | | // Copyright (c) the JPEG XL Project Authors. All rights reserved. |
2 | | // |
3 | | // Use of this source code is governed by a BSD-style |
4 | | // license that can be found in the LICENSE file. |
5 | | |
6 | | #ifndef LIB_JXL_TEST_IMAGE_H_ |
7 | | #define LIB_JXL_TEST_IMAGE_H_ |
8 | | |
9 | | #include <jxl/codestream_header.h> |
10 | | #include <jxl/types.h> |
11 | | |
12 | | #include <cstddef> |
13 | | #include <cstdint> |
14 | | #include <string> |
15 | | #include <vector> |
16 | | |
17 | | #include "lib/extras/packed_image.h" |
18 | | #include "lib/jxl/base/status.h" |
19 | | |
20 | | namespace jxl { |
21 | | namespace test { |
22 | | |
23 | | // Returns a test image with some autogenerated pixel content, using 16 bits per |
24 | | // channel, big endian order, 1 to 4 channels |
25 | | // The seed parameter allows to create images with different pixel content. |
26 | | std::vector<uint8_t> GetSomeTestImage(size_t xsize, size_t ysize, |
27 | | size_t num_channels, uint16_t seed); |
28 | | |
29 | | class TestImage { |
30 | | public: |
31 | | TestImage(); |
32 | | |
33 | 0 | extras::PackedPixelFile& ppf() { return ppf_; } |
34 | | |
35 | | Status DecodeFromBytes(const std::vector<uint8_t>& bytes); |
36 | | |
37 | | TestImage& ClearMetadata(); |
38 | | |
39 | | Status SetDimensions(size_t xsize, size_t ysize); |
40 | | |
41 | | Status SetChannels(size_t num_channels); |
42 | | |
43 | | // Sets the same bit depth on color, alpha and all extra channels. |
44 | | TestImage& SetAllBitDepths(uint32_t bits_per_sample, |
45 | | uint32_t exponent_bits_per_sample = 0); |
46 | | |
47 | | TestImage& SetDataType(JxlDataType data_type); |
48 | | |
49 | | TestImage& SetEndianness(JxlEndianness endianness); |
50 | | |
51 | | TestImage& SetRowAlignment(size_t align); |
52 | | |
53 | | Status SetColorEncoding(const std::string& description); |
54 | | |
55 | | Status CoalesceGIFAnimationWithAlpha(); |
56 | | |
57 | | class Frame { |
58 | | public: |
59 | | Frame(TestImage* parent, bool is_preview, size_t index); |
60 | | |
61 | | void ZeroFill(); |
62 | | void RandomFill(uint16_t seed = 177); |
63 | | |
64 | | Status SetValue(size_t y, size_t x, size_t c, float val); |
65 | | |
66 | | private: |
67 | 0 | extras::PackedPixelFile& ppf() const { return parent_->ppf(); } |
68 | | |
69 | 0 | extras::PackedFrame& frame() { |
70 | 0 | return is_preview_ ? *ppf().preview_frame : ppf().frames[index_]; |
71 | 0 | } |
72 | | |
73 | | TestImage* parent_; |
74 | | bool is_preview_; |
75 | | size_t index_; |
76 | | }; |
77 | | |
78 | | StatusOr<Frame> AddFrame(); |
79 | | |
80 | | private: |
81 | | extras::PackedPixelFile ppf_; |
82 | | JxlPixelFormat format_ = {3, JXL_TYPE_UINT8, JXL_LITTLE_ENDIAN, 0}; |
83 | | |
84 | | static void CropLayerInfo(size_t xsize, size_t ysize, JxlLayerInfo* info); |
85 | | |
86 | | static void CropImage(size_t xsize, size_t ysize, extras::PackedImage* image); |
87 | | |
88 | | static JxlDataType DefaultDataType(const JxlBasicInfo& info); |
89 | | }; |
90 | | |
91 | | } // namespace test |
92 | | } // namespace jxl |
93 | | |
94 | | #endif // LIB_JXL_TEST_IMAGE_H_ |