Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ctb: Fix bug where missing preview images would corrupt bottom lift height & speed #140

Merged
merged 1 commit into from
Mar 13, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 0 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -205,10 +205,3 @@ The command line tool is designed to be used in a 'pipeline' style, for example:

Known resins: (from local user ChiTuBox config)

Profile bottom 5 layers, 50; nominal 15
Voxelab Black for 0.05mm bottom 6 layers, 50; nominal 10
Voxelab Green for 0.05mm bottom 6 layers, 50; nominal 10
Voxelab Grey for 0.05mm bottom 6 layers, 50; nominal 8
Voxelab Red for 0.05mm bottom 6 layers, 50; nominal 10
Voxelab Transparent for 0.05mm bottom 6 layers, 50; nominal 10
Voxelab White for 0.05mm bottom 6 layers, 50; nominal 9
38 changes: 17 additions & 21 deletions cmd/uv3dp/info.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,22 @@ func NewInfoCommand() (info *InfoCommand) {
return
}

func printExposure(mode string, exp *uv3dp.Exposure) {
fmt.Printf("%v:\n", mode)
fmt.Printf(" Exposure: %.2gs on, %.2gs off", exp.LightOnTime, exp.LightOffTime)
if exp.LightPWM != 255 {
fmt.Printf(", PWM %v", exp.LightPWM)
}
fmt.Printf(" Lift: %v mm, %v mm/min\n",
exp.LiftHeight, exp.LiftSpeed)
fmt.Printf(" Retract: %v mm, %v mm/min\n",
exp.RetractHeight, exp.RetractSpeed)
}

func (info *InfoCommand) Filter(input uv3dp.Printable) (output uv3dp.Printable, err error) {
exp := input.Exposure()
bot := input.Bottom()

if info.SizeSummary {
size := input.Size()
fmt.Printf("Layers: %v, %vx%v slices, %.2f x %.2f x %.2f mm bed required\n",
Expand All @@ -55,27 +70,8 @@ func (info *InfoCommand) Filter(input uv3dp.Printable) (output uv3dp.Printable,
}

if info.ExposureSummary {
exp := input.Exposure()
bot := input.Bottom()

fmt.Printf("Exposure: %.2gs on, %.2gs off",
exp.LightOnTime,
exp.LightOffTime)
if exp.LightPWM != 255 {
fmt.Printf(", PWM %v", exp.LightPWM)
}
fmt.Println()
fmt.Printf("Bottom: %.2gs on, %.2gs off",
bot.Exposure.LightOnTime,
bot.Exposure.LightOffTime)
if bot.Exposure.LightPWM != 255 {
fmt.Printf(", PWM %v", bot.Exposure.LightPWM)
}
fmt.Printf(" (%v layers)\n", bot.Count)
fmt.Printf("Lift: %v mm, %v mm/min\n",
exp.LiftHeight, exp.LiftSpeed)
fmt.Printf("Retract: %v mm, %v mm/min\n",
exp.RetractHeight, exp.RetractSpeed)
printExposure(fmt.Sprintf("Bottom (%v layers)", bot.Count), &bot.Exposure)
printExposure("Normal", &exp)

keys := input.MetadataKeys()

Expand Down
23 changes: 18 additions & 5 deletions ctb/format.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ const (

type ctbHeader struct {
Magic uint32 // 00:
Version uint32 // 04: Always '2'
Version uint32 // 04: Always '3'
BedSizeMM [3]float32 // 08:
_ [2]uint32 // 14:
HeightMM float32 // 1c:
Expand Down Expand Up @@ -220,7 +220,6 @@ func (cf *Formatter) Encode(writer uv3dp.Writer, printable uv3dp.Printable) (err
return base
}

base += uint32(previewSize)
size := pic.Bounds().Size()
if size == image.Pt(0, 0) {
return base
Expand All @@ -232,6 +231,8 @@ func (cf *Formatter) Encode(writer uv3dp.Writer, printable uv3dp.Printable) (err
return base
}

base += uint32(previewSize)

rleHash[hash] = rleInfo{offset: base, rle: rle}
rleHashList = append(rleHashList, hash)

Expand All @@ -246,7 +247,14 @@ func (cf *Formatter) Encode(writer uv3dp.Writer, printable uv3dp.Printable) (err
previewHugeBase := headerBase + uint32(headerSize)

previewTinyBase := savePreview(previewHugeBase, &previewHuge, uv3dp.PreviewTypeHuge)
if previewTinyBase == previewHugeBase {
previewHugeBase = 0
}

paramBase := savePreview(previewTinyBase, &previewTiny, uv3dp.PreviewTypeTiny)
if paramBase == previewTinyBase {
previewTinyBase = 0
}

param := ctbParam{}
paramSize, _ := restruct.SizeOf(&param)
Expand Down Expand Up @@ -440,8 +448,13 @@ func (cf *Formatter) Encode(writer uv3dp.Writer, printable uv3dp.Printable) (err
fileData[base], _ = restruct.Pack(binary.LittleEndian, &layer)
}

fileData[int(previewHugeBase)], _ = restruct.Pack(binary.LittleEndian, &previewHuge)
fileData[int(previewTinyBase)], _ = restruct.Pack(binary.LittleEndian, &previewTiny)
if previewHugeBase > 0 {
fileData[int(previewHugeBase)], _ = restruct.Pack(binary.LittleEndian, &previewHuge)
}

if previewTinyBase > 0 {
fileData[int(previewTinyBase)], _ = restruct.Pack(binary.LittleEndian, &previewTiny)
}

for _, hash := range rleHashList {
info := rleHash[hash]
Expand Down Expand Up @@ -623,7 +636,7 @@ func (cf *Formatter) Decode(file uv3dp.Reader, filesize int64) (printable uv3dp.
var param ctbParam

addr := int(header.ParamOffset)
err = restruct.Unpack(data[addr:], binary.LittleEndian, &param)
err = restruct.Unpack(data[addr:addr+int(header.ParamSize)], binary.LittleEndian, &param)
if err != nil {
return
}
Expand Down