Skip to content

Commit 86bfa2f

Browse files
committed
Frame: Fix interlaced AddImage
1 parent 49972b2 commit 86bfa2f

File tree

1 file changed

+15
-8
lines changed

1 file changed

+15
-8
lines changed

src/Frame.cpp

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -818,16 +818,23 @@ void Frame::AddImage(std::shared_ptr<QImage> new_image, bool only_odd_lines)
818818
// Ignore image of different sizes or formats
819819
bool ret=false;
820820
#pragma omp critical (AddImage)
821-
if (image == new_image || image->size() != image->size() || image->format() != image->format())
822-
ret=true;
823-
if (ret)
821+
{
822+
if (image == new_image || image->size() != new_image->size()) {
823+
ret = true;
824+
}
825+
else if (new_image->format() != image->format()) {
826+
new_image = std::shared_ptr<QImage>(new QImage(new_image->convertToFormat(image->format())));
827+
}
828+
}
829+
if (ret) {
824830
return;
825-
831+
}
832+
826833
// Get the frame's image
827834
const GenericScopedLock<juce::CriticalSection> lock(addingImageSection);
828835
#pragma omp critical (AddImage)
829836
{
830-
const unsigned char *pixels = image->constBits();
837+
unsigned char *pixels = image->bits();
831838
const unsigned char *new_pixels = new_image->constBits();
832839

833840
// Loop through the scanlines of the image (even or odd)
@@ -836,13 +843,13 @@ void Frame::AddImage(std::shared_ptr<QImage> new_image, bool only_odd_lines)
836843
start = 1;
837844

838845
for (int row = start; row < image->height(); row += 2) {
839-
memcpy((unsigned char *) pixels, new_pixels + (row * image->bytesPerLine()), image->bytesPerLine());
840-
new_pixels += image->bytesPerLine();
846+
int offset = row * image->bytesPerLine();
847+
memcpy(pixels + offset, new_pixels + offset, image->bytesPerLine());
841848
}
842849

843850
// Update height and width
844-
width = image->width();
845851
height = image->height();
852+
width = image->width();
846853
has_image_data = true;
847854
}
848855
}

0 commit comments

Comments
 (0)