home *** CD-ROM | disk | FTP | other *** search
/ DOS/V Power Report 1997 March / VPR9703A.ISO / VPR_DATA / DOGA / SOURCES / REND.LZH / PIC1600 / F_DISP.C < prev    next >
C/C++ Source or Header  |  1996-04-20  |  4KB  |  165 lines

  1. #ifdef X68K
  2. #include    <stdio.h>
  3. #include    <stdlib.h>
  4. #include    <doslib.h>
  5. #include    <iocslib.h>
  6. #include    <string.h>
  7. #include    "piclib.h"
  8.  
  9. typedef struct {
  10.     unsigned short *p;
  11.     Pixel *pixelbuffer;
  12.     PicReduceData *reduce;
  13. }    PicWork;
  14.  
  15. #define GRAM ((unsigned short *)(0xc00000))
  16.  
  17. int        PicReadHeader_Display(PicData *pd, FILE *fp, unsigned char *magic)
  18. {
  19.     extern PicFunction PicFunction_Display;
  20.     if (strncmp(pd->filename, "_DISPLAY_", 9) != 0) {
  21.         return FALSE;
  22.     }
  23.     pd->func = &PicFunction_Display;
  24.     pd->mode = DSP;
  25.     pd->pixelX = 512;
  26.     pd->pixelY = 512;
  27.     return TRUE;
  28. }
  29.  
  30. int        PicOpen_Display(PicData *pd, FILE *fp, int flag)
  31. {
  32.     PicWork *work;
  33.     int nowmode;
  34.     if ((work = malloc(sizeof(PicWork))) == NULL) {
  35.         return FALSE;
  36.     }
  37.     nowmode = CRTMOD(-1);
  38.     pd->work = work;
  39.     if (pd->flag == PIC_READ) {
  40.         pd->fullcolor = FALSE;
  41.         work->p = GRAM;
  42.         if (nowmode == 12 || nowmode == 13) {
  43.             pd->pixelX = pd->pixelY = 512;
  44.         } else if (nowmode == 14 || nowmode == 15) {
  45.             pd->pixelX = pd->pixelY = 256;
  46.         } else {
  47.             return FALSE;
  48.         }
  49.  
  50.     } else {
  51.         if (pd->pixelX <= 256 && pd->pixelY <= 256) {
  52.             if (nowmode != 13 && nowmode != 14) {
  53.                 CRTMOD(14);
  54.                 G_CLR_ON();
  55.             }
  56.         } else if (pd->pixelX <= 512 && pd->pixelY <= 512) {
  57.             if (nowmode != 12 && nowmode != 13) {
  58.                 CRTMOD(12);
  59.                 G_CLR_ON();
  60.             }
  61.         } else {
  62.             return FALSE;
  63.         }
  64.         work->reduce = NULL;
  65.         work->pixelbuffer = NULL;
  66.         if ((work->reduce = PicColorReduceOpen(pd->pixelX, flag)) == NULL) {
  67.             return FALSE;
  68.         }
  69.         if ((work->pixelbuffer = malloc(sizeof(Pixel) * pd->pixelX)) == NULL) {
  70.             return FALSE;
  71.         }
  72.         work->p = GRAM;
  73.     }
  74.     return TRUE;
  75. }
  76.  
  77. static inline Pixel Convert_16_24(unsigned short color)
  78. {
  79. /*                        gggg grrr rrbb bbbt*/
  80. /*  gggg gggg rrrr rrrr bbbb bbbb tttt tttt*/
  81. /*
  82.     return ((color & 0xf800) << 16)
  83.          | ((color & 0x07c0) << 13)
  84.          | ((color & 0x003e) << 10)
  85.          | ((color & 0x0001) ? 0xff : 0);
  86. */
  87.     Pixel c = ((color & 0xf800) << 11)
  88.             | ((color & 0x07c0) <<  8)
  89.             | ((color & 0x003e) <<  5);
  90.     return  (c << 5) | (c & 0x07070700);
  91. }
  92.  
  93. static inline unsigned short Convert_24_16(Pixel p)
  94. {
  95. #if 0
  96.     return ((p & 0xf8000000) >> 16)
  97.          | ((p & 0x00f80000) >> 13)
  98.          | ((p & 0x0000f800) >> 10)
  99.          | ((p & 0x00000080) ? 1 : 0);
  100. #else
  101.     return ((p & 0xf8000000) >> 16)
  102.          | ((p & 0x00f80000) >> 13)
  103.          | ((p & 0x0000f800) >> 10);
  104. #endif
  105. }
  106.  
  107. int        PicOutput_Display(PicData *pd, Pixel *p)
  108. {
  109.     int pixels = pd->pixelX;
  110.     int sp;
  111.     PicWork *work = pd->work;
  112.     unsigned short *gram = work->p;
  113.     Pixel *pixel = work->pixelbuffer;
  114.     PicColorReduce(work->reduce, pixel, p);
  115. DUMMY1:
  116.     sp = SUPER(0);
  117.     for (; pixels > 0; --pixels) {
  118.         *gram++ = Convert_24_16(*pixel++);
  119.     }
  120.     gram += 512 - pd->pixelX;
  121.     work->p = gram;
  122. DUMMY2:
  123.     SUPER(sp);
  124.     return TRUE;
  125. }
  126.  
  127. int        PicInput_Display(PicData *pd, Pixel *pixel)
  128. {
  129.     int sp;
  130.     int pixels = pd->pixelX;
  131.     PicWork *work = pd->work;
  132.     unsigned short *gram = work->p;
  133. DUMMY1:
  134.     sp = SUPER(0);
  135.     for (; pixels > 0; --pixels) {
  136.         *pixel++ = Convert_16_24(*gram++);
  137.     }
  138.     gram += 512 - pd->pixelX;
  139.     work->p = gram;
  140. DUMMY2:
  141.     SUPER(sp);
  142.     return TRUE;
  143. }
  144.  
  145. int        PicClose_Display(PicData *pd)
  146. {
  147.     PicWork *work = pd->work;
  148.     if (pd->flag == PIC_WRITE) {
  149.         PicColorReduceClose(work->reduce);
  150.         free(work->pixelbuffer);
  151.     }
  152.     free(work);
  153.     return TRUE;
  154. }
  155.  
  156. PicFunction PicFunction_Display = {
  157.     "",
  158.     PicReadHeader_Display,
  159.     PicOpen_Display,
  160.     PicOutput_Display,
  161.     PicInput_Display,
  162.     PicClose_Display
  163. };
  164. #endif
  165.