diff --git a/src/Frame.cpp b/src/Frame.cpp index 8a843aa8..7d4dc42e 100644 --- a/src/Frame.cpp +++ b/src/Frame.cpp @@ -818,16 +818,23 @@ void Frame::AddImage(std::shared_ptr new_image, bool only_odd_lines) // Ignore image of different sizes or formats bool ret=false; #pragma omp critical (AddImage) - if (image == new_image || image->size() != image->size() || image->format() != image->format()) - ret=true; - if (ret) + { + if (image == new_image || image->size() != new_image->size()) { + ret = true; + } + else if (new_image->format() != image->format()) { + new_image = std::shared_ptr(new QImage(new_image->convertToFormat(image->format()))); + } + } + if (ret) { return; - + } + // Get the frame's image const GenericScopedLock lock(addingImageSection); #pragma omp critical (AddImage) { - const unsigned char *pixels = image->constBits(); + unsigned char *pixels = image->bits(); const unsigned char *new_pixels = new_image->constBits(); // Loop through the scanlines of the image (even or odd) @@ -836,13 +843,13 @@ void Frame::AddImage(std::shared_ptr new_image, bool only_odd_lines) start = 1; for (int row = start; row < image->height(); row += 2) { - memcpy((unsigned char *) pixels, new_pixels + (row * image->bytesPerLine()), image->bytesPerLine()); - new_pixels += image->bytesPerLine(); + int offset = row * image->bytesPerLine(); + memcpy(pixels + offset, new_pixels + offset, image->bytesPerLine()); } // Update height and width - width = image->width(); height = image->height(); + width = image->width(); has_image_data = true; } }