github.com/shogo82148/std@v1.22.1-0.20240327122250-4e474527810c/image/png/writer.go (about)

     1  // Copyright 2009 The Go Authors. All rights reserved.
     2  // Use of this source code is governed by a BSD-style
     3  // license that can be found in the LICENSE file.
     4  
     5  package png
     6  
     7  import (
     8  	"github.com/shogo82148/std/image"
     9  	"github.com/shogo82148/std/io"
    10  )
    11  
    12  // Encoderは、PNG画像のエンコーディングを設定します。
    13  type Encoder struct {
    14  	CompressionLevel CompressionLevel
    15  
    16  	// BufferPoolは、画像をエンコードする際に一時的な
    17  	// EncoderBuffersを取得するためのバッファプールをオプションで指定します。
    18  	BufferPool EncoderBufferPool
    19  }
    20  
    21  // EncoderBufferPoolは、一時的な [EncoderBuffer] 構造体のインスタンスを取得し、
    22  // 返すためのインターフェースです。これは、複数の画像をエンコードする際にバッファを再利用するために使用できます。
    23  type EncoderBufferPool interface {
    24  	Get() *EncoderBuffer
    25  	Put(*EncoderBuffer)
    26  }
    27  
    28  // EncoderBufferは、PNG画像のエンコーディングに使用されるバッファを保持します。
    29  type EncoderBuffer encoder
    30  
    31  // CompressionLevelは、圧縮レベルを示します。
    32  type CompressionLevel int
    33  
    34  const (
    35  	DefaultCompression CompressionLevel = 0
    36  	NoCompression      CompressionLevel = -1
    37  	BestSpeed          CompressionLevel = -2
    38  	BestCompression    CompressionLevel = -3
    39  )
    40  
    41  // Encodeは、画像mをPNG形式でwに書き込みます。任意の画像をエンコードできますが、
    42  // [image.NRGBA] でない画像は、損失を伴ってエンコードされる可能性があります。
    43  func Encode(w io.Writer, m image.Image) error
    44  
    45  // Encodeは、画像mをPNG形式でwに書き込みます。
    46  func (enc *Encoder) Encode(w io.Writer, m image.Image) error