ShowPicture Saving Ham Images

miker1264 · 2580

miker1264

  • Legendary Member
  • *****
    • Posts: 1827
    • Karma: +84/-6
on: May 31, 2019, 08:50:36 PM
After a full year of constant development my Graphics program called ShowPicture is nearly ready for it's first release. It is capable of Loading, Displaying, Converting, Saving many Standard Picture Types such as PNG, BMP, JPG, TGA, etc. It can also save ILBM Bitmap Images of 8 bitplanes and below as well as ILBM Deep Images of 24 bitplanes. Now it can also save 24bit RGB pixel data directly as HAM6 or HAM8 images! There are also many new features on the menu.

Future versions will include Color Quantizing, Color Statistics using HSL, Histograms & Clustering, Color Group Operations, as well as the use of Opacity Masks and Overlay Masks. It can already convert many Bit Depths and Color Quantizing will allow converting from 32bit and 24bit to 8bit  and below. It will also have a menu system for loading, displaying and modifying PNG icon files and also Amiga IFF icon files. It has been an exciting journey so far programming ShowPicture.

The program itself will function as a graphics framework for many different graphics effects and hopefully it will serve as a prototype for future graphics programs. ShowPicture is been developed for Icaros Desktop ABIv0 (version 2.2.5). It is being tested on Icaros Hosted on Windows and Hosted on Linux and Icaros Native.



miker1264

  • Legendary Member
  • *****
    • Posts: 1827
    • Karma: +84/-6
Reply #1 on: May 31, 2019, 09:09:28 PM
The sample pcx image has an odd size of 474 x 329. In order to save HAM6 & HAM8 images the scanline length must be modulus 16 (evenly divisible by 16). Padding bytes are added at the end of each scanline to make it the correct length so that the bitplanes will be of equal length. I recently got this to work using the following code: 

    //Check if image width is modulus 16.
    int alignedwidth = (Ham_Width + 15) & ~15;
    "bytesPerLine = (alignedwidth / 8 );"
    //UBYTE chunkyBuffer[(HamDepth * bytesPerLine)]; //Causes Save Ham6 to Crash!
    //UBYTE chunkyBuffer[Ham_Width];
    UBYTE chunkyBuffer[alignedwidth];

The HAM save function wasn't working correctly for HAM6 images until I set the size of chunkyBuffer to alignedwidth which is modulus 16. The chunkyBuffer is used to hold all the hambytes before chunky bytes are converted to planar data before writing to the HAM ILBM file. The function also saves RGB data as HAM8. The C2P conversion that I used was adapted from one of my C# ILBM Viewers. It allows converting from 8 bitplanes to any number of lesser values such as 6 bitplanes for saving HAM6. This process can also be used to convert an 8bit standard image to an ILBM bitmap image of 5 bitplanes for use in Amiga IFF icons.

ChunkyBufferToBitplanes(UBYTE *chunkyBuffer, UBYTE *bitBuffer, int bitPlanes, int imagewidth)
{
    //Convert one scanline from chunky to planar.
    int i, j;
    int hOffset = 0;
    int bitplaneIndex = 0;
    //int bit = 0;
    "int bytesPerLine = (imagewidth / 8 );"
    int rowSize = (bitPlanes * bytesPerLine);

    //Block of 8 colors
    UBYTE colorBytes[8];

    //EasyRequest(NULL, &ResultReq, NULL, "ChunkyPixelsToBitplanes");
    while (hOffset < bytesPerLine)
    {
        //Copy 8 colorBytes to new buffer. Chunky Buffer is Modulus 16 & therefore Modulus 8.
        "memcpy(colorBytes, chunkyBuffer + (hOffset * 8 ), 8 );"
        for (j = 0; j < bitPlanes; j++) //Fill bitplane byte locations (Up to bytesPerLine)
        {
            bitplaneIndex = (j * bytesPerLine);
            //UBYTE bitmask = (UBYTE)(1 << bit);
            //Set corresponding bits in bitplane buffers.
            for (i = 0; i < 8; i++)
            {
                /* Check if the current bit of the index value is set */
                if ((colorBytes & (1 << j)) != 0)
                {
                    //("Bit is Set (1).")
                    /* Modify the current bit in the bitplane byte to be 1 and leave the others untouched */
                    bitBuffer[bitplaneIndex + hOffset] |= (UBYTE)(1 << 7 - i);
                    //Set bit = number |= 1 << x; //return value |= (UBYTE)(1 << pos);
                }
                else
                {
                    //("Bit is Not Set (0). ")
                    /* Modify the current bit in the bitplane byte to be 0 and leave the others untouched */
                    bitBuffer[bitplaneIndex + hOffset] &= (UBYTE)(~(1 << 7 - i));
                    //Clear bit = number &= ~(1 << x); //return value &= (UBYTE)(~(1 << pos));
                }
            }

        }
        hOffset++;

    }//End while loop

}
« Last Edit: May 31, 2019, 09:13:22 PM by miker1264 »



salvatore

  • Guest
Reply #2 on: June 01, 2019, 08:14:46 AM
thank yo very much is great



miker1264

  • Legendary Member
  • *****
    • Posts: 1827
    • Karma: +84/-6
Reply #3 on: August 31, 2019, 09:54:06 PM
For anyone that is interested here is my Main Graphics Program called "ShowPicture". Though it is far from complete, it is currently being used for testing purposes.
Double-click the App Icon to start. A File Requester should appear to select a picture file to open. It is completely menu driven but some of the menu items are incomplete or not working. So be advised before you tell me it crashes, many items work correctly, but some don't. The message boxes at startup are just for informational purposes. I haven't decided whether to keep them or not in the version of the program that will be released. I may release a smaller graphics program first that contains all the picture display, picture type conversion, bitdepth conversion functions as well as saving 24bit directly to Ham6 or Ham8. The last two items that refer to Ham6/Ham8 are based on ham conversion code provided by Allain Thellier which I have with permission included in "ShowPicture".

Here is the original ham conversion code included in Allain's program on Aminet (hint: some of it is in French):
http://aminet.net/package/gfx/conv/DatatypeToHam



You can open a picture file such as a "png" and convert it to another picture type such as "iff" or "ham" then save it. On the "Convert" Menu you may convert to
other picture types. On the "Depths" menu you may convert the BitDepth but currently I haven't included Color Quantizing so you can only go up, not down. If you open an 8bit png and choose to convert 8bit to 24bit or 32bit a new picture file with the desired bitdepth is saved to the selected location. On the "Colors" menu you may choose a color change operation to see an immediate change. To restore to the previous image choose "Picture>Prev Picture". After a Color Change or Adjustment such as Flip or Rotate in order to save the changed image choose "Picture>Save Picture" otherwise the original image will be saved.

This is just meant to give you an idea of what I'm working on, and what is possible with just a window and a simple menu system. Hopefully, when I fully comprehend MUI/Zune User Interface Design my programs will become a little more complex and more useful.

Have fun...
« Last Edit: August 31, 2019, 11:38:15 PM by miker1264 »



miker1264

  • Legendary Member
  • *****
    • Posts: 1827
    • Karma: +84/-6
Reply #4 on: August 31, 2019, 10:11:22 PM
Here are a couple of test images that I have used. When you open HAM8 they are converted to 24bit RGB.
They can be saved as PNG, IFF24, JPEG, PNM, PCX or TGA.

Let me know if the HAM8 images work for you. The originals before I saved to HAM8 were JPEG samples.



miker1264

  • Legendary Member
  • *****
    • Posts: 1827
    • Karma: +84/-6
Reply #5 on: August 31, 2019, 10:12:14 PM
Here is the second sample image.

Here is a clue how to use ShowPicture to Save As HAM6 & Save As HAM8.
Always Double-click the App Icon to open another picture file. Multiple picture files can be opened at a time.
Each picture has it's own window and it's own menu that only pertains to that picture.
Open a 24bit picture file such as a png or jpeg. Choose "Project>Save As HAM to save 24bit directly to HAM6.
If you'd like to Save As HAM8, choose "Project>Save As IFF" and you will be prompted to Save As HaM8 or IFF24.

Note if the image being displayed is larger than the screen I haven't yet allowed for resizing the display to fit screen.
« Last Edit: August 31, 2019, 10:17:54 PM by miker1264 »



miker1264

  • Legendary Member
  • *****
    • Posts: 1827
    • Karma: +84/-6
Reply #6 on: September 02, 2019, 03:43:21 PM
There is a story behind the App Icon for ShowPicture.



salvatore

  • Guest
Reply #7 on: September 02, 2019, 05:13:51 PM
beautiful, in my opinion you can also leave zune and apply to the rest of the functions, at least for me the classic interface does not look bad ;)



paolone

  • Moderator
  • Legendary Member
  • *****
    • Posts: 568
    • Karma: +90/-0
Reply #8 on: September 05, 2019, 04:26:42 AM
@Miker


Hi, I really like your ShowPicture. Just my basic suggestions: 1. avoid the "image successfully opened" message when opening a new image, and 2. do not show information before opening the image. Go straight to image showing. Users generally don't like unnecessary clicks and steps before getting the main result. I guess those message windows are there just for debug operations, but I felt the need to tell you anyway.





miker1264

  • Legendary Member
  • *****
    • Posts: 1827
    • Karma: +84/-6
Reply #9 on: September 05, 2019, 05:25:43 AM
Good point. I'll remove them.