From 1a898dd1b9b959433ff25ff3a522131b733c8527 Mon Sep 17 00:00:00 2001 From: Hajime Hoshi Date: Thu, 1 Mar 2018 02:49:45 +0900 Subject: [PATCH] Add comments --- internal/restorable/copy.go | 2 ++ internal/restorable/image.go | 4 ++++ 2 files changed, 6 insertions(+) diff --git a/internal/restorable/copy.go b/internal/restorable/copy.go index fb4676822..b0df6c42f 100644 --- a/internal/restorable/copy.go +++ b/internal/restorable/copy.go @@ -27,6 +27,8 @@ import ( // If origImg is a paletted image, an optimized copying method is used. // // CopyImage is used only internally but it is exposed for testing. +// +// TODO: CopyImage should return []byte (#521) func CopyImage(origImg image.Image) *image.RGBA { size := origImg.Bounds().Size() w, h := size.X, size.Y diff --git a/internal/restorable/image.go b/internal/restorable/image.go index e5b7e3175..a7e8ffb54 100644 --- a/internal/restorable/image.go +++ b/internal/restorable/image.go @@ -164,7 +164,11 @@ func (i *Image) ReplacePixels(pixels []byte, x, y, width, height int) { if x < 0 || y < 0 || w <= x || h <= y || x+width <= 0 || y+height <= 0 || w < x+width || h < y+height { panic(fmt.Sprintf("restorable: out of range x: %d, y: %d, width: %d, height: %d", x, y, width, height)) } + + // TODO: Avoid making other images stale if possible. + // For this purpuse, images should remember which part of that is used for DrawImage. theImages.makeStaleIfDependingOn(i) + i.image.ReplacePixels(pixels, x, y, width, height) // Copy the pixels so that this works even p is modified just after ReplacePixels.