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.

Dark GDK / Direct pixel access in images? (Without MAKE MEMBLOCK or dbMakeMemblock)

Author
Message
Paisleys finest
19
Years of Service
User Offline
Joined: 11th Nov 2005
Location: In a house
Posted: 18th Jan 2008 17:22
Hi, I was wondering if there was a way of directly accessing the pixels of an image WITHOUT Make Memblock (or its C# API equivalent)

If so, how? Code please

Regards, Scott T.

Looking for mature software developer to finish my Bruce Lee remake.. apply via email to MSN address.
Pharoseer
17
Years of Service
User Offline
Joined: 21st Feb 2007
Location: Right behind you
Posted: 18th Jan 2008 21:31
Hey PF,

As far as I know you can't get direct access to the pixels of an IMAGE without using memblocks. However, if you instead load the resource as a BITMAP you can treat the bitmap as if you were drawing to the screen, then update an image based on your workspace bitmap. It can be kinda slow, but it works.

Here's a quick example that updates an image based on changes to a workspace bitmap:



Hope this helps!
-Frank
Paisleys finest
19
Years of Service
User Offline
Joined: 11th Nov 2005
Location: In a house
Posted: 19th Jan 2008 12:28
Thanks Frank, but that method looks a wee bit slow because of the API calls instead of direct memory access via pointers.

I guess I'll have to stick with memblocks for the moment.

Cheers,
Scott.

Regards, Scott T.

Looking for mature software developer to finish my Bruce Lee remake.. apply via email to MSN address.
Sephnroth
22
Years of Service
User Offline
Joined: 10th Oct 2002
Location: United Kingdom
Posted: 19th Jan 2008 15:51
give me a few minutes and i'll upload two extensions i've written. Both give access to writing to images and provide functions for drawing lines, circles, etc.

The first one I used for Iro1 and is a software library for directly drawing to the image surface through directx.

The second one I wrote recently for the Iro2 project and it uses directx to draw to surfaces using hardware and is a hell of alot faster. It also supports batching so you can startbatch->drawlots of lines->endbatch which is even faster still!

Lets me go dig them out.

Sephnroth
22
Years of Service
User Offline
Joined: 10th Oct 2002
Location: United Kingdom
Posted: 19th Jan 2008 16:00 Edited at: 19th Jan 2008 16:03
Quick Edit: Forgot to say that you must call SetupExtendedImage_GPU() somewhere during program intialisation so it gets the directx device properly.

Original Post:

Okay, these may not be finished and i've not tidied them up at all - improvements can probably be made! Provided AS-IS, no gurantees

First the newer, faster system. Copy code into relevent files:

ExtendedImageGPU.cpp:



ExtendedImageGPU.h:



and here is some code I quickly lifted from Iro2 for an example of usage - it may look a bit weird but try and ignore all the calculations and see the actual drawing bit because thats all you care about. It Clears an image, calls StartNew2dImageLineBatch(), draws several lines and then draws them all to the image by calling Draw2dImageBatch_GPU(imageid);

This is the only example I have im afraid:



Now, just for the curious, the original extended image functions that did everything by hand:

ExtendedImage.cpp:



ExtendedImage.h:



Used in much the same way as the other one, but a bit redundant because the new one i made is so much faster. Still, interesting to look at. At least I think so xD

Morcilla
21
Years of Service
User Offline
Joined: 1st Dec 2002
Location: Spain
Posted: 19th Jan 2008 17:39
Hey Sephnroth, needless to say that your functions are great.
Do you have handy those batch functions but the ones for dots?
That would be great, as I'm still using the 'old' version. Thanks in advance.
Paisleys finest
19
Years of Service
User Offline
Joined: 11th Nov 2005
Location: In a house
Posted: 21st Jan 2008 00:28
Not quite what I was after

I was looking to modify pixel by pixel, not draw lines etc

Basically iterate through the pixels to say IF this colour THEN change to other colour.

Are images in DarkGDK stored as surfaces??

Because if so, then that makes things a lot easier!

Cheers,
Scott

Regards, Scott T.

Looking for mature software developer to finish my Bruce Lee remake.. apply via email to MSN address.
Sephnroth
22
Years of Service
User Offline
Joined: 10th Oct 2002
Location: United Kingdom
Posted: 22nd Jan 2008 23:28
i havnt tried it, but cant you draw dots (pixels) just by using the line batching functions and making the lines 1pixel long? or possiably by making the start and end the same coordinates?

let me know if that doesnt work morcilla and i'll try and write some proper dot commands as soon as i free some time up (really busy with work all hours of the day atm!).

paisley: I havnt written a get pixel function, though it would be very easy to do in the software library. not sure about the hardware one because i've never come across a function to do that, but dx must be able to fetch a value from a surface (?). But you can take the PutImagePixel() function and reverse it so where it sets the pixel colour value it returns it instead and then you can use the normal PutImagePixel() function to draw them. Software though and quite slow.

have a play and again i'll see what i can do if i find any free time.

Morcilla
21
Years of Service
User Offline
Joined: 1st Dec 2002
Location: Spain
Posted: 25th Jan 2008 09:57
Ok then, I'll give that a try. It should work, I wonder if that would be faster than your old dot function. So many things to test and so little time.
Thanks again Sephnroth.
Sephnroth
22
Years of Service
User Offline
Joined: 10th Oct 2002
Location: United Kingdom
Posted: 25th Jan 2008 15:59
it should without a doubt be hugely faster than the original putpixel function that locked a surface and wrote to the memory for every single dot you made. my only concern is wether or not the line drawing will draw a "perfect" dot or if it will blend/antialias into surrounding pixels. let me know

Codger
21
Years of Service
User Offline
Joined: 23rd Nov 2002
Location:
Posted: 26th Jan 2008 02:24
Paisleys finest

Quote: "Hi, I was wondering if there was a way of directly accessing the pixels of an image WITHOUT Make Memblock (or its C# API equivalent)

If so, how? Code please "


What would be a reason to do so?
Images on the screen of 3D objects have been manipulated by the graphics card to adjust for rotation, position shadows etc. Even if you changed it for one frame it would revert back the next. Modifying images on the fly using memblocks is very straightforward once you learn the syntax

Just curious

Codger

System
PIV 2.8 MZ 512 Mem
FX 5600 256 mem
Paisleys finest
19
Years of Service
User Offline
Joined: 11th Nov 2005
Location: In a house
Posted: 26th Jan 2008 21:38
Codger, I know how to modify images in memblocks. I'm doing it already.

I am implementing colour cycling and I need pixel-by-pixel access.
Memblocks seem a half-assed approach, there must be better way of changing pixels but I can't find it - YET.

Here's why I need colour cycling (this is my work in progress) :

http://uk.youtube.com/watch?v=4LGTbi_fs0M

I always try to optimise my code and use best practices.

Regards, Scott T.

Looking for mature software developer to finish my Bruce Lee remake.. apply via email to MSN address.
Law
16
Years of Service
User Offline
Joined: 15th Feb 2008
Location:
Posted: 15th Feb 2008 18:49 Edited at: 15th Feb 2008 21:05
Woops didn't notice the approval delay. Ignore/delete this.
Law
16
Years of Service
User Offline
Joined: 15th Feb 2008
Location:
Posted: 15th Feb 2008 21:02
Quote: "
Hi, I was wondering if there was a way of directly accessing the pixels of an image WITHOUT Make Memblock (or its C# API equivalent)

If so, how? Code please
"


Hi! I just made something you may be interested in. It may not be the prettiest (yet?), but it's my first successfull attempt at changing image pixels without memblocks. I haven't tested it's speed yet, but I'm hoping dbSetImageData()/dbGetImageData() are fairly speedy.

As usual, I'd love to know about better/faster methods - so let me know if you have something.

Here's what I made:

Login to post a reply

Server time is: 2024-11-20 01:44:40
Your offset time is: 2024-11-20 01:44:40