gambas-source-code/main/lib/image/CImageStat.c
Benoît Minisini b3db598050 [DEVELOPMENT ENVIRONMENT]
* BUG: Breakpoints are correctly reset when opening a new project.

[INTERPRETER]
* BUG: The GB.NewString(), GB.NewZeroString() and GB.TempString() API 
  signature has changed. All components have been updated accordingly.
* OPT: Many optimizations to speed up the interpreter.

[GB.EVAL]
* NEW: During syntax highlighting, the first character of class names is
  automatically converted to uppercase.


git-svn-id: svn://localhost/gambas/trunk@2992 867c0c6c-44f3-4631-809d-bfa615b0a4ec
2010-06-04 23:48:53 +00:00

138 lines
3 KiB
C

/***************************************************************************
CImageStat.c
(c) 2000-2009 Benoît Minisini <gambas@users.sourceforge.net>
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2, or (at your option)
any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
***************************************************************************/
#define __CIMAGESTAT_C
#include <sys/mman.h>
#include "main.h"
#include "image_stat.h"
#include "CImageStat.h"
// static int my_mmap(const char *path, char **paddr, int *plen)
// {
// struct stat info;
// int fd;
// void *addr;
// size_t len;
//
// fd = open(path, O_RDONLY);
// if (fd < 0)
// return -1;
//
// if (fstat(fd, &info) < 0)
// return -1;
//
// len = info.st_size;
// addr = mmap(NULL, len, PROT_READ, MAP_PRIVATE, fd, 0);
// if (addr == MAP_FAILED)
// return -1;
//
// *paddr = addr;
// *plen = len;
// return fd;
// }
BEGIN_METHOD(CIMAGESTAT_call, GB_STRING path)
char *path = GB.FileName(STRING(path), LENGTH(path));
IMAGE_STREAM stream;
IMAGE_INFO info = {0};
CIMAGESTAT *stat;
if (GB.LoadFile(path, strlen(path), &stream.addr, &stream.len))
return;
stream.pos = 0;
if (IMAGE_get_info(&stream, &info))
{
GB.Error(IMAGE_error);
}
else
{
GB.New(POINTER(&stat), GB.FindClass("ImageStat"), NULL, NULL);
stat->path = GB.NewZeroString(path);
stat->type = info.type;
stat->width = info.width;
stat->height = info.height;
stat->depth = info.depth;
}
GB.ReleaseFile(stream.addr, stream.len);
GB.ReturnObject(stat);
END_METHOD
BEGIN_METHOD_VOID(CIMAGESTAT_free)
GB.FreeString(&THIS->path);
END_METHOD
BEGIN_PROPERTY(CIMAGESTAT_path)
GB.ReturnString(THIS->path);
END_PROPERTY
BEGIN_PROPERTY(CIMAGESTAT_type)
GB.ReturnConstZeroString(THIS->type);
END_PROPERTY
BEGIN_PROPERTY(CIMAGESTAT_width)
GB.ReturnInteger(THIS->width);
END_PROPERTY
BEGIN_PROPERTY(CIMAGESTAT_height)
GB.ReturnInteger(THIS->height);
END_PROPERTY
BEGIN_PROPERTY(CIMAGESTAT_depth)
GB.ReturnInteger(THIS->depth);
END_PROPERTY
GB_DESC CImageStatDesc[] =
{
GB_DECLARE("ImageStat", sizeof(CIMAGESTAT)),
GB_NOT_CREATABLE(),
GB_STATIC_METHOD("_call", "ImageStat", CIMAGESTAT_call, "(Path)s"),
GB_METHOD("_free", NULL, CIMAGESTAT_free, NULL),
GB_PROPERTY_READ("Path", "s", CIMAGESTAT_path),
GB_PROPERTY_READ("Type", "s", CIMAGESTAT_type),
GB_PROPERTY_READ("Width", "i", CIMAGESTAT_width),
GB_PROPERTY_READ("Height", "i", CIMAGESTAT_height),
GB_PROPERTY_READ("Depth", "i", CIMAGESTAT_depth),
GB_END_DECLARE
};