March 05, 2021, 07:31:54 PM

Author Topic: Loaded Image Colours  (Read 218 times)

Offline _PJ_

Loaded Image Colours
« on: February 07, 2021, 03:03:09 PM »
Image colours are not correctly reproduced.

I have changed AutoImageFlags to enable/disable filter and mipmapping (Not sure if this impacts pixmaps? or is only relevant on load/create/display)

I have checked the PixMap format is '6' for Pix and ScaledPix which corresponds to PF_BGRA8888 32 bit little endian RGB with alpha

In every instance, the colours of the image frames when drawn are wrong.

Code: [Select]
Function LoadVideoAsset:TImage(FileName:String)

   Local Pix:TPixmap = LoadPixmap(ENV_ASSETS_VIDEO_PATH + FileName + ENV_ASSETS_VIDEO_EXTENSION)
Local ScaledPix:TPixmap = ResizePixmap(Pix,PIXEL_SCALE_X * GPU_NUM_FRAMES_PER_ANIM, PIXEL_SCALE_Y)
Local Image:TImage = LoadAnimImage(ScaledPix,PIXEL_SCALE_X,PIXEL_SCALE_Y,0,GPU_NUM_FRAMES_PER_ANIM)

Return Image
End Function

____________

In testing, I tried simply loading a specific imagestrip with hardcoded values...

Code: [Select]
Function LoadVideoAsset:TImage(FileName:String)
Local Image:TImage = LoadAnimImage(ENV_ASSETS_VIDEO_PATH + FileName + ENV_ASSETS_VIDEO_EXTENSION,24,24,0,4)

Return Image
End Function
         
The colours are still wrong when the image is drawn. Coudl there be somethign with the choice of GraphicsDriver ?

The original image is a 24-bit BMP as saved by MSPaint. I have also used a version saved as PNG using MSPaint.

I have tried both D3D9Max2DDriver() and GLMax2DDriver() but the results are the same.


Offline col

Re: Loaded Image Colours
« Reply #1 on: February 07, 2021, 03:20:54 PM »
Pixmap format PF_BGRA8888 is 5 no?

Have you tried with PF_RGBA8888 which is 6.

You could try saving the image as 32bit too to see if it resolves automatically.

If that still doesn't work you can also try changing the 'endian-ness'.
To be is to be perceived.

https://github.com/davecamp

Offline Scaremonger

Re: Loaded Image Colours
« Reply #2 on: February 07, 2021, 05:36:20 PM »
When you draw the image, what blend mode are you using and what colour do you select before you draw it?
Follow me at ITSpeedway.net.

Offline Derron

Re: Loaded Image Colours
« Reply #3 on: February 07, 2021, 05:52:27 PM »
Dunno why people do not simply attach a screenshot showing the issue (here the original image/part of it, and then app displaying it wrong).

Thought we had an issue with MSPaint and 24bit images in the past already (RLE encoded vs another variant).


bye
Ron

Offline _PJ_

Re: Loaded Image Colours
« Reply #4 on: February 14, 2021, 03:34:40 PM »
Dunno why people do not simply attach a screenshot showing the issue (here the original image/part of it, and then app displaying it wrong).

Thought we had an issue with MSPaint and 24bit images in the past already (RLE encoded vs another variant).


bye
Ron
I didn't honestly think a screenshot would be of particular help, but please request such if you need it in future.

I created a small Blitz3D program to convert images to its SaveImage bitmap and these were apparently considered as "format 3" wheen loaded αΊƒith the BMax app - yet still they were not showing correctly. It turns out Scaremonger had the right of it.

Different blendmodes altered the images in ways that I had not anticipated by the description (I think due in part to the mipmapping/filtering and scaling of the image as well), but I was not using this command and left it as default.
The real culprit was SetColor

Prior to drawing the images, other dynamic features are drawn which are procedurally determined so there are numerous SetColor calls. Ensuring that SetColor(255,255,255) is called just before drawing the loaded images was sufficient to render the colours correctly.

Whilst it seemed an unusual and confusing 'feature', I actually now think that there may be some neat potential with this - for example, handling pseudo lighting-effects in 2D!



Offline Derron

Re: Loaded Image Colours
« Reply #5 on: February 14, 2021, 07:27:01 PM »
Yes, when working with max2d you should always "undo" your color changes

So eg you could do this (especially with NG...):

Code: BlitzMax
  1. Function DrawColoredRectangle(x:int, y:int, w:int, h:int, r:Byte, g:Byte, b:Byte, a:Float)
  2.   local oldCol:SColor8; GetColor(oldCol) 'a struct consisting of r,g,b - and a byte alpha which is not much of use here)
  3.   local oldA:Float = GetAlpha()
  4.  
  5.   SetColor(r,g,b)
  6.   SetAlpha(a)
  7.   DrawRect(x,y,w,h)
  8.  
  9.   SetColor(oldCol)
  10.   SetAlpha(oldA)
  11. End Function
  12.  
  13. 'overload example
  14. Function DrawColoredRectangle(x:int, y:int, w:int, h:int, c:SColor8)
  15.   DrawColoredRectangle(x,y,w,h, c.r, c.g, c.b, c.a/255.0)
  16. End Function
  17.  
  18.  

Doing so is rather cheap:
- setcolor() and setalpha() are two cheap function calls (the calls itself - and what they actually do, they do not change the render matrix or so)
- the struct can of course also be oldR, oldG, oldB ... it is a "group of properties/fields". - it might just be easier to read


bye
Ron

 

SimplePortal 2.3.6 © 2008-2014, SimplePortal