Skip to content

Commit

Permalink
fix type conversion warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
farindk committed Oct 12, 2023
1 parent 34b9468 commit 0f265bd
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 13 deletions.
4 changes: 2 additions & 2 deletions libheif/heif_regions.cc
Original file line number Diff line number Diff line change
Expand Up @@ -342,7 +342,7 @@ struct heif_error heif_region_item_add_region_inline_mask(struct heif_region_ite
for (uint32_t y = 0; y < mask_height; y++) {
for (uint32_t x = 0; x < mask_width; x++) {
uint8_t mask_bit = p[y * stride + x] & 0x80; // use high-order bit of the 8-bit mask value as binary mask value
region->mask_data.data()[pixel_index/8] |= (mask_bit >> (pixel_index % 8));
region->mask_data.data()[pixel_index/8] |= uint8_t(mask_bit >> (pixel_index % 8));

pixel_index++;
}
Expand Down Expand Up @@ -682,7 +682,7 @@ static struct heif_error heif_region_get_inline_mask_image(const struct heif_reg
for (uint32_t x = 0; x < width; x++)
{
uint64_t mask_byte = pixel_index / 8;
uint8_t pixel_bit = 0x80U >> (pixel_index % 8);
uint8_t pixel_bit = uint8_t(0x80U >> (pixel_index % 8));

p[y * stride + x] = (mask_data[mask_byte] & pixel_bit) ? 255 : 0;

Expand Down
2 changes: 1 addition & 1 deletion libheif/jpeg2000.cc
Original file line number Diff line number Diff line change
Expand Up @@ -357,7 +357,7 @@ JPEG2000_SIZ_segment jpeg2000_get_SIZ_segment(const HeifFile& file, heif_item_id
JPEG2000_SIZ_segment::component comp;
comp.precision = data[42 + c * 3];
comp.is_signed = (comp.precision & 0x80);
comp.precision = (comp.precision & 0x7F) + 1;
comp.precision = uint8_t((comp.precision & 0x7F) + 1);
comp.h_separation = data[43 + c * 3];
comp.v_separation = data[44 + c * 3];
siz.components.push_back(comp);
Expand Down
22 changes: 15 additions & 7 deletions libheif/uncompressed_image.cc
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ Error Box_uncC::parse(BitstreamRange& range)
for (unsigned int i = 0; i < component_count && !range.error() && !range.eof(); i++) {
Component component;
component.component_index = range.read16();
component.component_bit_depth = range.read8() + 1;
component.component_bit_depth = uint16_t(range.read8() + 1);
component.component_format = range.read8();
component.component_align_size = range.read8();
m_components.push_back(component);
Expand Down Expand Up @@ -281,20 +281,24 @@ Error Box_uncC::write(StreamWriter& writer) const
writer.write32(m_profile);
writer.write32((uint32_t) m_components.size());
for (const auto& component : m_components) {
if (component.component_bit_depth < 1 || component.component_bit_depth > 256) {
return {heif_error_Invalid_input, heif_suberror_Invalid_parameter_value, "component bit-depth out of range [1..256]"};
}

writer.write16(component.component_index);
writer.write8(component.component_bit_depth - 1);
writer.write8(uint8_t(component.component_bit_depth - 1));
writer.write8(component.component_format);
writer.write8(component.component_align_size);
}
writer.write8(m_sampling_type);
writer.write8(m_interleave_type);
writer.write8(m_block_size);
uint8_t flags = 0;
flags |= (m_components_little_endian ? 1 : 0) << 7;
flags |= (m_block_pad_lsb ? 1 : 0) << 6;
flags |= (m_block_little_endian ? 1 : 0) << 5;
flags |= (m_block_reversed ? 1 : 0) << 4;
flags |= (m_pad_unknown ? 1 : 0) << 3;
flags |= (m_components_little_endian ? 0x80 : 0);
flags |= (m_block_pad_lsb ? 0x40 : 0);
flags |= (m_block_little_endian ? 0x20 : 0);
flags |= (m_block_reversed ? 0x10 : 0);
flags |= (m_pad_unknown ? 0x08 : 0);
writer.write8(flags);
writer.write32(m_pixel_size);
writer.write32(m_row_align_size);
Expand Down Expand Up @@ -415,6 +419,10 @@ static Error get_heif_chroma_uncompressed(std::shared_ptr<Box_uncC>& uncC, std::
uint16_t component_index = component.component_index;
uint16_t component_type = cmpd->get_components()[component_index].component_type;

if (component_type >= 16) {
return { heif_error_Unsupported_feature, heif_suberror_Invalid_parameter_value, "a component_type >= 16 is not supported"};
}

componentSet |= (1 << component_type);
}

Expand Down
2 changes: 1 addition & 1 deletion libheif/uncompressed_image.h
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ class Box_uncC : public FullBox
struct Component
{
uint16_t component_index;
uint8_t component_bit_depth;
uint16_t component_bit_depth; // range [1..256]
uint8_t component_format;
uint8_t component_align_size;
};
Expand Down
4 changes: 2 additions & 2 deletions libheif/vvc.cc
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ Error Box_vvcC::parse(BitstreamRange& range)
byte = range.read8();
c.constantFrameRate = (byte & 0xc0) >> 6;
c.numTemporalLayers = (byte & 0x38) >> 3;
c.lengthSize = (byte & 0x06) + 1;
c.lengthSize = uint8_t((byte & 0x06) + 1);
c.ptl_present_flag = (byte & 0x01);
// assert(c.ptl_present_flag == false); // TODO (removed the assert since it will trigger the fuzzers)

Expand All @@ -46,7 +46,7 @@ Error Box_vvcC::parse(BitstreamRange& range)
c.chroma_format_idc = (byte & 0x60) >> 5;

c.bit_depth_present_flag = (byte & 0x10);
c.bit_depth = ((byte & 0x0e) >> 1) + 8;
c.bit_depth = uint8_t(((byte & 0x0e) >> 1) + 8);

c.numOfArrays = range.read8();

Expand Down

0 comments on commit 0f265bd

Please sign in to comment.