Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.sys.apple2.programmer > #2704

Re: packBytes and unpackBytes

Path csiph.com!eternal-september.org!feeder.eternal-september.org!mx02.eternal-september.org!.POSTED!not-for-mail
From awanderin <awanderin@gmail.com>
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 <m360uymr9p.fsf@gmail.com> (permalink)
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

Show key headers only | View raw


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

Back to comp.sys.apple2.programmer | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

packBytes and unpackBytes markpmlim@yahoo.com.sg - 2016-04-28 01:04 -0700
  Re: packBytes and unpackBytes awanderin <awanderin@gmail.com> - 2016-04-30 20:44 -0600
  Re: packBytes and unpackBytes Bill Buckels <bbuckels@escape.ca> - 2016-05-14 11:13 -0700
    Re: packBytes and unpackBytes Michael Pohoreski <michael.pohoreski@gmail.com> - 2016-05-14 13:27 -0700
      Re: packBytes and unpackBytes Bill Buckels <bbuckels@escape.ca> - 2016-05-15 02:36 -0700
      Re: packBytes and unpackBytes Bill Buckels <bbuckels@escape.ca> - 2016-05-15 02:43 -0700
        Re: packBytes and unpackBytes Michael Pohoreski <michael.pohoreski@gmail.com> - 2016-05-15 15:19 -0700
    Re: packBytes and unpackBytes markpmlim@yahoo.com.sg - 2016-05-15 18:27 -0700
      Re: packBytes and unpackBytes wssimms@gmail.com - 2016-05-15 21:29 -0700
        Re: packBytes and unpackBytes markpmlim@yahoo.com.sg - 2016-05-16 18:42 -0700
          Re: packBytes and unpackBytes markpmlim@yahoo.com.sg - 2016-05-18 04:52 -0700
            Re: packBytes and unpackBytes Bill Buckels <bbuckels@escape.ca> - 2016-07-17 18:21 -0700
              Re: packBytes and unpackBytes markpmlim@yahoo.com.sg - 2016-07-18 14:23 -0700
            Re: Load and display an Apple IIGS SHR graphic markpmlim@yahoo.com.sg - 2018-09-18 18:19 -0700
  Re: packBytes and unpackBytes burgerbecky@gmail.com - 2016-07-27 17:52 -0700
    Re: packBytes and unpackBytes burgerbecky@gmail.com - 2016-07-27 17:53 -0700
    Re: packBytes and unpackBytes Michael Pohoreski <michael.pohoreski@gmail.com> - 2016-07-27 19:37 -0700
  Re: packBytes and unpackBytes markpmlim@yahoo.com.sg - 2018-09-18 18:29 -0700
    Re: packBytes and unpackBytes markpmlim@yahoo.com.sg - 2018-12-05 17:23 -0800
      Re: packBytes and unpackBytes markpmlim@yahoo.com.sg - 2018-12-07 17:46 -0800

csiph-web