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

ESC/Label: SpeedUp through less delete operations (Z#23124315) #77

Merged
merged 1 commit into from Mar 4, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -11,6 +11,7 @@ import java8.util.concurrent.CompletableFuture
import java.io.ByteArrayOutputStream
import java.io.InputStream
import java.io.OutputStream
import java.util.UUID
import java.util.concurrent.TimeUnit


Expand Down Expand Up @@ -48,25 +49,31 @@ class ESCLabel : StreamByteProtocol<Bitmap> {
//
// Command notes:
// ~DY: Store file to printer memory
// Contrary to the documentation, the file name should also contain the extension

// Delete all files volatile memory
ostream.write("^XA^IDR:*.*^FS^XZ".toByteArray())
// Contrary to the documentation, the file name should also contain the extension.
// Diverging from the sample in the documentation, we are also naming each file
// explicitly, so that we can delete it rather than issue a "delete everything" command
// ~ID: Delete file or files from printer memory
// As confirmed by Ivar, the delete operations take for bloody ever and slow down the
// printer a lot. As such, we diverge from the official documentation/sample and only
// delete the printed file at the end of the job. Should too many prints fail and clog
// up the volatile memory, the user will have manually clear the memory from the
// printer's menu.

// Register image in printer in volatile memory as a PNG
val stream = ByteArrayOutputStream()
img.compress(Bitmap.CompressFormat.PNG, 100, stream)
ostream.write("~DYR:IMAGE.PNG,B,P,${stream.size()},0,".toByteArray())
val filename = UUID.randomUUID().toString().replace("-", "").take(8).uppercase()
ostream.write("~DYR:${filename}.PNG,B,P,${stream.size()},0,".toByteArray())
stream.writeTo(ostream)
img.recycle()

// Create label and print previously transferred image
ostream.write("^XA".toByteArray())
ostream.write("^ILR:IMAGE.PNG^FS".toByteArray())
ostream.write("^ILR:${filename}.PNG^FS".toByteArray())
ostream.write("^XZ".toByteArray())

// Delete the image from the printer again
ostream.write("^XA^IDR:*.*^FS^XZ".toByteArray())
ostream.write("^XA^IDR:${filename}.PNG^FS^XZ".toByteArray())

ostream.flush()
return ostream.toByteArray()
Expand Down