forked from old/legacy-imlib2
Indent.
This commit is contained in:
parent
5cabf38155
commit
93e6176764
|
@ -17,27 +17,33 @@ load(ImlibImage *im, ImlibProgressFunction progress,
|
|||
uint8_t *dat;
|
||||
|
||||
/* open the file for reading */
|
||||
if (!(f = fopen(im->real_file, "rb"))) {
|
||||
if (!(f = fopen(im->real_file, "rb")))
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* read and check the header */
|
||||
if (!im->data) {
|
||||
if (!im->data)
|
||||
{
|
||||
if (fread(hdr, sizeof(uint32_t), LEN(hdr), f) != LEN(hdr) ||
|
||||
memcmp("farbfeld", hdr, sizeof("farbfeld") - 1)) {
|
||||
memcmp("farbfeld", hdr, sizeof("farbfeld") - 1))
|
||||
{
|
||||
fclose(f);
|
||||
return 0;
|
||||
}
|
||||
im->w = ntohl(hdr[2]);
|
||||
im->h = ntohl(hdr[3]);
|
||||
if (!IMAGE_DIMENSIONS_OK(im->w, im->h)) {
|
||||
if (!IMAGE_DIMENSIONS_OK(im->w, im->h))
|
||||
{
|
||||
fclose(f);
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* set format */
|
||||
if (!im->loader) {
|
||||
if (!(im->format = strdup("ff"))) {
|
||||
if (!im->loader)
|
||||
{
|
||||
if (!(im->format = strdup("ff")))
|
||||
{
|
||||
fclose(f);
|
||||
return 0;
|
||||
}
|
||||
|
@ -46,14 +52,16 @@ load(ImlibImage *im, ImlibProgressFunction progress,
|
|||
}
|
||||
|
||||
/* load the data */
|
||||
if (im->loader || immediate_load || progress) {
|
||||
if (im->loader || immediate_load || progress)
|
||||
{
|
||||
w = im->w;
|
||||
h = im->h;
|
||||
rowlen = w * (sizeof("RGBA") - 1);
|
||||
|
||||
free(im->data);
|
||||
if (!(im->data = malloc(rowlen * h)) ||
|
||||
!(row = malloc(rowlen * sizeof(uint16_t)))) {
|
||||
!(row = malloc(rowlen * sizeof(uint16_t))))
|
||||
{
|
||||
free(im->data);
|
||||
im->data = NULL;
|
||||
free(row);
|
||||
|
@ -62,16 +70,18 @@ load(ImlibImage *im, ImlibProgressFunction progress,
|
|||
}
|
||||
|
||||
dat = (uint8_t *) im->data;
|
||||
for (i = 0; i < h; i++, dat += rowlen) {
|
||||
if (fread(row, sizeof(uint16_t), rowlen, f) !=
|
||||
rowlen) {
|
||||
for (i = 0; i < h; i++, dat += rowlen)
|
||||
{
|
||||
if (fread(row, sizeof(uint16_t), rowlen, f) != rowlen)
|
||||
{
|
||||
free(im->data);
|
||||
im->data = NULL;
|
||||
free(row);
|
||||
fclose(f);
|
||||
return 0;
|
||||
}
|
||||
for (j = 0; j < rowlen; j += 4) {
|
||||
for (j = 0; j < rowlen; j += 4)
|
||||
{
|
||||
/*
|
||||
* 16-Bit to 8-Bit (RGBA -> BGRA)
|
||||
* 255 * 257 = 65535 = 2^16-1 = UINT16_MAX
|
||||
|
@ -82,7 +92,8 @@ load(ImlibImage *im, ImlibProgressFunction progress,
|
|||
dat[j + 3] = ntohs(row[j + 3]) / 257;
|
||||
}
|
||||
}
|
||||
if (progress) {
|
||||
if (progress)
|
||||
{
|
||||
progress(im, 100, 0, 0, im->w, im->h);
|
||||
}
|
||||
|
||||
|
@ -103,32 +114,38 @@ save(ImlibImage *im, ImlibProgressFunction progress, char progress_gran)
|
|||
uint8_t *dat;
|
||||
|
||||
/* open the file for writing */
|
||||
if (!(f = fopen(im->real_file, "wb"))) {
|
||||
if (!(f = fopen(im->real_file, "wb")))
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* write header */
|
||||
fputs("farbfeld", f);
|
||||
tmp32 = htonl(im->w);
|
||||
if (fwrite(&tmp32, sizeof(uint32_t), 1, f) != 1) {
|
||||
if (fwrite(&tmp32, sizeof(uint32_t), 1, f) != 1)
|
||||
{
|
||||
fclose(f);
|
||||
return 0;
|
||||
}
|
||||
tmp32 = htonl(im->h);
|
||||
if (fwrite(&tmp32, sizeof(uint32_t), 1, f) != 1) {
|
||||
if (fwrite(&tmp32, sizeof(uint32_t), 1, f) != 1)
|
||||
{
|
||||
fclose(f);
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* write data */
|
||||
rowlen = im->w * (sizeof("RGBA") - 1);
|
||||
if (!(row = malloc(rowlen * sizeof(uint16_t)))) {
|
||||
if (!(row = malloc(rowlen * sizeof(uint16_t))))
|
||||
{
|
||||
fclose(f);
|
||||
return 0;
|
||||
}
|
||||
dat = (uint8_t *) im->data;
|
||||
for (i = 0; i < (uint32_t)im->h; ++i, dat += rowlen) {
|
||||
for (j = 0; j < rowlen; j += 4) {
|
||||
for (i = 0; i < (uint32_t) im->h; ++i, dat += rowlen)
|
||||
{
|
||||
for (j = 0; j < rowlen; j += 4)
|
||||
{
|
||||
/*
|
||||
* 8-Bit to 16-Bit
|
||||
* 255 * 257 = 65535 = 2^16-1 = UINT16_MAX
|
||||
|
@ -138,13 +155,15 @@ save(ImlibImage *im, ImlibProgressFunction progress, char progress_gran)
|
|||
row[j + 2] = htons(dat[j + 0] * 257);
|
||||
row[j + 3] = htons(dat[j + 3] * 257);
|
||||
}
|
||||
if (fwrite(row, sizeof(uint16_t), rowlen, f) != rowlen) {
|
||||
if (fwrite(row, sizeof(uint16_t), rowlen, f) != rowlen)
|
||||
{
|
||||
free(row);
|
||||
fclose(f);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
if (progress) {
|
||||
if (progress)
|
||||
{
|
||||
progress(im, 100, 0, 0, im->w, im->h);
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue