Documentation: engine/docs assembles one registry from the script
bindings, the schema, module docs and module-owned script paths; problems
are reported as warnings at build time. Module registries record doc
sources and script module owners; diag.Codes lists every diagnostic code.
Project bootstrap: project.defaultSpace ("2d"/"3d"), EnsureDirs creates
the default folders when the editor opens a project (reported in the
console), prefabs/ is a pipeline root. Native builds drop -trimpath so
binding locations resolve inside native/.
Editor files: create scene/prefab/script from menus, move/rename/duplicate
/delete with undo, script package retargeting on move, open scenes and
script panels follow renames, Save As / Rename Scene prompts, scene
picker, startup scene. Scoped shortcuts fall back to the global command
when disabled; Save As is Ctrl+Shift+S, Save All Ctrl+Alt+S.
Script editor: Go to Implementation (stub → native/ source), host
definitions always resolve to stubs, bracket match/mismatch states,
rainbow brackets (persisted), mono code font (ui-mono atlases, per-command
fonts in draw.List, PushFont/PopFont restored by Mark/Restore).
Tests: langsvc definition/implementation, bracket states, dispatch
fallback, script renames, font stack, editor file-op integration, golden
mono glyph and bracket references; depcheck rule for engine/docs.
Docs pipeline: engine, render2d and script/engine ship their own res/docs;
keyword hover text comes from the registry through manifest.Keywords;
project script symbols join the registry; aego docs export|check|build|
serve, --tool docs in native binaries, aego check --explain; app/docstool
and the tools/gendocs module (goldmark) build the static site.
Playground: app/playground + cmd/aego-playground (js/wasm, 3.3 MB gzip)
compile, highlight and run scripts in the browser; run blocks in the
language docs become examples. engine/builtin/headless is the module set
without render3d; workspace.Config.FS; StubFor/StubPaths; backends and the
script importer drop out of js builds.
VM: one frame pointer in the interpreter loop, direct host calls, panic
recovery once per run instead of per host call (Update2k -19%,
Schedule10k -24% against the previous head). bench-build/compare/profile
run pre-built, pinned, interleaved binaries.
Editor: structural bracket levels and current-block highlight, indent
guides, occurrence highlighting with write marks, multi-format clipboard
(copy/cut/paste assets, paste images as sprites or textures). gl33 probes
a renderable depth format and reports framebuffer failures by stage.
7 E:
- project templates empty/2d/2.5d/3d, app/projects as the single creation path (D148)
- launcher and recent projects (D149)
- orthographic Camera3D and Scene View (D150)
- reference states in the Inspector, ids.Short (D151)
- sceneio remaps node references when loading without KeepIDs (D152)
- exported ComponentRef<T> (D153)
- aego icons via module.Audit (D146)
104 lines
2.3 KiB
Go
104 lines
2.3 KiB
Go
package clip
|
|
|
|
import (
|
|
"encoding/binary"
|
|
"errors"
|
|
"image"
|
|
"math/bits"
|
|
)
|
|
|
|
var errBMP = errors.New("unsupported or truncated bmp")
|
|
|
|
func channel(v, m uint32) uint8 {
|
|
if m == 0 {
|
|
return 0
|
|
}
|
|
s := bits.TrailingZeros32(m)
|
|
n := bits.OnesCount32(m)
|
|
x := (v & m) >> s
|
|
if n >= 8 {
|
|
return uint8(x >> (n - 8))
|
|
}
|
|
return uint8(x * 255 / (1<<n - 1))
|
|
}
|
|
|
|
func DecodeBMP(data []byte) (*image.NRGBA, error) {
|
|
le := binary.LittleEndian
|
|
b := data
|
|
off := -1
|
|
if len(b) >= 14 && b[0] == 'B' && b[1] == 'M' {
|
|
off = int(le.Uint32(b[10:])) - 14
|
|
b = b[14:]
|
|
}
|
|
if len(b) < 40 {
|
|
return nil, errBMP
|
|
}
|
|
hs := int(le.Uint32(b))
|
|
w := int(int32(le.Uint32(b[4:])))
|
|
h := int(int32(le.Uint32(b[8:])))
|
|
bpp := int(le.Uint16(b[14:]))
|
|
comp := le.Uint32(b[16:])
|
|
if hs < 40 || hs > len(b) || w <= 0 || h == 0 || (bpp != 24 && bpp != 32) || (comp != 0 && comp != 3) {
|
|
return nil, errBMP
|
|
}
|
|
masks := [4]uint32{0x00FF0000, 0x0000FF00, 0x000000FF, 0}
|
|
if bpp == 32 {
|
|
masks[3] = 0xFF000000
|
|
}
|
|
end := hs
|
|
if comp == 3 {
|
|
switch {
|
|
case hs >= 56:
|
|
masks = [4]uint32{le.Uint32(b[40:]), le.Uint32(b[44:]), le.Uint32(b[48:]), le.Uint32(b[52:])}
|
|
case hs >= 52:
|
|
masks = [4]uint32{le.Uint32(b[40:]), le.Uint32(b[44:]), le.Uint32(b[48:]), 0}
|
|
default:
|
|
if len(b) < hs+12 {
|
|
return nil, errBMP
|
|
}
|
|
masks = [4]uint32{le.Uint32(b[hs:]), le.Uint32(b[hs+4:]), le.Uint32(b[hs+8:]), 0}
|
|
end = hs + 12
|
|
}
|
|
}
|
|
if off < 0 {
|
|
off = end + int(le.Uint32(b[32:]))*4
|
|
}
|
|
top := h < 0
|
|
if top {
|
|
h = -h
|
|
}
|
|
stride := (w*bpp/8 + 3) &^ 3
|
|
if off < 0 || w > 1<<15 || h > 1<<15 || off+stride*h > len(b) {
|
|
return nil, errBMP
|
|
}
|
|
img := image.NewNRGBA(image.Rect(0, 0, w, h))
|
|
alpha := false
|
|
for y := 0; y < h; y++ {
|
|
row := h - 1 - y
|
|
if top {
|
|
row = y
|
|
}
|
|
src := b[off+row*stride:]
|
|
dst := img.Pix[y*img.Stride:]
|
|
for x := 0; x < w; x++ {
|
|
o := x * 4
|
|
if bpp == 24 {
|
|
dst[o], dst[o+1], dst[o+2], dst[o+3] = src[x*3+2], src[x*3+1], src[x*3], 255
|
|
continue
|
|
}
|
|
v := le.Uint32(src[x*4:])
|
|
dst[o], dst[o+1], dst[o+2], dst[o+3] = channel(v, masks[0]), channel(v, masks[1]), channel(v, masks[2]), 255
|
|
if masks[3] != 0 {
|
|
dst[o+3] = channel(v, masks[3])
|
|
alpha = alpha || dst[o+3] != 0
|
|
}
|
|
}
|
|
}
|
|
if bpp == 32 && masks[3] != 0 && !alpha {
|
|
for i := 3; i < len(img.Pix); i += 4 {
|
|
img.Pix[i] = 255
|
|
}
|
|
}
|
|
return img, nil
|
|
}
|