cbiffle / catibo

Rust implementation of the CTB/CBDDLP/PHZ 3d printing file formats.
BSD 2-Clause "Simplified" License
46 stars 11 forks source link

CTB Yields Unrecognized Format on Creality LD002R #4

Open wbrickner opened 4 years ago

wbrickner commented 4 years ago

Hello,

I think I am using your library incorrectly, as when I try to print a CTB file generated with catibo, it is unrecognized by the printer.

Hopefully you can spot something incorrect in my usage:

println!("Reading layer mask...");
let full_image = image::open(&args[0]).unwrap();
let (full_image_width, full_image_height) = full_image.dimensions();

println!("Encoding layer mask...");

// restructure to 1 byte per pixel (brightness)
let bpp_layer_data: Vec<u8> = full_image.clone().into_luma().pixels().map(|p| p[0]).collect();

let mut layer_data = Vec::<u8>::with_capacity(full_image_width as usize * full_image_height as usize);
encode_rle7_slice(
    bpp_layer_data.iter().map(|&b| b).peekable(),
    0,  // no encryption dammit
    0,  // unused, but is layer index (IV for crypto cypher, hence unused)
    &mut layer_data
);

println!("Generating preview images...");

// scale down to fit inside 512x512
println!("   Resizing to large preview image (512px * 512px)...");
let large_preview = full_image.resize(512, 512, image::imageops::FilterType::Nearest);
let (large_preview_width, large_preview_height) = large_preview.dimensions();

// scale down to fit inside 128x128 using nearest-neighbor scaling
println!("   Resizing to small preview image (128px * 128px)...");
let small_preview = full_image.resize(128, 128, image::imageops::FilterType::Nearest);
let (small_preview_width, small_preview_height) = small_preview.dimensions();

// decide on an output path and announce it
let output_path = format!("output-{}.ctb", mnemonic::to_string(rand::thread_rng().gen::<[u8; 2]>()));
println!("Building output to `./{}`", output_path);

Builder::for_revision(Magic::CTB, 2)
            .encryption_key(0) // disable encryption
            .large_preview(
                large_preview_width, 
                large_preview_height, 
                encode_image(&large_preview.into_rgb())
            )
            .small_preview(
                small_preview_width, 
                small_preview_height, 
                encode_image(&small_preview.into_rgb())
            )
            .layer_height_mm(layer_height_mm * 1E-3)
            .overall_height_mm(layer_height_mm * 1E-3)
            .exposure_s(exposure_time_s)
            .bot_exposure_s(exposure_time_s)
            .bot_layer_count(1)
            .pwm_level(exposure_pwm)
            .bot_pwm_level(exposure_pwm)
            .print_time_s(3 + exposure_time_s as u32)   // meh, 3s overhead sounds good.
            .bot_lift_speed_mmpm(withdraw_speed)
            .resolution([full_image_width, full_image_height])
            .layer(
                0.0,             // layer z
                exposure_time_s, // light on time
                0.0,             // 0s light off time after 
                layer_data
            )
            .write(
                std::fs::File::create(output_path)?
            )?;

Thanks!

cbiffle commented 4 years ago

Wow, someone is actually using this code to produce files! Neat! Sorry for the ... two month delay, looks like. Things have been a little weird.

What does the printer say, specifically? Have you tried loading the file into the CHITUBOX proprietary software? (If it fails there, check the console output -- you may need to run it from a terminal to see it.)

I happen to have a Creality LD-002R, and I have successfully generated files that it accepts -- let me find my code and compare it to yours.

X3msnake commented 4 years ago

use UVTools or UV3DP

Cliff L. Biffle notifications@github.com escreveu no dia segunda, 7/09/2020 à(s) 18:34:

Wow, someone is actually using this code to produce files! Neat! Sorry for the ... two month delay, looks like. Things have been a little weird.

What does the printer say, specifically? Have you tried loading the file into the CHITUBOX proprietary software? (If it fails there, check the console output -- you may need to run it from a terminal to see it.)

I happen to have a Creality LD-002R, and I have successfully generated files that it accepts -- let me find my code and compare it to yours.

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/cbiffle/catibo/issues/4#issuecomment-688449886, or unsubscribe https://github.com/notifications/unsubscribe-auth/ACUR56XUCMZQU6FGVOU3NCDSEUKTVANCNFSM4ORCCBNQ .

-- Com os melhores cumprimentos, Vinicius Silva

cbiffle commented 4 years ago

That's not helpful for finding the bug in this library.

X3msnake commented 4 years ago

it is https://github.com/ezrec/uv3dp/tree/master/ctb

Cliff L. Biffle notifications@github.com escreveu no dia segunda, 7/09/2020 à(s) 18:38:

That's not helpful for finding the bug in this library.

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/cbiffle/catibo/issues/4#issuecomment-688451109, or unsubscribe https://github.com/notifications/unsubscribe-auth/ACUR56WYKXQTQUXPPDWDRL3SEULAPANCNFSM4ORCCBNQ .

-- Com os melhores cumprimentos, Vinicius Silva

wbrickner commented 4 years ago

No problem about the delay! Thank you for spending your time reverse engineering the format, that's invaluable, I would have given up!

Its been a little while and I don't remember if I put it in chitubox or what the printer said, but I think it either did not show up as a valid model in the UI or said something along the lines of "invalid file".

I think the issue is going to be what I am supplying to your library in the sample above, probably not the internals. I was mostly jumping around the docs and guessing what I was supposed to be doing. Do you spot anything obviously wrong? I'll regenerate the CTB file and provide my output.

cbiffle commented 4 years ago

I didn't spot anything obviously wrong in the code -- ideally the library should either generate a valid file or produce a (run-time or compile-time) error. Basically, if you find out that the file is bogus from the printer, I consider that a bug in my code.

Could be all sorts of things though! This is exciting.

Your code looks complete enough that I ought to be able to build and run it, if I provide my own PNG, yes?

wbrickner commented 4 years ago

Interesting!

Chitubox manages to open the file, displays all the parameters correctly, and even can display the layer data as intended. Could the preview images I provided be the issue? They don't appear on Chitubox anyway, so I can't tell if they're invalid.

Screen Shot 2020-09-09 at 12 08 34 AM

Original layer image:

test

Output CTB (GitHub won't allow direct CTB, so here's the zip):

output-shampoo-analog.ctb.zip

wbrickner commented 4 years ago

Don't have a public repo, but here's a quick archive of my project if you want to run exactly what I am running: slamask.zip

Also I purchased the printer a few months ago, could it ship with a different firmware that expects something more from a CTB...?

X3msnake commented 4 years ago

what do you mean by the file is jot recognized by the printer?

there is a known bug on chitu boards that any complex image will try to print and give a usb read error.

No dia quarta-feira, 9 de setembro de 2020, Will Brickner < notifications@github.com> escreveu:

Don't have a public repo, but here's a quick archive of my project if you want to run exactly what I am running: slamask.zip https://github.com/cbiffle/catibo/files/5192724/slamask.zip

Also I purchased the printer a few months ago, could it ship with a different firmware that expects something more from a CTB...?

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/cbiffle/catibo/issues/4#issuecomment-689307497, or unsubscribe https://github.com/notifications/unsubscribe-auth/ACUR56Q2FOHSNOBH3EW6PILSE4FJHANCNFSM4ORCCBNQ .

-- Com os melhores cumprimentos, Vinicius Silva

Andy-Big commented 3 years ago

My Chitu L V3 board just reboots after 15 seconds of reading a file with a complex gradient layer :)