home *** CD-ROM | disk | FTP | other *** search
/ Graphics Plus / Graphics Plus.iso / general / procssng / ccs / ccs-11tl.lha / lbl / lib / c_map1.c < prev    next >
Encoding:
C/C++ Source or Header  |  1992-09-15  |  1.7 KB  |  67 lines

  1. /*    C_MAP1 . C
  2. #
  3. %    Copyright (c)    Jin Guojun
  4. %
  5. % AUTHOR:    Jin Guojun - LBL    10/1/91
  6. */
  7.  
  8. #include "header.def"
  9. #include "imagedef.h"
  10.  
  11. /*    return    0 in failure when reading color maps    */
  12. bool
  13. ReadRGBMap(U_IMAGE *img, color_cell *cmbuf, int mlen, bool OsameI)
  14. {
  15.     if ((*img->read)(cmbuf, sizeof(*cmbuf), mlen, img->IN_FP) != mlen)
  16.         return    prgmerr(-1, "bad colormap");
  17.     rgbmap_to_othermap(cmbuf, mlen, True /* to reg_cmap */);
  18. return    True;
  19. }
  20.  
  21.  
  22. read_hex_rgbmap(U_IMAGE *img, register color_cell *cmbuf, int mlen)
  23. {
  24. register int    i;
  25. for (i=0; i < mlen; i++)    {
  26. #ifndef    NO_ALIGN
  27. MType    align;    /* works for both Endian machines    */
  28.     if (fscanf(img->IN_FP, "%x ", &align) < 1)
  29. #else    /* for BGR cmap only since %x format reverses reading order    */
  30.     if (fscanf(img->IN_FP, "%x ", cmbuf + i) < 1)
  31. #endif
  32.         return    prgmerr(-1, "hex colormap");
  33. #ifndef    NO_ALIGN
  34.     cmbuf[i].b = align & 0xFF;
  35.     cmbuf[i].g = (align >> 8) & 0xFF;
  36.     cmbuf[i].r = (align >> 16)& 0xFF;
  37. #endif
  38. }
  39. rgbmap_to_othermap(cmbuf, mlen, True);
  40. return    True;
  41. }
  42.  
  43. read_ras_cmap(U_IMAGE*    img, register int mlen, int chans)
  44. {
  45.     verify_buffer_size(reg_cmap, mlen * 3, sizeof(cmap_t), "rast_cmap");
  46.     reg_cmap[1] = reg_cmap[0] + mlen;
  47.     reg_cmap[2] = reg_cmap[1] + mlen;
  48. return    ((*img->read)(reg_cmap[0], sizeof(cmap_t)*3, mlen, img->IN_FP) == mlen);
  49. }
  50.  
  51.  
  52. /*    return    color fromat    */
  53. imageform_to_colorform(register int    iform)
  54. {
  55.     switch (iform)    {
  56.     case IFMT_SCF:    iform = CFM_SCF;    break;
  57.     case IFMT_ILC:    iform = CFM_ILC;    break;
  58.     case IFMT_ILL:    iform = CFM_ILL;    break;
  59.     case IFMT_ALPHA:    iform = CFM_ALPHA;    break;
  60.     case IFMT_SEPLANE:    iform = CFM_SEPLANE;    break;
  61.     case IFMT_BITMAP:    iform = CFM_BITMAP;    break;
  62.     case IFMT_SGF:
  63.     default:    iform = CFM_SGF;    break;
  64.     }
  65. return    iform;
  66. }
  67.