Skip to content

Commit

Permalink
ultrahdr: fix compiler warnings
Browse files Browse the repository at this point in the history
Test: Build
Test: ultrahdr_unit_test
  • Loading branch information
ram-mohan committed Sep 22, 2023
1 parent 3011395 commit cb0e4fb
Show file tree
Hide file tree
Showing 13 changed files with 82 additions and 83 deletions.
1 change: 0 additions & 1 deletion fuzzer/ultrahdr_enc_fuzzer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,6 @@ void UltraHdrEncFuzzer::process() {
p010Img.height = height;
p010Img.colorGamut = p010Cg;
p010Img.luma_stride = hasYStride ? yStride : 0;
int bppP010 = 2;
if (isUVContiguous) {
size_t p010Size = yStride * height * 3 / 2;
bufferYHdr = std::make_unique<uint16_t[]>(p010Size);
Expand Down
19 changes: 10 additions & 9 deletions gainmapmath.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ namespace ultrahdr {

static const std::vector<float> kPqOETF = [] {
std::vector<float> result;
for (int idx = 0; idx < kPqOETFNumEntries; idx++) {
for (size_t idx = 0; idx < kPqOETFNumEntries; idx++) {
float value = static_cast<float>(idx) / static_cast<float>(kPqOETFNumEntries - 1);
result.push_back(pqOetf(value));
}
Expand All @@ -29,7 +29,7 @@ static const std::vector<float> kPqOETF = [] {

static const std::vector<float> kPqInvOETF = [] {
std::vector<float> result;
for (int idx = 0; idx < kPqInvOETFNumEntries; idx++) {
for (size_t idx = 0; idx < kPqInvOETFNumEntries; idx++) {
float value = static_cast<float>(idx) / static_cast<float>(kPqInvOETFNumEntries - 1);
result.push_back(pqInvOetf(value));
}
Expand All @@ -38,7 +38,7 @@ static const std::vector<float> kPqInvOETF = [] {

static const std::vector<float> kHlgOETF = [] {
std::vector<float> result;
for (int idx = 0; idx < kHlgOETFNumEntries; idx++) {
for (size_t idx = 0; idx < kHlgOETFNumEntries; idx++) {
float value = static_cast<float>(idx) / static_cast<float>(kHlgOETFNumEntries - 1);
result.push_back(hlgOetf(value));
}
Expand All @@ -47,7 +47,7 @@ static const std::vector<float> kHlgOETF = [] {

static const std::vector<float> kHlgInvOETF = [] {
std::vector<float> result;
for (int idx = 0; idx < kHlgInvOETFNumEntries; idx++) {
for (size_t idx = 0; idx < kHlgInvOETFNumEntries; idx++) {
float value = static_cast<float>(idx) / static_cast<float>(kHlgInvOETFNumEntries - 1);
result.push_back(hlgInvOetf(value));
}
Expand All @@ -56,7 +56,7 @@ static const std::vector<float> kHlgInvOETF = [] {

static const std::vector<float> kSrgbInvOETF = [] {
std::vector<float> result;
for (int idx = 0; idx < kSrgbInvOETFNumEntries; idx++) {
for (size_t idx = 0; idx < kSrgbInvOETFNumEntries; idx++) {
float value = static_cast<float>(idx) / static_cast<float>(kSrgbInvOETFNumEntries - 1);
result.push_back(srgbInvOetf(value));
}
Expand Down Expand Up @@ -472,6 +472,7 @@ ColorTransformFn getHdrConversionFn(ultrahdr_color_gamut sdr_gamut,
case ULTRAHDR_COLORGAMUT_UNSPECIFIED:
return nullptr;
}
return nullptr;
}

// All of these conversions are derived from the respective input YUV->RGB conversion followed by
Expand Down Expand Up @@ -727,10 +728,10 @@ float sampleMap(jr_uncompressed_ptr map, size_t map_scale_factor, size_t x, size
ShepardsIDW& weightTables) {
// TODO: If map_scale_factor is guaranteed to be an integer power of 2, then optimize the
// following by computing log2(map_scale_factor) once and then using >> log2(map_scale_factor)
int x_lower = x / map_scale_factor;
int x_upper = x_lower + 1;
int y_lower = y / map_scale_factor;
int y_upper = y_lower + 1;
size_t x_lower = x / map_scale_factor;
size_t x_upper = x_lower + 1;
size_t y_lower = y / map_scale_factor;
size_t y_upper = y_lower + 1;

x_lower = std::min(x_lower, map->width - 1);
x_upper = std::min(x_upper, map->width - 1);
Expand Down
2 changes: 1 addition & 1 deletion icc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ std::shared_ptr<DataStruct> IccHelper::write_trc_tag(const int table_entries,
dataStruct->write32(Endian_SwapBE32(kTAG_CurveType)); // Type
dataStruct->write32(0); // Reserved
dataStruct->write32(Endian_SwapBE32(table_entries)); // Value count
for (size_t i = 0; i < table_entries; ++i) {
for (int i = 0; i < table_entries; ++i) {
uint16_t value = reinterpret_cast<const uint16_t*>(table_16)[i];
dataStruct->write16(value);
}
Expand Down
4 changes: 2 additions & 2 deletions include/ultrahdr/gainmapmath.h
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ constexpr size_t kGainFactorPrecision = 10;
constexpr size_t kGainFactorNumEntries = 1 << kGainFactorPrecision;
struct GainLUT {
GainLUT(ultrahdr_metadata_ptr metadata) {
for (int idx = 0; idx < kGainFactorNumEntries; idx++) {
for (size_t idx = 0; idx < kGainFactorNumEntries; idx++) {
float value = static_cast<float>(idx) / static_cast<float>(kGainFactorNumEntries - 1);
float logBoost = log2(metadata->minContentBoost) * (1.0f - value)
+ log2(metadata->maxContentBoost) * value;
Expand All @@ -160,7 +160,7 @@ struct GainLUT {

GainLUT(ultrahdr_metadata_ptr metadata, float displayBoost) {
float boostFactor = displayBoost > 0 ? displayBoost / metadata->maxContentBoost : 1.0f;
for (int idx = 0; idx < kGainFactorNumEntries; idx++) {
for (size_t idx = 0; idx < kGainFactorNumEntries; idx++) {
float value = static_cast<float>(idx) / static_cast<float>(kGainFactorNumEntries - 1);
float logBoost = log2(metadata->minContentBoost) * (1.0f - value)
+ log2(metadata->maxContentBoost) * value;
Expand Down
4 changes: 2 additions & 2 deletions include/ultrahdr/icc.h
Original file line number Diff line number Diff line change
Expand Up @@ -170,11 +170,11 @@ static uint16_t float_round_to_unorm16(float x) {
return static_cast<uint16_t>(x);
}

static void float_to_table16(const float f, uint8_t* table_16) {
static inline void float_to_table16(const float f, uint8_t* table_16) {
*reinterpret_cast<uint16_t*>(table_16) = Endian_SwapBE16(float_round_to_unorm16(f));
}

static bool isfinitef_(float x) { return 0 == x*0; }
static inline bool isfinitef_(float x) { return 0 == x*0; }

struct ICCHeader {
// Size of the profile (computed)
Expand Down
2 changes: 1 addition & 1 deletion include/ultrahdr/jpegdecoderhelper.h
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ class JpegDecoderHelper {
size_t mHeight;

// Position of EXIF package, default value is -1 which means no EXIF package appears.
ssize_t mExifPos = -1;
int mExifPos = -1;
};
} /* namespace ultrahdr */

Expand Down
10 changes: 5 additions & 5 deletions include/ultrahdr/jpegr.h
Original file line number Diff line number Diff line change
Expand Up @@ -81,9 +81,9 @@ struct jpegr_uncompressed_struct {
// Pointer to the data location.
void* data;
// Width of the gain map or the luma plane of the image in pixels.
int width;
size_t width;
// Height of the gain map or the luma plane of the image in pixels.
int height;
size_t height;
// Color gamut.
ultrahdr_color_gamut colorGamut;

Expand All @@ -94,15 +94,15 @@ struct jpegr_uncompressed_struct {
// Stride of Y plane in number of pixels. 0 indicates the member is uninitialized. If
// non-zero this value must be larger than or equal to luma width. If stride is
// uninitialized then it is assumed to be equal to luma width.
int luma_stride = 0;
size_t luma_stride = 0;
// Stride of UV plane in number of pixels.
// 1. If this handle points to P010 image then this value must be larger than
// or equal to luma width.
// 2. If this handle points to 420 image then this value must be larger than
// or equal to (luma width / 2).
// NOTE: if chroma_data is nullptr, chroma_stride is irrelevant. Just as the way,
// chroma_data is derived from luma ptr, chroma stride is derived from luma stride.
int chroma_stride = 0;
size_t chroma_stride = 0;
};

/*
Expand All @@ -126,7 +126,7 @@ struct jpegr_exif_struct {
// Pointer to the data location.
void* data;
// Data length;
int length;
size_t length;
};

typedef struct jpegr_uncompressed_struct* jr_uncompressed_ptr;
Expand Down
4 changes: 2 additions & 2 deletions jpegdecoderhelper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -425,7 +425,7 @@ bool JpegDecoderHelper::decompressYUV(jpeg_decompress_struct* cinfo, const uint8
std::unique_ptr<uint8_t[]> empty = std::make_unique<uint8_t[]>(cinfo->image_width);
memset(empty.get(), 0, cinfo->image_width);

const int aligned_width = ALIGNM(cinfo->image_width, kCompressBatchSize);
const size_t aligned_width = ALIGNM(cinfo->image_width, kCompressBatchSize);
bool is_width_aligned = (aligned_width == cinfo->image_width);
std::unique_ptr<uint8_t[]> buffer_intrm = nullptr;
uint8_t* y_plane_intrm = nullptr;
Expand Down Expand Up @@ -500,7 +500,7 @@ bool JpegDecoderHelper::decompressSingleChannel(jpeg_decompress_struct* cinfo,
std::unique_ptr<uint8_t[]> empty = std::make_unique<uint8_t[]>(cinfo->image_width);
memset(empty.get(), 0, cinfo->image_width);

int aligned_width = ALIGNM(cinfo->image_width, kCompressBatchSize);
const size_t aligned_width = ALIGNM(cinfo->image_width, kCompressBatchSize);
bool is_width_aligned = (aligned_width == cinfo->image_width);
std::unique_ptr<uint8_t[]> buffer_intrm = nullptr;
uint8_t* y_plane_intrm = nullptr;
Expand Down
2 changes: 0 additions & 2 deletions jpegencoderhelper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,6 @@ bool JpegEncoderHelper::compressYuv(jpeg_compress_struct* cinfo, const uint8_t*
JSAMPROW cr[kCompressBatchSize / 2];
JSAMPARRAY planes[3]{y, cb, cr};

size_t y_plane_size = lumaStride * cinfo->image_height;
size_t u_plane_size = chromaStride * cinfo->image_height / 2;
uint8_t* y_plane = const_cast<uint8_t*>(yBuffer);
uint8_t* u_plane = const_cast<uint8_t*>(uvBuffer);
Expand Down Expand Up @@ -236,7 +235,6 @@ bool JpegEncoderHelper::compressY(jpeg_compress_struct* cinfo, const uint8_t* yB
const bool need_padding = (lumaStride < aligned_width);
std::unique_ptr<uint8_t[]> buffer_intrm = nullptr;
uint8_t* y_plane_intrm = nullptr;
uint8_t* u_plane_intrm = nullptr;
JSAMPROW y_intrm[kCompressBatchSize];
JSAMPARRAY planes_intrm[]{y_intrm};
if (need_padding) {
Expand Down
29 changes: 14 additions & 15 deletions jpegr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -100,17 +100,17 @@ status_t JpegR::areInputArgumentsValid(jr_uncompressed_ptr p010_image_ptr,
return ERROR_JPEGR_INVALID_NULL_PTR;
}
if (p010_image_ptr->width % 2 != 0 || p010_image_ptr->height % 2 != 0) {
ALOGE("Image dimensions cannot be odd, image dimensions %dx%d", p010_image_ptr->width,
ALOGE("Image dimensions cannot be odd, image dimensions %zux%zu", p010_image_ptr->width,
p010_image_ptr->height);
return ERROR_JPEGR_INVALID_INPUT_TYPE;
}
if (p010_image_ptr->width < kMinWidth || p010_image_ptr->height < kMinHeight) {
ALOGE("Image dimensions cannot be less than %dx%d, image dimensions %dx%d", kMinWidth,
ALOGE("Image dimensions cannot be less than %dx%d, image dimensions %zux%zu", kMinWidth,
kMinHeight, p010_image_ptr->width, p010_image_ptr->height);
return ERROR_JPEGR_INVALID_INPUT_TYPE;
}
if (p010_image_ptr->width > kMaxWidth || p010_image_ptr->height > kMaxHeight) {
ALOGE("Image dimensions cannot be larger than %dx%d, image dimensions %dx%d", kMaxWidth,
ALOGE("Image dimensions cannot be larger than %dx%d, image dimensions %zux%zu", kMaxWidth,
kMaxHeight, p010_image_ptr->width, p010_image_ptr->height);
return ERROR_JPEGR_INVALID_INPUT_TYPE;
}
Expand All @@ -120,13 +120,13 @@ status_t JpegR::areInputArgumentsValid(jr_uncompressed_ptr p010_image_ptr,
return ERROR_JPEGR_INVALID_INPUT_TYPE;
}
if (p010_image_ptr->luma_stride != 0 && p010_image_ptr->luma_stride < p010_image_ptr->width) {
ALOGE("Luma stride must not be smaller than width, stride=%d, width=%d",
ALOGE("Luma stride must not be smaller than width, stride=%zu, width=%zu",
p010_image_ptr->luma_stride, p010_image_ptr->width);
return ERROR_JPEGR_INVALID_INPUT_TYPE;
}
if (p010_image_ptr->chroma_data != nullptr &&
p010_image_ptr->chroma_stride < p010_image_ptr->width) {
ALOGE("Chroma stride must not be smaller than width, stride=%d, width=%d",
ALOGE("Chroma stride must not be smaller than width, stride=%zu, width=%zu",
p010_image_ptr->chroma_stride, p010_image_ptr->width);
return ERROR_JPEGR_INVALID_INPUT_TYPE;
}
Expand All @@ -147,19 +147,19 @@ status_t JpegR::areInputArgumentsValid(jr_uncompressed_ptr p010_image_ptr,
}
if (yuv420_image_ptr->luma_stride != 0 &&
yuv420_image_ptr->luma_stride < yuv420_image_ptr->width) {
ALOGE("Luma stride must not be smaller than width, stride=%d, width=%d",
ALOGE("Luma stride must not be smaller than width, stride=%zu, width=%zu",
yuv420_image_ptr->luma_stride, yuv420_image_ptr->width);
return ERROR_JPEGR_INVALID_INPUT_TYPE;
}
if (yuv420_image_ptr->chroma_data != nullptr &&
yuv420_image_ptr->chroma_stride < yuv420_image_ptr->width / 2) {
ALOGE("Chroma stride must not be smaller than (width / 2), stride=%d, width=%d",
ALOGE("Chroma stride must not be smaller than (width / 2), stride=%zu, width=%zu",
yuv420_image_ptr->chroma_stride, yuv420_image_ptr->width);
return ERROR_JPEGR_INVALID_INPUT_TYPE;
}
if (p010_image_ptr->width != yuv420_image_ptr->width ||
p010_image_ptr->height != yuv420_image_ptr->height) {
ALOGE("Image resolutions mismatch: P010: %dx%d, YUV420: %dx%d", p010_image_ptr->width,
ALOGE("Image resolutions mismatch: P010: %zux%zu, YUV420: %zux%zu", p010_image_ptr->width,
p010_image_ptr->height, yuv420_image_ptr->width, yuv420_image_ptr->height);
return ERROR_JPEGR_RESOLUTION_MISMATCH;
}
Expand Down Expand Up @@ -204,7 +204,7 @@ status_t JpegR::encodeJPEGR(jr_uncompressed_ptr p010_image_ptr, ultrahdr_transfe
p010_image.chroma_stride = p010_image.luma_stride;
}

const int yu420_luma_stride = ALIGNM(p010_image.width, JpegEncoderHelper::kCompressBatchSize);
const size_t yu420_luma_stride = ALIGNM(p010_image.width, JpegEncoderHelper::kCompressBatchSize);
unique_ptr<uint8_t[]> yuv420_image_data =
make_unique<uint8_t[]>(yu420_luma_stride * p010_image.height * 3 / 2);
jpegr_uncompressed_struct yuv420_image = {.data = yuv420_image_data.get(),
Expand Down Expand Up @@ -326,7 +326,7 @@ status_t JpegR::encodeJPEGR(jr_uncompressed_ptr p010_image_ptr,
unique_ptr<uint8_t[]> yuv_420_bt601_data;
// Convert to bt601 YUV encoding for JPEG encode
if (yuv420_image.colorGamut != ULTRAHDR_COLORGAMUT_P3) {
const int yuv_420_bt601_luma_stride =
const size_t yuv_420_bt601_luma_stride =
ALIGNM(yuv420_image.width, JpegEncoderHelper::kCompressBatchSize);
yuv_420_bt601_data =
make_unique<uint8_t[]>(yuv_420_bt601_luma_stride * yuv420_image.height * 3 / 2);
Expand Down Expand Up @@ -1011,8 +1011,8 @@ status_t JpegR::applyGainMap(jr_uncompressed_ptr yuv420_image_ptr,
size_t map_height = image_height / kMapDimensionScaleFactor;
if (map_width != gainmap_image_ptr->width || map_height != gainmap_image_ptr->height) {
ALOGE("gain map dimensions and primary image dimensions are not to scale, computed gain map "
"resolution is %dx%d, received gain map resolution is %dx%d",
(int)map_width, (int)map_height, gainmap_image_ptr->width, gainmap_image_ptr->height);
"resolution is %zux%zu, received gain map resolution is %zux%zu",
map_width, map_height, gainmap_image_ptr->width, gainmap_image_ptr->height);
return ERROR_JPEGR_INVALID_INPUT_TYPE;
}

Expand All @@ -1023,11 +1023,10 @@ status_t JpegR::applyGainMap(jr_uncompressed_ptr yuv420_image_ptr,
GainLUT gainLUT(metadata, display_boost);

JobQueue jobQueue;
std::function<void()> applyRecMap = [yuv420_image_ptr, gainmap_image_ptr, metadata, dest,
std::function<void()> applyRecMap = [yuv420_image_ptr, gainmap_image_ptr, dest,
&jobQueue, &idwTable, output_format, &gainLUT,
display_boost]() -> void {
size_t width = yuv420_image_ptr->width;
size_t height = yuv420_image_ptr->height;

size_t rowStart, rowEnd;
while (jobQueue.dequeueJob(rowStart, rowEnd)) {
Expand Down Expand Up @@ -1105,7 +1104,7 @@ status_t JpegR::applyGainMap(jr_uncompressed_ptr yuv420_image_ptr,
workers.push_back(std::thread(applyRecMap));
}
const int rowStep = threads == 1 ? yuv420_image_ptr->height : kJobSzInRows;
for (int rowStart = 0; rowStart < yuv420_image_ptr->height;) {
for (size_t rowStart = 0; rowStart < yuv420_image_ptr->height;) {
int rowEnd = std::min(rowStart + rowStep, yuv420_image_ptr->height);
jobQueue.enqueueJob(rowStart, rowEnd);
rowStart = rowEnd;
Expand Down
16 changes: 8 additions & 8 deletions tests/gainmapmath_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -740,35 +740,35 @@ TEST_F(GainMapMathTest, PqInvOetf) {
}

TEST_F(GainMapMathTest, PqInvOetfLUT) {
for (int idx = 0; idx < kPqInvOETFNumEntries; idx++) {
for (size_t idx = 0; idx < kPqInvOETFNumEntries; idx++) {
float value = static_cast<float>(idx) / static_cast<float>(kPqInvOETFNumEntries - 1);
EXPECT_FLOAT_EQ(pqInvOetf(value), pqInvOetfLUT(value));
}
}

TEST_F(GainMapMathTest, HlgInvOetfLUT) {
for (int idx = 0; idx < kHlgInvOETFNumEntries; idx++) {
for (size_t idx = 0; idx < kHlgInvOETFNumEntries; idx++) {
float value = static_cast<float>(idx) / static_cast<float>(kHlgInvOETFNumEntries - 1);
EXPECT_FLOAT_EQ(hlgInvOetf(value), hlgInvOetfLUT(value));
}
}

TEST_F(GainMapMathTest, pqOetfLUT) {
for (int idx = 0; idx < kPqOETFNumEntries; idx++) {
for (size_t idx = 0; idx < kPqOETFNumEntries; idx++) {
float value = static_cast<float>(idx) / static_cast<float>(kPqOETFNumEntries - 1);
EXPECT_FLOAT_EQ(pqOetf(value), pqOetfLUT(value));
}
}

TEST_F(GainMapMathTest, hlgOetfLUT) {
for (int idx = 0; idx < kHlgOETFNumEntries; idx++) {
for (size_t idx = 0; idx < kHlgOETFNumEntries; idx++) {
float value = static_cast<float>(idx) / static_cast<float>(kHlgOETFNumEntries - 1);
EXPECT_FLOAT_EQ(hlgOetf(value), hlgOetfLUT(value));
}
}

TEST_F(GainMapMathTest, srgbInvOetfLUT) {
for (int idx = 0; idx < kSrgbInvOETFNumEntries; idx++) {
for (size_t idx = 0; idx < kSrgbInvOETFNumEntries; idx++) {
float value = static_cast<float>(idx) / static_cast<float>(kSrgbInvOETFNumEntries - 1);
EXPECT_FLOAT_EQ(srgbInvOetf(value), srgbInvOetfLUT(value));
}
Expand All @@ -780,7 +780,7 @@ TEST_F(GainMapMathTest, applyGainLUT) {
.minContentBoost = 1.0f / static_cast<float>(boost) };
GainLUT gainLUT(&metadata);
GainLUT gainLUTWithBoost(&metadata, metadata.maxContentBoost);
for (int idx = 0; idx < kGainFactorNumEntries; idx++) {
for (size_t idx = 0; idx < kGainFactorNumEntries; idx++) {
float value = static_cast<float>(idx) / static_cast<float>(kGainFactorNumEntries - 1);
EXPECT_RGB_NEAR(applyGain(RgbBlack(), value, &metadata),
applyGainLUT(RgbBlack(), value, gainLUT));
Expand Down Expand Up @@ -810,7 +810,7 @@ TEST_F(GainMapMathTest, applyGainLUT) {
.minContentBoost = 1.0f };
GainLUT gainLUT(&metadata);
GainLUT gainLUTWithBoost(&metadata, metadata.maxContentBoost);
for (int idx = 0; idx < kGainFactorNumEntries; idx++) {
for (size_t idx = 0; idx < kGainFactorNumEntries; idx++) {
float value = static_cast<float>(idx) / static_cast<float>(kGainFactorNumEntries - 1);
EXPECT_RGB_NEAR(applyGain(RgbBlack(), value, &metadata),
applyGainLUT(RgbBlack(), value, gainLUT));
Expand Down Expand Up @@ -841,7 +841,7 @@ TEST_F(GainMapMathTest, applyGainLUT) {
powf(static_cast<float>(boost), 1.0f / 3.0f)};
GainLUT gainLUT(&metadata);
GainLUT gainLUTWithBoost(&metadata, metadata.maxContentBoost);
for (int idx = 0; idx < kGainFactorNumEntries; idx++) {
for (size_t idx = 0; idx < kGainFactorNumEntries; idx++) {
float value = static_cast<float>(idx) / static_cast<float>(kGainFactorNumEntries - 1);
EXPECT_RGB_NEAR(applyGain(RgbBlack(), value, &metadata),
applyGainLUT(RgbBlack(), value, gainLUT));
Expand Down
Loading

0 comments on commit cb0e4fb

Please sign in to comment.