WriteJPEGToMem is the only JPEG code in the tree (encode only, no decoding), and libjpeg-turbo came in as an ExternalProject whose imported target passed its include dir as -isystem. Any other jpeglib.h on the include path (conda, the distribution, the CUDA directory) could then win, and a build failed with "Wrong JPEG library version: library is 62, caller expects 80". stb_image_write v1.16 (commit 31c1ad3) is vendored in preview/stb/ and compiled into JFJochJPEG.cpp alone with STB_IMAGE_WRITE_STATIC and STBI_WRITE_NO_STDIO, so no JPEG symbol or header leaves that file. Output is baseline JPEG (it was progressive); the API is unchanged. Size limits are checked up front (JPEG's 65535 per side, stb's int pixel index) and an encoder failure throws JFJochException. Quality is clamped to 1-100. stb encodes an 18 Mpx frame in ~350 ms against ~210 ms for the scalar libjpeg-turbo we built; accepted. Removed: the ExternalProject and JPEG::JPEG target in preview/, nasm from the Docker images, licenses/libjpeg-turbo.txt and its manifest row, and the CI check that counted libjpeg-turbo copies in the viewer (the Qt JPEG/TIFF plugin check stays, as does the viewer's plugin exclusion). Licence: MIT OR Unlicense, recorded in licenses/ and THIRD_PARTY_NOTICES.md. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01HVeDQqrcrEZy6XBUCMZvyT
43 lines
1.2 KiB
C++
43 lines
1.2 KiB
C++
// SPDX-FileCopyrightText: 2024 Filip Leonarski, Paul Scherrer Institute <filip.leonarski@psi.ch>
|
|
// SPDX-License-Identifier: GPL-3.0-only
|
|
|
|
#include <catch2/catch_all.hpp>
|
|
|
|
#include <fstream>
|
|
#include "../preview//JFJochJPEG.h"
|
|
#include "../preview//PreviewImage.h"
|
|
#include "../writer/HDF5Objects.h"
|
|
#include "../common/RawToConvertedGeometry.h"
|
|
|
|
TEST_CASE("JPEGTest","[JPEG]") {
|
|
size_t width = 1024;
|
|
size_t height = 1024;
|
|
std::vector<rgb> val(width * height);
|
|
for (int i = 0; i < width * height; i++) {
|
|
size_t x = i % width;
|
|
if (x < 512) {
|
|
val[i].r = 234;
|
|
val[i].g = 0;
|
|
val[i].b = 0;
|
|
} else {
|
|
val[i].r = 0;
|
|
val[i].g = 0;
|
|
val[i].b = 255;
|
|
}
|
|
}
|
|
|
|
std::string s;
|
|
|
|
CompressedImage image(val, width, height);
|
|
REQUIRE_NOTHROW(s = WriteJPEGToMem(image));
|
|
std::ofstream f("x.jpeg", std::ios::binary);
|
|
f.write(s.data(), s.size());
|
|
}
|
|
|
|
// An image the encoder cannot take must come back as an exception.
|
|
TEST_CASE("JPEGTest_ErrorThrows","[JPEG]") {
|
|
const std::vector<rgb> val(70000); // wider than the JPEG limit of 65535
|
|
const CompressedImage image(val, 70000, 1);
|
|
CHECK_THROWS_AS(WriteJPEGToMem(image), JFJochException);
|
|
}
|