Click here to Skip to main content
15,913,773 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: how to calculate all columns amount? Pin
gentleguy25-Jun-08 23:46
gentleguy25-Jun-08 23:46 
GeneralRe: how to calculate all columns amount? Pin
gentleguy25-Jun-08 23:55
gentleguy25-Jun-08 23:55 
GeneralRe: how to calculate all columns amount? Pin
Saurabh.Garg26-Jun-08 0:05
Saurabh.Garg26-Jun-08 0:05 
GeneralRe: how to calculate all columns amount? [modified] Pin
gentleguy28-Jun-08 1:06
gentleguy28-Jun-08 1:06 
GeneralRe: how to calculate all columns amount? Pin
gentleguy28-Jun-08 23:02
gentleguy28-Jun-08 23:02 
AnswerRe: how to calculate all columns amount? Pin
Iain Clarke, Warrior Programmer25-Jun-08 23:44
Iain Clarke, Warrior Programmer25-Jun-08 23:44 
GeneralRe: how to calculate all columns amount? Pin
gentleguy25-Jun-08 23:51
gentleguy25-Jun-08 23:51 
GeneralRe: how to calculate all columns amount? Pin
Iain Clarke, Warrior Programmer26-Jun-08 0:17
Iain Clarke, Warrior Programmer26-Jun-08 0:17 
So, you have a block of bytes, and you know it is W wide, and H high.

First - images often have the width padded by 4. Check whether this is the case or not.

void Count255s (BYTE *blob, UINT W, UINT H)
{
   UINT nColumnCounts [W]; // W columns...
   UINT x,y;

   // clear counts.
   for (x = 0; x < W; x++)  nColumnCounts [x] = 0;

   for (y = 0; y < H; y++)
   {
       for (x = 0; x < W; x++)
       {
           if (blob [x + y*W] == 255)
                nColumnCounts [x] += 1;
       }
    }

    // now we have counts!
    DoSomethingwithCounts (W, nColumnCounts);
}


There's no error checking, and there are more efficient ways of doing this, but this should be fairly clear for you, I hope.

You could replace the check with:
if (*blob++ == 255)

to remove the expensive multiplication, but I'd avoid that unless you are very happy with pointers.

Did that help at all?

Iain.

Plz sir... CPallini CPallini abuz drugz, plz plz help urgent.

GeneralRe: how to calculate all columns amount? [modified] Pin
gentleguy26-Jun-08 1:28
gentleguy26-Jun-08 1:28 
GeneralRe: how to calculate all columns amount? Pin
Iain Clarke, Warrior Programmer26-Jun-08 2:23
Iain Clarke, Warrior Programmer26-Jun-08 2:23 
GeneralRe: how to calculate all columns amount? Pin
gentleguy26-Jun-08 15:23
gentleguy26-Jun-08 15:23 
GeneralRe: how to calculate all columns amount? Pin
Iain Clarke, Warrior Programmer26-Jun-08 21:46
Iain Clarke, Warrior Programmer26-Jun-08 21:46 
AnswerRe: how to calculate all columns amount? Pin
Hamid_RT27-Jun-08 8:13
Hamid_RT27-Jun-08 8:13 
GeneralRe: how to calculate all columns amount? Pin
gentleguy28-Jun-08 1:07
gentleguy28-Jun-08 1:07 
QuestionSort by Date Pin
manju#12325-Jun-08 23:05
manju#12325-Jun-08 23:05 
AnswerRe: Sort by Date Pin
Rajesh R Subramanian25-Jun-08 23:09
professionalRajesh R Subramanian25-Jun-08 23:09 
GeneralRe: Sort by Date Pin
manju#12325-Jun-08 23:24
manju#12325-Jun-08 23:24 
GeneralRe: Sort by Date Pin
Rajesh R Subramanian25-Jun-08 23:40
professionalRajesh R Subramanian25-Jun-08 23:40 
GeneralRe: Sort by Date Pin
manju#12325-Jun-08 23:44
manju#12325-Jun-08 23:44 
GeneralRe: Sort by Date Pin
manju#12325-Jun-08 23:45
manju#12325-Jun-08 23:45 
GeneralRe: Sort by Date Pin
manju#12325-Jun-08 23:47
manju#12325-Jun-08 23:47 
GeneralRe: Sort by Date Pin
Rajesh R Subramanian25-Jun-08 23:58
professionalRajesh R Subramanian25-Jun-08 23:58 
GeneralRe: Sort by Date Pin
manju#12326-Jun-08 0:09
manju#12326-Jun-08 0:09 
Questiondisplaying the integers in multiple lines in an edit box? Pin
MahaKh25-Jun-08 21:44
MahaKh25-Jun-08 21:44 
AnswerRe: displaying the integers in multiple lines in an edit box? Pin
Iain Clarke, Warrior Programmer25-Jun-08 21:56
Iain Clarke, Warrior Programmer25-Jun-08 21:56 

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.