From aecf13302aa9b2e9aa847ff636b5369c6e7975b9 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Thu, 9 Oct 2025 08:30:20 +0530 Subject: [PATCH] Fix off-by-one in NRGB --- tools/utils/images/to_rgb.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tools/utils/images/to_rgb.go b/tools/utils/images/to_rgb.go index 8e6fc1ea8..bcaae41c3 100644 --- a/tools/utils/images/to_rgb.go +++ b/tools/utils/images/to_rgb.go @@ -31,8 +31,8 @@ func (c NRGBColor) RGBA() (r, g, b, a uint32) { // NRGB is an in-memory image whose At method returns NRGBColor values. type NRGB struct { - // Pix holds the image's pixels, in R, G, B, A order. The pixel at - // (x, y) starts at Pix[(y-Rect.Min.Y)*Stride + (x-Rect.Min.X)*4]. + // Pix holds the image's pixels, in R, G, B order. The pixel at + // (x, y) starts at Pix[(y-Rect.Min.Y)*Stride + (x-Rect.Min.X)*3]. Pix []uint8 // Stride is the Pix stride (in bytes) between vertically adjacent pixels. Stride int @@ -80,7 +80,7 @@ func (p *NRGB) NRGBAt(x, y int) NRGBColor { // PixOffset returns the index of the first element of Pix that corresponds to // the pixel at (x, y). func (p *NRGB) PixOffset(x, y int) int { - return (y-p.Rect.Min.Y)*p.Stride + (x-p.Rect.Min.X)*4 + return (y-p.Rect.Min.Y)*p.Stride + (x-p.Rect.Min.X)*3 } func (p *NRGB) Set(x, y int, c color.Color) {