[gs-bugs] [Bug 691437] Empty ResourceDictionary not handled.
bugzilla-daemon at ghostscript.com
bugzilla-daemon at ghostscript.com
Thu Jul 1 11:07:48 UTC 2010
http://bugs.ghostscript.com/show_bug.cgi?id=691437
--- Comment #3 from norbert.janssen at oce.com 2010-07-01 11:07:47 UTC ---
After reading in the stops and sorting, still some rangechecking has to be
done.
Here my solution, to be inserted in xps_parse_gradient_stops() after sorting
the offsets/colors arrays, just before returning 'count';
{
float *from, *to;
/* check for first stop 0.0 */
if (offsets[0] > 0.0)
{
/* add offset 0.0, with same color as next stop */
int tmp;
for (tmp = count; tmp > 0; tmp--)
{
offsets[tmp] = offsets[tmp-1];
from = &colors[(tmp-1) * 4 + 0];
to = &colors[(tmp) * 4 + 0];
*to++ = *from++;
*to++ = *from++;
*to++ = *from++;
*to = *from;
}
count++;
}
else if (offsets[0] < 0.0)
{
/* find location of 0.0 */
int tmp;
for (tmp = 1; tmp < count; tmp++)
{
if (offsets[tmp] >= 0.0)
break;
}
if ((tmp < count) && (offsets[tmp] == 0.0))
{
int moveto;
/* discard everything before tmp */
for (moveto = 0; tmp < count; tmp++, moveto++)
{
offsets[moveto] = offsets[tmp];
to = &colors[moveto * 4 + 0];
from = &colors[(tmp) * 4 + 0];
*to++ = *from++;
*to++ = *from++;
*to++ = *from++;
*to = *from;
}
count -= tmp;
}
else if ((tmp < count) && (offsets[tmp] > 0.0))
{
/* interpolate between tmp-1 and tmp
* put it in tmp-1
* and discard everything before tmp-1
*/
int moveto;
float val1, val2, interval;
val1 = offsets[tmp-1];
val2 = offsets[tmp];
interval = (0.0 - val1) / (val2 - val1);
offsets[tmp-1] = 0.0;
to = &colors[(tmp-1)*4 + 0];
from = &colors[tmp*4 + 0];
val1 = *to;
*to += interval * (*from - val1);
to++;
from++;
val1 = *to;
*to += interval * (*from - val1);
to++;
from++;
val1 = *to;
*to += interval * (*from - val1);
to++;
from++;
val1 = *to;
*to += interval * (*from - val1);
tmp--; /* offsets[tmp] = 0.0; */
if (tmp > 0)
{
/* discard everything before tmp */
for (moveto = 0; tmp < count; tmp++, moveto++)
{
float *from, *to;
offsets[moveto] = offsets[tmp];
to = &colors[moveto * 4 + 0];
from = &colors[(tmp) * 4 + 0];
*to++ = *from++;
*to++ = *from++;
*to++ = *from++;
*to = *from;
}
count -= tmp;
}
}
else /* only values < 0.0 */
{
/* add offset 0.0 with highest value color
* discard everything below offset 0.0
*/
offsets[0] = 0.0;
to = &colors[0];
from = &colors[(count-1)*4 + 0];
*to++ = *from++;
*to++ = *from++;
*to++ = *from++;
*to = *from;
count = 1;
}
}
/* check for last stop 1.0 */
/* at this point offsets[0] == 0.0 */
if (offsets[count-1] < 1.0)
{
/* add offset 1.0, with same color as previous stop */
offsets[count] = offsets[count-1];
to = &colors[count * 4 + 0];
from = &colors[(count-1) * 4 + 0];
*to++ = *from++;
*to++ = *from++;
*to++ = *from++;
*to = *from;
count++;
}
else if (offsets[count-1] > 1.0)
{
/* find location of 1.0 */
int tmp;
for (tmp = count-2; tmp >= 0; tmp--)
{
if (offsets[tmp] <= 1.0)
break;
}
if ((tmp > 0) && (offsets[tmp] == 1.0))
{
/* discard everything after tmp */
count = tmp + 1;
}
else if ((tmp >= 0) && (offsets[tmp] < 1.0))
{
/* interpolate between tmp and tmp+1
* put it in tmp+1
* and discard everything after tmp+1
*/
float val1, val2, interval;
val1 = offsets[tmp];
val2 = offsets[tmp+1];
interval = (val2 - 1.0) / (val2 - val1);
offsets[tmp+1] = 1.0;
to = &colors[(tmp+1)*4 + 0];
from = &colors[tmp*4+0];
val2 = *to;
*to -= interval * (val2 - *from);
to++;
from++;
val2 = *to;
*to -= interval * (val2 - *from);
to++;
from++;
val2 = *to;
*to -= interval * (val2 - *from);
to++;
from++;
val2 = *to;
*to -= interval * (val2 - *from);
tmp++; /* offsets[tmp] = 1.0; */
count = tmp+1; /* zero based */
}
else /* only values > 1.0 */
{
/* not possible, because in previous step a 0.0 was added */
}
}
}
--
Configure bugmail: http://bugs.ghostscript.com/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are the QA contact for the bug.
More information about the gs-bugs
mailing list