re-arrange icon_draw_rect, also use an assert() for odd icon sizes. this can happen in some cases but hard to find when.

This commit is contained in:
Campbell Barton 2010-10-17 09:01:12 +00:00
parent 7d10ad012d
commit 856389eac7

@ -28,6 +28,7 @@
#include <math.h> #include <math.h>
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#include <assert.h>
#ifndef WIN32 #ifndef WIN32
#include <unistd.h> #include <unistd.h>
@ -845,6 +846,15 @@ static void icon_set_image(bContext *C, ID *id, PreviewImage* prv_img, int miple
static void icon_draw_rect(float x, float y, int w, int h, float UNUSED(aspect), int rw, int rh, unsigned int *rect, float alpha, float *rgb, short is_preview) static void icon_draw_rect(float x, float y, int w, int h, float UNUSED(aspect), int rw, int rh, unsigned int *rect, float alpha, float *rgb, short is_preview)
{ {
ImBuf *ima= NULL;
/* sanity check */
if(w<=0 || h<=0 || w>2000 || h>2000) {
printf("icon_draw_rect: icons are %i x %i pixels?\n", w, h);
assert(!"invalid icon size");
return;
}
/* modulate color */ /* modulate color */
if(alpha != 1.0f) if(alpha != 1.0f)
glPixelTransferf(GL_ALPHA_SCALE, alpha); glPixelTransferf(GL_ALPHA_SCALE, alpha);
@ -861,46 +871,22 @@ static void icon_draw_rect(float x, float y, int w, int h, float UNUSED(aspect),
} }
/* draw */ /* draw */
if((w<1 || h<1)) {
// XXX - TODO 2.5 verify whether this case can happen
if (G.f & G_DEBUG)
printf("what the heck! - icons are %i x %i pixels?\n", w, h);
}
/* rect contains image in 'rendersize', we only scale if needed */ /* rect contains image in 'rendersize', we only scale if needed */
else if(rw!=w && rh!=h) { if(rw!=w && rh!=h) {
if(w>2000 || h>2000) { /* something has gone wrong! */ /* first allocate imbuf for scaling and copy preview into it */
if (G.f & G_DEBUG) ima = IMB_allocImBuf(rw, rh, 32, IB_rect);
printf("insane icon size w=%d h=%d\n",w,h); memcpy(ima->rect, rect, rw*rh*sizeof(unsigned int));
} IMB_scaleImBuf(ima, w, h); /* scale it */
else { rect= ima->rect;
ImBuf *ima;
/* first allocate imbuf for scaling and copy preview into it */
ima = IMB_allocImBuf(rw, rh, 32, IB_rect);
memcpy(ima->rect, rect, rw*rh*sizeof(unsigned int));
/* scale it */
IMB_scaleImBuf(ima, w, h);
if(is_preview) {
glaDrawPixelsSafe(x, y, w, h, w, GL_RGBA, GL_UNSIGNED_BYTE, ima->rect);
}
else {
glDrawPixels(w, h, GL_RGBA, GL_UNSIGNED_BYTE, ima->rect);
}
IMB_freeImBuf(ima);
}
}
else {
if(is_preview) {
glaDrawPixelsSafe(x, y, w, h, w, GL_RGBA, GL_UNSIGNED_BYTE, rect);
}
else {
glDrawPixels(w, h, GL_RGBA, GL_UNSIGNED_BYTE, rect);
}
} }
if(is_preview) glaDrawPixelsSafe(x, y, w, h, w, GL_RGBA, GL_UNSIGNED_BYTE, rect);
else glDrawPixels(w, h, GL_RGBA, GL_UNSIGNED_BYTE, rect);
if(ima)
IMB_freeImBuf(ima);
/* restore color */ /* restore color */
if(alpha != 0.0f) if(alpha != 0.0f)
glPixelTransferf(GL_ALPHA_SCALE, 1.0f); glPixelTransferf(GL_ALPHA_SCALE, 1.0f);