1 /**
2  ** gengiscl.c ---- generic, VERY SLOW getindexscanline routine
3  **
4  ** Copyright (c) 1998 Hartmut Schirmer
5  **
6  ** This file is part of the GRX graphics library.
7  **
8  ** The GRX graphics library is free software; you can redistribute it
9  ** and/or modify it under some conditions; see the "copying.grx" file
10  ** for details.
11  **
12  ** This library is distributed in the hope that it will be useful,
13  ** but WITHOUT ANY WARRANTY; without even the implied warranty of
14  ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
15  **
16  **/
17 
18 #include "libgrx.h"
19 #include "grdriver.h"
20 #include "allocate.h"
21 
22 /* will return an array of pixel values pv[] read from frame   */
23 /*    if indx == NULL: pv[i=0..w-1] = readpixel(x+i,y)         */
24 /*    else             pv[i=0..w-1] = readpixel(x+indx[i],y)   */
25 
_GrFrDrvGenericGetIndexedScanline(GrFrame * c,int x,int y,int w,int * indx)26 GrColor far *_GrFrDrvGenericGetIndexedScanline(GrFrame *c,
27 					       int x,int y,int w,
28 					       int *indx          )
29 {
30    GrColor far *pixels;
31    GrColor far *p;
32    GRX_ENTER();
33    DBGPRINTF(DBG_DRIVER,("x=%d, y=%d, w=%d\n",x,y,w));
34    p = pixels = _GrTempBufferAlloc(sizeof(GrColor) * (w+1));
35    if (pixels) {
36      _GR_readPix readpix = c->gf_driver->readpixel;
37      if (indx) {
38        int i, oldx = -1;
39        GrColor col = 0;
40        for (i=0; i < w; ++i) {
41 	 int xx = x+indx[i];
42 	 if (oldx != xx) {
43 	   oldx = xx;
44 	   col = (*readpix)(c,xx,y);
45 	 }
46 	 *(p++) = col;
47        }
48      } else {
49        for ( ; w > 0; --w)
50 	 *(p++) = (*readpix)(c,x++,y);
51      }
52    }
53    GRX_RETURN(pixels);
54 }
55