Loading libs/ultrahdr/fuzzer/ultrahdr_enc_fuzzer.cpp +4 −14 Original line number Diff line number Diff line Loading @@ -24,21 +24,11 @@ // User include files #include "ultrahdr/gainmapmath.h" #include "ultrahdr/jpegencoderhelper.h" #include "ultrahdr/jpegdecoderhelper.h" #include "utils/Log.h" using namespace android::ultrahdr; // constants const int kMinWidth = 8; const int kMaxWidth = 7680; const int kMinHeight = 8; const int kMaxHeight = 4320; const int kScaleFactor = 4; const int kJpegBlock = 16; // Color gamuts for image data, sync with ultrahdr.h const int kCgMin = ULTRAHDR_COLORGAMUT_UNSPECIFIED + 1; const int kCgMax = ULTRAHDR_COLORGAMUT_MAX; Loading Loading @@ -164,8 +154,8 @@ void UltraHdrEncFuzzer::process() { fillP010Buffer(bufferUV.get(), width, height / 2, uvStride); } } else { int map_width = width / kScaleFactor; int map_height = height / kScaleFactor; int map_width = width / kMapDimensionScaleFactor; int map_height = height / kMapDimensionScaleFactor; map_width = static_cast<size_t>(floor((map_width + kJpegBlock - 1) / kJpegBlock)) * kJpegBlock; map_height = ((map_height + 1) >> 1) << 1; Loading Loading @@ -249,7 +239,7 @@ void UltraHdrEncFuzzer::process() { jpegGainMap.data = gainMapEncoder.getCompressedImagePtr(); jpegGainMap.colorGamut = ULTRAHDR_COLORGAMUT_UNSPECIFIED; ultrahdr_metadata_struct metadata; metadata.version = "1.0"; metadata.version = kJpegrVersion; if (tf == ULTRAHDR_TF_HLG) { metadata.maxContentBoost = kHlgMaxNits / kSdrWhiteNits; } else if (tf == ULTRAHDR_TF_PQ) { Loading libs/ultrahdr/gainmapmath.cpp +13 −29 Original line number Diff line number Diff line Loading @@ -531,21 +531,21 @@ void transformYuv420(jr_uncompressed_ptr image, size_t x_chroma, size_t y_chroma Color new_uv = (yuv1 + yuv2 + yuv3 + yuv4) / 4.0f; size_t pixel_y1_idx = x_chroma * 2 + y_chroma * 2 * image->width; size_t pixel_y2_idx = (x_chroma * 2 + 1) + y_chroma * 2 * image->width; size_t pixel_y3_idx = x_chroma * 2 + (y_chroma * 2 + 1) * image->width; size_t pixel_y4_idx = (x_chroma * 2 + 1) + (y_chroma * 2 + 1) * image->width; size_t pixel_y1_idx = x_chroma * 2 + y_chroma * 2 * image->luma_stride; size_t pixel_y2_idx = (x_chroma * 2 + 1) + y_chroma * 2 * image->luma_stride; size_t pixel_y3_idx = x_chroma * 2 + (y_chroma * 2 + 1) * image->luma_stride; size_t pixel_y4_idx = (x_chroma * 2 + 1) + (y_chroma * 2 + 1) * image->luma_stride; uint8_t& y1_uint = reinterpret_cast<uint8_t*>(image->data)[pixel_y1_idx]; uint8_t& y2_uint = reinterpret_cast<uint8_t*>(image->data)[pixel_y2_idx]; uint8_t& y3_uint = reinterpret_cast<uint8_t*>(image->data)[pixel_y3_idx]; uint8_t& y4_uint = reinterpret_cast<uint8_t*>(image->data)[pixel_y4_idx]; size_t pixel_count = image->width * image->height; size_t pixel_uv_idx = x_chroma + y_chroma * (image->width / 2); size_t pixel_count = image->chroma_stride * image->height / 2; size_t pixel_uv_idx = x_chroma + y_chroma * (image->chroma_stride); uint8_t& u_uint = reinterpret_cast<uint8_t*>(image->data)[pixel_count + pixel_uv_idx]; uint8_t& v_uint = reinterpret_cast<uint8_t*>(image->data)[pixel_count * 5 / 4 + pixel_uv_idx]; uint8_t& u_uint = reinterpret_cast<uint8_t*>(image->chroma_data)[pixel_uv_idx]; uint8_t& v_uint = reinterpret_cast<uint8_t*>(image->chroma_data)[pixel_count + pixel_uv_idx]; y1_uint = static_cast<uint8_t>(CLIP3((yuv1.y * 255.0f + 0.5f), 0, 255)); y2_uint = static_cast<uint8_t>(CLIP3((yuv2.y * 255.0f + 0.5f), 0, 255)); Loading Loading @@ -599,17 +599,9 @@ Color applyGainLUT(Color e, float gain, GainLUT& gainLUT) { Color getYuv420Pixel(jr_uncompressed_ptr image, size_t x, size_t y) { uint8_t* luma_data = reinterpret_cast<uint8_t*>(image->data); size_t luma_stride = image->luma_stride == 0 ? image->width : image->luma_stride; uint8_t* chroma_data; size_t chroma_stride; if (image->chroma_data == nullptr) { chroma_stride = luma_stride / 2; chroma_data = &reinterpret_cast<uint8_t*>(image->data)[luma_stride * image->height]; } else { chroma_stride = image->chroma_stride; chroma_data = reinterpret_cast<uint8_t*>(image->chroma_data); } size_t luma_stride = image->luma_stride; uint8_t* chroma_data = reinterpret_cast<uint8_t*>(image->chroma_data); size_t chroma_stride = image->chroma_stride; size_t offset_cr = chroma_stride * (image->height / 2); size_t pixel_y_idx = x + y * luma_stride; Loading @@ -629,16 +621,8 @@ Color getYuv420Pixel(jr_uncompressed_ptr image, size_t x, size_t y) { Color getP010Pixel(jr_uncompressed_ptr image, size_t x, size_t y) { uint16_t* luma_data = reinterpret_cast<uint16_t*>(image->data); size_t luma_stride = image->luma_stride == 0 ? image->width : image->luma_stride; uint16_t* chroma_data; size_t chroma_stride; if (image->chroma_data == nullptr) { chroma_stride = luma_stride; chroma_data = &reinterpret_cast<uint16_t*>(image->data)[luma_stride * image->height]; } else { chroma_stride = image->chroma_stride; chroma_data = reinterpret_cast<uint16_t*>(image->chroma_data); } uint16_t* chroma_data = reinterpret_cast<uint16_t*>(image->chroma_data); size_t chroma_stride = image->chroma_stride; size_t pixel_y_idx = y * luma_stride + x; size_t pixel_u_idx = (y >> 1) * chroma_stride + (x & ~0x1); Loading Loading
libs/ultrahdr/fuzzer/ultrahdr_enc_fuzzer.cpp +4 −14 Original line number Diff line number Diff line Loading @@ -24,21 +24,11 @@ // User include files #include "ultrahdr/gainmapmath.h" #include "ultrahdr/jpegencoderhelper.h" #include "ultrahdr/jpegdecoderhelper.h" #include "utils/Log.h" using namespace android::ultrahdr; // constants const int kMinWidth = 8; const int kMaxWidth = 7680; const int kMinHeight = 8; const int kMaxHeight = 4320; const int kScaleFactor = 4; const int kJpegBlock = 16; // Color gamuts for image data, sync with ultrahdr.h const int kCgMin = ULTRAHDR_COLORGAMUT_UNSPECIFIED + 1; const int kCgMax = ULTRAHDR_COLORGAMUT_MAX; Loading Loading @@ -164,8 +154,8 @@ void UltraHdrEncFuzzer::process() { fillP010Buffer(bufferUV.get(), width, height / 2, uvStride); } } else { int map_width = width / kScaleFactor; int map_height = height / kScaleFactor; int map_width = width / kMapDimensionScaleFactor; int map_height = height / kMapDimensionScaleFactor; map_width = static_cast<size_t>(floor((map_width + kJpegBlock - 1) / kJpegBlock)) * kJpegBlock; map_height = ((map_height + 1) >> 1) << 1; Loading Loading @@ -249,7 +239,7 @@ void UltraHdrEncFuzzer::process() { jpegGainMap.data = gainMapEncoder.getCompressedImagePtr(); jpegGainMap.colorGamut = ULTRAHDR_COLORGAMUT_UNSPECIFIED; ultrahdr_metadata_struct metadata; metadata.version = "1.0"; metadata.version = kJpegrVersion; if (tf == ULTRAHDR_TF_HLG) { metadata.maxContentBoost = kHlgMaxNits / kSdrWhiteNits; } else if (tf == ULTRAHDR_TF_PQ) { Loading
libs/ultrahdr/gainmapmath.cpp +13 −29 Original line number Diff line number Diff line Loading @@ -531,21 +531,21 @@ void transformYuv420(jr_uncompressed_ptr image, size_t x_chroma, size_t y_chroma Color new_uv = (yuv1 + yuv2 + yuv3 + yuv4) / 4.0f; size_t pixel_y1_idx = x_chroma * 2 + y_chroma * 2 * image->width; size_t pixel_y2_idx = (x_chroma * 2 + 1) + y_chroma * 2 * image->width; size_t pixel_y3_idx = x_chroma * 2 + (y_chroma * 2 + 1) * image->width; size_t pixel_y4_idx = (x_chroma * 2 + 1) + (y_chroma * 2 + 1) * image->width; size_t pixel_y1_idx = x_chroma * 2 + y_chroma * 2 * image->luma_stride; size_t pixel_y2_idx = (x_chroma * 2 + 1) + y_chroma * 2 * image->luma_stride; size_t pixel_y3_idx = x_chroma * 2 + (y_chroma * 2 + 1) * image->luma_stride; size_t pixel_y4_idx = (x_chroma * 2 + 1) + (y_chroma * 2 + 1) * image->luma_stride; uint8_t& y1_uint = reinterpret_cast<uint8_t*>(image->data)[pixel_y1_idx]; uint8_t& y2_uint = reinterpret_cast<uint8_t*>(image->data)[pixel_y2_idx]; uint8_t& y3_uint = reinterpret_cast<uint8_t*>(image->data)[pixel_y3_idx]; uint8_t& y4_uint = reinterpret_cast<uint8_t*>(image->data)[pixel_y4_idx]; size_t pixel_count = image->width * image->height; size_t pixel_uv_idx = x_chroma + y_chroma * (image->width / 2); size_t pixel_count = image->chroma_stride * image->height / 2; size_t pixel_uv_idx = x_chroma + y_chroma * (image->chroma_stride); uint8_t& u_uint = reinterpret_cast<uint8_t*>(image->data)[pixel_count + pixel_uv_idx]; uint8_t& v_uint = reinterpret_cast<uint8_t*>(image->data)[pixel_count * 5 / 4 + pixel_uv_idx]; uint8_t& u_uint = reinterpret_cast<uint8_t*>(image->chroma_data)[pixel_uv_idx]; uint8_t& v_uint = reinterpret_cast<uint8_t*>(image->chroma_data)[pixel_count + pixel_uv_idx]; y1_uint = static_cast<uint8_t>(CLIP3((yuv1.y * 255.0f + 0.5f), 0, 255)); y2_uint = static_cast<uint8_t>(CLIP3((yuv2.y * 255.0f + 0.5f), 0, 255)); Loading Loading @@ -599,17 +599,9 @@ Color applyGainLUT(Color e, float gain, GainLUT& gainLUT) { Color getYuv420Pixel(jr_uncompressed_ptr image, size_t x, size_t y) { uint8_t* luma_data = reinterpret_cast<uint8_t*>(image->data); size_t luma_stride = image->luma_stride == 0 ? image->width : image->luma_stride; uint8_t* chroma_data; size_t chroma_stride; if (image->chroma_data == nullptr) { chroma_stride = luma_stride / 2; chroma_data = &reinterpret_cast<uint8_t*>(image->data)[luma_stride * image->height]; } else { chroma_stride = image->chroma_stride; chroma_data = reinterpret_cast<uint8_t*>(image->chroma_data); } size_t luma_stride = image->luma_stride; uint8_t* chroma_data = reinterpret_cast<uint8_t*>(image->chroma_data); size_t chroma_stride = image->chroma_stride; size_t offset_cr = chroma_stride * (image->height / 2); size_t pixel_y_idx = x + y * luma_stride; Loading @@ -629,16 +621,8 @@ Color getYuv420Pixel(jr_uncompressed_ptr image, size_t x, size_t y) { Color getP010Pixel(jr_uncompressed_ptr image, size_t x, size_t y) { uint16_t* luma_data = reinterpret_cast<uint16_t*>(image->data); size_t luma_stride = image->luma_stride == 0 ? image->width : image->luma_stride; uint16_t* chroma_data; size_t chroma_stride; if (image->chroma_data == nullptr) { chroma_stride = luma_stride; chroma_data = &reinterpret_cast<uint16_t*>(image->data)[luma_stride * image->height]; } else { chroma_stride = image->chroma_stride; chroma_data = reinterpret_cast<uint16_t*>(image->chroma_data); } uint16_t* chroma_data = reinterpret_cast<uint16_t*>(image->chroma_data); size_t chroma_stride = image->chroma_stride; size_t pixel_y_idx = y * luma_stride + x; size_t pixel_u_idx = (y >> 1) * chroma_stride + (x & ~0x1); Loading