Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

DarkBASIC Discussion / quick negative function?

Author
Message
That1Smart Guy
16
Years of Service
User Offline
Joined: 26th Feb 2009
Location: Somewhere...... yep
Posted: 28th Mar 2009 02:04
is there anyway to make one?\

i got one to work, but notice how fast it works

Libervurto
19
Years of Service
User Offline
Joined: 30th Jun 2006
Location: On Toast
Posted: 28th Mar 2009 02:12
try copying over to an offscreen bitmap (you have to create one) and doing the function there, db is always faster working on offscreen bitmaps
another thing; you only need to use the point command once, store it in a variable before the rgbr (etc) stuff and use the variable in them instead, will saves whole bags of time!

The Universe has been erased by a mod because it was larger
than 240x80 pixels.
That1Smart Guy
16
Years of Service
User Offline
Joined: 26th Feb 2009
Location: Somewhere...... yep
Posted: 28th Mar 2009 02:34 Edited at: 28th Mar 2009 02:42
so like this?

BN2 Productions
21
Years of Service
User Offline
Joined: 22nd Jan 2004
Location:
Posted: 28th Mar 2009 08:24
Not exactly sure if it will work, but what you could do is just use a memblock and go pixel for pixel and set the color to 65535 minus the color.

Just a guess, but I have no idea how it will compare.

Great Quote:
"Time...LINE??? Time isn't made out of lines...it is made out of circles. That is why clocks are round!" -Caboose
That1Smart Guy
16
Years of Service
User Offline
Joined: 26th Feb 2009
Location: Somewhere...... yep
Posted: 28th Mar 2009 18:21
im not familiar with memblocks, mind giving me a crash course?
BN2 Productions
21
Years of Service
User Offline
Joined: 22nd Jan 2004
Location:
Posted: 28th Mar 2009 20:39
Well for images I can try, though I am far from the best person to ask.

Memblocks are BLOCKS stored in MEMory that can be referenced quickly.

Using the command MAKE MEMBLOCK FROM IMAGE, you can do just that, load an image into memory for editing on its most basic level.

There are 4 types of data to be read/written from/to a memblock:

BYTE-1 byte
WORD-2 bytes
DWORD-4 bytes
FLOAT-4 bytes

A byte will be a number between 0 and 255
Words will be between 0 and 65535
DWords will be between 0 and 2147483648
Floats will be between -2147483648 and 2147483648

When an image resolution is 16 bit, each pixel will be 2 bytes. For 32 (which I have had more luck making work) it uses 4 bytes (DWORD).

For the rest of this, I will assume we are working in 32 bit depth, since it works a little nicer.

There are 4 bytes to every pixel:
Byte 1: Red Color Value
Byte 2: Green Color Value
Byte 3: Blue Color Value
Byte 4: Alpha value (don't worry about it)

To figure out where each pixel is in the memblock, you use this conversion:

Position=HeaderSize+BytesPerPixel*PixelNumber

and

PixelNumber=Y*Width+X

The header to an image is broken down like:

Bytes 0-3 (4 bytes-DWORD): Width
Bytes 4-7 (4 bytes-DWORD): Height
Bytes 8-11 (4 bytes-DWORD): Depth

So, the header size will be 12 (4+4+4)

In a 32 bit picture, the equation to figure out the position number of a pixel will be:

Position=12+4*(Y*Width+X)

So, now we know where everything is stored, but how do we get to it. We use the Position number and the following commands:

MEMBLOCK BYTE
MEMBLOCK WORD
MEMBLOCK DWORD
MEMBLOCK FLOAT

Amazing stuff huh? Each command requires 2 arguments in this fashion:

MEMBLOCK DWORD(Memblock Number,Position)

So if you read the color value from the pixel, you can get the color values and do what you need to with them.

Again, I am not the GREATEST with memblocks, but I have used them here and there.

Let me know if I can clear anything up.

Great Quote:
"Time...LINE??? Time isn't made out of lines...it is made out of circles. That is why clocks are round!" -Caboose
That1Smart Guy
16
Years of Service
User Offline
Joined: 26th Feb 2009
Location: Somewhere...... yep
Posted: 28th Mar 2009 20:57 Edited at: 28th Mar 2009 20:59
wat r y and x?

[edit] o nvm

[edit 2]
is there a make memblock from bitmap command to, and does it work the same way?
BN2 Productions
21
Years of Service
User Offline
Joined: 22nd Jan 2004
Location:
Posted: 28th Mar 2009 21:05
It looks like yes and yes. Or you could use the GET IMAGE command.

Great Quote:
"Time...LINE??? Time isn't made out of lines...it is made out of circles. That is why clocks are round!" -Caboose
That1Smart Guy
16
Years of Service
User Offline
Joined: 26th Feb 2009
Location: Somewhere...... yep
Posted: 28th Mar 2009 21:16
but thats one unnecessary (pretty sure i misspelled that) command that wont improve the program at all
BN2 Productions
21
Years of Service
User Offline
Joined: 22nd Jan 2004
Location:
Posted: 28th Mar 2009 21:38
except freeing a bitmap

Great Quote:
"Time...LINE??? Time isn't made out of lines...it is made out of circles. That is why clocks are round!" -Caboose
Caleb1994
16
Years of Service
User Offline
Joined: 10th Oct 2008
Location: The Internet you idiot!
Posted: 29th Mar 2009 03:04
the number of bytes per pixel is just depth/8(16 = 2, 32 = 4)

just saying. other then that great example bn2

New Site! Check it out \/
BN2 Productions
21
Years of Service
User Offline
Joined: 22nd Jan 2004
Location:
Posted: 30th Mar 2009 01:54
My problem is usually in the 16 bit format, I always get the wrong color value.

Great Quote:
"Time...LINE??? Time isn't made out of lines...it is made out of circles. That is why clocks are round!" -Caboose
Benjamin
22
Years of Service
User Offline
Joined: 24th Nov 2002
Location: France
Posted: 30th Mar 2009 03:14 Edited at: 30th Mar 2009 04:32
When inverting colours of an image you don't need to separate the channels and recombine them, it's simply a matter of flipping every single bit in the image. With DBPro you can simply NOT each byte, but as DBC doesn't have this you can instead just do 255 - pixel_value, like so:



Works regardless of the bit depth.

That1Smart Guy
16
Years of Service
User Offline
Joined: 26th Feb 2009
Location: Somewhere...... yep
Posted: 30th Mar 2009 03:20
nice benj, but i think u need to use imgnum more in the function to make it more compatible in a larger program, u have image 1 used more than it should
Benjamin
22
Years of Service
User Offline
Joined: 24th Nov 2002
Location: France
Posted: 30th Mar 2009 04:32
Oops, I forgot to actually incorporate that when I made the function. Either way, it is just an example.

Login to post a reply

Server time is: 2025-08-08 20:42:25
Your offset time is: 2025-08-08 20:42:25