void NoRSX::ResizeBuffer(){ u32 TgtWidth = buffers[0].width; u32 TgtHeight = buffers[0].height; u32 *Target = buffers[currentBuffer].ptr; u32 *Source = buffer; if(TgtWidth == width && TgtHeight == height){ memcpy(Target, Source, TgtHeight*TgtWidth*sizeof(u32)); return; } int NumPixels = TgtHeight; int IntPart = (height / TgtHeight) * width; int FractPart = height % TgtHeight; int E = 0; u32 *PrevSource = NULL; while (NumPixels-- > 0) { if (Source == PrevSource) { memcpy(Target, Target-TgtWidth, TgtWidth*sizeof(*Target)); } else { ScaleLine(Target, Source, width, TgtWidth); PrevSource = Source; } Target += TgtWidth; Source += IntPart; E += FractPart; if (E >= (int)TgtHeight) { E -= TgtHeight; Source += width; } } return; }
bool MatrixInverse(const GzMatrix mat, GzMatrix result) { //use Gauss Jordan elimination float augment[4][8]; for(int i=0; i<4; i++) { for(int j=0; j<4; j++) { augment[i][j] = mat[i][j]; augment[i][j+4] = (i==j ? 1 : 0); } } for(int i=0; i< 4; i++) { //Scale int pivot=i; while(augment[pivot][i] == 0 && pivot <4) { pivot++; } if(pivot == 4) return false; SwapLine(augment, i, pivot); ScaleLine(augment, i, 1.0f/augment[i][i]); assert(abs(augment[i][i] - 1.0f) < 1e-6); //Eliminate for(int j=0; j<4; j++) { if(j == i) continue; AddLine(augment, j, i, -augment[j][i]); } } for(int i=0; i<4; i++) for(int j=0; j<4; j++) result[i][j] = augment[i][j+4]; return true; }
/* Uses variant of Bresenham algorithm. */ void PixBufBlitScaled(PixBufT *dstBuf, size_t x, size_t y, int w, int h, PixBufT *srcBuf) { ASSERT(srcBuf->mode == BLIT_NORMAL || srcBuf->mode == BLIT_TRANSPARENT, "Blit mode (%d) not supported.", srcBuf->mode); if (w && h) { const int du2 = 2 * srcBuf->width; const int dv2 = 2 * srcBuf->height; const int sy = sign(h) * dstBuf->width; const int dy = abs(h); uint8_t *src = srcBuf->data; uint8_t *dst = dstBuf->data; int error = dv2 - dy; dst += ((h > 0) ? (y) : (y - h - 1)) * dstBuf->width; dst += (w > 0) ? (x) : (x - w - 1); h = dy; do { ScaleLine(dst, src, w, du2, srcBuf->mode == BLIT_TRANSPARENT); while (error >= 0) { src += srcBuf->width; error -= 2 * dy; } dst += sy; error += dv2; } while (--h); } }