home *** CD-ROM | disk | FTP | other *** search
/ Amiga Magazin: Amiga-CD 2000 April & May / AMIGA_2000_04.iso / patches / mesa3.1 / mesa-3_1.lha / src / AOS / cybDisplay / cybFastPixels.c < prev    next >
Encoding:
Text File  |  1999-09-05  |  15.6 KB  |  593 lines

  1. /*
  2.  * $Id: $
  3.  */
  4.  
  5. /*
  6.  * Mesa 3-D graphics library
  7.  * Version:  3.1
  8.  * Copyright (C) 1995  Brian Paul  (brianp@ssec.wisc.edu)
  9.  *
  10.  * This library is free software; you can redistribute it and/or
  11.  * modify it under the terms of the GNU Library General Public
  12.  * License as published by the Free Software Foundation; either
  13.  * version 2 of the License, or (at your option) any later version.
  14.  *
  15.  * This library is distributed in the hope that it will be useful,
  16.  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  17.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  18.  * Library General Public License for more details.
  19.  *
  20.  * You should have received a copy of the GNU Library General Public
  21.  * License along with this library; if not, write to the Free
  22.  * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  23.  */
  24.  
  25. GLboolean cybDirectDrawPixels(GLcontext *ctx,
  26.                               GLint x, GLint y, GLsizei width, GLsizei height,
  27.                               GLenum format, GLenum type,
  28.                               const struct gl_pixelstore_attrib *unpack,
  29.                               const GLvoid *pixels ) {
  30.   amigaMesaContext amesa;
  31.   struct RastPort *rp;
  32.  
  33.   amesa = (amigaMesaContext) ctx->DriverCtx;
  34.   rp = amesa->rp;
  35.  
  36.   if ((ctx->RasterMask & (~(SCISSOR_BIT | WINCLIP_BIT))) == 0
  37.       && ctx->Pixel.RedBias == 0.0 && ctx->Pixel.RedScale == 1.0
  38.       && ctx->Pixel.GreenBias == 0.0 && ctx->Pixel.GreenScale == 1.0
  39.       && ctx->Pixel.BlueBias == 0.0 && ctx->Pixel.BlueScale == 1.0
  40.       && ctx->Pixel.AlphaBias == 0.0 && ctx->Pixel.AlphaScale == 1.0
  41.       && ctx->Pixel.IndexShift == 0 && ctx->Pixel.IndexOffset == 0
  42.       && ctx->Pixel.MapColorFlag == 0
  43.       && unpack->Alignment == 1
  44.       && !unpack->SwapBytes
  45.       && !unpack->LsbFirst) {
  46.     GLint skipSize;
  47.     GLint skipPixels = unpack->SkipPixels;
  48.     GLint skipRows = unpack->SkipRows;
  49.     GLint rowLength;
  50.     GLdepth zSpan[amesa->width];                        /* only used when zooming */
  51.     GLint zoomY0 = y;                                /* save Y value of first row */
  52.  
  53.     GLboolean isZoom = GL_FALSE;
  54.     if ((ctx->Pixel.ZoomX == 1.0F) &&
  55.     (ctx->Pixel.ZoomY == 1.0F))
  56.       isZoom = GL_TRUE;
  57.  
  58.     if (unpack->RowLength > 0)
  59.       rowLength = unpack->RowLength;
  60.     else
  61.       rowLength = width;
  62.  
  63.     /* If we're not using pixel zoom then do all clipping calculations
  64.      * now.  Otherwise, we'll let the gl_write_zoomed_*_span() functions
  65.      * handle the clipping.
  66.      */
  67.     if (!isZoom) {
  68.       /* horizontal clipping */
  69.       if (x < ctx->Buffer->Xmin) {
  70.     skipPixels += (ctx->Buffer->Xmin - x);
  71.     width -= (ctx->Buffer->Xmin - x);
  72.     x = ctx->Buffer->Xmin;
  73.       }
  74.       if (x + width > ctx->Buffer->Xmax)
  75.     width -= (x + width - ctx->Buffer->Xmax - 1);
  76.       if (width <= 0)
  77.     return GL_TRUE;
  78.  
  79.       /* vertical clipping */
  80.       if (y < ctx->Buffer->Ymin) {
  81.     skipRows += (ctx->Buffer->Ymin - y);
  82.     height -= (ctx->Buffer->Ymin - y);
  83.     y = ctx->Buffer->Ymin;
  84.       }
  85.       if (y + height > ctx->Buffer->Ymax)
  86.     height -= (y + height - ctx->Buffer->Ymax - 1);
  87.       if (height <= 0)
  88.     return GL_TRUE;
  89.     }
  90.     else {
  91.       /* setup array of fragment Z value to pass to zoom function */
  92.       GLdepth z = (GLdepth) (ctx->Current.RasterPos[2] * DEPTH_SCALE);
  93.       GLint i;
  94.  
  95.       for (i = 0; i < width; i++)
  96.     zSpan[i] = z;
  97.     }
  98.  
  99.     /*
  100.      * Ready to draw!
  101.      * The window region at (x, y) of size (width, height)
  102.      * will be written to.
  103.      * We'll take pixel data from buffer pointed to by "pixels" but we'll
  104.      * skip "skipRows" rows and skip "skipPixels" pixels/row.
  105.      */
  106.     skipSize = (skipRows * rowLength + skipPixels);
  107.  
  108.     if (format == GL_RGBA && type == GL_UNSIGNED_BYTE) {
  109.       if (ctx->Visual->RGBAflag) {
  110.     GLubyte *src = (GLubyte *) pixels + skipSize * 4;
  111.  
  112.     if (!isZoom)
  113.       /* no zooming */
  114.       MyWritePixelArray(src, 0, 0, rowLength * 4, rp, FIXx(x), FIXy(y), width, height, RECTFMT_RGBA);
  115.     else {
  116.       /* with zooming */
  117.       while (--height >= 0) {
  118.         gl_write_zoomed_rgba_span(ctx, width, x, y, zSpan, (void *)src, zoomY0);
  119.  
  120.         src += rowLength * 4;
  121.         y++;
  122.       }
  123.     }
  124.       }
  125.  
  126.       return GL_TRUE;
  127.     }
  128.     else if (format == GL_RGB && type == GL_UNSIGNED_BYTE) {
  129.       if (ctx->Visual->RGBAflag) {
  130.     GLubyte *src = (GLubyte *) pixels + skipSize * 3;
  131.  
  132.     if (!isZoom)
  133.       MyWritePixelArray(src, 0, 0, rowLength * 3, rp, FIXx(x), FIXy(y), width, height, RECTFMT_RGB);
  134.     else {
  135.       /* with zooming */
  136.       while (--height >= 0) {
  137.         gl_write_zoomed_rgb_span(ctx, width, x, y, zSpan, (void *)src, zoomY0);
  138.  
  139.         src += rowLength * 3;
  140.         y++;
  141.       }
  142.     }
  143.       }
  144.  
  145.       return GL_TRUE;
  146.     }
  147.     else if (format == GL_LUMINANCE && type == GL_UNSIGNED_BYTE) {
  148.       if (ctx->Visual->RGBAflag) {
  149.     GLubyte *src = (GLubyte *) pixels + skipSize * 1;
  150.  
  151.     if (!isZoom)
  152.       MyWritePixelArray(src, 0, 0, rowLength * 1, rp, FIXx(x), FIXy(y), width, height, RECTFMT_GREY8);
  153.     else {
  154.       /* with zooming */
  155.       while (--height >= 0) {
  156.         GLshort i = width;
  157.         GLubyte *il = amesa->imageline;
  158.  
  159.         while (--i >= 0) {
  160.           GLushort pel = *src++;
  161.           *((GLushort *)il)++ = (pel << 8) | pel;
  162.           *il++ = pel;
  163.         }
  164.         gl_write_zoomed_rgb_span(ctx, width, x, y, zSpan, (void *)amesa->imageline, zoomY0);
  165.  
  166.         src += rowLength - width;
  167.         y++;
  168.       }
  169.     }
  170.       }
  171.       return GL_TRUE;
  172.     }
  173.     else if (format == GL_LUMINANCE_ALPHA && type == GL_UNSIGNED_BYTE) {
  174.       if (ctx->Visual->RGBAflag) {
  175.     GLubyte *src = (GLubyte *) pixels + skipSize * 2;
  176.  
  177.     if (!isZoom)
  178.       /* with zooming */
  179.       while (--height >= 0) {
  180.         GLshort i = width;
  181.         GLubyte *il = amesa->imageline;
  182.  
  183.         while (--i >= 0) {
  184.           *il++ = *src++;
  185.           src++;
  186.         }
  187.         MyWritePixelArray(amesa->imageline, 0, 0, rowLength * 1, rp, FIXx(x), FIXy(y), width, height, RECTFMT_GREY8);    /* alpha isn't on amiga */
  188.  
  189.         src += rowLength * 2 - width * 2;
  190.         y++;
  191.       }
  192.     else {
  193.       /* with zooming */
  194.       while (--height >= 0) {
  195.         GLshort i = width;
  196.         GLuint *il = (GLuint *)amesa->imageline;
  197.  
  198.         while (--i >= 0) {
  199.           GLuint pel = *src++;
  200.           *il++ = ((((pel << 8) | pel) << 8) | pel) << 8 | *src++;
  201.         }
  202.         gl_write_zoomed_rgba_span(ctx, width, x, y, zSpan, (void *)amesa->imageline, zoomY0);
  203.  
  204.         src += rowLength * 2 - width * 2;
  205.         y++;
  206.       }
  207.     }
  208.       }
  209.  
  210.       return GL_TRUE;
  211.     }
  212.     else if (format == GL_COLOR_INDEX && type == GL_UNSIGNED_BYTE) {
  213.       GLubyte *src = (GLubyte *) pixels + skipSize * 1;
  214.  
  215.       if (ctx->Visual->RGBAflag) {
  216.     /* convert CI data to RGBA */
  217.     if (!isZoom) {
  218.       /* no zooming */
  219.       if (!ctx->Pixel.MapItoRsize &&
  220.           !ctx->Pixel.MapItoGsize &&
  221.           !ctx->Pixel.MapItoBsize) {
  222.         /* no masking */
  223.         GLshort i;
  224.         ULONG xrgb[256];
  225.         const GLubyte *rMap = ctx->Pixel.MapItoR8;
  226.         const GLubyte *gMap = ctx->Pixel.MapItoG8;
  227.         const GLubyte *bMap = ctx->Pixel.MapItoB8;
  228.  
  229.         for (i = 256 - 1; i >= 0; i--)
  230.           xrgb[i] = (((rMap[i] << 8) | gMap[i]) << 8) | bMap[i];
  231.  
  232.         MyWriteLUTPixelArray(src, 0, 0, rowLength * 1, rp, xrgb, FIXx(x), FIXy(y), width, height, CTABFMT_XRGB8);
  233.       }
  234.       else {
  235.         /* with masking */
  236.         while (--height >= 0) {
  237.           gl_map_ci8_to_rgba(ctx, width, src, amesa->imageline);            /* masks */
  238.           MyWritePixelArray(amesa->imageline, 0, 0, 4 * width, rp, FIXx(x), FIXy(y), width, 1, RECTFMT_RGBA);
  239.  
  240.           src += rowLength;
  241.           y++;
  242.         }
  243.       }
  244.  
  245.       return GL_TRUE;
  246.     }
  247.     else {
  248.       /* with zooming */
  249.       while (--height >= 0) {
  250.         gl_map_ci8_to_rgba(ctx, width, src, amesa->imageline);            /* masks */
  251.         gl_write_zoomed_rgba_span(ctx, width, x, y, zSpan, (void *)amesa->imageline, zoomY0);
  252.  
  253.         src += rowLength;
  254.         y++;
  255.       }
  256.  
  257.       return GL_TRUE;
  258.     }
  259.       }
  260.       else {
  261.     /* write CI data to CI frame buffer */
  262.     if (!isZoom) {
  263.       MyWriteLUTPixelArray(src, 0, 0, rowLength * 1, rp, (ULONG *)((GLubyte *)amesa->ItoP - 1), FIXx(x), FIXy(y), width, height, CTABFMT_XRGB8);
  264.  
  265.       return GL_TRUE;
  266.     }
  267.     else {
  268.       /* with zooming */
  269.       return GL_FALSE;
  270.     }
  271.       }
  272.     }
  273.     else {
  274.       /* can't handle this pixel format and/or data type here */
  275.       return GL_FALSE;
  276.     }
  277.   }
  278.   else {
  279.     /* can't do direct render, have to use slow path */
  280.     return GL_FALSE;
  281.   }
  282. }
  283.  
  284. GLboolean cybDirectDrawPixelsDB(GLcontext *ctx,
  285.                                 GLint x, GLint y, GLsizei width, GLsizei height,
  286.                                 GLenum format, GLenum type,
  287.                                 const struct gl_pixelstore_attrib *unpack,
  288.                                 const GLvoid *pixels ) {
  289.   amigaMesaContext amesa;
  290.   GLuint *db;
  291.  
  292.   amesa = (amigaMesaContext) ctx->DriverCtx;
  293.   db = dbRGBA(dbRGBAGet(amesa), FIXx(x), FIXy(y));
  294.  
  295.   if ((ctx->RasterMask & (~(SCISSOR_BIT | WINCLIP_BIT))) == 0
  296.       && ctx->Pixel.RedBias == 0.0 && ctx->Pixel.RedScale == 1.0
  297.       && ctx->Pixel.GreenBias == 0.0 && ctx->Pixel.GreenScale == 1.0
  298.       && ctx->Pixel.BlueBias == 0.0 && ctx->Pixel.BlueScale == 1.0
  299.       && ctx->Pixel.AlphaBias == 0.0 && ctx->Pixel.AlphaScale == 1.0
  300.       && ctx->Pixel.IndexShift == 0 && ctx->Pixel.IndexOffset == 0
  301.       && ctx->Pixel.MapColorFlag == 0
  302.       && unpack->Alignment == 1
  303.       && !unpack->SwapBytes
  304.       && !unpack->LsbFirst) {
  305.     GLint skipSize;
  306.     GLint skipPixels = unpack->SkipPixels;
  307.     GLint skipRows = unpack->SkipRows;
  308.     GLint rowLength;
  309.     GLdepth zSpan[amesa->width];                        /* only used when zooming */
  310.     GLint zoomY0 = y;                                /* save Y value of first row */
  311.  
  312.     GLboolean isZoom = GL_FALSE;
  313.     if (ctx->Pixel.ZoomX == 1.0F && ctx->Pixel.ZoomY == 1.0F)
  314.       isZoom = GL_TRUE;
  315.  
  316.     if (unpack->RowLength > 0)
  317.       rowLength = unpack->RowLength;
  318.     else
  319.       rowLength = width;
  320.  
  321.     /* If we're not using pixel zoom then do all clipping calculations
  322.      * now.  Otherwise, we'll let the gl_write_zoomed_*_span() functions
  323.      * handle the clipping.
  324.      */
  325.     if (!isZoom) {
  326.       /* horizontal clipping */
  327.       if (x < ctx->Buffer->Xmin) {
  328.     skipPixels += (ctx->Buffer->Xmin - x);
  329.     width -= (ctx->Buffer->Xmin - x);
  330.     x = ctx->Buffer->Xmin;
  331.       }
  332.       if (x + width > ctx->Buffer->Xmax)
  333.     width -= (x + width - ctx->Buffer->Xmax - 1);
  334.       if (width <= 0)
  335.     return GL_TRUE;
  336.  
  337.       /* vertical clipping */
  338.       if (y < ctx->Buffer->Ymin) {
  339.     skipRows += (ctx->Buffer->Ymin - y);
  340.     height -= (ctx->Buffer->Ymin - y);
  341.     y = ctx->Buffer->Ymin;
  342.       }
  343.       if (y + height > ctx->Buffer->Ymax)
  344.     height -= (y + height - ctx->Buffer->Ymax - 1);
  345.       if (height <= 0)
  346.     return GL_TRUE;
  347.     }
  348.     else {
  349.       /* setup array of fragment Z value to pass to zoom function */
  350.       GLdepth z = (GLdepth) (ctx->Current.RasterPos[2] * DEPTH_SCALE);
  351.       GLint i;
  352.  
  353.       for (i = 0; i < width; i++)
  354.     zSpan[i] = z;
  355.     }
  356.  
  357.     /*
  358.      * Ready to draw!
  359.      * The window region at (x, y) of size (width, height)
  360.      * will be written to.
  361.      * We'll take pixel data from buffer pointed to by "pixels" but we'll
  362.      * skip "skipRows" rows and skip "skipPixels" pixels/row.
  363.      */
  364.     skipSize = (skipRows * rowLength + skipPixels);
  365.  
  366.     if (format == GL_RGBA && type == GL_UNSIGNED_BYTE) {
  367.       if (ctx->Visual->RGBAflag) {
  368.     GLubyte *src = (GLubyte *) pixels + skipSize * 4;
  369.  
  370.     if (!isZoom) {
  371.       /* no zooming */
  372.       while (--height >= 0) {
  373.         GLshort i = width;
  374.  
  375.         while (--i >= 0)
  376.           *db++ = *src++;
  377.  
  378.         src += rowLength * 4 - width * 4;
  379.         db += amesa->FixedWidth - width;
  380.       }
  381.     }
  382.     else {
  383.       /* with zooming */
  384.       while (--height >= 0) {
  385.         gl_write_zoomed_rgba_span(ctx, width, x, y, zSpan, (void *)src, zoomY0);
  386.  
  387.         src += rowLength * 4;
  388.         y++;
  389.       }
  390.     }
  391.       }
  392.       return GL_TRUE;
  393.     }
  394.     else if (format == GL_RGB && type == GL_UNSIGNED_BYTE) {
  395.       if (ctx->Visual->RGBAflag) {
  396.     GLubyte *src = (GLubyte *) pixels + skipSize * 3;
  397.  
  398.     if (!isZoom) {
  399.       /* no zooming */
  400.       while (--height >= 0) {
  401.         GLshort i = width;
  402.  
  403.         while (--i >= 0) {
  404.           *db++ = *((GLuint *)src);
  405.           src += 3;
  406.         }
  407.  
  408.         src += rowLength * 3 - width * 3;
  409.         db += amesa->FixedWidth - width;
  410.       }
  411.     }
  412.     else {
  413.       /* with zooming */
  414.       while (--height >= 0) {
  415.         gl_write_zoomed_rgb_span(ctx, width, x, y, zSpan, (void *)src, zoomY0);
  416.  
  417.         src += rowLength * 3;
  418.         y++;
  419.       }
  420.     }
  421.       }
  422.       return GL_TRUE;
  423.     }
  424.     else if (format == GL_LUMINANCE && type == GL_UNSIGNED_BYTE) {
  425.       if (ctx->Visual->RGBAflag) {
  426.     GLubyte *src = (GLubyte *) pixels + skipSize * 1;
  427.  
  428.     if (!isZoom) {
  429.       /* no zooming */
  430.       while (--height >= 0) {
  431.         GLshort i = width;
  432.  
  433.         while (--i >= 0) {
  434.           GLuint grey = *src++;
  435.           *db++ = ((((grey << 8) | grey) << 8) | grey) << 8;
  436.         }
  437.  
  438.         src += rowLength * 1 - width * 1;
  439.         db += amesa->FixedWidth - width;
  440.       }
  441.     }
  442.     else {
  443.       /* with zooming */
  444.       while (--height >= 0) {
  445.         GLshort i = width;
  446.         GLubyte *il = amesa->imageline;
  447.  
  448.         while (--i >= 0) {
  449.           GLushort pel = *src++;
  450.           *((GLushort *)il)++ = (pel << 8) | pel;
  451.           *il++ = pel;
  452.         }
  453.         gl_write_zoomed_rgb_span(ctx, width, x, y, zSpan, (void *)amesa->imageline, zoomY0);
  454.  
  455.         src += rowLength - width;
  456.         y++;
  457.       }
  458.     }
  459.       }
  460.       return GL_TRUE;
  461.     }
  462.     else if (format == GL_LUMINANCE_ALPHA && type == GL_UNSIGNED_BYTE) {
  463.       if (ctx->Visual->RGBAflag) {
  464.     GLubyte *src = (GLubyte *) pixels + skipSize * 2;
  465.  
  466.     if (!isZoom) {
  467.       /* no zooming */
  468.       while (--height >= 0) {
  469.         GLshort i = width;
  470.  
  471.         while (--i >= 0) {
  472.           GLuint grey = *src++;
  473.           *db++ = ((((grey << 8) | grey) << 8) | grey) << 8;
  474.           src++;
  475.         }
  476.  
  477.         src += rowLength * 2 - width * 2;
  478.         db += amesa->FixedWidth - width;
  479.       }
  480.     }
  481.     else {
  482.       /* with zooming */
  483.       while (--height >= 0) {
  484.         GLshort i = width;
  485.         GLuint *il = (GLuint *)amesa->imageline;
  486.  
  487.         while (--i >= 0) {
  488.           GLuint pel = *src++;
  489.           *il++ = ((((pel << 8) | pel) << 8) | pel) << 8 | *src++;
  490.         }
  491.         gl_write_zoomed_rgba_span(ctx, width, x, y, zSpan, (void *)amesa->imageline, zoomY0);
  492.  
  493.         src += rowLength * 2 - width * 2;
  494.         y++;
  495.       }
  496.     }
  497.       }
  498.  
  499.       return GL_TRUE;
  500.     }
  501.     else if (format == GL_COLOR_INDEX && type == GL_UNSIGNED_BYTE) {
  502.       GLubyte *src = (GLubyte *) pixels + skipSize * 1;
  503.  
  504.       if (ctx->Visual->RGBAflag) {
  505.     /* convert CI data to RGBA */
  506.     if (!isZoom) {
  507.       /* no zooming */
  508.       if (!ctx->Pixel.MapItoRsize &&
  509.           !ctx->Pixel.MapItoGsize &&
  510.           !ctx->Pixel.MapItoBsize) {
  511.         /* no masking */
  512.         GLshort i;
  513.         GLuint rgba[256];
  514.         const GLubyte *rMap = ctx->Pixel.MapItoR8;
  515.         const GLubyte *gMap = ctx->Pixel.MapItoG8;
  516.         const GLubyte *bMap = ctx->Pixel.MapItoB8;
  517.  
  518.         for (i = 256 - 1; i >= 0; i--)
  519.           rgba[i] = ((((rMap[i] << 8) | gMap[i]) << 8) | bMap[i]) << 8;
  520.  
  521.         while (--height >= 0) {
  522.           i = width;
  523.  
  524.           while (--i >= 0)
  525.             *db++ = rgba[*src++];
  526.  
  527.           src += rowLength * 1 - width * 1;
  528.           db += amesa->FixedWidth - width;
  529.         }
  530.       }
  531.       else {
  532.         /* with masking */
  533.         while (--height >= 0) {
  534.           GLshort i = width;
  535.           GLuint *il = (GLuint *)amesa->imageline;
  536.  
  537.           gl_map_ci8_to_rgba(ctx, width, src, il);                /* masks */
  538.           while (--i >= 0)
  539.             *db++ = *il++;
  540.  
  541.           src += rowLength;
  542.           db += amesa->FixedWidth - width;
  543.         }
  544.       }
  545.  
  546.       return GL_TRUE;
  547.     }
  548.     else {
  549.       /* with zooming */
  550.       while (--height >= 0) {
  551.         gl_map_ci8_to_rgba(ctx, width, src, amesa->imageline);            /* masks */
  552.         gl_write_zoomed_rgba_span(ctx, width, x, y, zSpan, (void *)amesa->imageline, zoomY0);
  553.         src += rowLength;
  554.         y++;
  555.       }
  556.  
  557.       return GL_TRUE;
  558.     }
  559.       }
  560.       else {
  561.     /* write CI data to CI frame buffer */
  562.     if (!isZoom) {
  563.       GLuint *rgba = amesa->ItoP;
  564.  
  565.       while (--height >= 0) {
  566.         GLshort i = width;
  567.  
  568.         while (--i >= 0)
  569.           *db++ = rgba[*src++];
  570.  
  571.         src += rowLength * 1 - width * 1;
  572.         db += amesa->FixedWidth - width;
  573.       }
  574.  
  575.       return GL_TRUE;
  576.     }
  577.     else {
  578.       /* with zooming */
  579.       return GL_FALSE;
  580.     }
  581.       }
  582.     }
  583.     else {
  584.       /* can't handle this pixel format and/or data type here */
  585.       return GL_FALSE;
  586.     }
  587.   }
  588.   else {
  589.     /* can't do direct render, have to use slow path */
  590.     return GL_FALSE;
  591.   }
  592. }
  593.