]> Cypherpunks repositories - gostls13.git/commitdiff
image/gif: use internal/byteorder
authorapocelipes <seve3r@outlook.com>
Sat, 11 May 2024 13:13:19 +0000 (13:13 +0000)
committerGopher Robot <gobot@golang.org>
Mon, 13 May 2024 21:38:09 +0000 (21:38 +0000)
Change-Id: Ic00e63aa35bcea4c97a5885d61edb8fc37d84e22
GitHub-Last-Rev: 1ad3a5d0edebbd0f0b98ce68ad81ea4c36f5a63d
GitHub-Pull-Request: golang/go#67324
Reviewed-on: https://go-review.googlesource.com/c/go/+/584997
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Ian Lance Taylor <iant@google.com>
Auto-Submit: Ian Lance Taylor <iant@google.com>
Reviewed-by: Dmitri Shuralyov <dmitshur@google.com>
src/image/gif/writer.go

index 0da47f3e35b966d504dc4bc5a683dca9050b61a6..0d2a1321c01b072eb2aef85254220b5fce92fd1c 100644 (file)
@@ -13,6 +13,7 @@ import (
        "image/color"
        "image/color/palette"
        "image/draw"
+       "internal/byteorder"
        "io"
 )
 
@@ -33,12 +34,6 @@ func log2(x int) int {
        return -1
 }
 
-// Little-endian.
-func writeUint16(b []uint8, u uint16) {
-       b[0] = uint8(u)
-       b[1] = uint8(u >> 8)
-}
-
 // writer is a buffered writer.
 type writer interface {
        Flush() error
@@ -151,8 +146,8 @@ func (e *encoder) writeHeader() {
        }
 
        // Logical screen width and height.
-       writeUint16(e.buf[0:2], uint16(e.g.Config.Width))
-       writeUint16(e.buf[2:4], uint16(e.g.Config.Height))
+       byteorder.LePutUint16(e.buf[0:2], uint16(e.g.Config.Width))
+       byteorder.LePutUint16(e.buf[2:4], uint16(e.g.Config.Height))
        e.write(e.buf[:4])
 
        if p, ok := e.g.Config.ColorModel.(color.Palette); ok && len(p) > 0 {
@@ -190,7 +185,7 @@ func (e *encoder) writeHeader() {
                }
                e.buf[0] = 0x03 // Block Size.
                e.buf[1] = 0x01 // Sub-block Index.
-               writeUint16(e.buf[2:4], uint16(e.g.LoopCount))
+               byteorder.LePutUint16(e.buf[2:4], uint16(e.g.LoopCount))
                e.buf[4] = 0x00 // Block Terminator.
                e.write(e.buf[:5])
        }
@@ -276,7 +271,7 @@ func (e *encoder) writeImageBlock(pm *image.Paletted, delay int, disposal byte)
                } else {
                        e.buf[3] = 0x00 | disposal<<2
                }
-               writeUint16(e.buf[4:6], uint16(delay)) // Delay Time (1/100ths of a second)
+               byteorder.LePutUint16(e.buf[4:6], uint16(delay)) // Delay Time (1/100ths of a second)
 
                // Transparent color index.
                if transparentIndex != -1 {
@@ -288,10 +283,10 @@ func (e *encoder) writeImageBlock(pm *image.Paletted, delay int, disposal byte)
                e.write(e.buf[:8])
        }
        e.buf[0] = sImageDescriptor
-       writeUint16(e.buf[1:3], uint16(b.Min.X))
-       writeUint16(e.buf[3:5], uint16(b.Min.Y))
-       writeUint16(e.buf[5:7], uint16(b.Dx()))
-       writeUint16(e.buf[7:9], uint16(b.Dy()))
+       byteorder.LePutUint16(e.buf[1:3], uint16(b.Min.X))
+       byteorder.LePutUint16(e.buf[3:5], uint16(b.Min.Y))
+       byteorder.LePutUint16(e.buf[5:7], uint16(b.Dx()))
+       byteorder.LePutUint16(e.buf[7:9], uint16(b.Dy()))
        e.write(e.buf[:9])
 
        // To determine whether or not this frame's palette is the same as the