func (me *FxImageInitFrom) loadImage(fxImg *FxImageBase) (img image.Image, err error) { var rawImg *fxImageCached prov, arg, remote := me.provider() if fxImg.needPreproc() && fxImg.Storage.DiskCache.Enabled && (!remote) && len(me.RefUrl) > 0 && len(Options.AppDir.Temp.CachedTextures) > 0 { rawImg = newFxImageCached(me, fxImg) } if rawImg == nil || rawImg.needImg { img, err = prov(arg) } if err == nil && img != nil { switch img.(type) { case *image.YCbCr, *image.Paletted: rect := img.Bounds() tmpImg := image.NewRGBA(rect) draw.Draw(tmpImg, rect, img, rect.Min, draw.Src) img = tmpImg } if fxImg.needPreproc() { pic, _ := ugfx.CreateLike(img, false) ugfx.PreprocessImage(img, pic, fxImg.Preprocess.FlipY, fxImg.Preprocess.ToBgra, fxImg.Preprocess.ToLinear) img = pic } } if err == nil && rawImg != nil { if rawImg.needImg && img != nil { err = rawImg.setImg(img, fxImg) } img = rawImg } return }
func (me *fxImageCached) setImg(img image.Image, fxImg *FxImageBase) (err error) { me.bounds[0], me.bounds[1] = uint64(img.Bounds().Dx()), uint64(img.Bounds().Dy()) _, me.pix = ugfx.CreateLike(img, true) if len(me.fullPath) > 0 { var file *os.File if file, err = os.Create(me.fullPath); err == nil { defer file.Close() packer := fxImg.Storage.DiskCache.Compressor(file) defer packer.Close() if err = binary.Write(packer, binary.LittleEndian, &me.bounds); err == nil { if err = binary.Write(packer, binary.LittleEndian, [3]int64{int64(len(me.pix)), me.src.ModTime().UnixNano(), me.src.Size()}); err == nil { err = binary.Write(packer, binary.LittleEndian, me.pix) } } } } return }
func makeEmbeds(srcDirPath string) { defer wait.Done() filePath := filepath.Join(srcDirPath, "splash.png") var buf ustr.Buffer buf.Writeln("\t//\tEmbedded binary from %s", filePath) if raw := ufs.ReadBinaryFile(filePath, true); len(raw) > 0 { if strings.HasSuffix(filePath, ".png") { if src, _, err := image.Decode(bytes.NewReader(raw)); err == nil { dst, _ := ugfx.CreateLike(src, false) ugfx.PreprocessImage(src, dst, true, true, true) w := new(bytes.Buffer) png.Encode(w, dst) raw = w.Bytes() } else { panic(err) } } if len(raw) > 0 { buf.Writeln("\tCore.Libs.Images.SplashScreen.InitFrom.RawData = %#v", raw) } } newSrc.embeds = buf.String() }