What are the image creation flags?

BlitzMax Forums/BlitzMax Programming/What are the image creation flags?

I'd like to create a dynamic image of format PF_BGR888
Nothing in the docs :)

You seem to be mixing images with pixmaps.
If you want to create a pixmap with format PF_BGR888 then
either use createpixmap or convertpixmap.
All pixmaps are 'dynamic' in that you can change them at a pixel level.
To then load this pixmap into an image use
loadimage(mypixmap,DYNAMICIMAGE) or the other flags documented under Loadimage.

I want to dynamically update an image through lock, but I can't seem to create it in the correct format. I'll see if loadimage are fast enough.

The following per frame update code, gives me a crash (and looks plain ugly)
Why can't I just create a dynamic image of the correct format, lock it and update it's pixmap?

		MemCopy(PixmapPixelPtr(tempPixMap),Frame,width*Height*3)	
		
		' Gotta flip it. Damn GDI
		tempPixMap = YFlipPixmap(tempPixMap)	
		
		' Draw it
		tempImage = LoadImage(tempPixMap, DYNAMICIMAGE)
		DrawImage(tempImage, x, y)


Graphics 640,480
image:TImage=LoadImage("max.png")
mypix:TPixmap=LockImage(image)
Print PixmapFormat(mypix)
mypix=ConvertPixmap(mypix,PF_BGR888)
Print PixmapFormat(mypix)
image=LoadImage(mypix)
DrawImage image,0,0
Flip
WaitKey()


I know, but my pixmap does not exist. It get's dynamically updated each frame.
I need scaling you see, and resizepixmap is just too damn slow for realtime updates :)

From your original post...

I'd like to create a dynamic image of format PF_BGR888



Where did you mention scaling?
Anyway, now the pixmap is in an image you can use SetScale.
P.S. Why are you dynamically converting the pixmap pixelformat each frame?

What is a pixmap?

What is a pixmap?
You are in the wrong forum! Beginners is next door ;-p only kidding. Type in TPixmap into the IDE and press F1 twice on it.

An area of storage which describe the pixels of an image.
From the doc...
Pixmaps
Pixmaps provide storage for rectangular regions of pixels.

You can create a new pixmap using the CreatePixmap command, or load a pixmap from a stream using LoadPixmap.

Pixmaps have 5 properties: width, height, a byte pointer to the pixmap's pixels, pitch and format.

You can retrieve a pointer to a pixmap's pixels using the PixmapPixelPtr command.

A pixmap's pitch refers to the number of bytes between one row of pixels in the pixmap and the next. To retrieve a pixmap's pitch, use the PixmapPitch command.

A pixmap's pixel format determines how the pixels within a pixmap are stored in memory. This must be taken into account if you want to access pixels directly via a pixmap's pixel pointer. You can retrieve the format of a pixmap using the PixmapFormat command, and convert pixmap's from one format to another using ConvertPixmap.

You can also resize a pixmap, flip a pixmap horizontally or vertically and more. 


Everything in Bmax is loaded as a pixmap (even images).
When you drawimage for the first time the pixmap information is used to create a textured surface. This and subsequent drawimages blit that surface to the backbuffer.

I know all of this :)
I need to create an image dynamically and lock and update it each frame. It's really quite simple and works with pixmap atm.
I just need scaling, and calling resizepixmap each frame is too slow. Anyone?

Ok, do you want to create a different image or the same image each frame?
You want to lock it to obtain a pixmap which *has* to be in
PF_BGR888 format... right? How is the format relevant?
How is the pixmap to be updated?
You mention you "just need scaling" but insist it has to be resizepixmap. What is the reason behind using resizepixmap? How come setscale can not be used?

Ok. One more time :)

I want a TImage so I can scale it using the underlying hardware.
What I have now is a pixmap solution which works fine.
However, I can't scale it and ResizePixmap is too damn slow.
So to reiterate. I can't use ResizePixmap.
The format must be BGR888, since the main datasource is the windows GDI.
So I need to create a TImage once, and then lock an memcopy to it's internal pointer each frame. Unlock, scale and draw it.
Using LoadImage on the pixmap, does not work and seems quite complicated since I just need to lock it each frame.

Hope it's a bit clearer for everybody now :)

You must be Mr McVague.
So I need to create a TImage once

Why? Why not skip that step and create a pixmap in the format you want and a placeholder for the image...
graphics 640,480
local mypix:TPixmap=createpixmap(200,200,PF_BGR888)
local image:TImage

or do you mean you load an image?
Start your loop and do your memcopy (or whatever) it is you need to do...
while not keyhit(key_escape)
  cls
  'memcopy stuff

then load you pixmap into an image. Not sure why you think that bit is complicated as it's simply...
  image=loadimage(pix)

Now scale your image and draw it...
  setscale 2.0,2.0
  drawimage image,0,0
  flip
wend


Anyway, this *might* be what you're after but who knows...
Graphics 640,480
SeedRnd MilliSecs()
' load an image. If it's not a specific image then just use...
' Pix=createpixmap(width,height,format)
' that means you can miss the convert step
image:Timage=LoadImage("max.png")
pix:TPixmap=LockImage(image)
pix=ConvertPixmap(pix,PF_BGR888)
While Not KeyHit(key_escape)
   Cls
' This is a substitution for your memcopy bit.
   For x = 1 To 30
     WritePixel(pix,Rand(0,pix.width-1),Rand(0,pix.height-1),-65536)
   Next
'load the pixmap into an image (not hard)
   image=LoadImage(pix)
' change the drawscale
   SetScale 2.0,2.0
' draw the image
   DrawImage image,0,0
   Flip
Wend


I perfectly understand the above, I just get a crash when trying to load my pixmap.
I'll look some more into it I guess :)

Thanks for your help

I just get a crash when trying to load my pixmap.

How are you loading your pixmap?
How was the pixmap created?
What error do you get in the crash?
What code can you supply (with any required images) to show the 'crash' problem?

This is what I do.
If I just draw the pixmap all is fine, but if I load to image like below, the MemCopy crashes without any explanation. (Except the generic access violation)
It seems like my pixmap becomes invalid some how.
Note that this memcopy is performed 60 times/sec so things are happening pretty fast.
I might just switch to OpenGL textures directly as this works without problems.
Unfortunately I can't make a small test case ATM.


MemCopy(PixmapPixelPtr(tempPixMap),Frame,width*Height*3)	
		
		' Gotta flip it. Damn GDI
		tempPixMap = YFlipPixmap(tempPixMap)	
		
		' Draw it
		tempImage = LoadImage(tempPixMap, DYNAMICIMAGE)
		DrawImage(tempImage, x, y)


What is 'Frame'? What are width/height set to?
My guess is '3' is some sort of pixmap.pitch but can't be sure so... why *3?
My guess would be your memcopying too much data to the pixmap. OK when you draw a pixmap but fails when trying to blit to a surface.
BTW, you are declaring all these as TPixmap, TImage etc... aren't you?

Yep the declarations are fine, but you're probably right on the pitch issue. I'll look into that and get back to you :)