[GB.IMAGE]
* NEW: Image.Format is a new property that returns the image internal format as a string. * BUG: Fix a possible crash that occurs when creating a temporary handle needs a conversion. git-svn-id: svn://localhost/gambas/trunk@3559 867c0c6c-44f3-4631-809d-bfa615b0a4ec
This commit is contained in:
parent
7ab5e8fe25
commit
10105e9feb
2 changed files with 51 additions and 0 deletions
|
@ -252,6 +252,35 @@ BEGIN_METHOD(Image_DrawAlpha, GB_OBJECT image; GB_INTEGER x; GB_INTEGER y; GB_IN
|
|||
|
||||
END_METHOD
|
||||
|
||||
BEGIN_PROPERTY(Image_Format)
|
||||
|
||||
char *format;
|
||||
|
||||
switch(THIS_IMAGE->format)
|
||||
{
|
||||
case GB_IMAGE_BGRX: format = "BGRX"; break;
|
||||
case GB_IMAGE_XRGB: format = "XRGB"; break;
|
||||
case GB_IMAGE_RGBX: format = "RGBX"; break;
|
||||
case GB_IMAGE_XBGR: format = "XBGR"; break;
|
||||
case GB_IMAGE_BGR : format = "BGR"; break;
|
||||
case GB_IMAGE_RGB : format = "RGB"; break;
|
||||
|
||||
case GB_IMAGE_BGRA: format = "BGRA"; break;
|
||||
case GB_IMAGE_ARGB: format = "ARGB"; break;
|
||||
case GB_IMAGE_RGBA: format = "RGBA"; break;
|
||||
case GB_IMAGE_ABGR: format = "ABGR"; break;
|
||||
|
||||
case GB_IMAGE_BGRP: format = "BGRP"; break;
|
||||
case GB_IMAGE_PRGB: format = "PRGB"; break;
|
||||
case GB_IMAGE_RGBP: format = "RGBP"; break;
|
||||
case GB_IMAGE_PBGR: format = "PBGR"; break;
|
||||
default: format = "?";
|
||||
}
|
||||
|
||||
GB.ReturnConstZeroString(format);
|
||||
|
||||
END_PROPERTY
|
||||
|
||||
GB_DESC CImageDesc[] =
|
||||
{
|
||||
GB_DECLARE("Image", sizeof(CIMAGE)),
|
||||
|
@ -272,6 +301,7 @@ GB_DESC CImageDesc[] =
|
|||
GB_PROPERTY_READ("H", "i", CIMAGE_height),
|
||||
GB_PROPERTY_READ("Depth", "i", CIMAGE_depth),
|
||||
GB_PROPERTY_READ("Data", "p", CIMAGE_data),
|
||||
GB_PROPERTY_READ("Format", "s", Image_Format),
|
||||
|
||||
GB_METHOD("Clear", NULL, CIMAGE_clear, NULL),
|
||||
GB_METHOD("Fill", "Image", CIMAGE_fill, "(Color)i"),
|
||||
|
|
|
@ -29,6 +29,7 @@ typedef
|
|||
struct { unsigned char d[3]; } PACKED uint24;
|
||||
|
||||
//#define DEBUG_CONVERT
|
||||
//#define DEBUG_ME 1
|
||||
|
||||
static int _default_format = GB_IMAGE_RGBA;
|
||||
|
||||
|
@ -414,6 +415,10 @@ void IMAGE_create(GB_IMG *img, int width, int height, int format)
|
|||
img->format = format;
|
||||
GB.Alloc(POINTER(&img->data), IMAGE_size(img));
|
||||
img->owner_handle = img->data;
|
||||
|
||||
#ifdef DEBUG_ME
|
||||
fprintf(stderr, "IMAGE_create: %p\n", img);
|
||||
#endif
|
||||
}
|
||||
|
||||
void IMAGE_create_with_data(GB_IMG *img, int width, int height, int format, unsigned char *data)
|
||||
|
@ -450,6 +455,14 @@ void *IMAGE_check(GB_IMG *img, GB_IMG_OWNER *temp_owner)
|
|||
if (img->temp_owner == temp_owner)
|
||||
return img->temp_handle;
|
||||
|
||||
#ifdef DEBUG_ME
|
||||
fprintf(stderr, "IMAGE_check: %p: %s (%p) / %s (%p) -> %s\n",
|
||||
img,
|
||||
img->owner->name, img->owner_handle,
|
||||
img->temp_owner ? img->temp_owner->name : "NULL", img->temp_handle,
|
||||
temp_owner ? temp_owner->name : "NULL");
|
||||
#endif
|
||||
|
||||
// If somebody else has a temporary handle
|
||||
if (img->temp_owner)
|
||||
{
|
||||
|
@ -457,6 +470,7 @@ void *IMAGE_check(GB_IMG *img, GB_IMG_OWNER *temp_owner)
|
|||
if (img->temp_owner != img->owner && img->temp_owner->release)
|
||||
(*img->temp_owner->release)(img, img->temp_handle);
|
||||
img->temp_handle = 0;
|
||||
img->temp_owner = NULL;
|
||||
}
|
||||
|
||||
// Get the temporary handle
|
||||
|
@ -479,6 +493,13 @@ void *IMAGE_check(GB_IMG *img, GB_IMG_OWNER *temp_owner)
|
|||
// Become the temporary owner
|
||||
img->temp_owner = temp_owner;
|
||||
|
||||
#ifdef DEBUG_ME
|
||||
fprintf(stderr, "==========>: %p: %s (%p) / %s (%p)\n",
|
||||
img,
|
||||
img->owner->name, img->owner_handle,
|
||||
img->temp_owner ? img->temp_owner->name : "NULL", img->temp_handle);
|
||||
#endif
|
||||
|
||||
return img->temp_handle;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue