home *** CD-ROM | disk | FTP | other *** search
/ Magazyn Amiga 5 / MA_Cover_5.iso / ppc / mesa / src / mmesa8.c < prev    next >
Encoding:
C/C++ Source or Header  |  1998-01-31  |  7.0 KB  |  201 lines

  1. /****************************************************************************
  2. *
  3. *                      Mesa bindings for SciTech MGL
  4. *
  5. *                   Copyright (C) 1996 SciTech Software.
  6. *                           All rights reserved.
  7. *
  8. * Filename:     $Workfile:   mmesa8.c  $
  9. * Version:      $Revision:   1.1  $
  10. *
  11. * Language:     ANSI C
  12. * Environment:  Any
  13. *
  14. * Description:  Optimized 8bpp rendering functions.
  15. *
  16. * This library is free software; you can redistribute it and/or
  17. * modify it under the terms of the GNU Library General Public
  18. * License as published by the Free Software Foundation; either
  19. * version 2 of the License, or (at your option) any later version.
  20. *
  21. * This library is distributed in the hope that it will be useful,
  22. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  23. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  24. * Library General Public License for more details.
  25. *
  26. * You should have received a copy of the GNU Library General Public
  27. * License along with this library; if not, write to the Free
  28. * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  29. *
  30. * $Date:   06 Apr 1997 14:40:00  $ $Author:   KendallB  $
  31. *
  32. ****************************************************************************/
  33.  
  34. #include "mmesap.h"
  35.  
  36. /*------------------------- Implementation --------------------------------*/
  37.  
  38. #pragma warn -par
  39. #include "mmesai.c"
  40.  
  41. /**********************************************************************/
  42. /*****            Write spans of pixels                           *****/
  43. /**********************************************************************/
  44.  
  45. void _mmesa_write_span_ci(GLcontext *ctx,GLuint n, GLint x, GLint y,
  46.     GLuint index[],GLubyte mask[])
  47. {
  48.     uchar *d = PACKED8_pixelAddr(x,FLIP(y));
  49.     while (n >= 8) {
  50.         if (mask[0]) d[0] = (uchar)index[0];
  51.         if (mask[1]) d[1] = (uchar)index[1];
  52.         if (mask[2]) d[2] = (uchar)index[2];
  53.         if (mask[3]) d[3] = (uchar)index[3];
  54.         if (mask[4]) d[4] = (uchar)index[4];
  55.         if (mask[5]) d[5] = (uchar)index[5];
  56.         if (mask[6]) d[6] = (uchar)index[6];
  57.         if (mask[7]) d[7] = (uchar)index[7];
  58.         d += 8; index += 8; mask += 8; n -= 8;
  59.         }
  60.     while (n--) {
  61.         if (mask[0]) d[0] = (uchar)index[0];
  62.         d++; index++; mask++;
  63.         }
  64. }
  65.  
  66. void _mmesa_write_span_mono_ci(GLcontext *ctx,GLuint n,GLint x,GLint y,
  67.     GLubyte mask[])
  68. {
  69.     uchar *d = PACKED8_pixelAddr(x,FLIP(y));
  70.     while (n >= 8) {
  71.         if (mask[0]) d[0] = (uchar)RC.color;
  72.         if (mask[1]) d[1] = (uchar)RC.color;
  73.         if (mask[2]) d[2] = (uchar)RC.color;
  74.         if (mask[3]) d[3] = (uchar)RC.color;
  75.         if (mask[4]) d[4] = (uchar)RC.color;
  76.         if (mask[5]) d[5] = (uchar)RC.color;
  77.         if (mask[6]) d[6] = (uchar)RC.color;
  78.         if (mask[7]) d[7] = (uchar)RC.color;
  79.         d += 8; mask += 8; n -= 8;
  80.         }
  81.     while (n--) {
  82.         if (mask[0]) d[0] = (uchar)RC.color;
  83.         d++; mask++;
  84.         }
  85. }
  86.  
  87. IMPLEMENT_WRITE_SPAN(8,8,uchar);
  88. IMPLEMENT_WRITE_SPAN_DITHER(8,DITHER8,uchar);
  89. IMPLEMENT_WRITE_SPAN_MONO(8,uchar);
  90. IMPLEMENT_WRITE_SPAN_MONO_DITHER(8,DITHER8,uchar);
  91.  
  92. /**********************************************************************/
  93. /*****              Write arrays of pixels                        *****/
  94. /**********************************************************************/
  95.  
  96. void _mmesa_write_pixels_ci(GLcontext *ctx,GLuint n, GLint x[],
  97.     GLint y[],GLuint index[], GLubyte mask[])
  98. {
  99.     while (n >= 4) {
  100.         if (mask[0]) *((uchar*)PACKED8_pixelAddr(x[0],FLIP(y[0]))) = (uchar)index[0];
  101.         if (mask[1]) *((uchar*)PACKED8_pixelAddr(x[1],FLIP(y[1]))) = (uchar)index[1];
  102.         if (mask[2]) *((uchar*)PACKED8_pixelAddr(x[2],FLIP(y[2]))) = (uchar)index[2];
  103.         if (mask[3]) *((uchar*)PACKED8_pixelAddr(x[3],FLIP(y[3]))) = (uchar)index[3];
  104.         index += 4; mask += 4; x += 4; y += 4; n -= 4;
  105.         }
  106.     while (n--) {
  107.         if (mask[0]) *((uchar*)PACKED8_pixelAddr(x[0],FLIP(y[0]))) = (uchar)index[0];
  108.         index++; mask++; x++; y++;
  109.         }
  110. }
  111.  
  112. void _mmesa_write_pixels_mono_ci(GLcontext *ctx,GLuint n,GLint x[],
  113.     GLint y[],GLubyte mask[])
  114. {
  115.     while (n >= 4) {
  116.         if (mask[0]) *((uchar*)PACKED8_pixelAddr(x[0],FLIP(y[0]))) = (uchar)RC.color;
  117.         if (mask[1]) *((uchar*)PACKED8_pixelAddr(x[1],FLIP(y[1]))) = (uchar)RC.color;
  118.         if (mask[2]) *((uchar*)PACKED8_pixelAddr(x[2],FLIP(y[2]))) = (uchar)RC.color;
  119.         if (mask[3]) *((uchar*)PACKED8_pixelAddr(x[3],FLIP(y[3]))) = (uchar)RC.color;
  120.         mask += 4; x += 4; y += 4; n -= 4;
  121.         }
  122.     while (n--) {
  123.         if (mask[0]) *((uchar*)PACKED8_pixelAddr(x[0],FLIP(y[0]))) = (uchar)RC.color;
  124.         mask++; x++; y++;
  125.         }
  126. }
  127.  
  128. IMPLEMENT_WRITE_PIXELS(8,8,uchar);
  129. IMPLEMENT_WRITE_PIXELS_DITHER(8,DITHER8,uchar);
  130. IMPLEMENT_WRITE_PIXELS_MONO(8,uchar);
  131. IMPLEMENT_WRITE_PIXELS_MONO_DITHER(8,DITHER8,uchar);
  132.  
  133. /**********************************************************************/
  134. /*****                 Read spans of pixels                       *****/
  135. /**********************************************************************/
  136.  
  137. void _mmesa_read_span_ci(GLcontext *ctx,GLuint n, GLint x, GLint y,
  138.     GLuint index[])
  139. {
  140.     uchar *d = PACKED8_pixelAddr(x,FLIP(y));
  141.     while (n >= 8) {
  142.         index[0] = d[0];
  143.         index[1] = d[1];
  144.         index[2] = d[2];
  145.         index[3] = d[3];
  146.         index[4] = d[4];
  147.         index[5] = d[5];
  148.         index[6] = d[6];
  149.         index[7] = d[7];
  150.         d += 8; index += 8; n -= 8;
  151.         }
  152.     while (n--) {
  153.         index[0] = d[0];
  154.         d++; index++;
  155.         }
  156. }
  157.  
  158. void _mmesa_read_span_8(GLcontext *ctx,GLuint n, GLint x, GLint y,
  159.     GLubyte red[], GLubyte green[],GLubyte blue[], GLubyte alpha[])
  160. {
  161.     color_t color,*colorTab = RC.dc->colorTab;
  162.     uchar *d = PACKED8_pixelAddr(x,FLIP(y));
  163.     while (n--) {
  164.         color = colorTab[d[0]];
  165.         UNPACK_COLOR_RGB(color,red[0],green[0],blue[0]);
  166.         red++; green++; blue++; d++;
  167.         }
  168. }
  169.  
  170. /**********************************************************************/
  171. /*****                   Read arrays of pixels                    *****/
  172. /**********************************************************************/
  173.  
  174. void _mmesa_read_pixels_ci(GLcontext *ctx,GLuint n, GLint x[],
  175.     GLint y[],GLuint index[], GLubyte mask[])
  176. {
  177.     while (n--) {
  178.         if (mask[0]) {
  179.             uchar *d = PACKED8_pixelAddr(x[0],FLIP(y[0]));
  180.             index[0] = d[0];
  181.             }   
  182.         index++; mask++; x++; y++;
  183.         }
  184. }
  185.  
  186. void _mmesa_read_pixels_8(GLcontext *ctx,GLuint n, GLint x[],
  187.     GLint y[],GLubyte red[], GLubyte green[],GLubyte blue[],
  188.     GLubyte alpha[],GLubyte mask[])
  189. {
  190.     color_t *colorTab = RC.dc->colorTab;
  191.     while (n--) {
  192.         if (mask[0]) {
  193.             uchar *d = PACKED8_pixelAddr(x[0],FLIP(y[0]));
  194.             color_t color = colorTab[d[0]];
  195.             UNPACK_COLOR(color,red[0],green[0],blue[0]);
  196.             }
  197.         red++; green++; blue++; mask++; x++; y++;
  198.         }
  199. }
  200.  
  201.