mirror of
https://github.com/gryf/wmaker.git
synced 2026-02-13 20:35:54 +01:00
Change to the linux kernel coding style
for arq in `git ls-files *.c`; do
echo $arq;
indent -linux -l115 $arq;
done
The different line break at 115 columns is because
I use a widescreen monitor :-)
This commit is contained in:
177
wrlib/tiff.c
177
wrlib/tiff.c
@@ -21,7 +21,6 @@
|
||||
|
||||
#include <config.h>
|
||||
|
||||
|
||||
#ifdef USE_TIFF
|
||||
|
||||
#include <stdlib.h>
|
||||
@@ -31,118 +30,114 @@
|
||||
#include <tiff.h>
|
||||
#include <tiffio.h>
|
||||
|
||||
|
||||
#include "wraster.h"
|
||||
|
||||
|
||||
RImage*
|
||||
RLoadTIFF(RContext *context, char *file, int index)
|
||||
RImage *RLoadTIFF(RContext * context, char *file, int index)
|
||||
{
|
||||
RImage *image = NULL;
|
||||
TIFF *tif;
|
||||
int i;
|
||||
unsigned char *r, *g, *b, *a;
|
||||
uint16 alpha, amode;
|
||||
uint32 width, height;
|
||||
uint32 *data, *ptr;
|
||||
uint16 extrasamples;
|
||||
uint16 *sampleinfo;
|
||||
int ch;
|
||||
RImage *image = NULL;
|
||||
TIFF *tif;
|
||||
int i;
|
||||
unsigned char *r, *g, *b, *a;
|
||||
uint16 alpha, amode;
|
||||
uint32 width, height;
|
||||
uint32 *data, *ptr;
|
||||
uint16 extrasamples;
|
||||
uint16 *sampleinfo;
|
||||
int ch;
|
||||
|
||||
tif = TIFFOpen(file, "r");
|
||||
if (!tif)
|
||||
return NULL;
|
||||
|
||||
tif = TIFFOpen(file, "r");
|
||||
if (!tif)
|
||||
return NULL;
|
||||
/* seek index */
|
||||
i = index;
|
||||
while (i > 0) {
|
||||
if (!TIFFReadDirectory(tif)) {
|
||||
RErrorCode = RERR_BADINDEX;
|
||||
TIFFClose(tif);
|
||||
return NULL;
|
||||
}
|
||||
i--;
|
||||
}
|
||||
|
||||
/* seek index */
|
||||
i = index;
|
||||
while (i>0) {
|
||||
if (!TIFFReadDirectory(tif)) {
|
||||
RErrorCode = RERR_BADINDEX;
|
||||
TIFFClose(tif);
|
||||
return NULL;
|
||||
}
|
||||
i--;
|
||||
}
|
||||
/* get info */
|
||||
TIFFGetField(tif, TIFFTAG_IMAGEWIDTH, &width);
|
||||
TIFFGetField(tif, TIFFTAG_IMAGELENGTH, &height);
|
||||
|
||||
/* get info */
|
||||
TIFFGetField(tif, TIFFTAG_IMAGEWIDTH, &width);
|
||||
TIFFGetField(tif, TIFFTAG_IMAGELENGTH, &height);
|
||||
TIFFGetFieldDefaulted(tif, TIFFTAG_EXTRASAMPLES, &extrasamples, &sampleinfo);
|
||||
|
||||
TIFFGetFieldDefaulted(tif, TIFFTAG_EXTRASAMPLES,
|
||||
&extrasamples, &sampleinfo);
|
||||
alpha = (extrasamples == 1 &&
|
||||
((sampleinfo[0] == EXTRASAMPLE_ASSOCALPHA) || (sampleinfo[0] == EXTRASAMPLE_UNASSALPHA)));
|
||||
amode = (extrasamples == 1 && sampleinfo[0] == EXTRASAMPLE_ASSOCALPHA);
|
||||
|
||||
alpha = (extrasamples == 1 &&
|
||||
((sampleinfo[0] == EXTRASAMPLE_ASSOCALPHA) || (sampleinfo[0] == EXTRASAMPLE_UNASSALPHA)));
|
||||
amode = (extrasamples == 1 && sampleinfo[0] == EXTRASAMPLE_ASSOCALPHA);
|
||||
if (width < 1 || height < 1) {
|
||||
RErrorCode = RERR_BADIMAGEFILE;
|
||||
TIFFClose(tif);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (width<1 || height<1) {
|
||||
RErrorCode = RERR_BADIMAGEFILE;
|
||||
TIFFClose(tif);
|
||||
return NULL;
|
||||
}
|
||||
/* read data */
|
||||
ptr = data = (uint32 *) _TIFFmalloc(width * height * sizeof(uint32));
|
||||
|
||||
/* read data */
|
||||
ptr = data = (uint32*)_TIFFmalloc(width * height * sizeof(uint32));
|
||||
if (!data) {
|
||||
RErrorCode = RERR_NOMEMORY;
|
||||
} else {
|
||||
if (!TIFFReadRGBAImage(tif, width, height, data, 0)) {
|
||||
RErrorCode = RERR_BADIMAGEFILE;
|
||||
} else {
|
||||
|
||||
if (!data) {
|
||||
RErrorCode = RERR_NOMEMORY;
|
||||
} else {
|
||||
if (!TIFFReadRGBAImage(tif, width, height, data, 0)) {
|
||||
RErrorCode = RERR_BADIMAGEFILE;
|
||||
} else {
|
||||
/* convert data */
|
||||
image = RCreateImage(width, height, alpha);
|
||||
|
||||
/* convert data */
|
||||
image = RCreateImage(width, height, alpha);
|
||||
if (alpha)
|
||||
ch = 4;
|
||||
else
|
||||
ch = 3;
|
||||
|
||||
if (alpha)
|
||||
ch = 4;
|
||||
else
|
||||
ch = 3;
|
||||
if (image) {
|
||||
int x, y;
|
||||
|
||||
if (image) {
|
||||
int x, y;
|
||||
r = image->data;
|
||||
g = image->data + 1;
|
||||
b = image->data + 2;
|
||||
a = image->data + 3;
|
||||
|
||||
r = image->data;
|
||||
g = image->data+1;
|
||||
b = image->data+2;
|
||||
a = image->data+3;
|
||||
/* data seems to be stored upside down */
|
||||
data += width * (height - 1);
|
||||
for (y = 0; y < height; y++) {
|
||||
for (x = 0; x < width; x++) {
|
||||
|
||||
/* data seems to be stored upside down */
|
||||
data += width * (height-1);
|
||||
for (y=0; y<height; y++) {
|
||||
for (x=0; x<width; x++) {
|
||||
*(r) = (*data) & 0xff;
|
||||
*(g) = (*data >> 8) & 0xff;
|
||||
*(b) = (*data >> 16) & 0xff;
|
||||
|
||||
*(r) = (*data) & 0xff;
|
||||
*(g) = (*data >> 8) & 0xff;
|
||||
*(b) = (*data >> 16) & 0xff;
|
||||
if (alpha) {
|
||||
*(a) = (*data >> 24) & 0xff;
|
||||
|
||||
if (alpha) {
|
||||
*(a) = (*data >> 24) & 0xff;
|
||||
if (amode && (*a > 0)) {
|
||||
*r = (*r * 255) / *(a);
|
||||
*g = (*g * 255) / *(a);
|
||||
*b = (*b * 255) / *(a);
|
||||
}
|
||||
|
||||
if (amode && (*a > 0)) {
|
||||
*r = (*r * 255) / *(a);
|
||||
*g = (*g * 255) / *(a);
|
||||
*b = (*b * 255) / *(a);
|
||||
}
|
||||
a += 4;
|
||||
}
|
||||
|
||||
a+=4;
|
||||
}
|
||||
r += ch;
|
||||
g += ch;
|
||||
b += ch;
|
||||
data++;
|
||||
}
|
||||
data -= 2 * width;
|
||||
}
|
||||
}
|
||||
}
|
||||
_TIFFfree(ptr);
|
||||
}
|
||||
|
||||
r+=ch; g+=ch; b+=ch;
|
||||
data++;
|
||||
}
|
||||
data -= 2*width;
|
||||
}
|
||||
}
|
||||
}
|
||||
_TIFFfree(ptr);
|
||||
}
|
||||
TIFFClose(tif);
|
||||
|
||||
TIFFClose(tif);
|
||||
|
||||
return image;
|
||||
return image;
|
||||
}
|
||||
|
||||
#endif /* USE_TIFF */
|
||||
|
||||
#endif /* USE_TIFF */
|
||||
|
||||
Reference in New Issue
Block a user