Skip to content

Commit

Permalink
simplify bit-depth conversion
Browse files Browse the repository at this point in the history
  • Loading branch information
dthoang-apple authored and kylophone committed Nov 20, 2023
1 parent 4196709 commit 2ac1f28
Showing 1 changed file with 9 additions and 14 deletions.
23 changes: 9 additions & 14 deletions libvmaf/tools/vmaf.c
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,6 @@ static int fetch_picture(video_input *vid, VmafPicture *pic, int depth)
} else if (depth > 8) {
// unequal bit-depth
// therefore depth must be > 8 since we do not support depth < 8
uint16_t value;
int left_shift = depth - info.depth;
if (info.depth == 8) {
for (unsigned i = 0; i < 3; i++) {
Expand All @@ -124,35 +123,31 @@ static int fetch_picture(video_input *vid, VmafPicture *pic, int depth)
uint8_t *ycbcr_data = ycbcr[i].data +
(info.pic_y >> ydec) * ycbcr[i].stride +
(info.pic_x >> xdec);
uint8_t *pic_data = (uint8_t *)pic->data[i];
uint16_t *pic_data = (uint16_t*)pic->data[i];

for (unsigned j = 0; j < pic->h[i]; j++) {
for (unsigned k = 0; k < pic->w[i]; k++) {
value=ycbcr_data[k]<<left_shift;
pic_data[2*k]=(value)&0xff;
pic_data[2*k+1]=(value>>8);
pic_data[k] = ycbcr_data[k] << left_shift;
}
pic_data += pic->stride[i];
pic_data += pic->stride[i] / 2;
ycbcr_data += ycbcr[i].stride;
}
}
} else {
for (unsigned i = 0; i < 3; i++) {
int xdec = i&&!(info.pixel_fmt&1);
int ydec = i&&!(info.pixel_fmt&2);
uint8_t *ycbcr_data = ycbcr[i].data +
(info.pic_y >> ydec) * ycbcr[i].stride +
uint16_t *ycbcr_data = (uint16_t*) ycbcr[i].data +
(info.pic_y >> ydec) * (ycbcr[i].stride / 2) +
(info.pic_x >> xdec);
uint8_t *pic_data = pic->data[i];
uint16_t *pic_data = pic->data[i];

for (unsigned j = 0; j < pic->h[i]; j++) {
for (unsigned k = 0; k < pic->w[i]; k++) {
value=((ycbcr_data[2*k+1]<<8)+ycbcr_data[2*k])<<left_shift;
pic_data[2*k]=(value)&0xff;
pic_data[2*k+1]=(value>>8);
pic_data[k] = ycbcr_data[k] << left_shift;
}
pic_data += pic->stride[i];
ycbcr_data += ycbcr[i].stride;
pic_data += pic->stride[i] / 2;
ycbcr_data += ycbcr[i].stride / 2;
}
}
}
Expand Down

0 comments on commit 2ac1f28

Please sign in to comment.