Ghost an image

A forum for general AmigaOS 4.x support questions that are not platform-specific

Ghost an image

Postby mritter0 » Fri Aug 14, 2015 12:03 am

I have loaded and scaled an image using DataTypes and CompositeTags.

I would like to give it a "ghosted/disabled" look.

I added COMPTAG_SrcAlpha,COMP_FLOAT_TO_FIX(0.75),
It looks ok on some images/colors, but terrible with white images.

Just like when you open Workbench window and do Show All and the C/Devs/S folders are ghosted.

Something simple that can be done on the fly quickly.
Workbench Explorer - A better way to browse drawers
User avatar
mritter0
 
Posts: 184
Joined: Mon Aug 25, 2014 10:41 pm
Location: Bettendorf, IA, USA

Re: Ghost an image

Postby broadblues » Fri Aug 14, 2015 5:29 pm

I have loaded and scaled an image using DataTypes and CompositeTags.

I would like to give it a "ghosted/disabled" look.

I added COMPTAG_SrcAlpha,COMP_FLOAT_TO_FIX(0.75),
It looks ok on some images/colors, but terrible with white images.

Just like when you open Workbench window and do Show All and the C/Devs/S folders are ghosted.


They are not ghosted they are (partially) transparent, subtle and important difference.

If you realy want ghosted, as in the imagery used for disabled images in gadgets, then I think, bitmap.image can create a ghosted version if the BITMAP_Disabled#? tag is not set. The autgenerated disabled image is a greyscale bumpmap variant on the Render image.

If you want partially transparent then render the image to the destination by blitting with alpha = 0.5 using BlitBitmapTags() (slow for larger images and the alpha blending is not hardware accelerated ) or perhaps CompositeTags()
User avatar
broadblues
AmigaOS Core Developer
AmigaOS Core Developer
 
Posts: 478
Joined: Sat Jun 18, 2011 3:40 am
Location: Portsmouth, UK

Re: Ghost an image

Postby mritter0 » Fri Aug 14, 2015 8:28 pm

Yes, half transparent is what I want. I am having trouble still. All of the error handling has been removed to shorten things up.

Load image
Code: Select all
   if (!(DTO=IDataTypes->NewDTObject(Path,
      DTA_GroupID,                  GID_PICTURE,
      PDTA_Screen,                  DefaultPubScreen,
//      PDTA_Remap,                     FALSE,
//      PDTA_AlphaChannel,               TRUE,
      PDTA_PromoteMask,               TRUE,
      PDTA_DestMode,                  PMODE_V43,
//      PDTA_WhichPicture,               WhichPicture,
   TAG_END)))
   {
   }


Allocate bitmap and set it up
Code: Select all
   if (!(OrigBM=IP96->p96AllocBitMap(bmhd->bmh_Width,bmhd->bmh_Height,32,BMF_DISPLAYABLE,NULL,RGBFB_A8R8G8B8)))
   {
   }

   Lock=IP96->p96LockBitMap(OrigBM,(uint8 *)&RenderInfoBuffer,sizeof RenderInfoBuffer);

   pdtBlitPixelArrayBuffer.MethodID=PDTM_READPIXELARRAY;
   pdtBlitPixelArrayBuffer.pbpa_PixelData=RenderInfoBuffer.Memory;
   pdtBlitPixelArrayBuffer.pbpa_PixelFormat=PBPAFMT_ARGB;
   pdtBlitPixelArrayBuffer.pbpa_PixelArrayMod=RenderInfoBuffer.BytesPerRow;
   pdtBlitPixelArrayBuffer.pbpa_Left=0;
   pdtBlitPixelArrayBuffer.pbpa_Top=0;
   pdtBlitPixelArrayBuffer.pbpa_Width=bmhd->bmh_Width;
   pdtBlitPixelArrayBuffer.pbpa_Height=bmhd->bmh_Height;

   IIntuition->IDoMethodA(DTO,(Msg)&pdtBlitPixelArrayBuffer);

   IP96->p96UnlockBitMap(OrigBM,Lock);

   IDataTypes->DisposeDTObject(DTO);
   DTO=NULL;


Create ScaleBM
Code: Select all
   if (!(ScaleBM=IP96->p96AllocBitMap(ScaleWidth,ScaleHeight,32,BMF_CLEAR | BMF_DISPLAYABLE,NULL,RGBFB_A8R8G8B8)))
   {
   }


Scale it and try to make it transparent
Code: Select all
   if (IGraphics->CompositeTags(
      COMPOSITE_Src,                  OrigBM, ScaleBM,
      COMPTAG_ScaleX,                  COMP_FLOAT_TO_FIX(ScaleFactorX),
      COMPTAG_ScaleY,                  COMP_FLOAT_TO_FIX(ScaleFactorY),
      !Ghost ? TAG_IGNORE : COMPTAG_SrcAlpha,               COMP_FLOAT_TO_FIX(0.75),
//      !Ghost ? TAG_IGNORE : COMPTAG_SrcAlpha,               COMP_FLOAT_TO_FIX(0.5),
   TAG_DONE) != COMPERR_Success)
   {
   }




Now, if I don't do use the COMPTAG_SrcAlpha tag and use your suggestion to BltBitMapTags(), it locks up. I know the BLIT_Alpha value is not correct, it was just for test and copied from autodoc.
Code: Select all
   if (Ghost)
   {
      if (!(GhostBM=IP96->p96AllocBitMap(ScaleWidth,ScaleHeight,32,BMF_CLEAR | BMF_DISPLAYABLE,NULL,RGBFB_A8R8G8B8)))
      {
      }
   }

    IGraphics->BltBitMapTags(
        BLITA_DestX,       0,
        BLITA_DestY,       0,
        BLITA_Width,       ScaleWidth,
        BLITA_Height,      ScaleHeight,
        BLITA_SrcType,     BLITT_BITMAP,
        BLITA_Source,      ScaleBM,
        BLITA_DestType,    BLITT_BITMAP,
        BLITA_Dest,        GhostBM,
      BLITA_Alpha,      0xfffffff,
//        BLITA_UseSrcAlpha, TRUE,
        TAG_END);


Then put it in a BitMapObject since only showing the images in a listbrowser or button gadget.
Code: Select all
   if (!(Img=BitMapObject,
      BITMAP_Screen,                  DefaultPubScreen,
      BITMAP_Precision,               PRECISION_EXACT,
      BITMAP_BitMap,                  Ghost ? GhostBM : ScaleBM,
      BITMAP_Width,                  ScaleWidth,
      BITMAP_Height,                  ScaleHeight,
      BITMAP_HasAlpha,               TRUE,
      BITMAP_Masking,                  TRUE,
      BITMAP_Transparent,               TRUE,                // optional
   TAG_DONE)))
   {
   }


I would prefer to do the scaling and transparency all at once with CompositeTags() and not have to use BltBitMapTags() so don't have to use 2 bitmaps (Scale and Ghost).

What would be the correct BLITA_Alpha value if I have to use it? 0x7fffffff or 0x7f7f7f7f maybe?
Workbench Explorer - A better way to browse drawers
User avatar
mritter0
 
Posts: 184
Joined: Mon Aug 25, 2014 10:41 pm
Location: Bettendorf, IA, USA

Re: Ghost an image

Postby Daytona675x » Fri Aug 14, 2015 9:31 pm

For the most common "I want a pretty simple semi-transparent blit over other stuff" IGraphics->CompositeTags(COMPOSITE_Src_Over_Dest,...); is probably what you're looking for.
Warp3D driver code-basher and bug-smasher - btw.: driver writing is nothing mysterious
User avatar
Daytona675x
AmigaOS Core Developer
AmigaOS Core Developer
 
Posts: 34
Joined: Wed Jan 22, 2014 6:18 pm
Location: Cologne, Germany

Re: Ghost an image

Postby broadblues » Sat Aug 15, 2015 1:46 am

Then put it in a BitMapObject since only showing the images in a listbrowser or button gadget.


Bitmap Image can do the scaling for you, and also transparency via a seperate AlphaBitmap see the autodoc.

If you have large number of images that are dramatical scaled down that might be a bit expensive in memory, so you might prescale using compositetags (or other methods )
User avatar
broadblues
AmigaOS Core Developer
AmigaOS Core Developer
 
Posts: 478
Joined: Sat Jun 18, 2011 3:40 am
Location: Portsmouth, UK

Re: Ghost an image

Postby mritter0 » Sun Aug 16, 2015 11:37 pm

.......and if I knew how to make a custom bitmap with transparency only I wouldn't have posted the original message......

IGraphics->CompositeTags(COMPOSITE_Src_Over_Dest,...); is probably what you're looking for.

Probably. Have an example???

1) so you might prescale using compositetags (or other methods )

2) Bitmap Image can do the scaling for you, and also transparency via a seperate AlphaBitmap see the autodoc.

1) I posted code doing that.
2) Again, have an example????
Workbench Explorer - A better way to browse drawers
User avatar
mritter0
 
Posts: 184
Joined: Mon Aug 25, 2014 10:41 pm
Location: Bettendorf, IA, USA

Re: Ghost an image

Postby mritter0 » Thu Aug 20, 2015 11:56 pm

I figured out a "hack" way to do it. I made a 50% transparent PNG image, just a blank image, load it and use COMPOSITE_Src_Over_Dest to put it over the actual image.

In the code above I use p96AllocBitMap() to create my bitmap. Anyone have an example to how to use p96WritePixelArray() to fill it with a 50% transparent alpha channel only (no RGB, just A)? Then I don't have to use the external PNG image.
Workbench Explorer - A better way to browse drawers
User avatar
mritter0
 
Posts: 184
Joined: Mon Aug 25, 2014 10:41 pm
Location: Bettendorf, IA, USA

Re: Ghost an image

Postby broadblues » Fri Aug 21, 2015 10:31 pm

mritter0 wrote:I figured out a "hack" way to do it. I made a 50% transparent PNG image, just a blank image, load it and use COMPOSITE_Src_Over_Dest to put it over the actual image.

In the code above I use p96AllocBitMap() to create my bitmap. Anyone have an example to how to use p96WritePixelArray() to fill it with a 50% transparent alpha channel only (no RGB, just A)? Then I don't have to use the external PNG image.


What is wrong with the following loop:

Load image
Foreeach pixel:
ReadPixel
Divide Alpha Part by 2
Write Pixel back (or to a second bitmap to cache the resulst)

Reander image with bitmap.image as normal.


Your talking small icons IIRC so hardware accelleration is not 100% required especially if you ultimatelt render to screen with bitmap.image.
User avatar
broadblues
AmigaOS Core Developer
AmigaOS Core Developer
 
Posts: 478
Joined: Sat Jun 18, 2011 3:40 am
Location: Portsmouth, UK

Re: Ghost an image

Postby broadblues » Fri Aug 21, 2015 10:46 pm

If you want to write alpha data into a bit map then you do something like this:

Allocate array of RGBFB_ALPHA8 pixels (basically 8 bits per pixlel o alpha only)

Copy your alpha data from your src (or explixitly set it by alpgorithm if you are generating it on the fly)

Fill out this structure

struct RenderInfo {
APTR Memory;
WORD BytesPerRow;
WORD pad;
RGBFTYPE RGBFormat;
};

Us P96WritePixelArray() to copy into your bitmap, which should then only modify the alpha (but testing required to chack that).

If you destination is also RGBFB_ALPHA8 you can use that with bitmap.image but I think this *replaces* the alpha information rather than multiplying it so you will need to start from the alpha map of your icon image (if it has one), so you are back with my loop above.
User avatar
broadblues
AmigaOS Core Developer
AmigaOS Core Developer
 
Posts: 478
Joined: Sat Jun 18, 2011 3:40 am
Location: Portsmouth, UK

Re: Ghost an image

Postby mritter0 » Tue Aug 25, 2015 1:18 am

I worked out a good method for my use. p96AllocBitMap(), AllocVecTags() a chunk of memory, fill it with 50% alpha only, p96WritePixelArray(), and keep using the COMPOSITE_Src_Over_Dest method in my "hack".
Workbench Explorer - A better way to browse drawers
User avatar
mritter0
 
Posts: 184
Joined: Mon Aug 25, 2014 10:41 pm
Location: Bettendorf, IA, USA


Return to General AmigaOS

Who is online

Users browsing this forum: No registered users and 3 guests