Sort of, but remember you have to toggle between read/write states. I'm writing this off the top of my head so the pseudocode may still have errors in it, but something like:
Code:
Uint32 skip_write[10000];
Precalc(image im)
int size = im.x * im.y;
bool state = 0;
int index = 0;
int count = 0;
for(int i=0; i<size; i++)
if(state)
if(im.pixel[i] == MASK)
count++;
else
skip_write[index] = count;
count = 1;
index++;
state = false;
else
if(im.pixel[i] != MASK)
count++;
else
skip_write[index] = count;
count =1;
index++;
state = true;
Edit: you also need to note if the first pixel is masked or not, also using a linked list for this can save a lot of memory.