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 Professional Discussion / How can I use copy memblock to copy a few images into one combined image ?

Author
Message
dman
21
Years of Service
User Offline
Joined: 21st Feb 2005
Location:
Posted: 18th May 2010 01:17
Trying to make several images into one long image.

I use the get image to grab the images and then make memblock from image and use copy memblock to copy another memblock.

how can I setup the copy memblock to copy?
Green Gandalf
VIP Member
21
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 18th May 2010 01:51
Why not use the bitmap commands and create the image when you have the final bitmap?
dman
21
Years of Service
User Offline
Joined: 21st Feb 2005
Location:
Posted: 18th May 2010 02:07
I can not use bitmap, cause I'm trying to create a long image.
I have a 640 width to work with, thats why I copy each image 640 wide. I need the width of the new image to be 640*30 long.

thats why I want to use copy memblock, to copy the images into one.
HowDo
23
Years of Service
User Offline
Joined: 28th Nov 2002
Location: United Kingdom
Posted: 18th May 2010 02:15
try



Dark Physics makes any hot drink go cold.
Green Gandalf
VIP Member
21
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 18th May 2010 02:40
Quote: "I use the get image to grab the images"


Quote: "I can not use bitmap, cause I'm trying to create a long image."


What do you mean? You are obviously using bitmaps aleady. How else do you use get image?

Just use copy bitmap plus create bitmap and get image when the bitmap is complete.
Neuro Fuzzy
19
Years of Service
User Offline
Joined: 11th Jun 2007
Location:
Posted: 18th May 2010 08:51
It's not too hard to do, I can find some code in a bit (leaving for somewhere in like 5 mines). But... first:

Do you know all about memblock images? Like, the header, the size in bytes of each pixel, etc.? What about how to write or read from a certain pixel?

if the problem is finding the address of a certain pixel, then take this into consideration:
Memblock images are stored like this:
header + first row of pixels + second row of pixels + ... + nth row of pixels

each row of pixels being the width of the image long.

So, an image like this:

///////
//:/://
//___//
///////
would be stored like this:
header+/////////:/:////___/////////

taking that into account, one can derive a formula for the location of any pixel given an x and y value, assuming both x and y are from 0 to image width/height.

index=(y-1)*image_width+x-1
this will give a general index, but to access a memblock, you need this:
index=((y-1)*image_width+x-1)*4+header_size
this will give the index in bytes. Then, you can "get memblock dword" this address, and get the color (or set the color) of that pixel.

Once you have your own equivalent of the dot command, it should be no problem copying an image over, provided you know how to setup the header.


Van B
Moderator
23
Years of Service
User Offline
Joined: 8th Oct 2002
Location: Sunnyvale
Posted: 18th May 2010 09:36
If speed is not too much of a concern, I would do it bit by bit - start with a memblock created for the size you need and convert images to memblocks and transpose the data. Maybe a good idea to start with a memblock point function, that returns the colour at a pixel location on the memblock, then it's a lot easier.

I posted up my width cropper, but I have done something similar recently, maybe I will have time tonight to make a little example, and actually comment it this time!

My concern would be that an image so big might just be a performance drag, I would consider using 30 x 640 wide images myself, then pasting just the images for that scroll position. The graphics pipeline might choke on a 37mb image. I might do some tests on that, see how much of a drain a trully huge image is.


Health, Ammo, and bacon and eggs!
Neuro Fuzzy
19
Years of Service
User Offline
Joined: 11th Jun 2007
Location:
Posted: 18th May 2010 12:14
Here, I have a code snippet:


Errm, it's untested. I had copied it for use in c++ code, lost the code in DBPro, and just copied it back over and edited some stuff, but it should work fine as-is.


I've used this method real-time fine. Here's a video of a map-maker thingy, the ground used this method to change the texture of each tile. Thats a single 400x400 image on the ground.

just tried it now with a 100x100 tile map (20 by 20 pixels per tile), which is a plane being textured by a 2000x2000 image, using this memblock technique (make image from memblock each update), and its working fine! definitely speedy enough.


dman
21
Years of Service
User Offline
Joined: 21st Feb 2005
Location:
Posted: 18th May 2010 15:45 Edited at: 18th May 2010 18:34
I did that Van B but when I start at zero for the index in copy memblcok ex. copy memblock 1,2,0,index,bytes I get an image.

there is no header when I use zero, the image copy just fine.
I use bytes = get memblock size (1)

but when I try to move the index up the memblock, i get a straight line no image. How to calculate the index for each image ?
what if I use bytes*index ?

I'm working a 640x30 width.

here is the code


Van B
Moderator
23
Years of Service
User Offline
Joined: 8th Oct 2002
Location: Sunnyvale
Posted: 18th May 2010 20:53
The problem is that your copying the memblock onto another with a different resolution, it's a single line because your main memblock is so big. There are 19200 pixels along, so if you copy a 640 wide image onto that, those 200 Y coordinates are only going down to 7 or 8 pixels, instead of 200.

It would work if you copied the memblock in chunks of 640 pixels, then offset the position to suit you Y coordinates, copying 640x4 bytes at a time, and offsetting the index by (Y*(640*30))+12


Health, Ammo, and bacon and eggs!
dman
21
Years of Service
User Offline
Joined: 21st Feb 2005
Location:
Posted: 18th May 2010 21:28
I have some what idea of what you talking about, but I still need some code to demonstrate what you mean.

I'm grabbing each 640 screen width times 30 thats the length I need, and copy to the memblock.
Van B
Moderator
23
Years of Service
User Offline
Joined: 8th Oct 2002
Location: Sunnyvale
Posted: 19th May 2010 00:55
Here you go, this is the best DBPro can do with the wide image idea...



Note this line: mainwidth=640*10

That changes the width of the image, it's set to 640*10 because I got a crash at 30 and 20, 10 worked. So there's obviously some issue with images that big - I think you have to use multiple images really, if you need 30 screens wide then personally I'd make 30 seperate screen images.


Health, Ammo, and bacon and eggs!
Latch
20
Years of Service
User Offline
Joined: 23rd Jul 2006
Location:
Posted: 19th May 2010 01:32
@dman
Is there a specific reason why you need to store such a image all at once? I ask because there may be other solutions to whatever you are trying to achieve. For example, you may be able to create a 30 frame AVI file at whatever resolution you need (or less) then run it and grab screens as the images come up. Or perhaps you could read chunks at a time from disk.

What is the goal in having a huge single image?

Enjoy your day.
Neuro Fuzzy
19
Years of Service
User Offline
Joined: 11th Jun 2007
Location:
Posted: 19th May 2010 03:12
Quote: "How to calculate the index for each image"

that's what I just answered :\

I took a brief look over the code... I'd say it's probably copying everything in a single row, and the three header dwords are being included.


dman
21
Years of Service
User Offline
Joined: 21st Feb 2005
Location:
Posted: 19th May 2010 03:18 Edited at: 19th May 2010 03:24
I adopted the code in mine, I get an error memblock position out of range.
I think it has to do with chunk.
What if for the chunk I just use zero, cause I'm just transferring what grabbed, so it do not need to change.
Because it copies good at zero, the problem is the index.
how to get it to update each frame.
dman
21
Years of Service
User Offline
Joined: 21st Feb 2005
Location:
Posted: 19th May 2010 03:33
I was wondering, do i need to update the chunk to store each frame or is it able to just update the copied memblock?

this one got me confused. I even have a book on memblocks.
Van B
Moderator
23
Years of Service
User Offline
Joined: 8th Oct 2002
Location: Sunnyvale
Posted: 19th May 2010 10:08
Chunk is the position in the source memblock, copies 640x4 bytes at a time.

The example works, CHUNK is the position starting at 12, that the source data is located in the source memblock. INDEX is the position that the data is being copied to in the main memblock. BYTECOUNT is the size of the data being copied.

Note that you had missed the image setup - once you've created a memblock, it's just a block of memory, unless you specify the width, height, and depth it won't convert into an image.

I have no idea what you are trying to do with CHUNK, or what you mean by frames. Explain what you actually want to achieve in good detail and we can suggest the best way to get it done, whether thats memblocks or other image pasting techniques.


Health, Ammo, and bacon and eggs!
dman
21
Years of Service
User Offline
Joined: 21st Feb 2005
Location:
Posted: 19th May 2010 15:30
I'm trying to create a scrolling waveform. The reason I need it to be one long image is for speed and able to go backward through the image.

I tried to break it into smaller images like using the image number, change it for each frame when I grab.
but when I do that I have to put them together that takes time and too much work.

if the image can not be 640x30 then I can not use it, unless there is away to grab half 640x15 and then 640x15 and put it together.

thanks
Van B
Moderator
23
Years of Service
User Offline
Joined: 8th Oct 2002
Location: Sunnyvale
Posted: 19th May 2010 15:43
Ahh, so for a sound wave?

Have you tried drawing the wave form directly? - it might be fast enough to just draw the 640 lines, like have a live update of it, depending on where the sound is (maybe calculated with timer()).

Anyhoo, I'm not sure that what your trying to do is possible, there seems to be a definite limit to the size of images in DX. I think you should look at drawing this stuff directly, maybe onto an image with ImageKit, or just try the 2D commands - because that way you'll be able to highlight areas, zoom in, and do whatever you need visually. I don't think that drawing 640 points is too big of an ask for DBPro, worth a shot anyway.

This whole time I was thinking it was some sort of Mario style platformer, with 30 screens of platforms and stuff all the way along. Audio waveforms should really be drawn 'live' I think. If you wanted to make a EQ meter thing, then it might be cool to do that with several images, like an animation that you render with code - the calculation involved in that can be intense, so pre-processing that is a very good idea.


Health, Ammo, and bacon and eggs!
dman
21
Years of Service
User Offline
Joined: 21st Feb 2005
Location:
Posted: 19th May 2010 16:12 Edited at: 19th May 2010 16:14
heres what I did in VB and Blitz3d.

I used the same concept in Blitz3d, its one long waveform but only display half of it.

go see what I mean :http://www.mediaandgames.com/media.html
dman
21
Years of Service
User Offline
Joined: 21st Feb 2005
Location:
Posted: 19th May 2010 16:59 Edited at: 19th May 2010 17:00
I decided to use the frames, I will grab 640 each frame. Then paste each frame accordingly. I just have to figure out how to have two at the same time one in front of the other and the other way around, when updating the positions. have one instance with separate properties for x. using only one paste command.

Mage
Valued Member
19
Years of Service
User Offline
Joined: 3rd Feb 2007
Location:
Posted: 20th May 2010 04:08
Are you trying to layer one image on top of another and merge them?

If so I solved this problem here:
http://forum.thegamecreators.com/?m=forum_view&t=107662&b=1


This code is a bit old but still should work. MergeImage will be layered on top of MyImage just like photoshop, with proper transparancy. Width is for MyImage and that can be changed easily. With this current version i think MergeImage has to be same size or smaller than MyImage. The code will merge the images and stretch MergeImage to same proportions as MyImage.

I made this a long while ago since i wanted characters that could wear many different clothes and have different skin tones/textures. This merge process cuts down on needed texture files immensely.

Login to post a reply

Server time is: 2026-07-25 16:18:58
Your offset time is: 2026-07-25 16:18:58