Skip to content

Instantly share code, notes, and snippets.

@danielsharvey
Last active September 15, 2022 14:32
Show Gist options
  • Select an option

  • Save danielsharvey/929a525712a2b89ebb561226cc32f3e7 to your computer and use it in GitHub Desktop.

Select an option

Save danielsharvey/929a525712a2b89ebb561226cc32f3e7 to your computer and use it in GitHub Desktop.

Revisions

  1. danielsharvey revised this gist May 28, 2017. No changes.
  2. danielsharvey revised this gist May 28, 2017. No changes.
  3. danielsharvey revised this gist May 28, 2017. 1 changed file with 2 additions and 2 deletions.
    4 changes: 2 additions & 2 deletions convert_cpbitmap
    Original file line number Diff line number Diff line change
    @@ -3,15 +3,15 @@ from PIL import Image,ImageOps
    import struct
    import sys
    if len(sys.argv) < 3:
    print "Need two args: filename and result_filename\n";
    print "Need two args: source_filename and result_filename\n";
    sys.exit(0)
    filename = sys.argv[1]
    result_filename = sys.argv[2]

    with open(filename) as f:
    contents = f.read()
    unk1, width, height, unk2, unk3, unk4 = struct.unpack('<6i', contents[-24:])
    im = Image.fromstring('RGBA', (width,height), contents, 'raw', 'RGBA', 0, 1)
    im = Image.frombytes('RGBA', (width,height), contents, 'raw', 'RGBA', 0, 1)
    r,g,b,a = im.split()
    im = Image.merge('RGBA', (b,g,r,a))
    im.save(result_filename)
  4. danielsharvey revised this gist May 28, 2017. 1 changed file with 16 additions and 0 deletions.
    16 changes: 16 additions & 0 deletions convert_cpbitmap
    Original file line number Diff line number Diff line change
    @@ -1 +1,17 @@
    #!/usr/bin/python
    from PIL import Image,ImageOps
    import struct
    import sys
    if len(sys.argv) < 3:
    print "Need two args: filename and result_filename\n";
    sys.exit(0)
    filename = sys.argv[1]
    result_filename = sys.argv[2]

    with open(filename) as f:
    contents = f.read()
    unk1, width, height, unk2, unk3, unk4 = struct.unpack('<6i', contents[-24:])
    im = Image.fromstring('RGBA', (width,height), contents, 'raw', 'RGBA', 0, 1)
    r,g,b,a = im.split()
    im = Image.merge('RGBA', (b,g,r,a))
    im.save(result_filename)
  5. danielsharvey created this gist May 28, 2017.
    1 change: 1 addition & 0 deletions convert_cpbitmap
    Original file line number Diff line number Diff line change
    @@ -0,0 +1 @@
    #!/usr/bin/python