From c3326a30f1bb17b81c8d0c5864c86dd23d15cb53 Mon Sep 17 00:00:00 2001 From: lord Date: Tue, 4 Aug 2020 19:23:26 -0700 Subject: [PATCH] fix lint errors for dc6 package (#681) --- d2common/d2fileformats/d2dc6/dc6.go | 30 +++++++++++++++++++++++++---- 1 file changed, 26 insertions(+), 4 deletions(-) diff --git a/d2common/d2fileformats/d2dc6/dc6.go b/d2common/d2fileformats/d2dc6/dc6.go index a148ba66..c95bbc80 100644 --- a/d2common/d2fileformats/d2dc6/dc6.go +++ b/d2common/d2fileformats/d2dc6/dc6.go @@ -9,6 +9,14 @@ const ( maxRunLength = 0x7f ) +type scanlineState int + +const ( + endOfLine scanlineState = iota + runOfTransparentPixels + runOfOpaquePixels +) + // DC6 represents a DC6 file. type DC6 struct { Version int32 @@ -75,22 +83,24 @@ func (d *DC6) DecodeFrame(frameIndex int) []byte { y := int(frame.Height) - 1 offset := 0 +loop: // this is a label for the loop, so the switch can break the loop (and not the switch) for { b := int(frame.FrameData[offset]) offset++ - if b == endOfScanLine { + switch scanlineType(b) { + case endOfLine: if y == 0 { - break + break loop } y-- x = 0 - } else if b&endOfScanLine > 0 { + case runOfTransparentPixels: transparentPixels := b & maxRunLength x += transparentPixels - } else { + case runOfOpaquePixels: for i := 0; i < b; i++ { indexData[x+y*int(frame.Width)+i] = frame.FrameData[offset] offset++ @@ -102,3 +112,15 @@ func (d *DC6) DecodeFrame(frameIndex int) []byte { return indexData } + +func scanlineType(b int) scanlineState { + if b == endOfScanLine { + return endOfLine + } + + if (b & endOfScanLine) > 0 { + return runOfTransparentPixels + } + + return runOfOpaquePixels +}