[GB.IMAGE]

* NEW: Simplify the job of components that can take ownership of images.


git-svn-id: svn://localhost/gambas/trunk@1811 867c0c6c-44f3-4631-809d-bfa615b0a4ec
This commit is contained in:
Benoît Minisini 2009-01-22 00:47:14 +00:00
parent 111ad81271
commit d4b3628df3
10 changed files with 111 additions and 108 deletions

View File

@ -239,6 +239,7 @@ Private Sub LastOpenedFiles()
Dim hActive As Object
Dim aFold As Integer[]
Inc Application.Busy
RestoringFiles = True
Workspace.Lock
@ -261,6 +262,10 @@ Private Sub LastOpenedFiles()
Activate(hActive)
If hActive Then Workspace.ActiveWindow = hActive
Finally
Dec Application.Busy
End

View File

@ -231,6 +231,10 @@ Public Sub InConflict(sPath As String) As Boolean
If $bSVN Then
'IF Exist(sPath & ".mine") THEN RETURN TRUE
If Not Exist(sPath) Then
Debug sPath; ": does not exist"
Return False
Endif
If Dir(File.Dir(sPath), File.Name(sPath) & ".r*").Count Then Return True
Endif

View File

@ -1,5 +1,5 @@
# Gambas Project File 3.0
# Compiled with Gambas 2.99.0 (r1796)
# Compiled with Gambas 2.99.0 (r1805)
Startup=FTest
StackTrace=1
Version=2.99.0

View File

@ -42,33 +42,30 @@ static void free_image(GB_IMG *img, void *image)
((gPicture *)image)->unref();
}
static void *temp_image(GB_IMG *img)
{
gPicture *image;
if (!img->data)
image = new gPicture();
else
image = gPicture::fromData((const char *)img->data, img->width, img->height);
image->setTag(new gGambasTag((void *)img));
return image;
}
static GB_IMG_OWNER _image_owner = {
"gb.gtk",
free_image,
free_image
free_image,
temp_image
};
gPicture *CIMAGE_get(CIMAGE *_object)
{
gPicture *image;
if (IMAGE.Check(&THIS->img, &_image_owner))
{
if (!THIS->img.data)
{
image = new gPicture();
}
else
{
IMAGE.Convert(&THIS->img, GB_IMAGE_RGBA);
image = gPicture::fromData((const char *)THIS->img.data, THIS->img.width, THIS->img.height);
}
image->setTag(new gGambasTag((void *)THIS));
THIS->img.temp_handle = image;
}
return PICTURE;
return (gPicture *)IMAGE.Check(&THIS->img, &_image_owner, GB_IMAGE_RGBA);
}
#define check_image CIMAGE_get

View File

@ -83,33 +83,29 @@ static void free_image(GB_IMG *img, void *image)
delete (QImage *)image;
}
static void *temp_image(GB_IMG *img)
{
QImage *image;
if (!img->data)
image = new QImage();
else
image = new QImage(img->data, img->width, img->height, 32, 0, 0, QImage::IgnoreEndian);
image->setAlphaBuffer(true);
return image;
}
static GB_IMG_OWNER _image_owner = {
"gb.qt",
free_image,
free_image
free_image,
temp_image,
};
static QImage *check_image(void *_object)
{
QImage *image;
if (IMAGE.Check(THIS_IMAGE, &_image_owner))
{
if (!THIS_IMAGE->data)
{
image = new QImage();
}
else
{
IMAGE.Convert(THIS_IMAGE, GB_IMAGE_BGRA);
image = new QImage(THIS_IMAGE->data, THIS_IMAGE->width, THIS_IMAGE->height, 32, 0, 0, QImage::IgnoreEndian);
}
image->setAlphaBuffer(true);
THIS_IMAGE->temp_handle = image;
}
return (QImage *)(THIS_IMAGE->temp_handle);
return (QImage *)IMAGE.Check(THIS_IMAGE, &_image_owner, GB_IMAGE_BGRA);
}
static void take_image(CIMAGE *_object, QImage *image)

View File

@ -82,6 +82,19 @@ static void free_image(GB_IMG *img, void *image)
delete (QImage *)image;
}
static void *temp_image(GB_IMG *img)
{
QImage *image;
if (!img->data)
image = new QImage();
else
image = new QImage((uchar *)img->data, img->width, img->height, QImage::Format_ARGB32);
image->setAlphaBuffer(true);
return image;
}
static GB_IMG_OWNER _image_owner = {
"gb.qt4",
free_image,
@ -90,25 +103,7 @@ static GB_IMG_OWNER _image_owner = {
QImage *CIMAGE_get(CIMAGE *_object)
{
QImage *image;
if (IMAGE.Check(THIS_IMAGE, &_image_owner))
{
if (!THIS_IMAGE->data)
{
image = new QImage();
}
else
{
IMAGE.Convert(THIS_IMAGE, GB_IMAGE_BGRA);
image = new QImage((uchar *)THIS_IMAGE->data, THIS_IMAGE->width, THIS_IMAGE->height, QImage::Format_ARGB32);
}
image->setAlphaBuffer(true);
THIS_IMAGE->temp_handle = image;
}
return (QImage *)(THIS_IMAGE->temp_handle);
return (QImage *)IMAGE.Check(THIS_IMAGE, &_image_owner, GB_IMAGE_BGRA);
}
#define check_image CIMAGE_get

View File

@ -32,33 +32,29 @@ static void free_image(GB_IMG *img, void *image)
delete (SDLsurface *)image;
}
static void *temp_image(GB_IMG *img)
{
SDLsurface *image;
if (!img->data)
image = new SDLsurface();
else
image = new SDLsurface((char *)img->data, img->width, img->height);
image->SetAlphaBuffer(true);
return image;
}
static GB_IMG_OWNER _image_owner = {
"gb.sdl",
free_image,
free_image
free_image,
temp_image
};
SDLsurface *CIMAGE_get(CIMAGE *_object)
{
SDLsurface *image;
if (IMAGE.Check(THIS_IMAGE, &_image_owner))
{
if (!THIS_IMAGE->data)
{
image = new SDLsurface();
}
else
{
IMAGE.Convert(THIS_IMAGE, GB_IMAGE_RGBA);
image = new SDLsurface((char *)THIS_IMAGE->data, THIS_IMAGE->width, THIS_IMAGE->height);
}
image->SetAlphaBuffer(true);
THIS_IMAGE->temp_handle = image;
}
return IMAGEID;
return (SDLsurface *)IMAGE.Check(THIS_IMAGE, &_image_owner, GB_IMAGE_RGBA);
}
#define check_image CIMAGE_get

View File

@ -65,9 +65,10 @@ struct GB_IMG;
typedef
struct {
const char *name;
void (*free)(struct GB_IMG *img, void *handle); // free owner or temporary handle
void (*release)(struct GB_IMG *img, void *handle); // free owner or temporary handle
const char *name; // owner name (this is the name of the component)
void (*free)(struct GB_IMG *img, void *handle); // free owner handle
void (*release)(struct GB_IMG *img, void *handle); // free temporary handle
void *(*temp)(struct GB_IMG *img); // create a temporary handle for an image and returns it
//void (*lock)(void *handle); // lock, before accessing pixels
//void (*unlock)(void *handle); // unlock, after accessing pixels
}
@ -84,7 +85,7 @@ typedef
int format; // image format (RGB, BGR, RGBA...)
GB_IMG_OWNER *owner; // owner of the data, NULL means gb.image
void *owner_handle; // handle for the owner
GB_IMG_OWNER *temp; // owner of the temporary handle that does not own the data
GB_IMG_OWNER *temp_owner; // owner of the temporary handle that does not own the data
void *temp_handle; // temporary handle
}
GB_IMG;
@ -107,12 +108,19 @@ typedef
typedef
struct {
intptr_t version;
// Create an image
GB_IMG *(*Create)(int width, int height, int format, unsigned char *data);
// Delete an image - You should never use it, it is called automatically
void (*Delete)(GB_IMG *img);
// Take image ownership by giving the image handle and information
void (*Take)(GB_IMG *img, GB_IMG_OWNER *owner, void *owner_handle, int width, int height, unsigned char *data);
int (*Check)(GB_IMG *img, GB_IMG_OWNER *temp);
// Create a temporary handle on the image without becoming the owner.
void *(*Check)(GB_IMG *img, GB_IMG_OWNER *temp_owner, int format);
// Convert an image to the specify format - You should never use it, it is called automatically
void (*Convert)(GB_IMG *img, int format);
// Return the size of the image data in bytes
int (*Size)(GB_IMG *img);
// Set the default format used when creating images
void (*SetDefaultFormat)(int format);
}
IMAGE_INTERFACE;

View File

@ -322,38 +322,40 @@ void IMAGE_create_with_data(GB_IMG *img, int width, int height, int format, unsi
memcpy(img->data, data, IMAGE_size(img));
}
// Check if a temporary handle is needed, and return 1 if it is
// Check if a temporary handle is needed, and create it if needed by calling the owner "temp" function
int IMAGE_check(GB_IMG *img, GB_IMG_OWNER *temp)
void *IMAGE_check(GB_IMG *img, GB_IMG_OWNER *temp_owner, int format)
{
// If we already have the temporary handle, then do nothing
if (img->temp == temp)
return 0;
if (img->temp_owner == temp_owner)
return img->temp_handle;
// If somebody else has a temporary handle
if (img->temp)
if (img->temp_owner)
{
// release it only if it is not the owner
if (img->temp != img->owner && img->temp->release)
(*img->temp->release)(img, img->temp_handle);
if (img->temp_owner != img->owner && img->temp_owner->release)
(*img->temp_owner->release)(img, img->temp_handle);
img->temp_handle = 0;
}
// Get the temporary handle
img->temp = temp;
img->temp_owner = temp_owner;
// If we are the owner, we must use our owner handle as temporary handle
if (img->owner == temp)
if (temp_owner)
{
img->temp_handle = img->owner_handle;
return 0;
// If we are the owner, we must use our owner handle as temporary handle
if (img->owner == temp_owner)
img->temp_handle = img->owner_handle;
// If we are not the owner, then we will have to create the temporary handle ourself
else
{
IMAGE_convert(img, format);
img->temp_handle = (*img->temp_owner->temp)(img);
}
}
// If we are not the owner, then we will have to create the temporary handle ourself
else
{
img->temp_handle = 0;
return 1;
}
return img->temp_handle;
}
// Take ownership of the image
@ -369,9 +371,9 @@ void IMAGE_take(GB_IMG *img, GB_IMG_OWNER *owner, void *owner_handle, int width,
(*img->owner->free)(img, img->owner_handle);
// If we have the temporary handle too, then clean it as it is necessarily the same
if (img->temp == img->owner)
if (img->temp_owner == img->owner)
{
img->temp = NULL;
img->temp_owner = NULL;
img->temp_handle = 0;
}
@ -380,8 +382,8 @@ void IMAGE_take(GB_IMG *img, GB_IMG_OWNER *owner, void *owner_handle, int width,
img->owner_handle = owner_handle;
// As we are now the owner, then we must have the temporary handle too
IMAGE_check(img, NULL);
img->temp = owner;
IMAGE_check(img, NULL, 0);
img->temp_owner = owner;
img->temp_handle = owner_handle;
// Initialize the data

View File

@ -37,7 +37,7 @@ int IMAGE_size(GB_IMG *img);
void IMAGE_create(GB_IMG *img, int width, int height, int format);
void IMAGE_create_with_data(GB_IMG *img, int width, int height, int format, unsigned char *data);
void IMAGE_take(GB_IMG *img, GB_IMG_OWNER *owner, void *owner_handle, int width, int height, unsigned char *data);
int IMAGE_check(GB_IMG *img, GB_IMG_OWNER *owner);
void *IMAGE_check(GB_IMG *img, GB_IMG_OWNER *temp_owner, int format);
void IMAGE_delete(GB_IMG *img);
void IMAGE_convert(GB_IMG *img, int format);
void IMAGE_fill(GB_IMG *img, GB_COLOR col);