Path: csiph.com!eternal-september.org!feeder.eternal-september.org!mx02.eternal-september.org!.POSTED!not-for-mail From: awanderin Newsgroups: comp.sys.apple2.programmer Subject: Re: packBytes and unpackBytes Date: Sat, 30 Apr 2016 20:44:02 -0600 Organization: A noiseless patient Spider Lines: 88 Message-ID: References: <0265e33a-44e4-4f07-a256-52c49c8033ba@googlegroups.com> Mime-Version: 1.0 Content-Type: text/plain Injection-Info: mx02.eternal-september.org; posting-host="083f5666d1dde324d222dc30997cf682"; logging-data="7424"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19CjqlKjsKdSZX6mLvFFeKFl2QRkKDfXP4=" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.3 (gnu/linux) Cancel-Lock: sha1:iVu/47BOBlR6V4M/1/m0oZSwz8A= sha1:PmCKJ7ljxUywOqdKSJnHHx4KZbM= Xref: csiph.com comp.sys.apple2.programmer:2704 markpmlim@yahoo.com.sg writes: > Using resources available on the Internet, the equivalent of the Apple > IIgs misc tool calls packBytes and unpackBytes have been coded in > Swift. > > The Swift playground project demonstrates how to encode and decode > files using the 2 methods packBytes and unpackBytes. If you wish to > encode/decode Apple Preferred Format (APF) IIgs graphic files, more > work needs to be done besides passing the scanlines as parameters to > the 2 methods. > > The project can be downloaded or previewed at > > https://github.com/markpmlim/PackBytesAndUnpackBytes > > A major part of the credit should go to the authors of packBytes and > unpackBytes who had made their source code available. > > Although Xcode 7.01 was used, it is possible to convert the code to a > lower version. > > Regards. > > Mark Interesting. FWIW, here's unpackBytes in Python that I wrote several years back: def unpackBytes(data): """ data is a bytearray PackBytes is a IIgs Toolset method. It is used to compress various formats of Super Hi-res pictures. 00xxxxxx - 1 to 64 bytes follow - all different bits 0-5 are the count - 1 01xxxxxx - 3, 5, 6, or 7 repeats of next byte bits 0-5 are 2, 4, 5, or 6. Add one to get count. [I've read some other stuff stating that these can have other values, but the Apple documentation does state these limitations.] 10xxxxxx - 1 to 64 repeats of next 4 bytes bits 0-5 are count - 1. 11xxxxxx - 1 to 64 repeats of next byte taken as 4 bytes bits 0-5 are count - 1 In other words, this repeats the byte 4 - 256 times See: http://www.fadden.com/techmisc/hdc/lesson02.htm http://web.pdx.edu/~heiss/technotes/iigs/tn.iigs.094.html """ out = bytearray() L = len(data) i = 0 while i < L: b = data[i] i += 1 op = (b & 0xc0) >> 6 count = (b & 0x3f) + 1 if op == 0: out += data[i:i+count] i += count elif op == 1: #if count not in [3, 5, 6, 7]: # sys.stderr.write('COUNT %d not in [3,5,6,7] ' # 'at offset %d (0x%x)\n' # % (count, i-1, i-1)) # # assert count in [3, 5, 6, 7] out += data[i:i + 1] * count i += 1 elif op == 2: out += data[i:i + 4] * count i += 4 elif op == 3: out += data[i:i + 1] * (4 * count) i += 1 else: assert False return out -- Jerry awanderin at gmail dot com