twitchapon-anim

Basic Twitchapon Receiver/Visuals
git clone git://bsandro.tech/twitchapon-anim
Log | Files | Refs | README | LICENSE

assets.go (1411B)


      1 // Copyright 2014 Hajime Hoshi
      2 //
      3 // Licensed under the Apache License, Version 2.0 (the "License");
      4 // you may not use this file except in compliance with the License.
      5 // You may obtain a copy of the License at
      6 //
      7 //     http://www.apache.org/licenses/LICENSE-2.0
      8 //
      9 // Unless required by applicable law or agreed to in writing, software
     10 // distributed under the License is distributed on an "AS IS" BASIS,
     11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     12 // See the License for the specific language governing permissions and
     13 // limitations under the License.
     14 
     15 //go:generate png2compressedrgba -input text.png -output /tmp/compressedTextRGBA
     16 //go:generate file2byteslice -input /tmp/compressedTextRGBA -output textrgba.go -package assets -var compressedTextRGBA
     17 //go:generate gofmt -s -w .
     18 
     19 package assets
     20 
     21 import (
     22 	"bytes"
     23 	"compress/gzip"
     24 	"fmt"
     25 	"image"
     26 	"io/ioutil"
     27 )
     28 
     29 const (
     30 	imgWidth  = 192
     31 	imgHeight = 128
     32 
     33 	CharWidth  = 6
     34 	CharHeight = 16
     35 )
     36 
     37 func CreateTextImage() *image.RGBA {
     38 	s, err := gzip.NewReader(bytes.NewReader(compressedTextRGBA))
     39 	if err != nil {
     40 		panic(fmt.Sprintf("assets: gzip.NewReader failed: %v", err))
     41 	}
     42 	defer s.Close()
     43 
     44 	pix, err := ioutil.ReadAll(s)
     45 	if err != nil {
     46 		panic(fmt.Sprintf("assets: ioutil.ReadAll failed: %v", err))
     47 	}
     48 	return &image.RGBA{
     49 		Pix:    pix,
     50 		Stride: 4 * imgWidth,
     51 		Rect:   image.Rect(0, 0, imgWidth, imgHeight),
     52 	}
     53 }