Skip to content

Commit

Permalink
bugfix: made partial byte generation deterministic in Image::Indexed:…
Browse files Browse the repository at this point in the history
…:separate for 2018-07-sam2p-crashes/sample-100 in #37
  • Loading branch information
Peter Szabo committed Jul 26, 2018
1 parent 852244f commit af05f34
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions image.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -867,7 +867,7 @@ Image::Indexed **Image::Indexed::separate() {
Indexed **ret=new Indexed*[nncols+1], **curimg=ret;
Image::Sampled::dimen_t htc;
assert(cpp==1);
slen_t wdcpp=wd/* *cpp*/;
const slen_t wdcpp=wd/* *cpp*/;
register unsigned char *p;
char *to, *toend;
register unsigned int i;
Expand All @@ -881,15 +881,22 @@ Image::Indexed **Image::Indexed::separate() {
curimg[0]->setTransp(1);
to=curimg[0]->rowbeg; p=(unsigned char*)rowbeg;
htc=ht; while (htc--!=0) {
toend=to+((wdcpp+7)>>3);
toend=to+(wdcpp>>3);
while (to!=toend) {
i =(*p++!=curcol)<<7; i|=(*p++!=curcol)<<6;
i|=(*p++!=curcol)<<5; i|=(*p++!=curcol)<<4;
i|=(*p++!=curcol)<<3; i|=(*p++!=curcol)<<2;
i|=(*p++!=curcol)<<1; i|=(*p++!=curcol);
*to++=i;
}
if (0!=(wdcpp&7)) p+=(wdcpp&7)-8; /* negative */
if (0 != (wdcpp & 7)) {
i = (*p++ != curcol) << 7;
unsigned char j = 6;
for (unsigned char *pend = p + (wdcpp & 7) - 1; p != pend; ++p, --j) {
i |= (*p != curcol) << j;
}
*to++ = i;
}
}
curimg++;
}
Expand Down

0 comments on commit af05f34

Please sign in to comment.