home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Acorn User 10
/
AU_CD10.iso
/
Archived
/
Updates
/
Flash
/
writeflash
/
!MakeFlash
/
c
/
gradient
< prev
next >
Wrap
Text File
|
2000-04-02
|
1KB
|
54 lines
#include <stdio.h>
#include <stdlib.h>
//
#include "proto.h"
#include "bucket.h"
#include "gradient.h"
int gradient_read(GRADIENT *grad, int alpha) {
int i;
grad->usealpha = alpha;
if (read_ubyte(&grad->n)) return 1;
if ((grad->n < 1) || (grad->n > 8)) return 1;
for (i = 0; i < grad->n; i++) {
U8 r, g, b, a;
if (read_ubyte(grad->ratio+i)) return 1;
if (read_ubyte(&r)) return 1;
if (read_ubyte(&g)) return 1;
if (read_ubyte(&b)) return 1;
if (alpha) {
if (read_ubyte(&a)) return 1;
} else
a = 255;
grad->rgba[i] = r | (g<<8) | (b<<16) | (a<<24);
}
return 0;
}
int gradient_write(GRADIENT *grad) {
int i;
if (write_ubyte(grad->n)) return 1;
for (i = 0; i < grad->n; i++) {
U32 rgba;
if (write_ubyte(grad->ratio[i])) return 1;
rgba = grad->rgba[i];
if (write_ubyte(rgba &255)) return 1;
if (write_ubyte((rgba>> 8) &255)) return 1;
if (write_ubyte((rgba>>16) &255)) return 1;
if (grad->usealpha)
if (write_ubyte((rgba>>24) &255)) return 1;
}
return 0;
}