Speed of simple add operation

Become a member of the CGSociety

Connect, Share, and Learn with our Large Growing CG Art Community. It's Free!

THREAD CLOSED
 
Thread Tools Display Modes
  08 August 2006
Speed of simple add operation

Hi,

Newbie here. Can somebody post how long it takes to composite two 4096 x 2048 bmp images together? Comp operation is simple add. I've written simple command line compositing app. Well.. It does just add right now, but I guess it can be called that way. My current time is 55 s on Athlon xp 2000+ with 768 MB RAM. That is slow, right?
 
  08 August 2006
You could check your results against the ImageMagick library, which is open source. I think you can use mogrify to composite, among others.
__________________

 
  08 August 2006
yes it is... Ps can do it in nearly realtime....
what language do you use?
 
  08 August 2006
Haven't tried ImageMagick yet..

But yeah. 55 s was really slow. I don't exactly remember my current times after few code changes, but it was about 11 s, which isn't fastest, but it's faster then before.
I use c++. Right now I am trying to add some script/flow like file support.
 
  08 August 2006
The quickest thing available for comping images together is the GPU and some blending operations (you might need to split the images up and do it there). Whilst normally sending that amount of data about isn't generally recommended, the benenifts of using the GPU should outweight the (comparitivly) small cost of sending and reading back the data.

/edit

btw, this sounds like a very slow thing imo. You are accessing raw data pointers i assume? ie, not doing something silly like :

setOutPixel( getInPixel1() + getInPixel2() );

Function call overhead of that sort would kill performance (and i assume you are building in release mode with optimisations turned on).

I assume you are using some sort of direct access to the pixels anyway, ie walking over the raw data with pointers rather than using some sort of (i*height + j) indexing to the pixels?


unsigned bytes_per_pixel=3; // rgb

unsigned char* pImage1 = someImageData;
 unsigned char* pImage2 = someOtherImageData;
 unsigned char* pOut = someOutputImage;
 unsigned char* pEndImage1 = pImage1 + img_w* img_h * bytes_per_pixel;

for( ; pImage1 != pEndImage1; )
{
	*pOut = *pImage1 + *pImage2;
	++pOut; ++pImage1; ++pImage2;
}

Last edited by Robert Bateman : 08 August 2006 at 02:51 PM.
 
  08 August 2006
GPU maybe later. As I said before I'm a newbie, I started learning c++ 2 months ago so yes, I'm probably making something that silly or maybe something even more silly. Right now it is loading whole image to image class. It does that through two loops, reads value through (ifstream) read function and stores pixels in two dimensional array, then add those two images together and write it to disk. Pixel values are floats. That bad?

edit: 3.5 s just thanks to the reading whole line of image instead of reading image by single char..

Last edited by T-bat : 08 August 2006 at 03:40 PM.
 
  08 August 2006
it's quicker to read the whole image in one go (I prefer the old C-style File IO for binary files - should be able to do something similar with streams though). Typically image files are stored as unsigned char's, however floating point formats are probably more useful for compositing (you'll get much better results, though it may be slightly slower).

This will load any file in one go, it's then a case of casting the data to your image file data and off you go.... (not sure what format you are using)



// load the whole file in one go....
unsigned char* imageData=0;
FILE* fp = fopen("image.whatever","rb");
if(fp)
{
   fseek(fp,0,SEEK_END);
   size_t pos = ftell(fp);
   rewind(fp);
   imageData = new unsigned char[pos];
   fread(imageData,0,pos,fp);
   fclose(fp);
}

//------------------------------------ define the image file format

// don't optimise memory layout !
#pragma pack(push,1)

struct PixelFormat {
   float r;
    float g;
    float b;
    float a;
};

struct SomeImageHeader
{
   unsigned int width;
    unsigned int height;
   PixelFormat pixels[1]; // << dirty hack to access pixel data
private:
   // dont instance me!
   SomeImageHeader() {}
};

// return to compiler defaults
#pragma pack(pop)




SomeImageHeader* asImage = (SomeImageHeader*)((void*)imageData);

// do something with image data


// when done, don't forget to delete the data...
delete [] imageData;
 
 
  09 September 2006
Thanks Robert Bateman.

It's quicker to read image in one go, but I have had some problems with it. Not sure if it's my mistake or limitation but when I try to read bigger images (not sure.. somewhere around 450 * 450) program crashes. Could it be char array limitation?

edit: Nevermind. Found solution.

Last edited by T-bat : 09 September 2006 at 05:51 PM.
 
  09 September 2006
Thread automatically closed

This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.
__________________
CGTalk Policy/Legalities
Note that as CGTalk Members, you agree to the terms and conditions of using this website.
 
Thread Closed share thread



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
CGSociety
Society of Digital Artists
www.cgsociety.org

Powered by vBulletin
Copyright 2000 - 2006,
Jelsoft Enterprises Ltd.
Minimize Ads
Forum Jump
Miscellaneous

All times are GMT. The time now is 01:29 PM.


Powered by vBulletin
Copyright ©2000 - 2018, Jelsoft Enterprises Ltd.