home *** CD-ROM | disk | FTP | other *** search
/ Acorn User 10 / AU_CD10.iso / Archived / Updates / Flash / writeflash / !MakeFlash / c / gradient < prev    next >
Text File  |  2000-04-02  |  1KB  |  54 lines

  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. //
  4. #include "proto.h"
  5. #include "bucket.h"
  6. #include "gradient.h"
  7.  
  8.  
  9. int gradient_read(GRADIENT *grad, int alpha) {
  10.  
  11.   int i;
  12.  
  13.   grad->usealpha = alpha;
  14.  
  15.   if (read_ubyte(&grad->n))             return 1;
  16.   if ((grad->n < 1) || (grad->n > 8))   return 1;
  17.  
  18.   for (i = 0; i < grad->n; i++) {
  19.     U8 r, g, b, a;
  20.     if (read_ubyte(grad->ratio+i))      return 1;
  21.     if (read_ubyte(&r))                 return 1;
  22.     if (read_ubyte(&g))                 return 1;
  23.     if (read_ubyte(&b))                 return 1;
  24.     if (alpha) {
  25.       if (read_ubyte(&a))               return 1;
  26.     } else
  27.       a = 255;
  28.     grad->rgba[i] = r | (g<<8) | (b<<16) | (a<<24);
  29.   }
  30.  
  31.   return 0;
  32. }
  33.  
  34.  
  35. int gradient_write(GRADIENT *grad) {
  36.  
  37.   int i;
  38.  
  39.   if (write_ubyte(grad->n))             return 1;
  40.  
  41.   for (i = 0; i < grad->n; i++) {
  42.     U32 rgba;
  43.     if (write_ubyte(grad->ratio[i]))    return 1;
  44.     rgba = grad->rgba[i];
  45.     if (write_ubyte(rgba       &255))   return 1;
  46.     if (write_ubyte((rgba>> 8) &255))   return 1;
  47.     if (write_ubyte((rgba>>16) &255))   return 1;
  48.     if (grad->usealpha)
  49.       if (write_ubyte((rgba>>24) &255)) return 1;
  50.   }
  51.  
  52.   return 0;
  53. }
  54.