|
| 1 | +/* |
| 2 | + * This file is part of the ZoneMinder Project. See AUTHORS file for Copyright information |
| 3 | + * |
| 4 | + * This program is free software; you can redistribute it and/or modify it |
| 5 | + * under the terms of the GNU General Public License as published by the |
| 6 | + * Free Software Foundation; either version 2 of the License, or (at your |
| 7 | + * option) any later version. |
| 8 | + * |
| 9 | + * This program is distributed in the hope that it will be useful, but WITHOUT |
| 10 | + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
| 11 | + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for |
| 12 | + * more details. |
| 13 | + * |
| 14 | + * You should have received a copy of the GNU General Public License along |
| 15 | + * with this program. If not, see <http://www.gnu.org/licenses/>. |
| 16 | + */ |
| 17 | + |
| 18 | +#include "zm_catch2.h" |
| 19 | + |
| 20 | +#include "zm_ffmpeg.h" |
| 21 | +#include "zm_swscale.h" |
| 22 | + |
| 23 | +#include <cstdlib> |
| 24 | +#include <vector> |
| 25 | + |
| 26 | +TEST_CASE("pix_fmt_is_jpeg_range identifies full-range YUVJ formats", "[swscale]") { |
| 27 | + REQUIRE(pix_fmt_is_jpeg_range(AV_PIX_FMT_YUVJ420P)); |
| 28 | + REQUIRE(pix_fmt_is_jpeg_range(AV_PIX_FMT_YUVJ422P)); |
| 29 | + REQUIRE(pix_fmt_is_jpeg_range(AV_PIX_FMT_YUVJ444P)); |
| 30 | + REQUIRE(pix_fmt_is_jpeg_range(AV_PIX_FMT_YUVJ440P)); |
| 31 | + |
| 32 | + REQUIRE_FALSE(pix_fmt_is_jpeg_range(AV_PIX_FMT_YUV420P)); |
| 33 | + REQUIRE_FALSE(pix_fmt_is_jpeg_range(AV_PIX_FMT_YUV422P)); |
| 34 | + REQUIRE_FALSE(pix_fmt_is_jpeg_range(AV_PIX_FMT_RGB24)); |
| 35 | + REQUIRE_FALSE(pix_fmt_is_jpeg_range(AV_PIX_FMT_GRAY8)); |
| 36 | +} |
| 37 | + |
| 38 | +// Colorimetric regression: a full-range JPEG (YUVJ420P) frame carries luma in |
| 39 | +// 0-255. swscale defaults to limited (16-235) input range, which would crush a |
| 40 | +// dark grey Y=16 down to ~0 (black). zm_sws_set_input_range() must mark the |
| 41 | +// input full range so Y=16 survives as ~16. |
| 42 | +TEST_CASE("SWScale treats YUVJ420P input as full range when converting to RGB", "[swscale]") { |
| 43 | + const int w = 16, h = 16; |
| 44 | + const uint8_t Y = 16; // full range -> ~16; limited range -> ~0 |
| 45 | + |
| 46 | + // YUVJ420P planar: Y plane (w*h), then U and V (w/2*h/2). Neutral chroma=128. |
| 47 | + std::vector<uint8_t> in(SWScale::GetBufferSize(AV_PIX_FMT_YUVJ420P, w, h, 1), 128); |
| 48 | + std::fill(in.begin(), in.begin() + w * h, Y); |
| 49 | + |
| 50 | + std::vector<uint8_t> out(SWScale::GetBufferSize(AV_PIX_FMT_RGB24, w, h, 1), 0); |
| 51 | + |
| 52 | + SWScale scaler; |
| 53 | + REQUIRE(scaler.init()); |
| 54 | + int r = scaler.Convert(in.data(), in.size(), out.data(), out.size(), |
| 55 | + AV_PIX_FMT_YUVJ420P, AV_PIX_FMT_RGB24, w, h, 1, 1); |
| 56 | + REQUIRE(r == 0); |
| 57 | + |
| 58 | + // Full-range interpretation keeps luma ~16; limited-range would crush to ~0. |
| 59 | + REQUIRE(out[0] >= 12); |
| 60 | + REQUIRE(out[0] <= 20); |
| 61 | + // Neutral chroma -> grey, so the three channels stay equal. |
| 62 | + REQUIRE(std::abs(static_cast<int>(out[0]) - static_cast<int>(out[1])) <= 2); |
| 63 | + REQUIRE(std::abs(static_cast<int>(out[1]) - static_cast<int>(out[2])) <= 2); |
| 64 | +} |
0 commit comments