New Picture Datatypes

miker1264 · 7143

AMIGASYSTEM

  • Legendary Member
  • *****
    • Posts: 712
    • Karma: +32/-1
  • AROS One
    • AROS One
Reply #90 on: May 30, 2021, 12:27:32 AM
Ah...much better.

Thank goodness, you saved the wine  :D


miker1264

  • Legendary Member
  • *****
    • Posts: 748
    • Karma: +34/-2
Reply #91 on: May 30, 2021, 03:50:06 AM
Simple physics!

When the glass is upside down, acceleration due to gravity, the wine falls out.

But the wine is safe now!  :D


Targa on the left, Bmp on the right.
Next I should focus on "saving" 16bit Targa.

Here is the gist of converting a 16bit scanline to 24bit.
Note: It took three days of research and experimentation to get this far...


for(x = 0; x < bmh->bmh_Width; x++)      
{
    /* Expand 16bit pixels to 24bit pixels */
   red = ((buf1[(x*2)+1] << 1) & 0xf8);
   red += red >> 5;
   green = ((buf1[x*2] & 0xe0) >> 2) | ((buf1[(x*2)+1] & 0x03) << 6);
   green += green >> 5;
    blue = ((buf1[x*2] << 3) & 0xf8);
   blue += blue >> 5;
   
    buf2[x*3] = red; buf2[(x*3)+1] = green; buf2[(x*3)+2] = blue;
}
« Last Edit: May 30, 2021, 07:33:40 PM by miker1264 »



miker1264

  • Legendary Member
  • *****
    • Posts: 748
    • Karma: +34/-2
Reply #92 on: June 02, 2021, 01:03:52 AM
Small update for datatypes.

A while ago I started writing save functions for Targa and PCX datatypes. Seems odd to start at the end and work forward. Sometimes I read novels like that.  :)

Recently I've been writing an entirely new Targa Datatype complete with Load and Save functions for 8bit, 16bit, 24bit and 32bit images. It's almost finished. I'm just finishing up 16bit.

I've started writing a new PCX Datatype as well that will support Loading and Saving 8bit and 24bit with PCX RLE compression. It will be couple weeks till it is finished. RLE compression is tricky to implement for PCX. So I have to be very cautious about it.

I recently wrote a new TIFF Datatype that actually works using LibTiff. But so far it only supports Loading and Saving 24bit. I'd like to write an internal decoder for Tiff images to remove dependency on LibTiff. That will require a major re-write and the LZW codec will be needed. It is also used in GIF datatype.

I finished the revisions for Jpeg datatype to support loading and saving 8bit bw images. But I haven't uploaded it yet.  :D

So, we should have three new dataypes soon to play with.



salvo

  • Legendary Member
  • *****
    • Posts: 1156
    • Karma: +14/-4
  • Invalid Civil
Reply #93 on: June 02, 2021, 09:57:01 PM
thank you miker :)

Software Contributor RNOPublisher, RNOArchive

Sign Up On AmigaMap
https://amigamap.com/


miker1264

  • Legendary Member
  • *****
    • Posts: 748
    • Karma: +34/-2
Reply #94 on: June 04, 2021, 12:10:51 AM
Hmm...

WriteScanlineRLE for Targa Datatype is a bit challenging.

But I suppose that's what makes all of this so interesting.

Luckily I already have ReadScanlineRLE & WriteScanlineRLE for the PCX Datatype. Writing the rest should be relatively easy! 😊



miker1264

  • Legendary Member
  • *****
    • Posts: 748
    • Karma: +34/-2
Reply #95 on: June 05, 2021, 05:52:06 AM
I was working on the Targa Datatype, more specifically the WriteRGB16 function that saves 16bit images.

As you can see it's kinda working! Oooops! Probably a wrong conversion formula.  8)



AMIGASYSTEM

  • Legendary Member
  • *****
    • Posts: 712
    • Karma: +32/-1
  • AROS One
    • AROS One
Reply #96 on: June 05, 2021, 03:53:09 PM
Verify well, try a Targa image saved by another program, I noticed that some programs save a non-standard format.


miker1264

  • Legendary Member
  • *****
    • Posts: 748
    • Karma: +34/-2
Reply #97 on: June 05, 2021, 05:56:26 PM
Verify well, try a Targa image saved by another program, I noticed that some programs save a non-standard format.

I have several test images that I've created from a 24bit BMP using PixelFormer in Windows and ImageMagick in Linux to create 16bit BMP and TGA files in rgb555 format. GIMP is also good for creating and viewing Targa images. But PaintDotNet is nearly useless for Targa. It forgets to swap bgr to rgb pixels.

I saw a documentary recently about code breakers in WWII, although I'm not that old.  ;)

Secret messages were being intercepted that had to be decoded. The encoded messages were generated by the Enigma Machine which was a box that consisted of 12 cylinders that could be arranged for encoding messages. It was the job of some highly skilled mathematicians to use the messages to work out the internal arrangements of the Enigma Machine.

I'm trying to break the code to come up with a formula involving bitwise operations such as bit masking and bit shifting to convert 3 bytes of 24bit rgb888 into 2 bytes of 16bit rgb555.

The scattered image you see is because my formula for conversion is only half correct. For the 2 byte values for 16bit the first byte is almost correct but my formula isn't including the 5bits from the blue element. So for example what should be 0xE3 0x3C becomes 0xE0 0x3C. All the second bytes are good.

Hehehe! I'm using an online Hex to Binary converter and online Bit Shift calculator and my favorite Hex Editor. I'm converting three bytes to binary then writing it out to get the formula. Once I get the correct formula to convert 24bit to 16bit pixels I can use it for any dataype that supports 16bit images. After Targa Datatype I may have to revise BMP Datatype to save 16bit also.

Happy Decoding! (But in this case Encoding).  8)
« Last Edit: June 05, 2021, 06:02:55 PM by miker1264 »



miker1264

  • Legendary Member
  • *****
    • Posts: 748
    • Karma: +34/-2
Reply #98 on: June 05, 2021, 07:53:09 PM
@AMIGASYSTEM

I know you are fond of blue. I have a blue problem...

I believe I found the problem with my formula. It seems to be a transliteration problem due to user error!  8) 8) 8)
Isn't it always user error!?  :D

            BYTE red, green, blue;

            /* Collect 24bit pixel elements */
            red = (buf2[x*3]);
            green = (buf2[(x*3)+1]);
            blue = (buf2[(x*3)+2]);

Everything looks good so far...but then what should be '11100011' is instead '11100000' because it isn't picking up 5bits of blue. But Why??

            linebuf[x*2] = ((green & 0xF8) << 2) | ((b & 0xF8) >> 3); // Take remaining 3 Bits of G component and 5 bits of Blue component E3 rgb555
            linebuf[(x*2)+1] = ((red & 0xF8) >> 1) | (green >> 6); // Take 5 bits of Red component and 2 bits of G component 3C rgb555

See this part: | ((b & 0xF8) >> 3); That is probably because I inadvertently used 'b' instead of 'blue'.
So the right side of the first conversion should be: | ((blue & 0xF8) >> 3); or just (blue >> 3);




miker1264

  • Legendary Member
  • *****
    • Posts: 748
    • Karma: +34/-2
Reply #99 on: June 07, 2021, 02:14:01 AM
Kitty looks pretty in pink!

But that also indicates a slight problem with my 24bit to 16bit conversion code.
Light blue gets washed out and there is too much red tint.

Notice the wine and bread image on top which is the original, if you look at the wine bottle label on bottom...
it is losing blue and gaining red.



miker1264

  • Legendary Member
  • *****
    • Posts: 748
    • Karma: +34/-2
Reply #100 on: June 07, 2021, 03:47:14 AM
After three days of experimentation & testing I have a working WriteRGB16 code that converts
24bit rgb888 to 16bit rgb555 or '5 bits per pixel". Orininal 24bit on left, new 16bit on the right.
There is only a slight perceived difference between them. The original is slightly darker overall.
I could use post processing to darken each pixel or simply leave it the way it is. It's working!

I had to tweak the conversion formula several times in different masking configurations to get
the correct color fidelity. It seems that different bit masking yields different results. So there is
still room to tweak it a little more if needed. Here's the working code if anyone is interested...

Only the working code is good. Everything behind '//' slashes is just old experimental code.



           /* Collect 24bit pixel elements */
            red = (buf2[x*3]);
            green = (buf2[(x*3)+1]);
            blue = (buf2[(x*3)+2]);

         //linebuf[x*2] = ((green & 0xF8) << 2) | ((blue & 0xF8) >> 3); //Causes light blue -> pink.
         //linebuf[(x*2)+1] = ((red & 0xF8) >> 1) | (green >> 6);

            //Working code. Good quality images. Blues still not dark enough.
         linebuf[x*2] = ((green & 0xF8) << 2) | ((blue & 0xF8) >> 3); // Take remaining 3 Bits of G component and 5 bits of Blue component E3 rgb555
            linebuf[(x*2)+1] = ((red & 0xF8) >> 1) | ((green & 0xC0) >> 6); // Take 5 bits of Red component and 2 bits of G component 3C rgb555

         //linebuf[x*2] = ((green & 0x38) << 2) | (blue >> 3);
         //linebuf[(x*2)+1] = ((red & 0xF8) >> 1) | ((green & 0xC0) >> 6);

            //rgb555 = (((blue) >> 3) | (((green) >> 3) << 5) | (((red) >> 3) << 10)); //Blue Washout.
         //linebuf[x*2] = (rgb555 & 0xFF);
         //linebuf[(x*2)+1] = (rgb555 >> 8) & 0xFF;
« Last Edit: June 07, 2021, 04:24:24 AM by miker1264 »



salvo

  • Legendary Member
  • *****
    • Posts: 1156
    • Karma: +14/-4
  • Invalid Civil
Reply #101 on: June 07, 2021, 02:10:06 PM
very impressive miker 8)

Software Contributor RNOPublisher, RNOArchive

Sign Up On AmigaMap
https://amigamap.com/


miker1264

  • Legendary Member
  • *****
    • Posts: 748
    • Karma: +34/-2
Reply #102 on: June 07, 2021, 03:44:18 PM
very impressive miker 8)

salvo

I'm very impressed with the quality of the output 16bit image.

I will have to compare the same input and output images in other graphics programs that deal with 16bit images such as GIMP and ImageMagick in Ubuntu and Pixelformer in Windows.



salvo

  • Legendary Member
  • *****
    • Posts: 1156
    • Karma: +14/-4
  • Invalid Civil
Reply #103 on: June 08, 2021, 12:09:48 AM
i understand miker

Software Contributor RNOPublisher, RNOArchive

Sign Up On AmigaMap
https://amigamap.com/


miker1264

  • Legendary Member
  • *****
    • Posts: 748
    • Karma: +34/-2
Reply #104 on: June 08, 2021, 09:03:07 PM
After two weeks of intense effort here is the completed Targa Datatype. It is currently compiled as x86-64.
But the x86 and 68k versions will follow soon.

Reading and writing 16bit images was tricky at first. But it works reaaly well now! Next on my list is a new PCX Datatype.

I have to hurry to produce new dataypes before @paolone releases a new version of IcarosDesktop! Wow! He is fast.  :D

It can read RLE Compressed Images, 8bit, 16bit, 24bit, 32bit. It can save 8bit, 16bit, 24bit, 32bit targa images.
« Last Edit: June 08, 2021, 09:13:23 PM by miker1264 »