final Context octx = (Context)ctx;
final ImageOutputStream ios = octx.outputStream;
final int length = octx.length * 8; // measured in bits
int pos = 0; // measured in bits
try {
ios.mark();
do {
if (pos >= length) {
ios.reset();
ios.mark();
pos = 0;