From 36205258c02d20099ac7bbbab1f1ce2a621ff8c5 Mon Sep 17 00:00:00 2001 From: Peter Keresztes Schmidt Date: Tue, 27 Apr 2021 19:24:44 +0200 Subject: [PATCH] Image: Fix crash in Annotate in GRAY8 and RGB24 mode Actually advance the image buffer pointer by one image line when looping through the codepoint lines. --- src/zm_image.cpp | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/zm_image.cpp b/src/zm_image.cpp index 08d803a4c..39cf9d55a 100644 --- a/src/zm_image.cpp +++ b/src/zm_image.cpp @@ -2033,10 +2033,11 @@ void Image::Annotate( } while (cp_row != 0) { - int column_idx = char_width - __builtin_ctzll(cp_row) + font_variant.GetCharPadding(); + uint32 column_idx = char_width - __builtin_ctzll(cp_row) + font_variant.GetCharPadding(); *(ptr + column_idx) = fg_colour & 0xff; cp_row = cp_row & (cp_row - 1); } + ptr += width; } ptr -= (width * char_height); ptr += char_width; @@ -2052,7 +2053,7 @@ void Image::Annotate( for (char c : line) { for (uint64 cp_row : font_variant.GetCodepoint(c)) { if (bg_colour != kRGBTransparent) { - for (int i = 0; i < char_width; i++) { // We need to set individual r,g,b components + for (uint16 i = 0; i < char_width; i++) { // We need to set individual r,g,b components uint8 *colour_ptr = ptr + (i * bytesPerPixel); RED_PTR_RGBA(colour_ptr) = RED_VAL_RGBA(bg_colour); GREEN_PTR_RGBA(colour_ptr) = GREEN_VAL_RGBA(bg_colour); @@ -2061,13 +2062,14 @@ void Image::Annotate( } while (cp_row != 0) { - int column_idx = char_width - __builtin_ctzll(cp_row) + font_variant.GetCharPadding(); + uint32 column_idx = char_width - __builtin_ctzll(cp_row) + font_variant.GetCharPadding(); uint8 *colour_ptr = ptr + (column_idx * bytesPerPixel); RED_PTR_RGBA(colour_ptr) = RED_VAL_RGBA(fg_colour); GREEN_PTR_RGBA(colour_ptr) = GREEN_VAL_RGBA(fg_colour); BLUE_PTR_RGBA(colour_ptr) = BLUE_VAL_RGBA(fg_colour); cp_row = cp_row & (cp_row - 1); } + ptr += width * bytesPerPixel; } ptr -= (width * char_height * bytesPerPixel); ptr += char_width * bytesPerPixel;