Index: [thread] [date] [subject] [author]
  From: teunis <teunis@computersupportcentre.com>
  To  : GGI Developers <ggi-develop@eskimo.com>
  Date: Fri, 19 Nov 1999 00:13:19 -0700 (MST)

Abuse patch

I couldn't upload it to GGI... where would I do that?  (permission
denied).  It'd be a bit silly to put it onto my geocities site:
http://www.geocities.com/Tokyo/Spa/1076
(or apparently http://www.geocities.com/winterlion :)

Anyways, any feedback (or patches :) would be most apreciated.  I'm just
taking a peek at writing a scaling-target...  growl.  Don't feel like it
right now - am hacking on an opengl-character editor!  (don't ask.  may
not get finished so...  but i'm basing on this really cool gtk-app called
'me3d' which unfortunately is based on an -old- gtk so first order is to
update :)

Anyone wanna write a simple one? :)  Go ahead and use the scaling code...
afaik it's public....  Just on principle I included it below:

incidentally, while the svgalib emu seems to work fine for visual stuff,
my keyboard has -never- worked.  When I load 'zgv' the only way to exit is
alt-sysrq-K.  *grr*.  That's why I made this patched abuse!

G'day, eh? :)
	- Teunis

Scaling code (clipped to protect the innocent/guilty :)
--- as in this code is unusable without additional stuff that happens to be
in the abuse patch-- but it's a start anyways :)

note:  predefined variables here:
extern unsigned int xres,yres;   /* set to 319,199 fwiw */
static const ggi_directbuffer  *sw_dbuf;
ggi_mode     sw_gmod;
ggi_visual_t sw_vis;
ggi_pixel    sw_pal[256];
	/* for nonworking bit... palette emu I'll leave to palemu! */

int sw_do_scale = FALSE;	/* TRUE if autoscale enabled */
void sw_calculateMaps(int srcWidth, int srcHeight,int dstWidth,int dstHeight);

then in init:
   sw_calculateMaps(source width, source height, dest width, dest height);


int* srcrows=NULL;
int* srccols=NULL;

void sw_calculateMaps(int srcWidth, int srcHeight,int destWidth,int destHeight)
  {
  srcrows = new int[destHeight + 1];
  for (int y = 0; y <= destHeight; y++)
     {
     srcrows[y] = (2 * y * srcHeight + srcHeight) / (2 * destHeight);
     }
  srccols = new int[destWidth + 1];
  for (int x = 0; x <= destWidth; x++)
     {
     srccols[x] = (2 * x * srcWidth + srcWidth) / (2 * destWidth);
     }
  };

void put_part(image *im, int x, int y, int x1, int y1, int x2, int y2)
{
  unsigned long screen_off;
  int ys,ye,         // ystart, yend
        xs,xe,      
        yy;
  unsigned char *line_addr;

  if (y>(int)yres || x>(int)xres) return ;
  CHECK(y1>=0 && y2>=y1 && x1>=0 && x2>=x1);

  if (y<0) { y1+=-y; y=0; }
  ys=y1;
  if (y+(y2-y1)>=(int)yres) 
       ye=(int)yres-y+y1-1;
  else ye=y2;

  if (x<0) { x1+=-x; x=0; }
  xs=x1;
  if (x+(x2-x1)>=(int)xres)
       xe=(int)xres-x+x1-1;
  else xe=x2;
  if (xs>xe || ys>ye) return ;

   if (sw_do_scale)
     {
	/* substitute 320,200 for source width,height */
	int sx, sy, dx;
	int dx1 = (2 * xs * sw_gmod.visible.x + 320 - 1) / (2 * 320);
	int dy1 = (2 * ys * sw_gmod.visible.y + 200 - 1) / (2 * 200);
	int dxe = (2 * ((xe-xs)+1) * sw_gmod.visible.x + 320 - 1) / (2 * 320);
	int adx = (2 * x  * sw_gmod.visible.x + 320 - 1) / (2 * 320);
	int ady = (2 * y  * sw_gmod.visible.y + 200 - 1) / (2 * 200);
	void* src;
	void* dest;
	if (sw_gmod.graphtype == GT_8BIT)
	  {
	     unsigned char* root = (unsigned char*) sw_dbuf->write;
	     root += sw_orig[ady];
	     for (int yy = dy1; (sy=srcrows[yy]) <= ye; yy++,root+=sw_orig[1])
	       {
		  src  = im->scan_line(sy);
		  dest = root + adx;
		  for (dx = 0; dx <= dxe; dx++)
		    { 
		       sx = srccols[dx+dx1];
		       ((unsigned char*)dest)[dx] = ((unsigned char*)src)[sx];
		    }
	       }
	  }
	else if ((sw_gmod.graphtype == GT_15BIT) ||
		 (sw_gmod.graphtype == GT_16BIT))
	  {
	     unsigned char* root = (unsigned char*) sw_dbuf->write;
	     root += sw_orig[ady];
	     for (int yy = dy1; (sy=srcrows[yy]) <= ye; yy++,root+=sw_orig[1])
	       {
		  src  = im->scan_line(sy);
		  dest = root + (adx<<1);
		  for (dx = 0; dx <= dxe; dx++)
		    { 
		       sx = srccols[dx+dx1];
		       ((unsigned short*)dest)[dx] = 
			 sw_pal[((unsigned char*)src)[sx]];
		    }
	       }
	  }
     }
   else
     {
	void* dest;
	int size;
	// find the memory offset for the scan line of interest
	screen_off=sw_orig[y];
	for (yy=ys;yy<=ye;yy++,screen_off+=sw_orig[1])
	  {
	     line_addr=im->scan_line(yy)+xs;  // get address of image scan line
	     dest = (unsigned char*)sw_dbuf->write + screen_off + x;
	     size = xe-xs+1;
	     memcpy(dest,line_addr,size);
	     y++; 
	  };
     };
   ggiFlush(sw_vis);
}


Index: [thread] [date] [subject] [author]