Login
Username:

Password:

Remember me



Lost Password?

Register now!
Main Menu
Who's Online
1 user(s) are online (1 user(s) are browsing Forum)

Members: 0
Guests: 1

more...

Browsing this Thread:   1 Anonymous Users





IFF24 ILBM Color Experiments

Joined:
5/2 17:15
From California, United States
Group:
Member
Posts: 162
Offline
While writing the Save_ILBM function and three subfunctions, SaveBitmapPic, SaveRGBPic, and SaveHAMPic I have discovered a few interesting things, such as how to convert an IFF24 (24 bitplanes) ILBM color image file into a greyscale image!







Posted on: 2017/12/3 14:44
Transfer the post to other applications Transfer


Re: IFF24 ILBM Color Experiments

Joined:
5/2 17:15
From California, United States
Group:
Member
Posts: 162
Offline
Here is the code I'm using. I tried to post a screenshot as well.

/* Convert Chunky ScanLine to Planar ScanLine. */
//chunky2planar(planarR, &Buffer, 8, bytesPerRow);
//Buffer = chunky2planar(planarR, 8, bytesPerRow);
UBYTE *bytesBuffer[3];
bytesBuffer[0] = planarR;
bytesBuffer[1] = planarG;
bytesBuffer[2] = planarB;

//chunkyBuffer = planarR
int bit = 0;
int hOffset = 0;
int bitplaneIndex = 0;
pBufferOffset = 0;
//UBYTE *redBuffer; //planarBuffer

for (k = 0; k < 3; k++)
{
while (hOffset < bytesPerRow) //bytesPerPixel
{
memcpy(colorBytes, bytesBuffer[k] + (hOffset * 8), 8);
//memcpy(colorBytes, planarG + (hOffset * 8), 8);
for (j = 0; j < 8; j++) //Fill bitplane byte locations (Up to bytesPerLine).
{
bitplaneIndex = (j * bytesPerRow);
UBYTE bitmask = (UBYTE)(1 << bit); //LONG mask = 0x80 >> (x & 7);
for (i = 0; i < 8; i++) //Set bits in bitplane buffers.
{
if ((colorBytes[i] & (1 << j)) != 0) //if (colorBytes[i] & (1 << j))
bitBuffer[bitplaneIndex + hOffset] |= (UBYTE)(1 << 7 - i); // Bit is Set (1). |= mask;
else
bitBuffer[bitplaneIndex + hOffset] &= (UBYTE)(~(1 << 7 - i)); //Bit is Not Set (0). &= ~mask;
}
bit++;
if (bit == 7) /* Reset the bit counter */
{
bit = 0;
}
}
hOffset++;
}
//memcpy(planarBuffer, bitBuffer, pBufferLength);
//memcpy(planarBuffer + pBufferOffset, bitBuffer, pBufferLength);
//pBufferOffset += pBufferLength;

int pOffset = offset + pBufferOffset;
WriteBytes(file, bitBuffer, pOffset, (bytesPerRow * 8));
pBufferOffset += pBufferLength;
offset += scanLength;

}


I am using a compound UBYTE array with three parts, one for each of the Red channel, Green channel, and Blue channel for the RGB color components. The For Loop also has three passes so that I can process each color channel on each successive passe using 'k' as a counter. This works quite well. However, I believe I will need to reset the 'bitBuffer' after each pass to clear all the data.

Posted on: 2017/12/3 14:54

Edited by miker on 2017/12/3 15:17:39
Transfer the post to other applications Transfer


Re: IFF24 ILBM Color Experiments

Joined:
5/2 17:15
From California, United States
Group:
Member
Posts: 162
Offline
When I started with SaveRGBPic I had already written the first draft of SaveBitmapPic which will be submitted soon.

So writing the file signature 'FORM' and the rest of the formalities such as 'ILBM' and 'BMHD' were already done. Now I was at the point where I had to convert 24 bit pixel data into planar data to write to the BODY of the ILBM. According to the documentation the RGB color components need to first be separated so that the Reds are in the first set of 8 bitplanes, the Greens are in the second set, and the Blues are in the last set of 8 bitplanes. 8x3=24.

I was successful at getting chunky RGB scanlines and also separating the color components into three 8 bitplane groups. When I tried to convert each color component from chunky to planar things got interesting. The chunky to planar conversion using my function from a few years ago worked great for the Red component, but the Green and Blue components (8 bitplanes each) had aberrations of data which resulted in some very nice greyscale images. So close! I'm very close to solving that issue so that SaveRGBPic will be capable of saving 24 bit pixel data as an IFF24 ILBM with 24 bitplanes.

Posted on: 2017/12/3 15:12
Transfer the post to other applications Transfer


Re: IFF24 ILBM Color Experiments

Joined:
5/2 17:15
From California, United States
Group:
Member
Posts: 162
Offline
The 24 bit RGB data from the picture datatype was correct.The RGB data collected into three sets of 8 bitplanes for each of the color channels was also correct. The problem here was that the data after converting to planar wasn't correct!

I had confidence in the RGB data but not in the chunky2planar function I was using, so I replaced it. Here is the new c2p function that is working. SaveRGBPic is now working for saving 24 bit pixel data directly to IFF24 which is an ILBM with 24 bitplanes! Yeah, finally!!

/**************************************************************************************************/

//Compound byte buffer for RGB channels.
UBYTE *bytesBuffer[3];
bytesBuffer[0] = planarR;
bytesBuffer[1] = planarG;
bytesBuffer[2] = planarB;
UBYTE bitBuffer[bytesPerRow * 8];

int bit = 0;
int hOffset = 0;
int bitplaneIndex = 0;
pBufferOffset = 0;

//Convert one chunky scanline to planar data.
UBYTE *source;
int alignedwidth, x, y, p, bpr, bpl;
alignedwidth = (imageWidth + 15) & ~15;
bpr = alignedwidth / 8; //bytesPerRow

for (k = 0; k < 3; k++)
{
source = bytesBuffer[k];
for(x = 0; x < imageWidth; x++)
{
LONG mask = 0x80 >> (x & 7);
LONG offset = x / 8;
UBYTE chunkypix = source[x];

for(p = 0; p < 8; p++)
{
if (chunkypix & (1 << p))
bitBuffer[p * bpr + offset] |= mask;
else
bitBuffer[p * bpr + offset] &= ~mask;
}
}
//Copy planar data to correct location in planar buffer.
memcpy(planarBuffer + pBufferOffset, bitBuffer, pBufferLength);
pBufferOffset += pBufferLength;

} /* End For Loop (k) */

//=====================================================================//


Continue the momentum! The next major task is to write SaveHAMPic for saving 24 bit pixel data directly to HAM8 and to enable saving IFF32 (32 bitplanes, RGBA) with SaveRGBPic.

Posted on: 2017/12/3 20:57
Transfer the post to other applications Transfer


Re: IFF24 ILBM Color Experiments

Joined:
2009/3/15 4:41
Group:
Member
Posts: 616
Offline
Be careful, some programs generated 24Bit IFF pictures with 8- Bit transparency but did not call them 32Bit IFF.

For a simple conversion algorithm I converted the 24Bit to 16Bit where I could easily count the colours for further colour reduction.

Posted on: 2017/12/4 10:29
Transfer the post to other applications Transfer


Re: IFF24 ILBM Color Experiments

Joined:
5/2 17:15
From California, United States
Group:
Member
Posts: 162
Offline
GreenNight,

That's good to know. The Load_ILBM function deals with reading the RGB or RGBA images. The Save_ILBM only saves pixel data. For IFF24 I intend to make it work according to the 24 bit ILBM documentation, three sets of 8 bitplanes for each scanline that correspond to each RGB channel.

For IFF32 I intend to just add an additional 8 bitplanes at the end of each scanline to hold alpha values. The picture datatype will provide all the RGB and RGBA values for me. My code merely saves the pixel data to an IFF-ILBM file.

As long as the BMHD indicates depth as 24 for IFF24 and 32 for IFF32 everything should be fine. But, as you mentioned, if an IFF32 is listed with a depth of 24 that's a problem.

It's also important to note that the length of the RGB scanLine should be modulus 16 or the IFF24 image file will be invalid. The same applies for IFF32.

When you say color reduction, do you mean color quantizing, or alpha reduction such as 32 bit to 24 bit?

Posted on: 2017/12/4 10:45

Edited by miker on 2017/12/5 12:20:39
Edited by miker on 2017/12/5 12:23:22
Transfer the post to other applications Transfer


Re: IFF24 ILBM Color Experiments

Joined:
5/2 17:15
From California, United States
Group:
Member
Posts: 162
Offline
I made a few changes to SaveRGBPic recently. It will be submitted soon. I have already made a commit of SaveILBM and SaveBitmapPic. Hopefully, I will be able to test them.

Posted on: 2017/12/6 10:47
Transfer the post to other applications Transfer


Re: IFF24 ILBM Color Experiments

Joined:
2009/3/15 4:41
Group:
Member
Posts: 616
Offline
Quote:

miker wrote:

When you say color reduction, do you mean color quantizing, or alpha reduction such as 32 bit to 24 bit?


I do not remember the exact problem I was working on.

It had to do with colour reduction (24Bit -> 8Bit) I needed a simple and fast algorithm something I could figure out in an afternoon.

First I reduced the 24Bit Pictures to 16Bit, because making a histogram for 65328 colours is much easier than doing it for 16777216 colours. And together with this histogram, I figured out what palette would be good enough for a 256 colour display.

---

BTW.:

When processing IFF Files you should do it with a state machine, when I started doing it I thought all the date will have the same data chunks coming in the same order, but this is not always true.


Posted on: 2017/12/6 11:55
Transfer the post to other applications Transfer


Re: IFF24 ILBM Color Experiments

Joined:
5/2 17:15
From California, United States
Group:
Member
Posts: 162
Offline
Reduction from (24Bit -> 8Bit) would require quantizing to get the color palette and the indexes. I havn't gotten that far in my graphics experiments. But there are some good quantizing algorithms available. I might need to do something like that for SaveHAMPic where I will attempt to save RGB pixel data directly to HAM8 rather than an IFF24.

Posted on: 2017/12/6 16:34
Transfer the post to other applications Transfer






You can view topic.
You cannot start a new topic.
You cannot reply to posts.
You cannot edit your posts.
You cannot delete your posts.
You cannot add new polls.
You cannot vote in polls.
You cannot attach files to posts.
You cannot post without approval.

[Advanced Search]


Search
Top Posters
1 paolone
paolone
4365
2 magorium
magorium
4095
3 phoenixkonsole
phoenixkonsole
3893
4 nikolaos
nikolaos
3694
5 deadwood
deadwood
2923
6 ncafferkey
ncafferkey
2648
7 mazze
mazze
2214
8 clusteruk
clusteruk
2111
9 Kalamatee
Kalamatee
2024
10 damocles
damocles
1789
© 2004-2017 AROS Exec