* configure: Regenerated file

* configure.ac: Added check for libicns. (http://icns.sourceforge.net/)
        * Headers/Additions/GNUstepGUI/config.h.in
        * Source/GNUmakefile: Added new files
        * Source/NSBitmapImageRep+ICNS.h: Header for ICNS category
        * Source/NSBitmapImageRep+ICNS.m: Implementation if ICNS reading
        logic.
        * Source/NSBitmapImageRep.m: Add support for the ICNS file 
        format so that GNUstep can read Mac OS X icon files.   Uses
        the libicns library available from sourceforge.


git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/gui/trunk@26805 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
Gregory John Casamento 2008-08-12 04:58:04 +00:00
parent d63f065d0a
commit 8b4277dcdc
8 changed files with 3908 additions and 3339 deletions

View file

@ -1,3 +1,16 @@
2008-08-12 00:52-EDT Gregory John Casamento <greg_casamento@yahoo.com>
* configure: Regenerated file
* configure.ac: Added check for libicns. (http://icns.sourceforge.net/)
* Headers/Additions/GNUstepGUI/config.h.in
* Source/GNUmakefile: Added new files
* Source/NSBitmapImageRep+ICNS.h: Header for ICNS category
* Source/NSBitmapImageRep+ICNS.m: Implementation if ICNS reading
logic.
* Source/NSBitmapImageRep.m: Add support for the ICNS file
format so that GNUstep can read Mac OS X icon files. Uses
the libicns library available from sourceforge.
2008-08-11 Fred Kiefer <FredKiefer@gmx.de>
* Source/NSWindow.m (-endEditingFor:): Change the first responder

View file

@ -45,6 +45,9 @@
/* Define to 1 if you have the `ungif' library (-lungif). */
#undef HAVE_LIBUNGIF
/* Define to 1 if you have the `icns' library (-licns). */
#undef HAVE_LIBICNS
/* Define to 1 if you have the `z' library (-lz). */
#undef HAVE_LIBZ

View file

@ -55,6 +55,7 @@ NSAttributedString.m \
NSBezierPath.m \
NSBitmapImageRep.m \
NSBitmapImageRep+GIF.m \
NSBitmapImageRep+ICNS.m \
NSBitmapImageRep+JPEG.m \
NSBitmapImageRep+PNG.m \
NSBitmapImageRep+PNM.m \

View file

@ -0,0 +1,41 @@
/*
NSBitmapImageRep+ICNS.m
Methods for loading .icns images.
Copyright (C) 2008 Free Software Foundation, Inc.
Written by: Gregory Casamento
Date: 2008-08-12
This file is part of the GNUstep GUI Library.
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library 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
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; see the file COPYING.LIB.
If not, see <http://www.gnu.org/licenses/> or write to the
Free Software Foundation, 51 Franklin Street, Fifth Floor,
Boston, MA 02110-1301, USA.
*/
#ifndef _NSBitmapImageRep_ICNS_H_include
#define _NSBitmapImageRep_ICNS_H_include
#include "AppKit/NSBitmapImageRep.h"
@interface NSBitmapImageRep (ICNS)
+ (BOOL) _bitmapIsICNS: (NSData *)imageData;
- (id) _initBitmapFromICNS: (NSData *)imageData;
// - (NSData *) _ICNSRepresentationWithProperties: (NSDictionary *) properties;
@end
#endif

View file

@ -0,0 +1,225 @@
/*
NSBitmapImageRep+ICNS.m
Methods for loading .icns images.
Copyright (C) 2008 Free Software Foundation, Inc.
Written by: Gregory Casamento
Date: 2008-08-12
This file is part of the GNUstep GUI Library.
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library 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
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; see the file COPYING.LIB.
If not, see <http://www.gnu.org/licenses/> or write to the
Free Software Foundation, 51 Franklin Street, Fifth Floor,
Boston, MA 02110-1301, USA.
*/
#include "config.h"
#include "NSBitmapImageRep+ICNS.h"
#if HAVE_LIBICNS
#include <icns.h>
#include <Foundation/NSData.h>
#include <Foundation/NSException.h>
#include <Foundation/NSValue.h>
#include "AppKit/NSGraphics.h"
#define ICNS_HEADER "icns"
// Define the pixel
typedef struct pixel_t
{
uint8_t r;
uint8_t g;
uint8_t b;
uint8_t a;
} pixel_t;
@implementation NSBitmapImageRep (ICNS)
+ (BOOL) _bitmapIsICNS: (NSData *)imageData
{
char header[5];
/*
* If the data is 0, return immediately.
*/
if (![imageData length])
{
return NO;
}
/*
* Check the beginning of the data for
* the string "icns".
*/
[imageData getBytes: header length: 4];
if(strncmp(header, ICNS_HEADER, 4) == 0)
{
return YES;
}
return NO;
}
- (id) _initBitmapFromICNS: (NSData *)imageData
{
int error = 0;
int size = [imageData length];
icns_byte_t *bytes = (icns_byte_t *)[imageData bytes];
icns_family_t *iconFamily = NULL;
unsigned long dataOffset = 0;
icns_byte_t *data = NULL;
char typeStr[5] = {0,0,0,0,0};
unsigned int iconWidth = 0, iconHeight = 0;
icns_image_t iconImage;
icns_element_t iconElement;
icns_icon_info_t iconInfo;
int sPP = 4;
unsigned char *rgbBuffer = NULL; /* image converted to rgb */
unsigned int rgbBufferPos = 0;
unsigned int rgbBufferSize = 0;
int i = 0, j = 0;
int imageChannels = 0;
// int maskChannels = 0;
// icns_image_t mask;
error = icns_import_family_data(size, bytes, &iconFamily);
if(error != ICNS_STATUS_OK)
{
NSLog(@"Error reading ICNS data.");
RELEASE(self);
return nil;
}
// skip the header...
dataOffset = sizeof(icns_type_t) + sizeof(icns_size_t);
data = (icns_byte_t *)iconFamily;
// read each icon...
while(((dataOffset + 8) < iconFamily->resourceSize))
{
icns_element_t element;
icns_icon_info_t info;
icns_size_t dataSize = 0;
unsigned int w = 0, h = 0;
memcpy(&element, (data+dataOffset),8);
memcpy(&typeStr, &(element.elementType),4);
dataSize = element.elementSize - 8;
info = icns_get_image_info_for_type(element.elementType);
h = info.iconHeight;
w = info.iconWidth;
if( w > iconWidth )
{
iconWidth = w;
iconHeight = h;
iconInfo = info;
iconElement = element;
}
// next...
dataOffset += element.elementSize;
}
// extract the image...
memset ( &iconImage, 0, sizeof(icns_image_t) );
error = icns_get_image32_with_mask_from_family(iconFamily,iconElement.elementType,&iconImage);
if(error)
{
NSLog(@"Error while extracting image from ICNS data.");
RELEASE(self);
return nil;
}
// allocate the buffer...
rgbBufferSize = iconHeight * (iconWidth * sizeof(unsigned char) * sPP);
rgbBuffer = NSZoneMalloc([self zone], rgbBufferSize);
if(rgbBuffer == NULL)
{
NSLog(@"Couldn't allocate memory for image data from ICNS.");
RELEASE(self);
return nil;
}
imageChannels = iconImage.imageChannels;
rgbBufferPos = 0;
for (i = 0; i < iconHeight; i++)
{
for(j = 0; j < iconWidth; j++)
{
pixel_t *src_rgb_pixel;
//pixel_t *src_pha_pixel;
src_rgb_pixel = (pixel_t *)&(iconImage.imageData[i*iconWidth*imageChannels+j*imageChannels]);
rgbBuffer[rgbBufferPos++] = src_rgb_pixel->r;
rgbBuffer[rgbBufferPos++] = src_rgb_pixel->g;
rgbBuffer[rgbBufferPos++] = src_rgb_pixel->b;
/*
if(mask != NULL) {
src_pha_pixel = (pixel_t *)&(mask.imageData[i*iconWidth*maskChannels+j*maskChannels]);
rgbBuffer[rgbBufferPos++] = src_pha_pixel->a;
} else {
*/
rgbBuffer[rgbBufferPos++] = src_rgb_pixel->a;
// }
}
}
/* initialize self */
[self initWithBitmapDataPlanes: &rgbBuffer
pixelsWide: (float)iconWidth
pixelsHigh: (float)iconHeight
bitsPerSample: 8
samplesPerPixel: sPP
hasAlpha: YES
isPlanar: NO
colorSpaceName: NSCalibratedRGBColorSpace
bytesPerRow: iconWidth * sPP
bitsPerPixel: 8 * sPP];
_imageData = [[NSData alloc] initWithBytesNoCopy: rgbBuffer
length: rgbBufferSize];
return self;
}
@end
#else /* !HAVE_LIBICNS */
@implementation NSBitmapImageRep (ICNS)
+ (BOOL) _bitmapIsICNS: (NSData *)imageData
{
return NO;
}
- (id) _initBitmapFromICNS: (NSData *)imageData
{
RELEASE(self);
return nil;
}
@end
#endif /* !HAVE_LIBICNS */

View file

@ -37,6 +37,7 @@
#include "NSBitmapImageRep+JPEG.h"
#include "NSBitmapImageRep+PNG.h"
#include "NSBitmapImageRep+PNM.h"
#include "NSBitmapImageRep+ICNS.h"
#include <Foundation/NSArray.h>
#include <Foundation/NSAutoreleasePool.h>
@ -116,6 +117,9 @@
if ([self _bitmapIsGIF: data])
return YES;
if ([self _bitmapIsICNS: data])
return YES;
image = NSTiffOpenDataRead ((char *)[data bytes], [data length]);
if (image != NULL)
@ -148,6 +152,9 @@
#endif
#if HAVE_LIBPNG
@"png",
#endif
#if HAVE_LIBICNS
@"icns",
#endif
nil];
}
@ -256,6 +263,19 @@
return a;
}
if ([self _bitmapIsICNS: imageData])
{
NSBitmapImageRep *rep;
NSArray *a;
rep=[[self alloc] _initBitmapFromICNS: imageData];
if (!rep)
return [NSArray array];
a = [NSArray arrayWithObject: rep];
DESTROY(rep);
return a;
}
image = NSTiffOpenDataRead((char *)[imageData bytes], [imageData length]);
if (image == NULL)
{
@ -307,6 +327,9 @@
return [self _initBitmapFromGIF: imageData
errorMessage: NULL];
if ([isa _bitmapIsICNS: imageData])
return [self _initBitmapFromICNS: imageData];
image = NSTiffOpenDataRead((char *)[imageData bytes], [imageData length]);
if (image == NULL)

6790
configure vendored

File diff suppressed because it is too large Load diff

View file

@ -345,6 +345,11 @@ if test "${ac_cv_lib_aspell_new_aspell_document_checker}" = yes; then
AC_DEFINE(HAVE_ASPELL,1,[Define if you have the aspell header])
fi
#--------------------------------------------------------------------
# Check for ICNS library.
#--------------------------------------------------------------------
AC_CHECK_LIB(icns, icns_read_family_from_file)
#--------------------------------------------------------------------
# NSSound
#--------------------------------------------------------------------