├── .github
└── workflows
│ └── main.yml
├── .gitignore
├── .gitmodules
├── CMakeLists.txt
├── LICENSE
├── README.md
└── src
├── main
├── CodestreamSequence.cpp
├── CodestreamSequence.h
├── J2KProfileULMap.h
├── jid-reader.cpp
└── jid-writer.cpp
└── test
└── resources
├── README.md
├── crowdrun-lowlatency.1920x1080-422-10bit-50p.mjc
├── j2c-sequence
├── mer_shrt_23976_vdm_sdr_rec709_g24_3840x2160_20170913.000000.j2c
└── mer_shrt_23976_vdm_sdr_rec709_g24_3840x2160_20170913.000001.j2c
├── part1.j2c
├── part1.mjc
├── part15.j2c
├── part15.mjc
└── yuv422_10b_p15.j2c
/.github/workflows/main.yml:
--------------------------------------------------------------------------------
1 | name: build and test
2 |
3 | on: push
4 |
5 | jobs:
6 | build:
7 | runs-on: ubuntu-latest
8 |
9 | steps:
10 | - name: install dependencies
11 | run: |
12 | sudo apt-get install libboost-all-dev
13 | sudo apt-get install libxerces-c-dev
14 | sudo apt-get install libssl-dev
15 | sudo apt-get install cmake
16 |
17 | - name: checkout repo
18 | uses: actions/checkout@v2
19 |
20 | - name: checkout submodules
21 | run: git submodule update --init --recursive
22 |
23 | - name: cmake initialization
24 | run: |
25 | mkdir build
26 | cd build
27 | cmake ..
28 |
29 | - name: build
30 | run: |
31 | cd build
32 | make
33 |
34 | - name: test
35 | run: |
36 | cd build
37 | ctest
38 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 | /.vscode
3 | /.devcontainer
--------------------------------------------------------------------------------
/.gitmodules:
--------------------------------------------------------------------------------
1 | [submodule "lib/asdcplib"]
2 | path = lib/asdcplib
3 | url = https://github.com/sandflow/asdcplib.git
4 |
--------------------------------------------------------------------------------
/CMakeLists.txt:
--------------------------------------------------------------------------------
1 | cmake_minimum_required (VERSION 2.8)
2 | project(jid)
3 |
4 | # import boost
5 |
6 | set(Boost_USE_STATIC_LIBS ON)
7 | set(Boost_USE_MULTITHREADED ON)
8 | find_package(Boost REQUIRED COMPONENTS program_options)
9 | include_directories(${Boost_INCLUDE_DIR})
10 |
11 | # import asdcplib
12 |
13 | add_subdirectory(lib/asdcplib)
14 | include_directories(lib/asdcplib/src)
15 |
16 | if(WIN32)
17 | add_definitions(/DKM_WIN32 /D_CONSOLE /DASDCP_PLATFORM=\"win32\" /D_CRT_SECURE_NO_WARNINGS /D_CRT_NONSTDC_NO_WARNINGS)
18 | set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} /SAFESEH:NO")
19 | elseif(UNIX)
20 | add_definitions(/DASDCP_PLATFORM=\"unix\")
21 | endif(WIN32)
22 |
23 | # coomon includes
24 |
25 | include_directories(src/main)
26 |
27 | # jid-writer
28 |
29 | set(JID_WRITER "jid-writer")
30 | add_executable(${JID_WRITER} src/main/jid-writer.cpp src/main/CodestreamSequence.cpp)
31 | target_link_libraries(${JID_WRITER} ${Boost_LIBRARIES} libas02)
32 |
33 | # jid-reader
34 |
35 | set(JID_READER "jid-reader")
36 | add_executable(${JID_READER} src/main/jid-reader.cpp)
37 | target_link_libraries(${JID_READER} ${Boost_LIBRARIES} libas02)
38 |
39 | # tests
40 |
41 | enable_testing()
42 |
43 | add_test(NAME "part1-j2c-wrapping" COMMAND ${JID_WRITER} --in "${PROJECT_SOURCE_DIR}/src/test/resources/part1.j2c" --format J2C --out part1-j2c.mxf)
44 |
45 | add_test(NAME "part15-j2c-wrapping" COMMAND ${JID_WRITER} --in "${PROJECT_SOURCE_DIR}/src/test/resources/part15.j2c" --format J2C --out part15-j2c.mxf)
46 |
47 | add_test(NAME "part1-mjc-wrapping" COMMAND ${JID_WRITER} --in "${PROJECT_SOURCE_DIR}/src/test/resources/part1.mjc" --format MJC --out part1-mjc.mxf)
48 |
49 | add_test(NAME "mjc-cbr-wrapping" COMMAND ${JID_WRITER} --in "${PROJECT_SOURCE_DIR}/src/test/resources/crowdrun-lowlatency.1920x1080-422-10bit-50p.mjc" --color COLOR.3 --quantization QE.1 --components YCbCr --format MJC --out part15-mjc-cbr.mxf)
50 |
51 | add_test(NAME "part15-mjc-wrapping" COMMAND ${JID_WRITER} --in "${PROJECT_SOURCE_DIR}/src/test/resources/part15.mjc" --format MJC --out part15-mjc.mxf)
52 |
53 | add_test(NAME "yuv422_10b_p15-wrapping" COMMAND ${JID_WRITER} --color COLOR.3 --quantization QE.1 --components YCbCr --format J2C --in "${PROJECT_SOURCE_DIR}/src/test/resources/yuv422_10b_p15.j2c" --out yuv422_10b_p15.mxf)
54 |
55 | add_test(NAME "j2c-seq-wrapping" COMMAND ${JID_WRITER} --color COLOR.3 --quantization QE.1 --components YCbCr --format J2C --in "${PROJECT_SOURCE_DIR}/src/test/resources/j2c-sequence" --out j2c-seq.mxf)
56 |
57 | add_test(NAME "j2c-wrapping-with-areas" COMMAND ${JID_WRITER}
58 | --in "${PROJECT_SOURCE_DIR}/src/test/resources/part1.j2c"
59 | --out j2c-wrapping-with-areas.mxf
60 | --format J2C
61 | --display_area 10 20 1000 1010
62 | --active_area 10 20 500 510
63 | )
64 |
65 | add_test(NAME "j2c-wrapping-with-color-volume" COMMAND ${JID_WRITER}
66 | --in "${PROJECT_SOURCE_DIR}/src/test/resources/part1.j2c"
67 | --out j2c-wrapping-with-color-volume.mxf
68 | --format J2C
69 | --color COLOR.3
70 | --mastering_display_primaries 35400 14600 8500 39850 6550 2300
71 | --mastering_display_white_point_chroma 15635 16450
72 | --mastering_display_max_luminance 10000000
73 | --mastering_display_min_luminance 50
74 | )
75 |
76 | set(J2C_OUT_DIR ${CMAKE_CURRENT_BINARY_DIR}/j2c-out)
77 |
78 | file(MAKE_DIRECTORY ${J2C_OUT_DIR})
79 |
80 | add_test(NAME "unwrapping-j2c" COMMAND ${JID_READER} --in part1-mjc.mxf --format J2C --out ${J2C_OUT_DIR})
81 |
82 | add_test(NAME "unwrapping-mjc-file" COMMAND ${JID_READER} --in part1-mjc.mxf --format MJC --out "out.mjc")
83 |
84 | # compiler settings
85 |
86 | set_property(DIRECTORY PROPERTY CXX_STANDARD 11)
87 | set_property(DIRECTORY PROPERTY LINKER_LANGUAGE CXX)
88 |
89 | # force warnings to be treated as errors
90 |
91 | if ( CMAKE_COMPILER_IS_GNUCC )
92 | set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall")
93 | endif ( CMAKE_COMPILER_IS_GNUCC )
94 |
95 | if ( MSVC )
96 | set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /W4")
97 | endif ( MSVC )
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | BSD 2-Clause License
2 |
3 | Copyright (c) 2020, Sandflow Consulting
4 | All rights reserved.
5 |
6 | Redistribution and use in source and binary forms, with or without
7 | modification, are permitted provided that the following conditions are met:
8 |
9 | 1. Redistributions of source code must retain the above copyright notice, this
10 | list of conditions and the following disclaimer.
11 |
12 | 2. Redistributions in binary form must reproduce the above copyright notice,
13 | this list of conditions and the following disclaimer in the documentation
14 | and/or other materials provided with the distribution.
15 |
16 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
17 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
20 | FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21 | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
22 | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
23 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
24 | OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
25 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # JPEG 2000 to IMF DCDM (jid)
2 |
3 | _THIS IS EXPERIMENTAL SOFTWARE_
4 |
5 | Wraps/unwraps JPEG 2000 codestreams to/from an Image Track File as specified in SMPTE ST 2067-21 (App 2E) and (proposed) SMPTE ST 2067-40 (App 4)
6 |
7 | ## Prerequisites
8 |
9 | * xerces (required by asdcplib)
10 | * openssl (required by asdcplib)
11 | * boost::program_options
12 | * cmake
13 |
14 | ## Known limitations
15 |
16 | * Does not support interlaced images
17 | * Supported input/output formats:
18 | * MJC codestream sequence
19 | * individual J2C codestreams
20 |
21 | ## Examples uses
22 |
23 | ### Coding/wrapping performance testing
24 |
25 | The following use the demonstration encoder/decoder available at .
26 |
27 | #### JPEG 2000 Part 1
28 |
29 | ```
30 | time ( kdu_v_compress -i ~/Downloads/tiff-files/mer_shrt_23976_vdm_sdr_rec709_g24_3840x2160_20170913_12bit_DCDM.00090000.tif+100 -o - \
31 | Simf="{6,0,rev}" -in_prec 12M -num_threads 1 \
32 | | jid-writer --format MJC --out ~/Downloads/part1-r.mxf )
33 | ```
34 |
35 | #### High-throughput JPEG 2000
36 |
37 | ```
38 | time ( kdu_v_compress -i ~/Downloads/tiff-files/mer_shrt_23976_vdm_sdr_rec709_g24_3840x2160_20170913_12bit_DCDM.00090000.tif+100 -o - Corder="CPRL" Clevels="{6}" \
39 | Cprecincts="{256,256},{256,256},{256,256},{256,256},{256,256},{256,256},{128,128}" ORGgen_tlm="{3}" ORGtparts=C Cblk="{32,32}" \
40 | -num_threads 1 Creversible=yes Cmodes=HT -in_prec 12M | jid-writer --format MJC --out ~/Downloads/part15-r.mxf )
41 | ```
42 |
43 | ### Coding/wrapping typical use
44 |
45 | #### JPEG 2000 Part 1
46 |
47 | ```
48 | kdu_v_compress -i ~/Downloads/tiff-files/mer_shrt_23976_vdm_sdr_rec709_g24_3840x2160_20170913_12bit_DCDM.00090000.tif+100 -o - Simf="{6,0,rev}" -in_prec 12M \
49 | | jid-writer --format MJC --out ~/Downloads/part1-r.mxf
50 | ```
51 |
52 | #### High-throughput JPEG 2000
53 |
54 | ```
55 | kdu_v_compress -i ~/Downloads/tiff-files/mer_shrt_23976_vdm_sdr_rec709_g24_3840x2160_20170913_12bit_DCDM.00090000.tif+100 -o - Corder="CPRL" Clevels="{6}" \
56 | Cprecincts="{256,256},{256,256},{256,256},{256,256},{256,256},{256,256},{128,128}" ORGgen_tlm="{3}" ORGtparts=C Cblk="{32,32}" Creversible=yes Cmodes=HT -in_prec 12M \
57 | | jid-writer --format MJC --out ~/Downloads/part15-r.mxf
58 | ```
59 |
60 | ### Unwrapping example use
61 |
62 | ```
63 | mkdir ~/Downloads/j2c-out
64 | jid-reader --in ~/Downloads/part15-r.mxf --format J2C --out ~/Downloads/j2c-out
65 | ```
66 |
67 | ## Ubuntu build instructions
68 |
69 | ```
70 | sudo apt-get install libboost-all-dev
71 | sudo apt-get install libxerces-c-dev
72 | sudo apt-get install libssl-dev
73 | sudo apt-get install cmake
74 |
75 | git clone --recurse-submodules https://github.com/sandflow/jid.git
76 | cd jid
77 | mkdir build
78 | cd build
79 | cmake -DCMAKE_BUILD_TYPE=Release ..
80 | make
81 |
82 | #tests
83 |
84 | ctest
85 | ```
86 |
87 | ## MacOS build instructions
88 |
89 | ```
90 | brew install boost
91 | brew install xerces-c
92 | brew install openssl
93 | brew install cmake
94 |
95 | git clone --recurse-submodules https://github.com/sandflow/jid.git
96 | cd jid
97 | mkdir build
98 | cd build
99 | cmake -DCMAKE_BUILD_TYPE=Release -DOpenSSLLib_include_DIR=/usr/local/opt/openssl@1.1/include \
100 | -DOpenSSLLib_PATH=/usr/local/opt/openssl@1.1/lib/libcrypto.dylib ..
101 | make
102 |
103 | #tests
104 |
105 | ctest
106 | ```
107 |
108 | ## Microsoft Visual Studio build instructions (MSVC)
109 |
110 | * install OpenSSL v1.0.2u binaries from https://slproweb.com/products/Win32OpenSSL.html
111 | * install boost binaries from
112 | https://sourceforge.net/projects/boost/files/boost-binaries/1.72.0/
113 | * download xerces c++ from http://xerces.apache.org/mirrors.cgi and
114 | build using MSVC
115 | * configure and generate an MSVC project using [CMake GUI](https://cmake.org/runningcmake/), setting:
116 | * `Boost_INCLUDE_DIR`, e.g. `"C:/bin/boost_1_72_0"`
117 | * `XercescppLib_PATH`, e.g. `"C:/bin/xerces-c/lib/xerces-c_3.lib"`
118 | * `XercescppLib_Debug_PATH`, e.g. `"C:/bin/xerces-c/lib/xerces-c_3D.lib"`
119 | * `XercescppLib_include_DIR`, e.g. `"C:/bin/xerces-c/include"`
120 | * `OpenSSLLib_PATH`, e.g. `"C:/bin/OpenSSL-Win64/lib/libeay32.lib"`
121 | * `OpenSSLLib_include_DIR`, e.g. `"C:/bin/OpenSSL-Win64/include"`
122 |
--------------------------------------------------------------------------------
/src/main/CodestreamSequence.cpp:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c), Pierre-Anthony Lemieux (pal@palemieux.com)
3 | * All rights reserved.
4 | *
5 | * Redistribution and use in source and binary forms, with or without
6 | * modification, are permitted provided that the following conditions are met:
7 | *
8 | * * Redistributions of source code must retain the above copyright notice, this
9 | * list of conditions and the following disclaimer.
10 | * * Redistributions in binary form must reproduce the above copyright notice,
11 | * this list of conditions and the following disclaimer in the documentation
12 | * and/or other materials provided with the distribution.
13 | *
14 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
15 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
18 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
19 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
20 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
21 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
22 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
23 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
24 | * POSSIBILITY OF SUCH DAMAGE.
25 | */
26 |
27 | #include "CodestreamSequence.h"
28 | #include
29 | #include
30 |
31 | /* J2CFile */
32 |
33 | J2CFile::J2CFile(FILE *fp,
34 | std::vector::size_type initial_buf_sz,
35 | std::vector::size_type read_buf_sz) :
36 | good_(true),
37 | codestream_(),
38 | file_paths_stack_(),
39 | initial_buf_sz_(initial_buf_sz),
40 | read_buf_sz_(read_buf_sz)
41 | {
42 | this->_fill_from_fp(fp);
43 | };
44 |
45 | J2CFile::J2CFile(const std::vector& file_paths,
46 | std::vector::size_type initial_buf_sz,
47 | std::vector::size_type read_buf_sz) :
48 | good_(true),
49 | codestream_(),
50 | file_paths_stack_(file_paths.rbegin(), file_paths.rend()),
51 | initial_buf_sz_(initial_buf_sz),
52 | read_buf_sz_(read_buf_sz)
53 | {
54 | this->next();
55 | };
56 |
57 | void J2CFile::_fill_from_fp(FILE* fp) {
58 |
59 | this->codestream_.reserve(this->initial_buf_sz_);
60 | this->codestream_.resize(0);
61 |
62 | while (true) {
63 |
64 | std::vector::size_type old_sz = this->codestream_.size();
65 |
66 | this->codestream_.resize(old_sz + this->read_buf_sz_);
67 |
68 | size_t sz = fread(this->codestream_.data() + old_sz, 1, this->read_buf_sz_, fp);
69 |
70 | if (sz != this->read_buf_sz_) {
71 |
72 | this->codestream_.resize(old_sz + sz);
73 |
74 | break;
75 | }
76 | }
77 | }
78 |
79 | void J2CFile::next() {
80 |
81 | if (this->file_paths_stack_.size() == 0) {
82 |
83 | this->good_ = false;
84 |
85 | return;
86 |
87 | }
88 |
89 | FILE* fp = fopen(file_paths_stack_.back().c_str(), "rb");
90 |
91 |
92 | if (!fp) {
93 | throw std::runtime_error("Cannot open file: " + file_paths_stack_.back());
94 | }
95 |
96 | this->_fill_from_fp(fp);
97 |
98 | fclose(fp);
99 |
100 | file_paths_stack_.pop_back();
101 |
102 | };
103 |
104 | bool J2CFile::good() const { return this->good_; };
105 |
106 | void J2CFile::fill(ASDCP::JP2K::FrameBuffer &fb)
107 | {
108 | ASDCP::Result_t result = ASDCP::RESULT_OK;
109 |
110 | result = fb.SetData(this->codestream_.data(), (uint32_t)this->codestream_.size());
111 |
112 | if (ASDCP_FAILURE(result)) {
113 | throw std::runtime_error("Frame buffer allocation failed");
114 | }
115 |
116 | assert(ASDCP_SUCCESS(result));
117 |
118 | uint32_t sz = fb.Size((uint32_t)this->codestream_.size());
119 |
120 | if (sz != this->codestream_.size()) {
121 | throw std::runtime_error("Frame buffer resizing failed");
122 | }
123 |
124 | };
125 |
126 | /* MJCFile */
127 |
128 | MJCFile::MJCFile(FILE *fp) : good_(true), codestream_len_(0), codestream_(), fp_(fp)
129 | {
130 |
131 | uint8_t header[16];
132 |
133 | size_t sz = fread(header, 1, sizeof header, this->fp_);
134 |
135 | if (sz != sizeof header || header[0] != 'M' || header[1] != 'J' || header[2] != 'C' || header[3] != '2')
136 | {
137 | throw std::runtime_error("Bad MJC file");
138 | }
139 |
140 | this->is_cbr_ = header[15] & 4;
141 |
142 | this->next();
143 | }
144 |
145 | void MJCFile::next()
146 | {
147 |
148 | size_t rd_sz;
149 |
150 | /* get codestream length */
151 |
152 | uint32_t len;
153 |
154 | if (!this->is_cbr_ || this->codestream_len_ == 0) {
155 |
156 | /* read the codestream length for every codestream if in vbr mode
157 | * otherwise read it from the first codestream only
158 | */
159 |
160 | uint8_t be_len[4];
161 |
162 | rd_sz = fread(be_len, 1, sizeof be_len, this->fp_);
163 |
164 | if (rd_sz != sizeof be_len) {
165 | this->good_ = false;
166 | return;
167 | }
168 |
169 | len = (be_len[0] << 24) + (be_len[1] << 16) + (be_len[2] << 8) + be_len[3];
170 |
171 | if (this->is_cbr_) {
172 |
173 | if (len == 0) {
174 | throw std::runtime_error("MJC CBR length is 0");
175 | }
176 |
177 | this->codestream_len_ = len;
178 | }
179 |
180 | } else {
181 |
182 | len = this->codestream_len_;
183 |
184 | }
185 |
186 | /* read codestream */
187 |
188 | this->codestream_.resize(len);
189 |
190 | rd_sz = fread(this->codestream_.data(), 1, len, this->fp_);
191 |
192 | if (rd_sz != len)
193 | {
194 | this->good_ = false;
195 | return;
196 | }
197 |
198 | /* trim codestream to EOC if CBR */
199 |
200 | if (this->is_cbr_) {
201 | auto it = std::find(this->codestream_.rbegin(), this->codestream_.rend(), 0xd9);
202 |
203 | if (it == this->codestream_.rend()) {
204 | throw std::runtime_error("Codestream is missing an EOC marker");
205 | }
206 |
207 | this->codestream_.resize(std::distance(it, this->codestream_.rend()));
208 | }
209 |
210 | };
211 |
212 | bool MJCFile::good() const { return this->good_; };
213 |
214 | void MJCFile::fill(ASDCP::JP2K::FrameBuffer &fb)
215 | {
216 | ASDCP::Result_t result = ASDCP::RESULT_OK;
217 |
218 | result = fb.SetData(this->codestream_.data(), (uint32_t)this->codestream_.size());
219 |
220 | if (ASDCP_FAILURE(result)) {
221 | throw std::runtime_error("Frame buffer allocation failed");
222 | }
223 |
224 | uint32_t sz = fb.Size((uint32_t)this->codestream_.size());
225 |
226 | if (sz != this->codestream_.size()) {
227 | throw std::runtime_error("Frame buffer resizing failed");
228 | }
229 | };
230 |
231 | /* FakeSequence */
232 |
233 | FakeSequence::FakeSequence(uint32_t frame_count, uint32_t frame_size) :
234 | frame_count_(frame_count), cur_frame_(0), codestream_(frame_size)
235 | {
236 | std::copy(CODESTREAM_HEADER_, CODESTREAM_HEADER_ + sizeof CODESTREAM_HEADER_, codestream_.begin());
237 |
238 | std::fill(codestream_.begin() + sizeof CODESTREAM_HEADER_, codestream_.end(), (uint8_t)0x00);
239 | };
240 |
241 | void FakeSequence::next()
242 | {
243 | this->cur_frame_++;
244 | };
245 |
246 | bool FakeSequence::good() const { return this->cur_frame_ < this->frame_count_; };
247 |
248 | void FakeSequence::fill(ASDCP::JP2K::FrameBuffer &fb)
249 | {
250 |
251 | ASDCP::Result_t result = ASDCP::RESULT_OK;
252 |
253 | result = fb.SetData(this->codestream_.data(), (uint32_t)this->codestream_.size());
254 |
255 | assert(ASDCP_SUCCESS(result));
256 |
257 | uint32_t sz = fb.Size((uint32_t)this->codestream_.size());
258 |
259 | if (sz != this->codestream_.size()) {
260 | throw std::runtime_error("Frame buffer resizing failed");
261 | }
262 | };
263 |
264 |
265 | const uint8_t FakeSequence::CODESTREAM_HEADER_[236] = {
266 | 0xFF, 0x4F, 0xFF, 0x51, 0x00, 0x2F, 0x40, 0x00, 0x00, 0x00, 0x0F, 0x00,
267 | 0x00, 0x00, 0x08, 0x70, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
268 | 0x00, 0x00, 0x0F, 0x00, 0x00, 0x00, 0x08, 0x70, 0x00, 0x00, 0x00, 0x00,
269 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x0F, 0x01, 0x01, 0x0F, 0x01, 0x01,
270 | 0x0F, 0x01, 0x01, 0xFF, 0x50, 0x00, 0x08, 0x00, 0x02, 0x00, 0x00, 0x00,
271 | 0x0C, 0xFF, 0x52, 0x00, 0x12, 0x01, 0x02, 0x00, 0x01, 0x01, 0x05, 0x03,
272 | 0x03, 0x40, 0x01, 0x77, 0x88, 0x88, 0x88, 0x88, 0x88, 0xFF, 0x5C, 0x00,
273 | 0x13, 0x20, 0x90, 0x98, 0x98, 0xA0, 0x98, 0x98, 0xA0, 0x98, 0x98, 0xA0,
274 | 0x98, 0x98, 0x98, 0x90, 0x90, 0x98, 0xFF, 0x64, 0x00, 0x18, 0x00, 0x01,
275 | 0x4B, 0x61, 0x6B, 0x61, 0x64, 0x75, 0x2D, 0x76, 0x78, 0x74, 0x37, 0x2E,
276 | 0x31, 0x31, 0x2D, 0x42, 0x65, 0x74, 0x61, 0x34, 0xFF, 0x64, 0x00, 0x5C,
277 | 0x00, 0x01, 0x4B, 0x64, 0x75, 0x2D, 0x4C, 0x61, 0x79, 0x65, 0x72, 0x2D,
278 | 0x49, 0x6E, 0x66, 0x6F, 0x3A, 0x20, 0x6C, 0x6F, 0x67, 0x5F, 0x32, 0x7B,
279 | 0x44, 0x65, 0x6C, 0x74, 0x61, 0x2D, 0x44, 0x28, 0x73, 0x71, 0x75, 0x61,
280 | 0x72, 0x65, 0x64, 0x2D, 0x65, 0x72, 0x72, 0x6F, 0x72, 0x29, 0x2F, 0x44,
281 | 0x65, 0x6C, 0x74, 0x61, 0x2D, 0x4C, 0x28, 0x62, 0x79, 0x74, 0x65, 0x73,
282 | 0x29, 0x7D, 0x2C, 0x20, 0x4C, 0x28, 0x62, 0x79, 0x74, 0x65, 0x73, 0x29,
283 | 0x0A, 0x2D, 0x31, 0x39, 0x32, 0x2E, 0x30, 0x2C, 0x20, 0x20, 0x33, 0x2E,
284 | 0x37, 0x65, 0x2B, 0x30, 0x37, 0x0A, 0xFF, 0x90, 0x00, 0x0A, 0x00, 0x00,
285 | 0x02, 0x2D, 0x2F, 0xD0, 0x00, 0x01, 0xFF, 0x93
286 | };
--------------------------------------------------------------------------------
/src/main/CodestreamSequence.h:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c), Pierre-Anthony Lemieux (pal@palemieux.com)
3 | * All rights reserved.
4 | *
5 | * Redistribution and use in source and binary forms, with or without
6 | * modification, are permitted provided that the following conditions are met:
7 | *
8 | * * Redistributions of source code must retain the above copyright notice, this
9 | * list of conditions and the following disclaimer.
10 | * * Redistributions in binary form must reproduce the above copyright notice,
11 | * this list of conditions and the following disclaimer in the documentation
12 | * and/or other materials provided with the distribution.
13 | *
14 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
15 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
18 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
19 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
20 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
21 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
22 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
23 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
24 | * POSSIBILITY OF SUCH DAMAGE.
25 | */
26 |
27 | #ifndef COM_SANDFLOW_CODESTREAMSEQUENCE_H
28 | #define COM_SANDFLOW_CODESTREAMSEQUENCE_H
29 |
30 | #include
31 | #include
32 | #include
33 |
34 | class CodestreamSequence {
35 |
36 | public:
37 |
38 | virtual void next() = 0;
39 | virtual bool good() const = 0;
40 | virtual void fill(ASDCP::JP2K::FrameBuffer& fb) = 0;
41 | virtual ~CodestreamSequence() {};
42 | };
43 |
44 | class J2CFile : public CodestreamSequence {
45 |
46 | public:
47 |
48 | J2CFile(FILE* fp,
49 | std::vector::size_type initial_buf_sz = 50 * 1024 * 1024,
50 | std::vector::size_type read_buf_sz = 64 * 1024);
51 |
52 | J2CFile(const std::vector& file_paths,
53 | std::vector::size_type initial_buf_sz = 50 * 1024 * 1024,
54 | std::vector::size_type read_buf_sz = 64 * 1024);
55 |
56 | virtual void next();
57 |
58 | virtual bool good() const;
59 |
60 | virtual void fill(ASDCP::JP2K::FrameBuffer& fb);
61 |
62 | protected:
63 |
64 | bool good_;
65 | std::vector codestream_;
66 | std::vector file_paths_stack_;
67 | std::vector::size_type initial_buf_sz_;
68 | std::vector::size_type read_buf_sz_;
69 |
70 | void _fill_from_fp(FILE* fp);
71 | };
72 |
73 | class MJCFile : public CodestreamSequence {
74 |
75 | public:
76 |
77 | MJCFile(FILE* fp);
78 |
79 | virtual void next();
80 |
81 | virtual bool good() const;
82 |
83 | virtual void fill(ASDCP::JP2K::FrameBuffer& fb);
84 |
85 | protected:
86 |
87 | bool good_;
88 | std::vector codestream_;
89 | FILE* fp_;
90 | bool is_cbr_;
91 | uint32_t codestream_len_;
92 | };
93 |
94 | class FakeSequence : public CodestreamSequence {
95 |
96 | public:
97 |
98 | FakeSequence(uint32_t frame_count = 360, uint32_t frame_size = 5 * 1024 * 1024);
99 |
100 | virtual void next();
101 |
102 | virtual bool good() const;
103 |
104 | virtual void fill(ASDCP::JP2K::FrameBuffer& fb);
105 |
106 | protected:
107 |
108 | uint32_t frame_count_;
109 | uint32_t cur_frame_;
110 | std::vector codestream_;
111 |
112 | const static uint8_t CODESTREAM_HEADER_[236];
113 |
114 |
115 | };
116 |
117 | #endif
--------------------------------------------------------------------------------
/src/main/J2KProfileULMap.h:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c), Pierre-Anthony Lemieux (pal@palemieux.com)
3 | * All rights reserved.
4 | *
5 | * Redistribution and use in source and binary forms, with or without
6 | * modification, are permitted provided that the following conditions are met:
7 | *
8 | * * Redistributions of source code must retain the above copyright notice, this
9 | * list of conditions and the following disclaimer.
10 | * * Redistributions in binary form must reproduce the above copyright notice,
11 | * this list of conditions and the following disclaimer in the documentation
12 | * and/or other materials provided with the distribution.
13 | *
14 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
15 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
18 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
19 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
20 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
21 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
22 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
23 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
24 | * POSSIBILITY OF SUCH DAMAGE.
25 | */
26 |
27 | #ifndef COM_SANDFLOW_J2KPROFILEULMAP_H
28 | #define COM_SANDFLOW_J2KPROFILEULMAP_H
29 |
30 | #include