Image manipulations

Just starting out? Need help? Post your questions and find answers here.
epog10
User
User
Posts: 90
Joined: Sat May 29, 2010 11:46 am
Location: UK

Image manipulations

Post by epog10 »

I would like to play about with manipulating photographs.
Appreciate that I want to 'play about' rather than import a ready-made library of image routines.

In order to do this (perhaps initially limited to loss-less formats such as .bmp and .png), I need to know how an image that is captured in memory is organised so that I can interact directly with the RGB bytes. Perhaps someone can tell me or point me to such information pertaining to Purebasic.

The other thing is that I am an irregular user of Purebasic. If somebody can indicate an appropriate skeletal to: show image - trap image - dispaly image routine, this would probably save me a lot of time.

Many thanks.
User avatar
Derren
Enthusiast
Enthusiast
Posts: 313
Joined: Sat Jul 23, 2011 1:13 am
Location: Germany

Re: Image manipulations

Post by Derren »

https://en.wikipedia.org/wiki/BMP_file_format

How BMP is organized in the memory.

A similar page can probably be found for PNG, or perhaps, it just gets uncompressed and is handled like a 32 bit bitmap internally? I don't know.

Independent of the image format, you can use the Drawing functions Point() and Plot(). But it's slower, apparently.
epog10
User
User
Posts: 90
Joined: Sat May 29, 2010 11:46 am
Location: UK

Re: Image manipulations

Post by epog10 »

Sorry for the delay but I have been away for a few days.

I don't think I made my needs clear. It is not the file format for images that I seek which, as pointed out, exist variously online.

In order to poke/peek the image data what I need to know is how Purebasic saves the image in active memory - say a buffer.

Presumably the UseXXXXImageDecoder plugins do take care of interpreting the external image format for loading into a buffer. This will surely be a standardised way, regardless of source format, that the ImageGadget can then display from the ImageID() buffer.

It is the ImageID buffer format that is of interest because it would be this that will be manipulated.
Is it simply RGB or BGR? Or four bytes per pixel? Size references? Etc. etc..

Come to think about it, my original quote mentions BMP and PNG. This is of course irrelevant because the UseXXXXImageDecoder where required would take care of buffering to a consistent format.

Regards
User avatar
Danilo
Addict
Addict
Posts: 3037
Joined: Sat Apr 26, 2003 8:26 am
Location: Planet Earth

Re: Image manipulations

Post by Danilo »

When you start drawing to an ImageOutput(#Image) you can use DrawingBuffer() to get a pointer to the image data.
You get informations about the buffer format using DrawingBufferPixelFormat() and DrawingBufferPitch().
epog10
User
User
Posts: 90
Joined: Sat May 29, 2010 11:46 am
Location: UK

Re: Image manipulations

Post by epog10 »

Thank you very much for your information.

It looks as if it is the answer i was looking for.

I shall this weekend create a small skeletal program that will allow me to examine the functions you suggested.

Regards,
epog10
epog10
User
User
Posts: 90
Joined: Sat May 29, 2010 11:46 am
Location: UK

Re: Image manipulations

Post by epog10 »

Well it has been a fun weekend and I am now confident I can handle byte operations within images.

The one thing I quickly discovered is that all images seem to be in reverse row order.
Presumably the UseXXXImageDecoder() decodes in a format suitable for the Purebasic image box but it does make the need for "#PB_PixelFormat_ReversedY" somewhat incomprehensible if all images end up reversed in memory.

The other thing I think I have found has to do with For/Next loops.

Having identified the image pixel string I set (amongst other things):-
L to the picture size,

Z = 3 for 24 bit
or
Z = 4 for 32 bits


For X = 1 to L Step Z
...... do something ......
Next X

does not work. It comes up with the error:-
An integer numeric constant is expected after 'Step'

Assuming I am not doing something wrong, should this be reported as an error or desirable feature?

regards,
epog10
infratec
Always Here
Always Here
Posts: 6883
Joined: Sun Sep 07, 2008 12:45 pm
Location: Germany

Re: Image manipulations

Post by infratec »

Since Z is not a constant (it's a variable) and the Step argument requires a constant: no bug

You can place it in feature request section.

As alternative you can use a repeat loop.

Like:

Code: Select all

X = 1
Repeat
  ...... do something ......
  X + Z
Until X >= L
Post Reply