Fixed crash in pupmenu for image icons

* Scaled down image can be smaller than icon - bad memory access
* Also needed to copy float buffer for exr images
* rectcpy only copied first row

There probably is some unnessary copying, will check with a little more time.
For now better be safe since it's no huge amount of mem that is copied.
This commit is contained in:
Andrea Weikert
2006-01-17 17:23:44 +00:00
parent eb839608be
commit d40162bc1a
2 changed files with 20 additions and 3 deletions

View File

@@ -113,7 +113,14 @@ void IMB_rectcpy(struct ImBuf *dbuf, struct ImBuf *sbuf, int destx,
for (;height > 0; height--){
memcpy(drect,srect, width * sizeof(int));
if (do_float) memcpy(drectf,srectf, width * sizeof(float) * 4);
drect += destx;
srect += srcx;
if (do_float) {
memcpy(drectf,srectf, width * sizeof(float) * 4);
drectf += destx;
srectf += srcx;
}
}
}

View File

@@ -620,6 +620,7 @@ void BIF_icons_init(int first_dyn_id)
static void icon_from_image(Image* img, RenderInfo* ri, unsigned int w, unsigned int h)
{
struct ImBuf *ima;
struct ImBuf *imb;
float scaledx, scaledy;
int pr_size = w*h*sizeof(unsigned int);
short ex, ey, dx, dy;
@@ -655,9 +656,18 @@ static void icon_from_image(Image* img, RenderInfo* ri, unsigned int w, unsigned
dx = (w - ex) / 2;
dy = (h - ey) / 2;
IMB_scaleImBuf(ima, ex, ey);
memcpy(ri->rect, ima->rect, pr_size);
IMB_scalefastImBuf(ima, ex, ey);
/* sigh, need to copy the float buffer too */
imb = IMB_allocImBuf(w, h, 32, IB_rect | IB_rectfloat, 0);
IMB_rectcpy(imb, ima, dx, dy, 0, 0, ex, ey);
IMB_freeImBuf(ima);
memcpy(ri->rect, imb->rect,pr_size);
IMB_freeImBuf(imb);
}