Skip to content

Commit

Permalink
Rename bitextend to bitextend16
Browse files Browse the repository at this point in the history
  • Loading branch information
aaaaaa123456789 committed Jan 24, 2022
1 parent e3f47d1 commit 34608d8
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 9 deletions.
8 changes: 4 additions & 4 deletions src/bmpread.c
Original file line number Diff line number Diff line change
Expand Up @@ -342,9 +342,9 @@ uint64_t load_BMP_RGB_pixel (const unsigned char * data, const void * bitmasks)

uint64_t load_BMP_bitmasked_pixel (uint_fast32_t pixel, const uint8_t * bitmasks) {
uint64_t result = 0;
if (bitmasks[1]) result |= bitextend((pixel >> *bitmasks) & (((uint64_t) 1 << bitmasks[1]) - 1), bitmasks[1]);
if (bitmasks[3]) result |= (uint64_t) bitextend((pixel >> bitmasks[2]) & (((uint64_t) 1 << bitmasks[3]) - 1), bitmasks[3]) << 16;
if (bitmasks[5]) result |= (uint64_t) bitextend((pixel >> bitmasks[4]) & (((uint64_t) 1 << bitmasks[5]) - 1), bitmasks[5]) << 32;
if (bitmasks[7]) result |= (~(uint64_t) bitextend((pixel >> bitmasks[6]) & (((uint64_t) 1 << bitmasks[7]) - 1), bitmasks[7])) << 48;
if (bitmasks[1]) result |= bitextend16((pixel >> *bitmasks) & (((uint64_t) 1 << bitmasks[1]) - 1), bitmasks[1]);
if (bitmasks[3]) result |= (uint64_t) bitextend16((pixel >> bitmasks[2]) & (((uint64_t) 1 << bitmasks[3]) - 1), bitmasks[3]) << 16;
if (bitmasks[5]) result |= (uint64_t) bitextend16((pixel >> bitmasks[4]) & (((uint64_t) 1 << bitmasks[5]) - 1), bitmasks[5]) << 32;
if (bitmasks[7]) result |= (~(uint64_t) bitextend16((pixel >> bitmasks[6]) & (((uint64_t) 1 << bitmasks[7]) - 1), bitmasks[7])) << 48;
return result;
}
2 changes: 1 addition & 1 deletion src/inline.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ static inline uintmax_t bitnegate (uintmax_t value) {
return ~value;
}

static inline uint16_t bitextend (uint16_t value, unsigned width) {
static inline uint16_t bitextend16 (uint16_t value, unsigned width) {
uint_fast32_t result = value;
while (width < 16) {
result |= result << width;
Expand Down
4 changes: 2 additions & 2 deletions src/pngread.c
Original file line number Diff line number Diff line change
Expand Up @@ -351,7 +351,7 @@ uint64_t add_PNG_background_metadata (struct context * context, const struct PNG
if (read_be32_unaligned(data - 8) != 2) throw(context, PLUM_ERR_INVALID_FILE_FORMAT);
color = read_le16_unaligned(data);
if (color >> bitdepth) throw(context, PLUM_ERR_INVALID_FILE_FORMAT);
color = 0x100010001u * (uint64_t) bitextend(color, bitdepth);
color = 0x100010001u * (uint64_t) bitextend16(color, bitdepth);
break;
case 3:
if (read_be32_unaligned(data - 8) != 1) throw(context, PLUM_ERR_INVALID_FILE_FORMAT);
Expand All @@ -377,7 +377,7 @@ uint64_t load_PNG_transparent_color (struct context * context, size_t offset, ui
if (!imagetype) {
uint_fast32_t color = read_be16_unaligned(data); // cannot be 16-bit because of the potential >> 16 in the next line
if (color >> bitdepth) throw(context, PLUM_ERR_INVALID_FILE_FORMAT);
return 0x100010001u * (uint64_t) bitextend(color, bitdepth);
return 0x100010001u * (uint64_t) bitextend16(color, bitdepth);
} else if (bitdepth == 8) {
if (*data || data[2] || data[4]) throw(context, PLUM_ERR_INVALID_FILE_FORMAT);
return ((uint64_t) data[1] | ((uint64_t) data[3] << 16) | ((uint64_t) data[5] << 32)) * 0x101;
Expand Down
2 changes: 1 addition & 1 deletion src/pngreadframe.c
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ void load_PNG_raw_frame_pass (struct context * context, unsigned char * restrict
default: {
unsigned char * buffer = ctxmalloc(context, width);
expand_bitpacked_PNG_data(buffer, rowdata, width, bitdepth);
for (col = 0; col < width; col ++) rowoutput[col * offsetH + coordH] = (uint64_t) bitextend(buffer[col], bitdepth) * 0x100010001u;
for (col = 0; col < width; col ++) rowoutput[col * offsetH + coordH] = (uint64_t) bitextend16(buffer[col], bitdepth) * 0x100010001u;
ctxfree(context, buffer);
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/pnmread.c
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,7 @@ void load_PNM_frame (struct context * context, const struct PNM_image_header * h
for (color = 0; color < 4; color ++) {
uint64_t converted;
if (bits)
converted = bitextend(values[color], bits);
converted = bitextend16(values[color], bits);
else
converted = (values[color] * 0xffffu + (header -> maxvalue >> 1)) / header -> maxvalue;
buffer[p] |= converted << (color * 16);
Expand Down

0 comments on commit 34608d8

Please sign in to comment.