Gamestudio Links
Zorro Links
Newest Posts
Free Live Data for Zorro with Paper Trading?
by AbrahamR. 05/18/24 13:28
Change chart colours
by 7th_zorro. 05/11/24 09:25
Data from CSV not parsed correctly
by dr_panther. 05/06/24 18:50
AUM Magazine
Latest Screens
The Bible Game
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Who's Online Now
4 registered members (degenerate_762, AbrahamR, AndrewAMD, ozgur), 667 guests, and 8 spiders.
Key: Admin, Global Mod, Mod
Newest Members
Hanky27, firatv, wandaluciaia, Mega_Rod, EternallyCurious
19051 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
Page 1 of 5 1 2 3 4 5
How to make a copy of a bmap? #367476
04/13/11 22:13
04/13/11 22:13
Joined: Aug 2005
Posts: 238
Caermundh Offline OP
Member
Caermundh  Offline OP
Member

Joined: Aug 2005
Posts: 238
I was wondering if its possible or if there is an easy way of creating a copy of a bmap?

What I would like to do is something like:

Code:
BMAP* my_bmap;
BMAP* my_copy;

my_bmap = bmap_create("my_file.jpg");
my_copy = bmap_copy(my_bmap);



I know there is no bmap_copy() command, but the idea is to create a copy of a given bmap - so i would have 2 seperate bmaps that are the same image. Is that possible?

Re: How to make a copy of a bmap? [Re: Caermundh] #367480
04/13/11 22:58
04/13/11 22:58
Joined: Oct 2007
Posts: 5,210
İstanbul, Turkey
Quad Offline
Senior Expert
Quad  Offline
Senior Expert

Joined: Oct 2007
Posts: 5,210
İstanbul, Turkey
what about:
my_bmap = bmap_create("my_file.jpg");
my_copy = bmap_create("my_file.jpg");


3333333333
Re: How to make a copy of a bmap? [Re: Quad] #367481
04/13/11 23:07
04/13/11 23:07
Joined: Apr 2007
Posts: 3,751
Canada
WretchedSid Offline
Expert
WretchedSid  Offline
Expert

Joined: Apr 2007
Posts: 3,751
Canada
This should do the trick
Code:
BMAP *bmap_copy(BMAP *source)
{
  if(!source)
    return NULL; // Oh look, invalid data...
    
  var width, height, format, bitDepth;
  BMAP *result; // The resulting bitmap
  
  
  width  = bmap_width(source); // Get the width
  height = bmap_height(source); // and height of the source bitmap
  
  format = bmap_lock(source, 0); // Lock the source bitmap
  
  // Get the bitdepth of the source
  // Only supported by the pixel functions is 16, 24 and 32 bit, so we don't care about the rest
  switch(format)
  {
    case 88:
    case 565:
      bitDepth = 16;
      break;
      
    case 888:
      bitDepth = 24;
      break;
    
    case 8888:
      bitDepth = 32;
      break;
      
    default:
      bmap_unlock(source);
      return NULL; // Well, the bitmap isn't in a format we can use
      break;
  }
    
  // Create a new, void, bitmap with the exact same size and bit depth
  result = bmap_createblack(width, height, bitDepth);
  if(result)
  {
    int x, y;
    bmap_lock(result, 0); // Lock the new bitmap so that we can write into it
    
    // Copy all pixels by iterating over each source pixel and storing it in the copy
    for(x=0; x<width; x++)
    {
      for(y=0; y<height; y++)
      {
        var pixel = pixel_for_bmap(source, x, y);
        pixel_to_bmap(result, x, y, pixel);
      }
    }
    
    bmap_unlock(result); // Unlock the previously locked copy
  }
  
  bmap_unlock(source); // Unlock the source
  return result; // Return the result, this might be NULL if the bmap_createblack() failed
}



Please remark: The code isn't tested as I don't have Gamestudio, but it should work.


Shitlord by trade and passion. Graphics programmer at Laminar Research.
I write blog posts at feresignum.com
Re: How to make a copy of a bmap? [Re: WretchedSid] #367482
04/13/11 23:13
04/13/11 23:13
Joined: Aug 2005
Posts: 238
Caermundh Offline OP
Member
Caermundh  Offline OP
Member

Joined: Aug 2005
Posts: 238
thanks, JustSid. I was thinking along those same lines, and that should work. The thing is, if im dealing with copying more than a few BMAPs, wouldnt a function like this be kinda slow? espicially if im dealing with large BMAPs?

Re: How to make a copy of a bmap? [Re: Caermundh] #367483
04/13/11 23:15
04/13/11 23:15
Joined: Apr 2007
Posts: 3,751
Canada
WretchedSid Offline
Expert
WretchedSid  Offline
Expert

Joined: Apr 2007
Posts: 3,751
Canada
Uh well, try it? I can't answer this for you.
Just let the function run a few thousand times with a large bmap and look how long it took.


Shitlord by trade and passion. Graphics programmer at Laminar Research.
I write blog posts at feresignum.com
Re: How to make a copy of a bmap? [Re: WretchedSid] #367484
04/13/11 23:23
04/13/11 23:23
Joined: Mar 2006
Posts: 3,538
WA, Australia
J
JibbSmart Offline
Expert
JibbSmart  Offline
Expert
J

Joined: Mar 2006
Posts: 3,538
WA, Australia
If you want it faster, try using bmap_process and a shader that just looks up the right input pixel.

Jibb


Formerly known as JulzMighty.
I made KarBOOM!
Re: How to make a copy of a bmap? [Re: JibbSmart] #367485
04/13/11 23:28
04/13/11 23:28
Joined: Jul 2008
Posts: 1,178
England
M
MrGuest Offline
Serious User
MrGuest  Offline
Serious User
M

Joined: Jul 2008
Posts: 1,178
England
fastest way i can think of
Code:
BMAP *bmap_clone(BMAP* bmp){
	
	if(bmp){
		BMAP* bmpNew = malloc(sizeof(BMAP));
		memcpy(bmpNew, bmp, sizeof(BMAP));
		return(bmpNew);
	}else{
		return(NULL);
	}
}



and to prove it's working, have a bmap called "bmap_to_copy.bmp"
Code:
///////////////////////////////
#include <acknex.h>
#include <default.c>

///////////////////////////////

ENTITY* e1;

BMAP* bmp_original = "bmap_to_copy.bmp";
BMAP* bmp_clone;

PANEL* pnl_original = {
	pos_x = 0;
	flags = SHOW;
}

PANEL* pnl_clone = {
	pos_x = 64;
	flags = SHOW;
}


void bmap_cross(){
	
	BMAP* tgablitz = pnl_original.bmap;
	var format; 
	var pixel;
	format = bmap_lock(tgablitz,0);
	if (format >= 565) {
		pixel = pixel_for_vec(vector(0,0,255),100,format); // red color
		pixel_to_bmap(tgablitz,10,10,pixel);
		pixel_to_bmap(tgablitz,10,11,pixel);
		pixel_to_bmap(tgablitz,10,12,pixel);
		pixel_to_bmap(tgablitz,10,13,pixel);
		pixel_to_bmap(tgablitz,10,14,pixel);
		pixel_to_bmap(tgablitz,8,12,pixel);
		pixel_to_bmap(tgablitz,9,12,pixel);
		pixel_to_bmap(tgablitz,11,12,pixel);
		pixel_to_bmap(tgablitz,12,12,pixel);
	}
	bmap_unlock(tgablitz);
}

BMAP *bmap_clone(BMAP* bmp){
	
	BMAP* bmpNew = malloc(sizeof(BMAP));
	memcpy(bmpNew, bmp, sizeof(BMAP));
	return(bmpNew);
}

void main(){
	
	wait(1);
	
	bmp_clone = bmap_clone(bmp_original);
	
	pnl_original.bmap = bmp_original;
	pnl_clone.bmap = bmp_clone;
	
	bmap_cross();
}




Re: How to make a copy of a bmap? [Re: MrGuest] #367488
04/14/11 01:41
04/14/11 01:41
Joined: Jan 2002
Posts: 4,225
Germany / Essen
Uhrwerk Offline
Expert
Uhrwerk  Offline
Expert

Joined: Jan 2002
Posts: 4,225
Germany / Essen
On the one hand this is a bit of genius. On the other hand I think it's quite a bit dangerous code as it creates an exact copy of the bitmap. In other words there are now two engine objects with the same handle. I don't know if that is a good idea. I'd go with JustSids solution. Maybe change the for loop copying the pixel data to a single call of bmap_blit. Speed isn't that important in this case anyways as you shouldn't create hundreds of bitmap copies.


Always learn from history, to be sure you make the same mistakes again...
Re: How to make a copy of a bmap? [Re: Uhrwerk] #367489
04/14/11 02:01
04/14/11 02:01
Joined: Jun 2004
Posts: 2,234
Wisconsin USA
FoxHound Offline
Expert
FoxHound  Offline
Expert

Joined: Jun 2004
Posts: 2,234
Wisconsin USA
I'm looking at the code and they would not have the same handle just the same texture. I can test this for sure when I get home but this looks good.


---------------------
There is no signature here.


QUIT LOOKING FOR ONE!
Re: How to make a copy of a bmap? [Re: FoxHound] #367490
04/14/11 02:13
04/14/11 02:13
Joined: Jan 2002
Posts: 4,225
Germany / Essen
Uhrwerk Offline
Expert
Uhrwerk  Offline
Expert

Joined: Jan 2002
Posts: 4,225
Germany / Essen
They would have the same handle. Have a look at atypes.h if you don't believe me. They would even share the same pixel data and texture buffer. So if you manipulated one of them the changes would affect all copies created with mem_cpy.


Always learn from history, to be sure you make the same mistakes again...
Page 1 of 5 1 2 3 4 5

Moderated by  HeelX, Lukas, rayp, Rei_Ayanami, Superku, Tobias, TWO, VeT 

Gamestudio download | chip programmers | Zorro platform | shop | Data Protection Policy

oP group Germany GmbH | Birkenstr. 25-27 | 63549 Ronneburg / Germany | info (at) opgroup.de

Powered by UBB.threads™ PHP Forum Software 7.7.1