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

  1. #include    <stdio.h>
  2. #include    <stdlib.h>
  3. #ifdef X68K
  4. #include    <doslib.h>
  5. #endif
  6. #include    "piclib.h"
  7.  
  8. int        PicOutputLine(PicData *pd, Pixel *pixel)
  9. {
  10.     return pd->func->PicOutputLine(pd, pixel);
  11. }
  12.  
  13. int        PicInputLine(PicData *pd, Pixel *pixel)
  14. {
  15.     return pd->func->PicInputLine(pd, pixel);
  16. }
  17.  
  18. int        PicClose(PicData *pd)
  19. {
  20.     return pd->func->PicClose(pd);
  21. }
  22.  
  23. #ifdef X68K
  24. static inline Pixel Convert_16_24(unsigned short color)
  25. {
  26. /*                        gggg grrr rrbb bbbt*/
  27. /*  gggg gggg rrrr rrrr bbbb bbbb tttt tttt*/
  28. /*
  29.     return ((color & 0xf800) << 16)
  30.          | ((color & 0x07c0) << 13)
  31.          | ((color & 0x003e) << 10)
  32.          | ((color & 0x0001) ? 0xff : 0);
  33. */
  34.     Pixel c = ((color & 0xf800) << 11)
  35.             | ((color & 0x07c0) <<  8)
  36.             | ((color & 0x003e) <<  5);
  37.     return  (c << 5) | (c & 0x07070700) | ((color & 0x0001) ? 0xff : 0);
  38. }
  39.  
  40. static inline unsigned short Convert_24_16(Pixel p)
  41. {
  42.     return ((p & 0xf8000000) >> 16)
  43.          | ((p & 0x00f80000) >> 13)
  44.          | ((p & 0x0000f800) >> 10)
  45.          | ((p & 0x00000080) ? 1 : 0);
  46. }
  47.  
  48. int    PicDisplay(PicData *pd, int x, int y, int scale, int mode)
  49. {
  50.     int ssp;
  51.     int i, j;
  52.     int sizex, sizey;
  53.     unsigned short *gram = (unsigned short*)0xc00000;
  54.     PicReduceData *reduce;
  55.     Pixel *pixel;
  56.  
  57.     if (x < 0 ) {
  58. /*        x = pd->picheader.positionX;*/
  59.         x = 0;
  60.     }
  61.     if (y < 0) {
  62. /*        y = pd->picheader.positionY;*/
  63.         y = 0;
  64.     }
  65.     gram += x * 512 + y;
  66.     sizex = pd->pixelX;
  67.     sizey = pd->pixelY;
  68.     if ((pixel = malloc(sizeof(Pixel) * pd->pixelX))==NULL) {
  69.         return FALSE;
  70.     }
  71.     if ((reduce = PicColorReduceOpen(pd->pixelX, mode)) == NULL) {
  72.         free(pixel);
  73.         return FALSE;
  74.     }
  75. label1:
  76.     ssp = SUPER(0);
  77. label2:
  78.     for (j = sizey; j > 0; --j) {
  79.         PicInputLine(pd, pixel);
  80.         PicColorReduce(reduce, pixel, pixel);
  81.         for (i = 0; i < sizex; ++i) {
  82.             *gram++ = Convert_24_16(pixel[i]);
  83.         }
  84.         gram += 512-sizex;
  85.     }
  86. label3:
  87.     SUPER(ssp);
  88. label4:
  89.     PicColorReduceClose(reduce);
  90.     free(pixel);
  91.     return TRUE;
  92. }
  93.  
  94. int        PicSave(PicData *pd, int x, int y, int scale)
  95. {
  96.     int ssp;
  97.     int i, j;
  98.     int sizex, sizey;
  99.     unsigned short *gram = (unsigned short*)0xc00000;
  100.     Pixel *pixel;
  101.     if (x < 0 ) {
  102. /*        x = pd->picheader.positionX;*/
  103.         x = 0;
  104.     }
  105.     if (y < 0) {
  106. /*        y = pd->picheader.positionY;*/
  107.         y = 0;
  108.     }
  109.     gram += x * 512 + y;
  110.     sizex = pd->pixelX;
  111.     sizey = pd->pixelY;
  112.     if ((pixel = malloc(sizeof(Pixel) * pd->pixelX))==NULL) {
  113.         return FALSE;
  114.     }
  115. label1:
  116.     ssp = SUPER(0);
  117. label2:
  118.     for (j = sizey; j > 0; --j) {
  119.         for (i = 0; i < sizex; ++i) {
  120.             pixel[i] = Convert_16_24(*gram++);
  121.         }
  122.  
  123.         PicOutputLine(pd, pixel);
  124.         gram += 512-sizex;
  125.     }
  126. label3:
  127.     SUPER(ssp);
  128. label4:
  129.     free(pixel);
  130.     return TRUE;
  131. }
  132.  
  133. #endif
  134.