zero size image bugfix
This commit is contained in:
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -90,6 +90,21 @@ AMSCIMGLIB4_API int amscimglib4_image_resize(amscimglib4_image *imgptr, int _siz
|
||||
return amscimglib4_failure;
|
||||
}
|
||||
|
||||
//handle zero size images
|
||||
if(_sizex<0) _sizex = 0;
|
||||
if(_sizey<0) _sizey = 0;
|
||||
if(_sizex == 0 || _sizey == 0)
|
||||
{
|
||||
imgptr->sizex = 0;
|
||||
imgptr->sizey = 0;
|
||||
if(imgptr->data != NULL)
|
||||
{
|
||||
free(imgptr->data);
|
||||
imgptr->data = NULL;
|
||||
}
|
||||
return amscimglib4_success;
|
||||
}
|
||||
|
||||
newdata = (unsigned char*) malloc(sizeof(unsigned char)*4*_sizex*_sizey);
|
||||
if(newdata==NULL)
|
||||
{
|
||||
@ -109,7 +124,7 @@ AMSCIMGLIB4_API int amscimglib4_image_resize(amscimglib4_image *imgptr, int _siz
|
||||
newdata[4*(I+_sizex*J)+K] = imgptr->data[4*(I+imgptr->sizex*J)+K];
|
||||
}
|
||||
|
||||
free(imgptr->data);
|
||||
if(imgptr->data != NULL) {free(imgptr->data); imgptr->data = NULL; }
|
||||
imgptr->data = newdata;
|
||||
imgptr->sizex = _sizex;
|
||||
imgptr->sizey = _sizey;
|
||||
|
@ -19,6 +19,11 @@ void amscimglib4_test_init()
|
||||
|
||||
res = amscimglib4_image_resize(img1,500,500); printf("res=%d (%d,%d)\n",res,img1->sizex,img1->sizey);
|
||||
res = amscimglib4_image_copy(img2,img1); printf("res=%d, img2=(%d,%d), img1=(%d,%d)\n",res, img2->sizex,img2->sizey,img1->sizex,img1->sizey);
|
||||
res = amscimglib4_image_resize(img1,-10,3); printf("res=%d (%d,%d)\n",res,img1->sizex,img1->sizey);
|
||||
res = amscimglib4_image_resize(img1,0,0); printf("res=%d (%d,%d)\n",res,img1->sizex,img1->sizey);
|
||||
res = amscimglib4_image_copy(img2,img1); printf("res=%d, img2=(%d,%d), img1=(%d,%d)\n",res, img2->sizex,img2->sizey,img1->sizex,img1->sizey);
|
||||
|
||||
|
||||
|
||||
amscimglib4_image_delete(&img1);
|
||||
amscimglib4_image_delete(&img2);
|
||||
|
@ -5,7 +5,7 @@ int main(int argc, char* argv[])
|
||||
{
|
||||
int ret = 0;
|
||||
|
||||
//amscimglib4_test_init();
|
||||
amscimglib4_test_init();
|
||||
amscimglib4_test_loadsave();
|
||||
|
||||
return ret;
|
||||
|
Reference in New Issue
Block a user