Exemplo n.º 1
0
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
}
Exemplo n.º 2
0
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()
}