src/video/SDL_stretch.c
branchSDL-1.2
changeset 4541 abb56f7699ea
parent 4356 ab2dfac9d5c1
child 4543 d7cdc25af9a2
equal deleted inserted replaced
4540:e978b888d87a 4541:abb56f7699ea
    76 		int status;
    76 		int status;
    77 	} last;
    77 	} last;
    78 
    78 
    79 	int i;
    79 	int i;
    80 	int pos, inc;
    80 	int pos, inc;
    81 	unsigned char *eip;
    81 	unsigned char *eip, *end;
    82 	unsigned char load, store;
    82 	unsigned char load, store;
    83 
    83 
    84 	/* See if we need to regenerate the copy buffer */
    84 	/* See if we need to regenerate the copy buffer */
    85 	if ( (src_w == last.src_w) &&
    85 	if ( (src_w == last.src_w) &&
    86 	     (dst_w == last.dst_w) && (bpp == last.bpp) ) {
    86 	     (dst_w == last.dst_w) && (bpp == last.bpp) ) {
   113 	}
   113 	}
   114 #endif
   114 #endif
   115 	pos = 0x10000;
   115 	pos = 0x10000;
   116 	inc = (src_w << 16) / dst_w;
   116 	inc = (src_w << 16) / dst_w;
   117 	eip = copy_row;
   117 	eip = copy_row;
   118 	for ( i=0; i<dst_w; ++i ) {
   118 	end = copy_row+sizeof(copy_row);
       
   119 	for ( i=0; i<dst_w && eip < end; ++i ) {
   119 		while ( pos >= 0x10000L ) {
   120 		while ( pos >= 0x10000L ) {
   120 			if ( bpp == 2 ) {
   121 			if ( bpp == 2 ) {
   121 				*eip++ = PREFIX16;
   122 				*eip++ = PREFIX16;
   122 			}
   123 			}
   123 			*eip++ = load;
   124 			*eip++ = load;
   130 		pos += inc;
   131 		pos += inc;
   131 	}
   132 	}
   132 	*eip++ = RETURN;
   133 	*eip++ = RETURN;
   133 
   134 
   134 	/* Verify that we didn't overflow (too late!!!) */
   135 	/* Verify that we didn't overflow (too late!!!) */
   135 	if ( eip > (copy_row+sizeof(copy_row)) ) {
   136 	if ( i < dst_w ) {
   136 		SDL_SetError("Copy buffer overflow");
   137 		SDL_SetError("Copy buffer too small");
   137 		return(-1);
   138 		return(-1);
   138 	}
   139 	}
   139 #ifdef HAVE_MPROTECT
   140 #ifdef HAVE_MPROTECT
   140 	/* Make the code executable but not writeable */
   141 	/* Make the code executable but not writeable */
   141 	if ( mprotect(copy_row, sizeof(copy_row), PROT_READ|PROT_EXEC) < 0 ) {
   142 	if ( mprotect(copy_row, sizeof(copy_row), PROT_READ|PROT_EXEC) < 0 ) {