English Amiga Board


Go Back   English Amiga Board > Coders > Coders. General

 
 
Thread Tools
Old 01 August 2023, 21:46   #1
Argh
Registered User
 
Join Date: Jun 2017
Location: Kiel/Germany
Posts: 13
Converting raw Amiga bitplane image data into an image

Hi, I’m currently coding a Python tool to spot structured data in binary files and ideally to rip graphics data from old Amiga files. This is mainly to satisfy my own curiosity and to learn, I have no background in graphics programming, and my knowledge about the Amiga’s hardware is pretty rudimentary.

So, I managed to rip 5 bit arrays from a file (screenshot attached) which look like different layers of a final image -- I suppose these represent the 5 bitplane data for the Amiga’s 32 color mode?

My question is: how to combine these bitplanes into a regular RGB image? And would I get only indexes referring to a palette table (which I also would have to get somehow) or are these the colors itself?

I’m out of my depth here, so I’d be happy if someone could point me into the right direction
Attached Thumbnails
Click image for larger version

Name:	ck.png
Views:	108
Size:	39.8 KB
ID:	79827  
Argh is offline  
Old 01 August 2023, 22:24   #2
paraj
Registered User
 
paraj's Avatar
 
Join Date: Feb 2017
Location: Denmark
Posts: 1,138
Going the other way round. Say you have an indexed-colored row of 32 pixels (i.e. one where each value represents a color value) from 0 to 31: [0, 1, ... 31] or in binary 0b00000, 0b00001, 0b11111. When represented as bitplanes the data is transposed:
Code:
01010101010101010101010101010101 bitplane 0
00110011001100110011001100110011 bitplane 1
00001111000011110000111100001111 bitplane 2
00000000111111110000000011111111 bitplane 3
00000000000000001111111111111111 bitplane 4
To get the palette index of the first pixel you read down the left most column (and read 0b00000), to get the right most similarly to get (0b11111).
As an aside, the first representation (where bits that belong together are read together) is often called "chunky", and the bitplane representation is called "planar".

To go from one to the other representation, you transpose the bits. In practical terms take the most significant bit of each bitplane and combine them to form a single palette entry for the first pixel, the next most significant bits for the second entry and so forth. When you run out of bits in a byte you move to the next byte.

So something like (not tested, and not optimal):
Code:
for x in range(image_width):
    bit0 = (bitplane0[x//8] >> (7 - (x&7) % 8)) & 1 # extract bit from bitplane
    # Same for the other planes
    palette_entry = bit4 << 4 | .. | bit0
One extra thing to keep in mind is that there are (at least) two competing ways of storing images in planar format: interleaved and non-interleaved. Your example shows the non-interleaved format. The alternative (interleaved) stores each row of the image togther (so you have row 0 bitplane 0, row 0 bitplane 1, ..., row 1 bitplane 0, ... rather than row 0 bitplane, row 1 bitplane 0, ... row 0 bitplane 1 like in your example).
paraj is offline  
Old 02 August 2023, 22:57   #3
Argh
Registered User
 
Join Date: Jun 2017
Location: Kiel/Germany
Posts: 13
Many thanks for taking the time, paraj! I think I have a better grasp of what to do now. 2 questions remain for me, though:
  1. Quote:
    When you run out of bits in a byte you move to the next byte.
    Does this mean that, when writing the final data, I would directly concatenate the 5-bit blocks instead of complete bytes ("padded" with zeroes to form a complete byte)?
  2. If I understand correctly, the result will be a list of palette indexes per pixel. Was there some kind of typical way Amiga software stores the actual palettes, as separate files or as part of the actual program code?
Argh is offline  
Old 03 August 2023, 18:39   #4
paraj
Registered User
 
paraj's Avatar
 
Join Date: Feb 2017
Location: Denmark
Posts: 1,138
1. Hmm, no, maybe I don't understand your question or my explanation was not clear. Each bitplane is a long sequence of bits, and that was just trying to describe how to get them from bytes in the source data. The Hardware Reference Manual (HRM) http://amigadev.elowar.com/read/ADCD.../node0063.html has a perhaps better explanation.
For each pixel in the output image you take one bit from each bitplane. How you output the final data is up to you. You could store each pixel as a byte (with 3 bits left clear) or you could do the palette lookup before storing and output a RGB triplet.

2. There is no standard way. Sometimes you have one palette per image (e.g. for a splash screen), but often you will find that many images share a common palette (e.g. tiles in a platform game). The palette can also be changed dynamically (using the copper) so you might encounter images where the palette isn't fixed. That's not even discussing various screen modes (HAM, dual play field etc.), but that's not worth considering at the start If you're heuristically searching for palettes it'll often be 8/16/32 words in a row with the most significant nibble set to zero (since OCS/ECS only supports 4 bits per channel).
paraj is offline  
Old 03 August 2023, 22:51   #5
jotd
This cat is no more
 
jotd's Avatar
 
Join Date: Dec 2004
Location: FRANCE
Age: 52
Posts: 8,298
get my python module "bitplanelib.py" at https://github.com/jotd666/amiga68ktools.git

It is able to convert amiga bitplanes to PNG and the other way round. I'm using it for all my arcade conversions.

Try to dump a simple PNG to amiga bitplanes, then you can analyze the output data format
jotd is offline  
Old 09 August 2023, 21:53   #6
Argh
Registered User
 
Join Date: Jun 2017
Location: Kiel/Germany
Posts: 13
Thanks everybody, I think I have all the pieces I need now

Quote:
get my python module "bitplanelib.py" at https://github.com/jotd666/amiga68ktools.git
Thanks, bitplanes_raw2image() did the trick!

Quote:
If you're heuristically searching for palettes it'll often be 8/16/32 words in a row with the most significant nibble set to zero (since OCS/ECS only supports 4 bits per channel).
Thanks for the hint, I tweaked my Python tool a little following this tip and I think I spotted what looks like palette data in the game’s binary

Attached Thumbnails
Click image for larger version

Name:	palette.png
Views:	157
Size:	5.2 KB
ID:	79928  
Argh is offline  
 


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools

Similar Threads
Thread Thread Starter Forum Replies Last Post
5 bitplane image with 16 colour non-repeat hw sprites? mcgeezer Coders. Asm / Hardware 19 26 June 2022 15:01
Tool for examining raw image data roger_bratseth Coders. General 2 31 May 2018 18:36
Odd request: a raw image of a real (RDB) Amiga hard drive bloodline Coders. General 10 04 November 2017 11:28
restore raw hdd image orange support.WinUAE 0 26 February 2011 18:47
Can amiblitz (blitz basic2) blit an image per bitplane? Michael Parent Coders. General 7 29 October 2009 17:59

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +2. The time now is 17:06.

Top

Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.
Page generated in 0.07431 seconds with 16 queries