mirror of
https://github.com/gryf/wmaker.git
synced 2025-12-22 14:08:06 +01:00
---------------
- Added retain/release mechanism to RImage by adding RRetainImage() and
RReleaseImage(). RDestroyImage() is an alias to RReleaseImage() now, but
will be removed in a future release because it no longer fits with the
semantics. Will be kept for a while to allow a smoother transition.
More about in wrlib/NEWS
For WINGs:
----------
- Small API change:
1. Renamed WMSetApplicationIconImage(), WMGetApplicationIconImage() and
WMSetWindowMiniwindowImage() to respectively WMSetApplicationIconPixmap(),
WMGetApplicationIconPixmap() and WMSetWindowMiniwindowPixmap()
They operate on a WMPixmap which is practically an X Pixmap with no alpha
channel information and the new name is more suggestive and also leaves
room for the new functions added for operating on images with alpha info.
2. Added WMSetApplicationIconImage() and WMGetApplicationIconImage() which
operate on an RImage and store alpha information too.
3. Added WMGetApplicationIconBlendedPixmap() which will take the image with
alpha set by WMSetApplicationIconImage() and will blend it with a color.
If color is NULL it will blend using the default panel color (#aeaaae)
All these changes will allow WINGs to handle images with alpha blending
correctly in panels and wherever else needed. More about in WINGs/NEWS.
- updated panels to use the newly available RImages if present and fallback
to old WMPixmaps if not, to properly show alpha blended images.
- replaced some still left malloc's with wmalloc's.
For Window Maker:
-----------------
- Fixed wrong mapping position of the "Docked Applications Panel" for some
icons.
- Smoother animation for the smiley =)
- Made images with alpha blending be shown correctly in the panels and the
icon chooser.
- The icon image set to be shown in panels ("Logo.WMPanel") will be
automatically updated if its entry in WMWindowAttributes changes (without
a need to restart as until now).
*** Note!!! ***
If you are developing applications with one of libwraster or libWINGs
then you should look to wrlib/NEWS and WINGs/NEWS to see what changed
and how should you update your code.
226 lines
4.8 KiB
C
226 lines
4.8 KiB
C
/* gif.c - load GIF image from file
|
|
*
|
|
* Raster graphics library
|
|
*
|
|
* Copyright (c) 1998 Alfredo K. Kojima
|
|
*
|
|
* This library is free software; you can redistribute it and/or
|
|
* modify it under the terms of the GNU Library 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
|
|
* Library General Public License for more details.
|
|
*
|
|
* You should have received a copy of the GNU Library General Public
|
|
* License along with this library; if not, write to the Free
|
|
* Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
|
*/
|
|
|
|
#include <config.h>
|
|
|
|
|
|
#ifdef USE_GIF
|
|
|
|
#include <stdlib.h>
|
|
#include <stdio.h>
|
|
#include <string.h>
|
|
|
|
#include <gif_lib.h>
|
|
|
|
#include "wraster.h"
|
|
|
|
|
|
static int InterlacedOffset[] = { 0, 4, 2, 1 };
|
|
static int InterlacedJumps[] = { 8, 8, 4, 2 };
|
|
|
|
|
|
/*
|
|
* Partially based on code in gif2rgb from giflib, by Gershon Elber.
|
|
*/
|
|
RImage*
|
|
RLoadGIF(RContext *context, char *file, int index)
|
|
{
|
|
RImage *image = NULL;
|
|
unsigned char *cptr;
|
|
GifFileType *gif = NULL;
|
|
GifPixelType *buffer = NULL;
|
|
int i, j, k;
|
|
int width, height;
|
|
GifRecordType recType;
|
|
ColorMapObject *colormap;
|
|
unsigned char rmap[256];
|
|
unsigned char gmap[256];
|
|
unsigned char bmap[256];
|
|
|
|
if (index < 0)
|
|
index = 0;
|
|
|
|
/* default error message */
|
|
RErrorCode = RERR_BADINDEX;
|
|
|
|
gif = DGifOpenFileName(file);
|
|
|
|
if (!gif) {
|
|
switch (GifLastError()) {
|
|
case D_GIF_ERR_OPEN_FAILED:
|
|
RErrorCode = RERR_OPEN;
|
|
break;
|
|
case D_GIF_ERR_READ_FAILED:
|
|
RErrorCode = RERR_READ;
|
|
break;
|
|
default:
|
|
RErrorCode = RERR_BADIMAGEFILE;
|
|
break;
|
|
}
|
|
return NULL;
|
|
}
|
|
|
|
colormap = gif->SColorMap;
|
|
|
|
i = 0;
|
|
|
|
do {
|
|
int extCode;
|
|
GifByteType *extension;
|
|
|
|
if (DGifGetRecordType(gif, &recType) == GIF_ERROR) {
|
|
goto giferr;
|
|
}
|
|
switch (recType) {
|
|
case IMAGE_DESC_RECORD_TYPE:
|
|
if (i++ != index)
|
|
break;
|
|
|
|
if (DGifGetImageDesc(gif)==GIF_ERROR) {
|
|
goto giferr;
|
|
}
|
|
|
|
width = gif->Image.Width;
|
|
height = gif->Image.Height;
|
|
|
|
if (gif->Image.ColorMap)
|
|
colormap = gif->Image.ColorMap;
|
|
|
|
/* the gif specs talk about a default colormap, but it
|
|
* doesnt say what the heck is this default colormap */
|
|
if (!colormap) {
|
|
/*
|
|
* Well, since the spec says the colormap can be anything,
|
|
* lets just render it with whatever garbage the stack
|
|
* has :)
|
|
*
|
|
|
|
goto bye;
|
|
*/
|
|
} else {
|
|
for (j = 0; j < colormap->ColorCount; j++) {
|
|
rmap[j] = colormap->Colors[j].Red;
|
|
gmap[j] = colormap->Colors[j].Green;
|
|
bmap[j] = colormap->Colors[j].Blue;
|
|
}
|
|
}
|
|
|
|
buffer = malloc(width * sizeof(GifColorType));
|
|
if (!buffer) {
|
|
RErrorCode = RERR_NOMEMORY;
|
|
goto bye;
|
|
}
|
|
|
|
image = RCreateImage(width, height, False);
|
|
if (!image) {
|
|
goto bye;
|
|
}
|
|
|
|
if (gif->Image.Interlace) {
|
|
int l;
|
|
int pelsPerLine;
|
|
|
|
if (RRGBAFormat==image->format)
|
|
pelsPerLine = width * 4;
|
|
else
|
|
pelsPerLine = width * 3;
|
|
|
|
for (j = 0; j < 4; j++) {
|
|
for (k = InterlacedOffset[j]; k < height;
|
|
k += InterlacedJumps[j]) {
|
|
if (DGifGetLine(gif, buffer, width)==GIF_ERROR) {
|
|
goto giferr;
|
|
}
|
|
cptr = image->data + (k*pelsPerLine);
|
|
for (l = 0; l < width; l++) {
|
|
int pixel = buffer[l];
|
|
*cptr++ = rmap[pixel];
|
|
*cptr++ = gmap[pixel];
|
|
*cptr++ = bmap[pixel];
|
|
}
|
|
}
|
|
}
|
|
} else {
|
|
cptr = image->data;
|
|
for (j = 0; j < height; j++) {
|
|
if (DGifGetLine(gif, buffer, width)==GIF_ERROR) {
|
|
goto giferr;
|
|
}
|
|
for (k = 0; k < width; k++) {
|
|
int pixel = buffer[k];
|
|
*cptr++ = rmap[pixel];
|
|
*cptr++ = gmap[pixel];
|
|
*cptr++ = bmap[pixel];
|
|
if (RRGBAFormat==image->format)
|
|
cptr++;
|
|
}
|
|
}
|
|
}
|
|
break;
|
|
|
|
case EXTENSION_RECORD_TYPE:
|
|
/* skip all extension blocks */
|
|
if (DGifGetExtension(gif, &extCode, &extension)==GIF_ERROR) {
|
|
goto giferr;
|
|
}
|
|
while (extension) {
|
|
if (DGifGetExtensionNext(gif, &extension)==GIF_ERROR) {
|
|
goto giferr;
|
|
}
|
|
}
|
|
break;
|
|
|
|
default:
|
|
break;
|
|
}
|
|
} while (recType != TERMINATE_RECORD_TYPE && i <= index);
|
|
|
|
/* yuck! */
|
|
goto did_not_get_any_errors;
|
|
giferr:
|
|
switch (GifLastError()) {
|
|
case D_GIF_ERR_OPEN_FAILED:
|
|
RErrorCode = RERR_OPEN;
|
|
break;
|
|
case D_GIF_ERR_READ_FAILED:
|
|
RErrorCode = RERR_READ;
|
|
break;
|
|
default:
|
|
RErrorCode = RERR_BADIMAGEFILE;
|
|
break;
|
|
}
|
|
bye:
|
|
if (image)
|
|
RReleaseImage(image);
|
|
image = NULL;
|
|
did_not_get_any_errors:
|
|
|
|
if (buffer)
|
|
free(buffer);
|
|
|
|
if (gif)
|
|
DGifCloseFile(gif);
|
|
|
|
return image;
|
|
}
|
|
|
|
#endif /* USE_GIF */
|