Click here to Skip to main content
15,900,714 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
QuestionClient server interaction Pin
William Engberts8-Oct-07 22:46
William Engberts8-Oct-07 22:46 
AnswerRe: Client server interaction Pin
jhwurmbach9-Oct-07 1:19
jhwurmbach9-Oct-07 1:19 
QuestionBitmap-Histogram using MFC Pin
go9398-Oct-07 22:45
go9398-Oct-07 22:45 
AnswerRe: Bitmap-Histogram using MFC Pin
Waldermort9-Oct-07 1:13
Waldermort9-Oct-07 1:13 
AnswerRe: Bitmap-Histogram using MFC Pin
jhwurmbach9-Oct-07 1:16
jhwurmbach9-Oct-07 1:16 
GeneralRe: Bitmap-Histogram using MFC Pin
Chris Losinger9-Oct-07 3:13
professionalChris Losinger9-Oct-07 3:13 
GeneralRe: Bitmap-Histogram using MFC Pin
jhwurmbach9-Oct-07 3:51
jhwurmbach9-Oct-07 3:51 
GeneralRe: Bitmap-Histogram using MFC [modified] Pin
Chris Losinger9-Oct-07 4:14
professionalChris Losinger9-Oct-07 4:14 
jhwurmbach wrote:
May or may not.


you're calling how many functions per pixel?

vs. my single macro (which is a couple of bit shifts and logical ORs) and an array index.

jhwurmbach wrote:
You are newing 28MB in one piece here


64MB. but that's really not a big deal. your map will potentially require many times more than that.

you're right that your map will require less memory (though more memory allocations) in cases where images have few colors.

jhwurmbach wrote:
AND you are still limited to 8-bit per color.


true. it's an easy enough problem to fix. and your map will potentially suffer the same memory bloat.


-- modified at 10:34 Tuesday 9th October, 2007

ok... i'm bored, so i did some testing:
typedef std::map< int, int> HistoMapT ;

const int w = 1000;
const int h = 1000;

BYTE *p = = new BYTE[w * h * 3];

// init to a gradient (also ran init'd to 0s)
for (int x=0;x< w;x++)
{
	for (int y=0;y< h;y++)
	{
		p[x * 3 + y * w * 3 + 0] = x % 256;
		p[x * 3 + y * w * 3 + 1] = y % 256;
		p[x * 3 + y * w * 3 + 2] = (x + y) % 256;
	}
}


{
	CTimer c("Map"); // TRACE's time elapsed from construction to destruction
	BYTE * pix = p;
	HistoMapT theMap;

	for (int x=0;x< w;x++)
	{
		for (int y=0;y< h;y++)
		{
			int color_number = RGB(pix[0], pix[1], pix[2]);
			HistoMapT::iterator theIterator = theMap.find(color_number);
			int value = 1;
				
			if (theIterator != theMap.end() ) 
			{
				value += (*theIterator).second;
			}
			theMap.insert(std::pair< int, int>(color_number, value));

			pix+=3;
		}
	}
}

{	
	CTimer c("C");
	BYTE * pix = p;
	int *histo = new int[256 * 256 * 256];
	memset(histo, 0, 256 * 256 * 256 * 4);
	for (int x=0;x< w;x++)
	{
		for (int y=0;y< h;y++)
		{
			histo[RGB(pix[0], pix[1], pix[2])]++;
			pix+=3;
		}
	}

	delete [] histo;
}

delete [] p;


here are the results:

// source image init'd to gradients
Map 2.01s
C 0.16s

// source image init'd to all zero
Map 0.30s
C 0.08s

// changing the source init to
p[x * 3 + y * w * 3 + 0] = x % 256;
p[x * 3 + y * w * 3 + 1] = y % 256;
p[x * 3 + y * w * 3 + 2] = x / 256;

Map 11.25s
C 0.08s

-- modified at 10:42 Tuesday 9th October, 2007


-- modified at 10:54 Tuesday 9th October, 2007



GeneralRe: Bitmap-Histogram using MFC Pin
jhwurmbach9-Oct-07 4:39
jhwurmbach9-Oct-07 4:39 
GeneralRe: Bitmap-Histogram using MFC [modified] Pin
Chris Losinger9-Oct-07 4:44
professionalChris Losinger9-Oct-07 4:44 
GeneralRe: Bitmap-Histogram using MFC Pin
jhwurmbach9-Oct-07 5:21
jhwurmbach9-Oct-07 5:21 
GeneralRe: Bitmap-Histogram using MFC Pin
Chris Losinger9-Oct-07 5:26
professionalChris Losinger9-Oct-07 5:26 
GeneralRe: Bitmap-Histogram using MFC Pin
jhwurmbach9-Oct-07 5:45
jhwurmbach9-Oct-07 5:45 
GeneralRe: Bitmap-Histogram using MFC Pin
Chris Losinger9-Oct-07 5:52
professionalChris Losinger9-Oct-07 5:52 
GeneralRe: Bitmap-Histogram using MFC Pin
jhwurmbach9-Oct-07 5:55
jhwurmbach9-Oct-07 5:55 
GeneralRe: Bitmap-Histogram using MFC Pin
Chris Losinger9-Oct-07 6:09
professionalChris Losinger9-Oct-07 6:09 
QuestionDisable a Menu Option upon right click on a folder Pin
narayanagvs8-Oct-07 22:13
narayanagvs8-Oct-07 22:13 
AnswerRe: Disable a Menu Option upon right click on a folder Pin
chandu0048-Oct-07 22:21
chandu0048-Oct-07 22:21 
AnswerRe: Disable a Menu Option upon right click on a folder Pin
William Engberts8-Oct-07 22:58
William Engberts8-Oct-07 22:58 
GeneralRe: Disable a Menu Option upon right click on a folder Pin
narayanagvs9-Oct-07 1:38
narayanagvs9-Oct-07 1:38 
GeneralRe: Disable a Menu Option upon right click on a folder Pin
narayanagvs9-Oct-07 1:44
narayanagvs9-Oct-07 1:44 
QuestionProblem about Precompiled Header (*.pch) directive Pin
TooShy2Talk8-Oct-07 21:36
TooShy2Talk8-Oct-07 21:36 
AnswerRe: Problem about Precompiled Header (*.pch) directive Pin
Naveen8-Oct-07 21:45
Naveen8-Oct-07 21:45 
GeneralRe: Problem about Precompiled Header (*.pch) directive Pin
TooShy2Talk8-Oct-07 21:58
TooShy2Talk8-Oct-07 21:58 
QuestionHow to update a particular contol? Pin
Sethuraman.K8-Oct-07 21:10
Sethuraman.K8-Oct-07 21:10 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.