From a84908b7e8a0e2423afd6b836eccf27a420270b4 Mon Sep 17 00:00:00 2001 From: nsfisis Date: Wed, 20 Sep 2023 19:56:52 +0900 Subject: feat(blog/nuldoc): change content format from DocBook to NulDoc --- .../index.html | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) (limited to 'vhosts/blog/public/posts/2023-04-01/implementation-of-minimal-png-image-encoder') diff --git a/vhosts/blog/public/posts/2023-04-01/implementation-of-minimal-png-image-encoder/index.html b/vhosts/blog/public/posts/2023-04-01/implementation-of-minimal-png-image-encoder/index.html index 547191b9..91020aaf 100644 --- a/vhosts/blog/public/posts/2023-04-01/implementation-of-minimal-png-image-encoder/index.html +++ b/vhosts/blog/public/posts/2023-04-01/implementation-of-minimal-png-image-encoder/index.html @@ -93,7 +93,7 @@ 以下のソースコードをベースにする。 今回 PNG のデコーダは扱わないので、読み込みには Go の標準ライブラリ image/png を用いる。

-
package main
+            
package main
 
 import (
 	"image"
@@ -184,7 +184,7 @@
                 writeSignature の実装はこちら: 
               

-
import "encoding/binary"
+              
import "encoding/binary"
 
 func writeSignature(w io.Writer) {
 	sig := [8]uint8{
@@ -233,7 +233,7 @@
                  CRC (Cyclic Redundancy Check) は誤り検出符号の一種。Go 言語では hash/crc32 パッケージにあるが、今回はこれも自前で実装する。PNG の仕様書に C 言語のサンプルコードが載っている (D. Sample CRC implementation) ので、これを Go に移植する。 
               

-
var (
+              
var (
 	crcTable         [256]uint32
 	crcTableComputed bool
 )
@@ -273,7 +273,7 @@
                  できた crc 関数を使って、chunk 一般を書き込む関数も用意しておこう。 
               

-
func writeChunk(w io.Writer, chunkType string, data []byte) {
+              
func writeChunk(w io.Writer, chunkType string, data []byte) {
 	typeAndData := make([]byte, 0, len(chunkType)+len(data))
 	typeAndData = append(typeAndData, []byte(chunkType)...)
 	typeAndData = append(typeAndData, data...)
@@ -367,7 +367,7 @@
                  今回ほとんどのデータは決め打ちするので、データに応じて変わるのは width と height だけになる。コードは次のようになる。 
               

-
import "bytes"
+              
import "bytes"
 
 func writeChunkIhdr(w io.Writer, width, height uint32) {
 	var buf bytes.Buffer
@@ -421,7 +421,7 @@
                    Adler-32 も CRC と同じく誤り検出符号である。こちらも zlib の仕様書に C 言語でサンプルコードが記載されている (9. Appendix: Sample code) ので、Go に移植する。 
                 

-
const adler32Base = 65521
+                
const adler32Base = 65521
 
 func updateAdler32(adler uint32, buf []byte) uint32 {
 	s1 := adler & 0xFFFF
@@ -468,7 +468,7 @@
                    実際にこの手抜き zlib を実装したものがこちら: 
                 

-
func encodeZlib(data []byte) []byte {
+                
func encodeZlib(data []byte) []byte {
 	var buf bytes.Buffer
 
 	binary.Write(&buf, binary.BigEndian, uint8(0x78))
@@ -508,7 +508,7 @@
                    先ほどの encodeZlib も使って実際に実装したものがこちら: 
                 

-
func writeChunkIdat(w io.Writer, width, height uint32, img image.Image) {
+                
func writeChunkIdat(w io.Writer, width, height uint32, img image.Image) {
 	var pixels bytes.Buffer
 	for y := uint32(0); y < height; y++ {
 		binary.Write(&pixels, binary.BigEndian, uint8(0))
@@ -535,7 +535,7 @@
                  特に追加のデータはなく、必要なのは chunk type の IEND くらいなので実装は簡単: 
               

-
func writeChunkIend(w io.Writer) {
+              
func writeChunkIend(w io.Writer) {
 	writeChunk(w, "IEND", nil)
 }
@@ -547,7 +547,7 @@ 最後に全ソースコードを再掲しておく。

-
package main
+            
package main
 
 import (
 	"bytes"
-- 
cgit v1.2.3-70-g09d2