diff --git a/lib/objgfx40/objgfx40.cpp b/lib/objgfx40/objgfx40.cpp index 22ea7e5..8eddb5a 100644 --- a/lib/objgfx40/objgfx40.cpp +++ b/lib/objgfx40/objgfx40.cpp @@ -1,24 +1,23 @@ /******************************************************* -$Id: objgfx40.cpp 89 2016-01-12 00:20:40Z reddawg $ -*******************************************************/ + $Id: objgfx40.cpp 89 2016-01-12 00:20:40Z reddawg $ + *******************************************************/ #ifndef __UBIXOS_KERNEL__ extern "C" { - #include - #include - #include - #include - } +#include +#include +#include +#include +} #endif #ifdef __UBIXOS_KERNEL__ extern "C" { - #include - #include - #include - #include - //#include - } +#include +#include +#include +#include +} #define abs(a) (((a) < 0) ? -(a) : (a)) #endif @@ -28,153 +27,158 @@ #include #include -#ifdef __UBIXOS__ +#ifdef __UBIXOS_KERNEL__ #include #endif -const - uInt32 OG_MASKS[32] = { - 0, - 1, - 3, - 7, - 15, - 31, - 63, - 127, - 255, - 511, - 1023, - 2047, - 4095, - 8191, - 16383, - 32767, - 65535, - 131071, - 262143, - 524287, - 1048575, - 2097151, - 4194303, - 8388607, - 16777215, - 33554431, - 67108863, - 134217727, - 268435455, - 536870911, - 1073741823, - 2147483647 - }; // OG_MASKS[] +const +uint32_t OG_MASKS[32] = { + 0, + 1, + 3, + 7, + 15, + 31, + 63, + 127, + 255, + 511, + 1023, + 2047, + 4095, + 8191, + 16383, + 32767, + 65535, + 131071, + 262143, + 524287, + 1048575, + 2097151, + 4194303, + 8388607, + 16777215, + 33554431, + 67108863, + 134217727, + 268435455, + 536870911, + 1073741823, + 2147483647 +}; // OG_MASKS[] const - float INTENSITIES[32] = { - 1.0, // 0 - 0.984250984251, // 1 - 0.968245836552, // 2 - 0.951971638233, // 3 - 0.935414346693, // 4 - 0.938558653544, // 5 - 0.901387818866, // 6 - 0.883883476483, // 7 - 0.866025403784, // 8 - 0.847791247891, // 9 - 0.829156197589, // 10 - 0.810092587301, // 11 - 0.790569415042, // 12 - 0.770551750371, // 13 - 0.75, // 14 - 0.728868986856, // 15 - 0.707106781187, // 16 - 0.684653196881, // 17 - 0.661437827766, // 18 - 0.637377439199, // 19 - 0.612372435696, // 20 - 0.586301969978, // 21 - 0.559016994375, // 22 - 0.53033008589, // 23 - 0.5, // 24 - 0.467707173347, // 25 - 0.433012701892, // 26 - 0.395284707521, // 27 - 0.353553390593, // 28 - 0.306186217848, // 29 - 0.25, // 30 - 0.176776695297 // 31 - }; // INTENSITIES[] +float INTENSITIES[32] = { + 1.0, // 0 + 0.984250984251,// 1 + 0.968245836552,// 2 + 0.951971638233,// 3 + 0.935414346693,// 4 + 0.938558653544,// 5 + 0.901387818866,// 6 + 0.883883476483,// 7 + 0.866025403784,// 8 + 0.847791247891,// 9 + 0.829156197589,// 10 + 0.810092587301,// 11 + 0.790569415042,// 12 + 0.770551750371,// 13 + 0.75,// 14 + 0.728868986856,// 15 + 0.707106781187,// 16 + 0.684653196881,// 17 + 0.661437827766,// 18 + 0.637377439199,// 19 + 0.612372435696,// 20 + 0.586301969978,// 21 + 0.559016994375,// 22 + 0.53033008589,// 23 + 0.5 ,// 24 + 0.467707173347,// 25 + 0.433012701892,// 26 + 0.395284707521,// 27 + 0.353553390593,// 28 + 0.306186217848,// 29 + 0.25,// 30 + 0.176776695297// 31 +}; // INTENSITIES[] // #include "../ubixos-home/src/sys/include/ubixos/types.h" -// #define ROUND(f) (int)((f) + ((f) > 0 ? 0.5 : -0.5)) +// #define ROUND(f) (int +)((f) + ((f) > 0 ? 0.5 : -0.5)) struct ogHLine { - int32 xStart; - int32 xEnd; + int32 xStart; + int32 xEnd; }; struct ogHLineList { - int32 length; - int32 yStart; - int32 * xLeft; - int32 * xRight; + int32 length; + int32 yStart; + int32 * xLeft; + int32 * xRight; }; struct ogPointListHeader { - int32 length; - ogPoint2d * PointPtr; + int32 length; + ogPoint2d * PointPtr; }; struct ogEdgeState { - ogEdgeState* nextEdge; - int32 x; - int32 startY; - int32 wholePixelXMove; - int32 xDirection; - int32 errorTerm; - int32 errorTermAdjUp; - int32 errorTermAdjDown; - int32 count; - ogRGBA8 colour; - int32 rStepY; - int32 gStepY; - int32 bStepY; - int32 aStepY; - int32 rIncY; - int32 gIncY; - int32 bIncY; - int32 aIncY; + ogEdgeState* nextEdge; + int32 x; + int32 startY; + int32 wholePixelXMove; + int32 xDirection; + int32 errorTerm; + int32 errorTermAdjUp; + int32 errorTermAdjDown; + int32 count; + ogRGBA8 colour; + int32 rStepY; + int32 gStepY; + int32 bStepY; + int32 aStepY; + int32 rIncY; + int32 gIncY; + int32 bIncY; + int32 aIncY; }; class ogEdgeTable { - public: - ogEdgeState * globalEdges; - ogEdgeState * activeEdges; - ogEdgeTable(void) { globalEdges = activeEdges = NULL; return; } - void AdvanceAET(void); - void BuildGET(uInt32 numPoints, ogPoint2d * polyPoints); - void BuildGET_G(uInt32 numPoints, ogPoint2d * polyPoints, ogRGBA8 * colours); - void MoveXSortedToAET(int32 yToMove); - void ScanOutAET(ogSurface & destObject, int32 yToScan, uInt32 colour); - void ScanOutAET_G(ogSurface & destObject, int32 yToScan); - void XSortAET(void); - ~ogEdgeTable(void); -}; // ogEdgeState + public: + ogEdgeState * globalEdges; + ogEdgeState * activeEdges; + ogEdgeTable(void) { + globalEdges = activeEdges = NULL; + return; + } + void AdvanceAET(void); + void BuildGET(uInt32 numPoints, ogPoint2d * polyPoints); + void BuildGET_G(uInt32 numPoints, ogPoint2d * polyPoints, ogRGBA8 * colours); + void MoveXSortedToAET(int32 yToMove); + void ScanOutAET(ogSurface & destObject, int32 yToScan, uInt32 colour); + void ScanOutAET_G(ogSurface & destObject, int32 yToScan); + void XSortAET(void); + ~ogEdgeTable(void); +}; +// ogEdgeState -void -ogEdgeTable::AdvanceAET(void) { - ogEdgeState * currentEdge; +void ogEdgeTable::AdvanceAET(void) { + ogEdgeState * currentEdge; ogEdgeState ** currentEdgePtr; currentEdgePtr = &activeEdges; currentEdge = activeEdges; - while (currentEdge!=NULL) { + while (currentEdge != NULL) { --currentEdge->count; if (currentEdge->count == 0) { // this edge is finished, so remove it from the AET *currentEdgePtr = currentEdge->nextEdge; // I'm thinking I should dispose currentEdge here!? - } else { + } + else { // advance the edge's x coord by minimum move currentEdge->x += currentEdge->wholePixelXMove; // determine whether it's time for X to advance one extra @@ -190,63 +194,63 @@ return; } // ogEdgeTable::AdvanceAET -void -ogEdgeTable::BuildGET(uInt32 numPoints, ogPoint2d * polyPoints) { +void ogEdgeTable::BuildGET(uInt32 numPoints, ogPoint2d * polyPoints) { int32 i, x1, y1, x2, y2, deltaX, deltaY, width, tmp; - ogEdgeState * newEdgePtr; - ogEdgeState * followingEdge; + ogEdgeState * newEdgePtr; + ogEdgeState * followingEdge; ogEdgeState ** followingEdgeLink; - - /* - * Creates a GET in the buffer pointed to by NextFreeEdgeStruc from - * the vertex list. Edge endpoints are flipped, if necessary, to - * guarantee all edges go top to bottom. The GET is sorted primarily - * by ascending Y start coordinate, and secondarily by ascending X - * start coordinate within edges with common Y coordinates } - */ + + /* + * Creates a GET in the buffer pointed to by NextFreeEdgeStruc from + * the vertex list. Edge endpoints are flipped, if necessary, to + * guarantee all edges go top to bottom. The GET is sorted primarily + * by ascending Y start coordinate, and secondarily by ascending X + * start coordinate within edges with common Y coordinates } + */ // Scan through the vertex list and put all non-0-height edges into // the GET, sorted by increasing Y start coordinate} - - for (i = 0; i < (int32)numPoints; i++) { + for (i = 0; i < (int32) numPoints; i++) { // calculate the edge height and width x1 = polyPoints[i].x; y1 = polyPoints[i].y; if (0 == i) { // wrap back around to the end of the list - x2 = polyPoints[numPoints-1].x; - y2 = polyPoints[numPoints-1].y; - } else { - x2 = polyPoints[i-1].x; - y2 = polyPoints[i-1].y; + x2 = polyPoints[numPoints - 1].x; + y2 = polyPoints[numPoints - 1].y; + } + else { + x2 = polyPoints[i - 1].x; + y2 = polyPoints[i - 1].y; } // else i!=0 if (y1 > y2) { tmp = x1; - x1 = x2; - x2 = tmp; + x1 = x2; + x2 = tmp; tmp = y1; - y1 = y2; - y2 = tmp; + y1 = y2; + y2 = tmp; } // if y1>y2 // skip if this can't ever be an active edge (has 0 height) - deltaY = y2-y1; + deltaY = y2 - y1; if (deltaY != 0) { newEdgePtr = new ogEdgeState; - newEdgePtr->xDirection = ((deltaX = x2-x1) > 0) ? 1 : -1; + newEdgePtr->xDirection = ((deltaX = x2 - x1) > 0) ? 1 : -1; width = abs(deltaX); newEdgePtr->x = x1; newEdgePtr->startY = y1; newEdgePtr->count = newEdgePtr->errorTermAdjDown = deltaY; - newEdgePtr->errorTerm = (deltaX >= 0) ? 0 : 1-deltaY; + newEdgePtr->errorTerm = (deltaX >= 0) ? 0 : 1 - deltaY; if (deltaY >= width) { newEdgePtr->wholePixelXMove = 0; newEdgePtr->errorTermAdjUp = width; - } else { + } + else { newEdgePtr->wholePixelXMove = (width / deltaY) * newEdgePtr->xDirection; newEdgePtr->errorTermAdjUp = width % deltaY; } // else @@ -254,10 +258,7 @@ followingEdgeLink = &globalEdges; while (true) { followingEdge = *followingEdgeLink; - if ((followingEdge == NULL) || - (followingEdge->startY > y1) || - ((followingEdge->startY == y1) && - (followingEdge->x>=x1))) { + if ((followingEdge == NULL) || (followingEdge->startY > y1) || ((followingEdge->startY == y1) && (followingEdge->x >= x1))) { newEdgePtr->nextEdge = followingEdge; *followingEdgeLink = newEdgePtr; break; @@ -269,27 +270,25 @@ return; } // ogEdgeTable::BuildGET -void -ogEdgeTable::BuildGET_G(uInt32 numPoints, ogPoint2d * polyPoints, ogRGBA8 * colours) { +void ogEdgeTable::BuildGET_G(uInt32 numPoints, ogPoint2d * polyPoints, ogRGBA8 * colours) { int32 i, x1, y1, x2, y2, deltaX, deltaY, width, tmp; - ogEdgeState * newEdgePtr; - ogEdgeState * followingEdge; + ogEdgeState * newEdgePtr; + ogEdgeState * followingEdge; ogEdgeState ** followingEdgeLink; ogRGBA8 c1, c2, cTmp; - /* - * Creates a GET in the buffer pointed to by NextFreeEdgeStruc from - * the vertex list. Edge endpoints are flipped, if necessary, to - * guarantee all edges go top to bottom. The GET is sorted primarily - * by ascending Y start coordinate, and secondarily by ascending X - * start coordinate within edges with common Y coordinates } - */ + /* + * Creates a GET in the buffer pointed to by NextFreeEdgeStruc from + * the vertex list. Edge endpoints are flipped, if necessary, to + * guarantee all edges go top to bottom. The GET is sorted primarily + * by ascending Y start coordinate, and secondarily by ascending X + * start coordinate within edges with common Y coordinates } + */ // Scan through the vertex list and put all non-0-height edges into // the GET, sorted by increasing Y start coordinate} - - for (i = 0; i < (int32)numPoints; i++) { + for (i = 0; i < (int32) numPoints; i++) { // calculate the edge height and width x1 = polyPoints[i].x; y1 = polyPoints[i].y; @@ -297,54 +296,56 @@ if (0 == i) { // wrap back around to the end of the list - x2 = polyPoints[numPoints-1].x; - y2 = polyPoints[numPoints-1].y; - c2 = colours[numPoints-1]; - } else { - x2 = polyPoints[i-1].x; - y2 = polyPoints[i-1].y; - c2 = colours[i-1]; + x2 = polyPoints[numPoints - 1].x; + y2 = polyPoints[numPoints - 1].y; + c2 = colours[numPoints - 1]; + } + else { + x2 = polyPoints[i - 1].x; + y2 = polyPoints[i - 1].y; + c2 = colours[i - 1]; } // else i!=0 if (y1 > y2) { tmp = x1; - x1 = x2; - x2 = tmp; - + x1 = x2; + x2 = tmp; + tmp = y1; - y1 = y2; - y2 = tmp; - + y1 = y2; + y2 = tmp; + cTmp = c1; c1 = c2; c2 = cTmp; } // if y1>y2 // skip if this can't ever be an active edge (has 0 height) - deltaY = y2-y1; + deltaY = y2 - y1; if (deltaY != 0) { newEdgePtr = new ogEdgeState; newEdgePtr->colour = c1; - newEdgePtr->xDirection = ((deltaX = x2-x1) > 0) ? 1 : -1; + newEdgePtr->xDirection = ((deltaX = x2 - x1) > 0) ? 1 : -1; - newEdgePtr -> rStepY = ((c2.red - c1.red +1) << 16) / deltaY; - newEdgePtr -> gStepY = ((c2.green - c1.green +1) << 16) / deltaY; - newEdgePtr -> bStepY = ((c2.blue - c1.blue +1) << 16) / deltaY; - newEdgePtr -> aStepY = ((c2.alpha - c1.alpha +1) << 16) / deltaY; + newEdgePtr->rStepY = ((c2.red - c1.red + 1) << 16) / deltaY; + newEdgePtr->gStepY = ((c2.green - c1.green + 1) << 16) / deltaY; + newEdgePtr->bStepY = ((c2.blue - c1.blue + 1) << 16) / deltaY; + newEdgePtr->aStepY = ((c2.alpha - c1.alpha + 1) << 16) / deltaY; - newEdgePtr -> rIncY = newEdgePtr -> gIncY = 0; - newEdgePtr -> bIncY = newEdgePtr -> aIncY = 0; + newEdgePtr->rIncY = newEdgePtr->gIncY = 0; + newEdgePtr->bIncY = newEdgePtr->aIncY = 0; width = abs(deltaX); newEdgePtr->x = x1; newEdgePtr->startY = y1; newEdgePtr->count = newEdgePtr->errorTermAdjDown = deltaY; - newEdgePtr->errorTerm = (deltaX >= 0) ? 0 : 1-deltaY; + newEdgePtr->errorTerm = (deltaX >= 0) ? 0 : 1 - deltaY; if (deltaY >= width) { newEdgePtr->wholePixelXMove = 0; newEdgePtr->errorTermAdjUp = width; - } else { + } + else { newEdgePtr->wholePixelXMove = (width / deltaY) * newEdgePtr->xDirection; newEdgePtr->errorTermAdjUp = width % deltaY; } // else @@ -352,10 +353,7 @@ followingEdgeLink = &globalEdges; while (true) { followingEdge = *followingEdgeLink; - if ((followingEdge == NULL) || - (followingEdge->startY > y1) || - ((followingEdge->startY == y1) && - (followingEdge->x >= x1))) { + if ((followingEdge == NULL) || (followingEdge->startY > y1) || ((followingEdge->startY == y1) && (followingEdge->x >= x1))) { newEdgePtr->nextEdge = followingEdge; *followingEdgeLink = newEdgePtr; break; @@ -367,12 +365,11 @@ return; } // ogEdgeTable::BuildGET_G -void -ogEdgeTable::MoveXSortedToAET(int32 yToMove) { - ogEdgeState * AETEdge; - ogEdgeState * tempEdge; +void ogEdgeTable::MoveXSortedToAET(int32 yToMove) { + ogEdgeState * AETEdge; + ogEdgeState * tempEdge; ogEdgeState ** AETEdgePtr; - int32 currentX; + int32 currentX; /* The GET is Y sorted. Any edges that start at the desired Y * coordinate will be first in the GET, so we'll move edges from @@ -396,14 +393,15 @@ AETEdgePtr = &globalEdges->nextEdge; globalEdges = tempEdge; break; - } else AETEdgePtr = &AETEdge->nextEdge; + } + else + AETEdgePtr = &AETEdge->nextEdge; } // while true } // while globalEdges!=NULL and globalEdges->startY==yToMove return; } // ogEdgeTable::MoveXSortedToAET -void -ogEdgeTable::ScanOutAET(ogSurface & destObject, int32 yToScan, uInt32 colour) { +void ogEdgeTable::ScanOutAET(ogSurface & destObject, int32 yToScan, uInt32 colour) { ogEdgeState * currentEdge; int32 leftX; @@ -420,7 +418,7 @@ if (currentEdge != NULL) { if (currentEdge->x > leftX) - destObject.ogHLine(leftX, currentEdge->x-1, yToScan, colour); + destObject.ogHLine(leftX, currentEdge->x - 1, yToScan, colour); currentEdge = currentEdge->nextEdge; } // if currentEdge != NULL } // while @@ -428,8 +426,7 @@ return; } // ogEdgeTable::ScanOutAET -void -ogEdgeTable::ScanOutAET_G(ogSurface & destObject, int32 yToScan) { +void ogEdgeTable::ScanOutAET_G(ogSurface & destObject, int32 yToScan) { ogEdgeState * currentEdge; int32 leftX, count; int32 rStepX, gStepX, bStepX, aStepX; @@ -464,7 +461,6 @@ currentEdge->bIncY += currentEdge->bStepY; currentEdge->aIncY += currentEdge->aStepY; - currentEdge = currentEdge->nextEdge; if (currentEdge != NULL) { @@ -498,11 +494,7 @@ rIncX = gIncX = bIncX = aIncX = 0; for (count = leftX; count < currentEdge->x; count++) { - destObject.ogSetPixel(count, yToScan, - lR + (rIncX >> 16), - lG + (gIncX >> 16), - lB + (bIncX >> 16), - lA + (aIncX >> 16) ); + destObject.ogSetPixel(count, yToScan, lR + (rIncX >> 16), lG + (gIncX >> 16), lB + (bIncX >> 16), lA + (aIncX >> 16)); rIncX += rStepX; gIncX += gStepX; bIncX += bStepX; @@ -512,18 +504,18 @@ currentEdge = currentEdge->nextEdge; } // if currentEdge != NULL } // while - + return; } // ogEdgeTable::ScanOutAET_G -void -ogEdgeTable::XSortAET(void) { - ogEdgeState * currentEdge; - ogEdgeState * tempEdge; +void ogEdgeTable::XSortAET(void) { + ogEdgeState * currentEdge; + ogEdgeState * tempEdge; ogEdgeState ** currentEdgePtr; bool swapOccurred; - if (activeEdges == NULL) return; + if (activeEdges == NULL) + return; do { swapOccurred = false; @@ -567,15 +559,13 @@ return; } // ogEdgeTable::~ogEdgeTable -static bool -fileExists(const char *file) -{ +static bool fileExists(const char *file) { #ifdef __UBIXOS_KERNEL__ fileDescriptor *f = fopen(file, "rb"); #else FILE *f = fopen(file, "rb"); #endif - + if (!f) return false; fclose(f); @@ -586,64 +576,69 @@ // ogSurface constructor ogSurface::ogSurface(void) { - version = ogVERSION; + version = ogVERSION + ; - dataState = ogNone; - buffer = NULL; - lineOfs = NULL; - pal = NULL; - attributes = NULL; - xRes = 0; - yRes = 0; - maxX = 0; - maxY = 0; - bSize = 0; - lSize = 0; - BPP = 0; - bytesPerPix = 0; - pixFmtID = 0; - redShifter = 0; + dataState = ogNone; + buffer = NULL; + lineOfs = NULL; + pal = NULL; + attributes = NULL; + xRes = 0; + yRes = 0; + maxX = 0; + maxY = 0; + bSize = 0; + lSize = 0; + BPP = 0; + bytesPerPix = 0; + pixFmtID = 0; + redShifter = 0; greenShifter = 0; - blueShifter = 0; + blueShifter = 0; alphaShifter = 0; - redFieldPosition = 0; + redFieldPosition = 0; greenFieldPosition = 0; - blueFieldPosition = 0; + blueFieldPosition = 0; alphaFieldPosition = 0; alphaMasker = 0; lastError = ogOK; return; } // ogSurface::ogSurface -void -ogSurface::AARawLine(uInt32 x1, uInt32 y1, uInt32 x2, uInt32 y2, uInt32 colour) { - /* - * aaRawLine - * - * private method - * - * draws an unclipped anti-aliased line from (x1,y1) to (x2,y2) using colour - * - */ +void ogSurface::AARawLine(uInt32 x1, uInt32 y1, uInt32 x2, uInt32 y2, uInt32 colour) { + /* + * aaRawLine + * + * private method + * + * draws an unclipped anti-aliased line from (x1,y1) to (x2,y2) using colour + * + */ uInt32 erradj, erracc; uInt32 erracctmp, intshift, wgt, wgtCompMask; - int32 dx, dy, tmp, xDir, i; + int32 dx, dy, tmp, xDir, i; uInt8 r, g, b, a; uInt32 alphas[32]; bool oldBlending; if (y1 > y2) { - tmp= y1; + tmp = y1; y1 = y2; y2 = tmp; - - tmp= x1; + + tmp = x1; x1 = x2; x2 = tmp; } // if - - dx = (x2-x1); - if (dx >= 0) xDir=1; else { dx = -dx; xDir=-1; } + + dx = (x2 - x1); + if (dx >= 0) + xDir = 1; + else { + dx = -dx; + xDir = -1; + } // dx = abs(dx); dy = (y2 - y1); @@ -659,17 +654,18 @@ ogUnpack(colour, r, g, b, a); - if (!ogIsBlending()) a = 255; + if (!ogIsBlending()) + a = 255; for (i = 0; i < 32; i++) { - alphas[i] = static_cast(INTENSITIES[i]*a + 0.5f); + alphas[i] = static_cast(INTENSITIES[i] * a + 0.5f); } // for oldBlending = ogSetBlending(true); RawSetPixel(x1, y1, r, g, b, a); - // this is incomplete.. diagonal lines don't travel through the + // this is incomplete.. diagonal lines don't travel through the // center of pixels exactly do { @@ -684,17 +680,17 @@ } // if dx==dy erracc = 0; - intshift = 32-5; + intshift = 32 - 5; wgt = 12; wgtCompMask = 31; if (dy > dx) { /* y-major. Calculate 32-bit fixed point fractional part of a pixel that * X advances every time Y advances 1 pixel, truncating the result so that - * we won't overrun the endpoint along the X axis + * we won't overrun the endpoint along the X axis */ // erradj = ((uInt64) dx << 32) / (uInt64)dy; - __asm__ __volatile__ ( + __asm__ __volatile__ ( " xor %%eax, %%eax \n" " div %1 \n" " mov %%eax, %2 \n" @@ -705,25 +701,27 @@ while (--dy) { erracctmp = erracc; erracc += erradj; - if (erracc <= erracctmp) x1 += xDir; + if (erracc <= erracctmp) + x1 += xDir; y1++; // y-major so always advance Y /* the nbits most significant bits of erracc give us the intensity * weighting for this pixel, and the complement of the weighting for - * the paired pixel. + * the paired pixel. */ wgt = erracc >> intshift; ogSetPixel(x1, y1, r, g, b, alphas[wgt]); - ogSetPixel(x1+xDir, y1, r, g, b, alphas[wgt ^ wgtCompMask]); + ogSetPixel(x1 + xDir, y1, r, g, b, alphas[wgt ^ wgtCompMask]); } // while - - } else { + + } + else { /* x-major line. Calculate 32-bit fixed-point fractional part of a pixel * that Y advances each time X advances 1 pixel, truncating the result so - * that we won't overrun the endpoint along the X axis. + * that we won't overrun the endpoint along the X axis. */ // erradj = ((uInt64)dy << 32) / (uInt64)dx; - __asm__ __volatile__ ( + __asm__ __volatile__ ( " xor %%eax, %%eax \n" " div %1 \n" " mov %%eax, %2 \n" @@ -731,19 +729,20 @@ : "d" (dy), "b" (dx), "m" (erradj) ); - // draw all pixels other than the first and last + // draw all pixels other than the first and last while (--dx) { erracctmp = erracc; erracc += erradj; - if (erracc <= erracctmp) y1++; + if (erracc <= erracctmp) + y1++; x1 += xDir; // x-major so always advance X /* the nbits most significant bits of erracc give us the intensity * weighting for this pixel, and the complement of the weighting for - * the paired pixel. + * the paired pixel. */ wgt = erracc >> intshift; ogSetPixel(x1, y1, r, g, b, alphas[wgt]); - ogSetPixel(x1, y1+1, r, g, b, alphas[wgt ^ wgtCompMask]); + ogSetPixel(x1, y1 + 1, r, g, b, alphas[wgt ^ wgtCompMask]); } // while } // else RawSetPixel(x2, y2, r, g, b, alphas[wgt]); @@ -754,69 +753,67 @@ return; } // ogSurface::AARawLine -uInt32 -ogSurface::RawGetPixel(uInt32 x, uInt32 y) { +uInt32 ogSurface::RawGetPixel(uInt32 x, uInt32 y) { uInt32 result; switch (bytesPerPix) { - case 4: - __asm__ __volatile__( - " shl $2, %%ecx \n" // shl ecx, 2 {adjust for pixel size} - " add %%esi, %%edi \n" // add edi, esi - " add %%ecx, %%edi \n" // add edi, ecx - " mov (%%edi),%%eax \n" // eax,word ptr [edi] - " mov %%eax, %3 \n" // mov result, eax - : - : "D" (buffer), "S" (lineOfs[y]), // %0, %1 - "c" (x), "m" (result) // %2, %3 - ); + case 4: + __asm__ __volatile__( + " shl $2, %%ecx \n" // shl ecx, 2 {adjust for pixel size} + " add %%esi, %%edi \n"// add edi, esi + " add %%ecx, %%edi \n"// add edi, ecx + " mov (%%edi),%%eax \n"// eax,word ptr [edi] + " mov %%eax, %3 \n"// mov result, eax + : + : "D" (buffer), "S" (lineOfs[y]),// %0, %1 + "c" (x), "m" (result)// %2, %3 + ); break; - case 3: - __asm__ __volatile__( - " mov %%ecx, %%eax \n" // mov eax, ecx - adjust for pixel size - " add %%ecx, %%ecx \n" // add ecx, ecx - adjust for pixel size - " add %%eax, %%ecx \n" // add ecx, eax - adjust for pixel size - " add %%esi, %%edi \n" // add edi, esi - " add %%ecx, %%edi \n" // add edi, ecx - " movzwl (%%edi),%%eax \n" // edx,word ptr [edi] - " xor %%eax, %%eax \n" - " mov 2(%%edi), %%al \n" // mov al, [edi+2] - " shl $16, %%eax \n" // shl eax, 16 - " mov (%%edi), %%ax \n" // mov ax, [edi] - " mov %%eax, %3 \n" // mov result, eax - : - : "D" (buffer), "S" (lineOfs[y]), // %0, %1 - "c" (x), "m" (result) // %2, %3 - ); + case 3: + __asm__ __volatile__( + " mov %%ecx, %%eax \n" // mov eax, ecx - adjust for pixel size + " add %%ecx, %%ecx \n"// add ecx, ecx - adjust for pixel size + " add %%eax, %%ecx \n"// add ecx, eax - adjust for pixel size + " add %%esi, %%edi \n"// add edi, esi + " add %%ecx, %%edi \n"// add edi, ecx + " movzwl (%%edi),%%eax \n"// edx,word ptr [edi] + " xor %%eax, %%eax \n" + " mov 2(%%edi), %%al \n"// mov al, [edi+2] + " shl $16, %%eax \n"// shl eax, 16 + " mov (%%edi), %%ax \n"// mov ax, [edi] + " mov %%eax, %3 \n"// mov result, eax + : + : "D" (buffer), "S" (lineOfs[y]),// %0, %1 + "c" (x), "m" (result)// %2, %3 + ); break; - case 2: - __asm__ __volatile__( - " add %%esi, %%edi \n" // add edi, esi - " add %%ecx, %%ecx \n" // add ecx, ecx {adjust for pixel size} - " add %%ecx, %%edi \n" // add edi, ecx - " movzwl (%%edi),%%eax \n" // movzx edx,word ptr [edi] - " mov %%eax, %0 \n" // mov result, eax - : "=m" (result) - : "D" (buffer), "S" (lineOfs[y]), // %0, %1 - "c" (x) // , "m" (result) // %2, %3 - ); + case 2: + __asm__ __volatile__( + " add %%esi, %%edi \n" // add edi, esi + " add %%ecx, %%ecx \n"// add ecx, ecx {adjust for pixel size} + " add %%ecx, %%edi \n"// add edi, ecx + " movzwl (%%edi),%%eax \n"// movzx edx,word ptr [edi] + " mov %%eax, %0 \n"// mov result, eax + : "=m" (result) + : "D" (buffer), "S" (lineOfs[y]),// %0, %1 + "c" (x)// , "m" (result) // %2, %3 + ); break; - case 1: - __asm__ __volatile__( - " add %%esi, %%edi \n" // add edi, esi - " add %%ecx, %%edi \n" // add edi, ecx - " movzbl (%%edi),%%eax \n" // movzx edx,byte ptr [edi] - " mov %%eax, %3 \n" // mov result, eax - : - : "D" (buffer), "S" (lineOfs[y]), // %0, %1 - "c" (x), "m" (result) // %2, %3 - ); + case 1: + __asm__ __volatile__( + " add %%esi, %%edi \n" // add edi, esi + " add %%ecx, %%edi \n"// add edi, ecx + " movzbl (%%edi),%%eax \n"// movzx edx,byte ptr [edi] + " mov %%eax, %3 \n"// mov result, eax + : + : "D" (buffer), "S" (lineOfs[y]),// %0, %1 + "c" (x), "m" (result)// %2, %3 + ); break; } // switch return result; } // ogSurface::RawGetPixel -void -ogSurface::RawSetPixel(uInt32 x, uInt32 y, uInt32 colour) { +void ogSurface::RawSetPixel(uInt32 x, uInt32 y, uInt32 colour) { uInt32 newR, newG, newB, inverseA; uInt8 sR, sG, sB, sA; uInt8 dR, dG, dB; @@ -824,8 +821,10 @@ do { if (ogIsBlending()) { ogUnpack(colour, sR, sG, sB, sA); - if (sA == 0) return; - if (sA == 255) break; + if (sA == 0) + return; + if (sA == 255) + break; inverseA = 255 - sA; ogUnpack(RawGetPixel(x, y), dR, dG, dB); newR = (dR * inverseA + sR * sA) >> 8; @@ -836,74 +835,74 @@ } while (false); switch (bytesPerPix) { - case 4: - __asm__ __volatile__( - // { Calculate offset, prepare the pixel to be drawn } - " shl $2, %%ecx \n" // shl eax, 2 {adjust for pixel size} - " add %%esi, %%edi \n" // add edi, esi - " add %%ecx, %%edi \n" // add edi, ecx - // { Draw the pixel } - " mov %%eax, (%%edi) \n" // mov [edi], eax + case 4: + __asm__ __volatile__( + // { Calculate offset, prepare the pixel to be drawn } + " shl $2, %%ecx \n"// shl eax, 2 {adjust for pixel size} + " add %%esi, %%edi \n"// add edi, esi + " add %%ecx, %%edi \n"// add edi, ecx + // { Draw the pixel } + " mov %%eax, (%%edi) \n"// mov [edi], eax : - : "D" (buffer), "S" (lineOfs[y]), // %0, %1 - "c" (x), "a" (colour) // %2, %3 - ); + : "D" (buffer), "S" (lineOfs[y]),// %0, %1 + "c" (x), "a" (colour)// %2, %3 + ); break; - case 3: - __asm__ __volatile__( - // Calculate offset, prepare the pixel to be drawn - " leal (%%ecx, %%ecx, 2), %%ecx \n" // lea ecx, [ecx + ecx*2] - " add %%esi, %%edi \n" // add edi, esi - " add %%ecx, %%edi \n" // add edi, ecx - // { Draw the pixel } - " mov %%ax, (%%edi) \n" // mov [edi], ax - " shr $16, %%eax \n" // shr eax, 16 - " mov %%al, 2(%%edi)\n" // mov [edi+2],al + case 3: + __asm__ __volatile__( + // Calculate offset, prepare the pixel to be drawn + " leal (%%ecx, %%ecx, 2), %%ecx \n"// lea ecx, [ecx + ecx*2] + " add %%esi, %%edi \n"// add edi, esi + " add %%ecx, %%edi \n"// add edi, ecx + // { Draw the pixel } + " mov %%ax, (%%edi) \n"// mov [edi], ax + " shr $16, %%eax \n"// shr eax, 16 + " mov %%al, 2(%%edi)\n"// mov [edi+2],al : - : "D" (buffer), "S" (lineOfs[y]), // %0, %1 - "c" (x), "a" (colour) // %2, %3 - ); + : "D" (buffer), "S" (lineOfs[y]),// %0, %1 + "c" (x), "a" (colour)// %2, %3 + ); break; - case 2: - __asm__ __volatile__( - // { Calculate offset, prepare the pixel to be drawn } - " add %%ecx, %%ecx \n" // add ecx, ecx {adjust for pixel size} - " add %%esi, %%edi \n" // add edi, esi - // " mov %3, %%eax \n" // mov eax, colour - " add %%ecx, %%edi \n" // add edi, ecx - // { Draw the pixel } - " mov %%ax, (%%edi) \n" // mov [edi], ax + case 2: + __asm__ __volatile__( + // { Calculate offset, prepare the pixel to be drawn } + " add %%ecx, %%ecx \n"// add ecx, ecx {adjust for pixel size} + " add %%esi, %%edi \n"// add edi, esi + // " mov %3, %%eax \n" // mov eax, colour + " add %%ecx, %%edi \n"// add edi, ecx + // { Draw the pixel } + " mov %%ax, (%%edi) \n"// mov [edi], ax : - : "D" (buffer), "S" (lineOfs[y]), // %0, %1 - "c" (x), "a" (colour) // %2, %3 - ); - break; - case 1: - __asm__ __volatile__( - // { Calculate offset, prepare the pixel to be drawn } - // " add (%%esi,%%ebx,4), %%edi \n" // add edi, [esi + ebx * 4] - " add %%esi, %%edi \n" // add edi, esi - " add %%ecx, %%edi \n" // add edi, ecx - // { Draw the pixel } - " mov %%al, (%%edi) \n" // mov [edi], al + : "D" (buffer), "S" (lineOfs[y]),// %0, %1 + "c" (x), "a" (colour)// %2, %3 + ); + break; + case 1: + __asm__ __volatile__( + // { Calculate offset, prepare the pixel to be drawn } + // " add (%%esi,%%ebx,4), %%edi \n" // add edi, [esi + ebx * 4] + " add %%esi, %%edi \n"// add edi, esi + " add %%ecx, %%edi \n"// add edi, ecx + // { Draw the pixel } + " mov %%al, (%%edi) \n"// mov [edi], al : - : "D" (buffer), "S" (lineOfs[y]), // %0, %1 - "c" (x), "a" (colour) // %2, %3 - ); - break; + : "D" (buffer), "S" (lineOfs[y]),// %0, %1 + "c" (x), "a" (colour)// %2, %3 + ); + break; } // switch return; } // ogSurface::RawSetPixel -void -ogSurface::RawSetPixel(uInt32 x, uInt32 y, uInt8 r, uInt8 g, uInt8 b, uInt8 a) { +void ogSurface::RawSetPixel(uInt32 x, uInt32 y, uInt8 r, uInt8 g, uInt8 b, uInt8 a) { uInt32 newR, newG, newB, inverseA; uInt8 dR, dG, dB; uInt32 colour; do { if (ogIsBlending()) { - if (a == 0) return; + if (a == 0) + return; if (a == 255) { colour = ogPack(r, g, b, a); break; @@ -915,75 +914,76 @@ newG = (dG * inverseA + g * a) >> 8; newB = (dB * inverseA + b * a) >> 8; colour = ogPack(newR, newG, newB, inverseA); - } else colour = ogPack(r, g, b, a); + } + else + colour = ogPack(r, g, b, a); } while (false); switch (bytesPerPix) { - case 4: - __asm__ __volatile__( - // { Calculate offset, prepare the pixel to be drawn } - " shl $2, %%ecx \n" // shl eax, 2 {adjust for pixel size} - " add %%esi, %%edi \n" // add edi, esi - " add %%ecx, %%edi \n" // add edi, ecx - // { Draw the pixel } - " mov %%eax, (%%edi) \n" // mov [edi], eax + case 4: + __asm__ __volatile__( + // { Calculate offset, prepare the pixel to be drawn } + " shl $2, %%ecx \n"// shl eax, 2 {adjust for pixel size} + " add %%esi, %%edi \n"// add edi, esi + " add %%ecx, %%edi \n"// add edi, ecx + // { Draw the pixel } + " mov %%eax, (%%edi) \n"// mov [edi], eax : - : "D" (buffer), "S" (lineOfs[y]), // %0, %1 - "c" (x), "a" (colour) // %2, %3 - ); + : "D" (buffer), "S" (lineOfs[y]),// %0, %1 + "c" (x), "a" (colour)// %2, %3 + ); break; - case 3: - __asm__ __volatile__( - // Calculate offset, prepare the pixel to be drawn - " leal (%%ecx, %%ecx, 2), %%ecx \n" // lea ecx, [ecx + ecx*2] - " add %%esi, %%edi \n" // add edi, esi - " add %%ecx, %%edi \n" // add edi, ecx - // { Draw the pixel } - " mov %%ax, (%%edi) \n" // mov [edi], ax - " shr $16, %%eax \n" // shr eax, 16 - " mov %%al, 2(%%edi)\n" // mov [edi+2],al + case 3: + __asm__ __volatile__( + // Calculate offset, prepare the pixel to be drawn + " leal (%%ecx, %%ecx, 2), %%ecx \n"// lea ecx, [ecx + ecx*2] + " add %%esi, %%edi \n"// add edi, esi + " add %%ecx, %%edi \n"// add edi, ecx + // { Draw the pixel } + " mov %%ax, (%%edi) \n"// mov [edi], ax + " shr $16, %%eax \n"// shr eax, 16 + " mov %%al, 2(%%edi)\n"// mov [edi+2],al : - : "D" (buffer), "S" (lineOfs[y]), // %0, %1 - "c" (x), "a" (colour) // %2, %3 - ); + : "D" (buffer), "S" (lineOfs[y]),// %0, %1 + "c" (x), "a" (colour)// %2, %3 + ); break; - case 2: - __asm__ __volatile__( - // { Calculate offset, prepare the pixel to be drawn } - " add %%ecx, %%ecx \n" // add ecx, ecx {adjust for pixel size} - " add %%esi, %%edi \n" // add edi, esi - // " mov %3, %%eax \n" // mov eax, colour - " add %%ecx, %%edi \n" // add edi, ecx - // { Draw the pixel } - " mov %%ax, (%%edi) \n" // mov [edi], ax + case 2: + __asm__ __volatile__( + // { Calculate offset, prepare the pixel to be drawn } + " add %%ecx, %%ecx \n"// add ecx, ecx {adjust for pixel size} + " add %%esi, %%edi \n"// add edi, esi + // " mov %3, %%eax \n" // mov eax, colour + " add %%ecx, %%edi \n"// add edi, ecx + // { Draw the pixel } + " mov %%ax, (%%edi) \n"// mov [edi], ax : - : "D" (buffer), "S" (lineOfs[y]), // %0, %1 - "c" (x), "a" (colour) // %2, %3 - ); - break; - case 1: - __asm__ __volatile__( - // { Calculate offset, prepare the pixel to be drawn } - // " add (%%esi,%%ebx,4), %%edi \n" // add edi, [esi + ebx * 4] - " add %%esi, %%edi \n" // add edi, esi - " add %%ecx, %%edi \n" // add edi, ecx - // { Draw the pixel } - " mov %%al, (%%edi) \n" // mov [edi], al + : "D" (buffer), "S" (lineOfs[y]),// %0, %1 + "c" (x), "a" (colour)// %2, %3 + ); + break; + case 1: + __asm__ __volatile__( + // { Calculate offset, prepare the pixel to be drawn } + // " add (%%esi,%%ebx,4), %%edi \n" // add edi, [esi + ebx * 4] + " add %%esi, %%edi \n"// add edi, esi + " add %%ecx, %%edi \n"// add edi, ecx + // { Draw the pixel } + " mov %%al, (%%edi) \n"// mov [edi], al : - : "D" (buffer), "S" (lineOfs[y]), // %0, %1 - "c" (x), "a" (colour) // %2, %3 - ); - break; + : "D" (buffer), "S" (lineOfs[y]),// %0, %1 + "c" (x), "a" (colour)// %2, %3 + ); + break; } // switch return; } // ogSurface::RawSetPixel -bool -ogSurface::ClipLine(int32& x1, int32& y1, int32& x2, int32& y2) { +bool ogSurface::ClipLine(int32& x1, int32& y1, int32& x2, int32& y2) { /* * clipLine() * - * private method + * private method * * clips a line to (0,0),(maxX,maxY); returns true if * the line segment is in bounds, false if none of the line segment is @@ -996,27 +996,37 @@ AndResult = 15; OrResult = 0; OutCode = 0; - if (x1 < 0) OutCode+=8; - if (x1 > (int32)maxX) OutCode+=4; - if (y1 < 0) OutCode+=2; - if (y1 > (int32)maxY) OutCode++; - + if (x1 < 0) + OutCode += 8; + if (x1 > (int32) maxX) + OutCode += 4; + if (y1 < 0) + OutCode += 2; + if (y1 > (int32) maxY) + OutCode++; + AndResult &= OutCode; OrResult |= OutCode; OutCode = 0; - - if (x2 < 0) OutCode+=8; - if (x2 > (int32)maxX) OutCode+=4; - if (y2 < 0) OutCode+=2; - if (y2 > (int32)maxY) OutCode++; - + + if (x2 < 0) + OutCode += 8; + if (x2 > (int32) maxX) + OutCode += 4; + if (y2 < 0) + OutCode += 2; + if (y2 > (int32) maxY) + OutCode++; + AndResult &= OutCode; OrResult |= OutCode; - if (AndResult > 0) return false; - if (OrResult == 0) return true; + if (AndResult > 0) + return false; + if (OrResult == 0) + return true; - // some clipping is required here. + // some clipping is required here. tx1 = x1; ty1 = y1; @@ -1024,49 +1034,46 @@ ty2 = y2; if (x1 < 0) { - ty1 = (x2*y1-x1*y2) / (x2-x1); + ty1 = (x2 * y1 - x1 * y2) / (x2 - x1); tx1 = 0; } // if - else - if (x2 < 0) { - ty2 = (x2*y1-x1*y2) / (x2-x1); - tx2 = 0; - } // elseif + else if (x2 < 0) { + ty2 = (x2 * y1 - x1 * y2) / (x2 - x1); + tx2 = 0; + } // elseif - if (x1 > (int32)maxX) { - ty1 = (y1*(x2-maxX)+y2*(maxX-x1)) / (x2-x1); + if (x1 > (int32) maxX) { + ty1 = (y1 * (x2 - maxX) + y2 * (maxX - x1)) / (x2 - x1); tx1 = maxX; } // if - else - if (x2 > (int32)maxX) { - ty2 = (y1*(x2-maxX)+y2*(maxX-x1)) / (x2-x1); - tx2 = maxX; - } // elseif + else if (x2 > (int32) maxX) { + ty2 = (y1 * (x2 - maxX) + y2 * (maxX - x1)) / (x2 - x1); + tx2 = maxX; + } // elseif - if (((ty1 < 0) && (ty2 < 0)) || - ((ty1>(int32)maxY) && (ty2>(int32)maxY))) return false; + if (((ty1 < 0) && (ty2 < 0)) || ((ty1 > (int32) maxY) && (ty2 > (int32) maxY))) + return false; if (ty1 < 0) { - tx1 = (x1*y2-x2*y1) / (y2-y1); + tx1 = (x1 * y2 - x2 * y1) / (y2 - y1); ty1 = 0; } // if - else - if (ty2 < 0) { - tx2 = (x1*y2-x2*y1) / (y2-y1); - ty2 = 0; - } // elseif + else if (ty2 < 0) { + tx2 = (x1 * y2 - x2 * y1) / (y2 - y1); + ty2 = 0; + } // elseif - if (ty1 > (int32)maxY) { - tx1 = (x1*(y2-maxY)+x2*(maxY-y1)) / (y2-y1); + if (ty1 > (int32) maxY) { + tx1 = (x1 * (y2 - maxY) + x2 * (maxY - y1)) / (y2 - y1); ty1 = maxY; } // if - else - if (ty2 > (int32)maxY) { - tx2 = (x1*(y2-maxY)+x2*(maxY-y1)) / (y2-y1); - ty2 = maxY; - } // elseif + else if (ty2 > (int32) maxY) { + tx2 = (x1 * (y2 - maxY) + x2 * (maxY - y1)) / (y2 - y1); + ty2 = maxY; + } // elseif - if (((uInt32)tx1 > maxX) || ((uInt32)tx2 > maxX)) return false; + if (((uInt32) tx1 > maxX) || ((uInt32) tx2 > maxX)) + return false; x1 = tx1; y1 = ty1; @@ -1084,8 +1091,20 @@ int32 dx = x2 - x1; int32 stepx, stepy; - if (dy < 0) { dy = -dy; stepy = -1; } else { stepy = 1; } - if (dx < 0) { dx = -dx; stepx = -1; } else { stepx = 1; } + if (dy < 0) { + dy = -dy; + stepy = -1; + } + else { + stepy = 1; + } + if (dx < 0) { + dx = -dx; + stepx = -1; + } + else { + stepx = 1; + } RawSetPixel(x1, y1, colour); RawSetPixel(x2, y2, colour); @@ -1098,7 +1117,7 @@ if (incr2 < 0) { int32 c = dy << 1; int32 incr1 = c << 1; - int32 d = incr1 - dx; + int32 d = incr1 - dx; for (int32 i = 0; i < length; i++) { x1 += stepx; @@ -1111,16 +1130,18 @@ RawSetPixel(x2 -= stepx, y2, colour); d += incr1; - } else { + } + else { if (d < c) { // Pattern: RawSetPixel(x1, y1, colour); // o RawSetPixel(x1 += stepx, y1 += stepy, colour); // x o RawSetPixel(x2, y2, colour); // RawSetPixel(x2 -= stepx, y2 -= stepy, colour); - } else { + } + else { RawSetPixel(x1, y1 += stepy, colour); // Pattern: - RawSetPixel(x1 += stepx, y1, colour); // o o + RawSetPixel(x1 += stepx, y1, colour); // o o RawSetPixel(x2, y2 -= stepy, colour); // x RawSetPixel(x2 -= stepx, y2, colour); // } // else @@ -1133,23 +1154,31 @@ if (d < 0) { RawSetPixel(x1 += stepx, y1, colour); - if (extras > 1) RawSetPixel(x1 += stepx, y1, colour); - if (extras > 2) RawSetPixel(x2 -= stepx, y2, colour); - } else - if (d < c) { + if (extras > 1) RawSetPixel(x1 += stepx, y1, colour); - if (extras > 1) RawSetPixel(x1 += stepx, y1 += stepy, colour); - if (extras > 2) RawSetPixel(x2 -= stepx, y2, colour); - } else { + if (extras > 2) + RawSetPixel(x2 -= stepx, y2, colour); + } + else if (d < c) { + RawSetPixel(x1 += stepx, y1, colour); + if (extras > 1) RawSetPixel(x1 += stepx, y1 += stepy, colour); - if (extras > 1) RawSetPixel(x1 += stepx, y1, colour); - if (extras > 2) RawSetPixel(x2 -= stepx, y2 -= stepy, colour); - } + if (extras > 2) + RawSetPixel(x2 -= stepx, y2, colour); + } + else { + RawSetPixel(x1 += stepx, y1 += stepy, colour); + if (extras > 1) + RawSetPixel(x1 += stepx, y1, colour); + if (extras > 2) + RawSetPixel(x2 -= stepx, y2 -= stepy, colour); + } } // if extras > 0 - } else { + } + else { int32 c = (dy - dx) << 1; int32 incr1 = c << 1; - int32 d = incr1 + dx; + int32 d = incr1 + dx; for (int32 i = 0; i < length; i++) { x1 += stepx; @@ -1161,13 +1190,15 @@ RawSetPixel(x2, y2 -= stepy, colour); // o RawSetPixel(x2 -= stepx, y2 -= stepy, colour); // x d += incr1; - } else { + } + else { if (d < c) { RawSetPixel(x1, y1, colour); // Pattern: RawSetPixel(x1 += stepx, y1 += stepy, colour); // o RawSetPixel(x2, y2, colour); // x o RawSetPixel(x2 -= stepx, y2 -= stepy, colour); // - } else { + } + else { RawSetPixel(x1, y1 += stepy, colour); // Pattern: RawSetPixel(x1 += stepx, y1, colour); // o o RawSetPixel(x2, y2 -= stepy, colour); // x @@ -1181,30 +1212,37 @@ if (extras > 0) { if (d > 0) { RawSetPixel(x1 += stepx, y1 += stepy, colour); - if (extras > 1) RawSetPixel(x1 += stepx, y1 += stepy, colour); - if (extras > 2) RawSetPixel(x2 -= stepx, y2 -= stepy, colour); - } else - if (d < c) { - RawSetPixel(x1 += stepx, y1, colour); - if (extras > 1) RawSetPixel(x1 += stepx, y1 += stepy, colour); - if (extras > 2) RawSetPixel(x2 -= stepx, y2, colour); - } else { - + if (extras > 1) RawSetPixel(x1 += stepx, y1 += stepy, colour); + if (extras > 2) + RawSetPixel(x2 -= stepx, y2 -= stepy, colour); + } + else if (d < c) { + RawSetPixel(x1 += stepx, y1, colour); + if (extras > 1) + RawSetPixel(x1 += stepx, y1 += stepy, colour); + if (extras > 2) + RawSetPixel(x2 -= stepx, y2, colour); + } + else { - if (extras > 1) RawSetPixel(x1 += stepx, y1, colour); - if (extras > 2) { - if (d > c) - RawSetPixel(x2 -= stepx, y2 -= stepy, colour); - else - RawSetPixel(x2 -= stepx, y2, colour); - } // if extras > 2 + RawSetPixel(x1 += stepx, y1 += stepy, colour); - } // else - } // if extras > 0 + if (extras > 1) + RawSetPixel(x1 += stepx, y1, colour); + if (extras > 2) { + if (d > c) + RawSetPixel(x2 -= stepx, y2 -= stepy, colour); + else + RawSetPixel(x2 -= stepx, y2, colour); + } // if extras > 2 + + } // else + } // if extras > 0 } // else - } else { + } + else { int32 length = (dy - 1) >> 2; int32 extras = (dy - 1) & 3; @@ -1213,7 +1251,7 @@ if (incr2 < 0) { int32 c = dx << 1; int32 incr1 = c << 1; - int32 d = incr1 - dy; + int32 d = incr1 - dy; for (int32 i = 0; i < length; i++) { y1 += stepy; @@ -1226,14 +1264,16 @@ RawSetPixel(x2, y2 -= stepy, colour); d += incr1; - } else { + } + else { if (d < c) { RawSetPixel(x1, y1, colour); RawSetPixel(x1 += stepx, y1 += stepy, colour); RawSetPixel(x2, y2, colour); RawSetPixel(x2 -= stepx, y2 -= stepy, colour); - } else { + } + else { RawSetPixel(x1 += stepx, y1, colour); RawSetPixel(x1, y1 += stepy, colour); RawSetPixel(x2 -= stepx, y2, colour); @@ -1247,23 +1287,31 @@ if (extras > 0) { if (d < 0) { RawSetPixel(x1, y1 += stepy, colour); - if (extras > 1) RawSetPixel(x1, y1 += stepy, colour); - if (extras > 2) RawSetPixel(x2, y2 -= stepy, colour); - } else - if (d < c) { + if (extras > 1) RawSetPixel(x1, y1 += stepy, colour); - if (extras > 1) RawSetPixel(x1 += stepx, y1 += stepy, colour); - if (extras > 2) RawSetPixel(x2, y2 -= stepy, colour); - } else { + if (extras > 2) + RawSetPixel(x2, y2 -= stepy, colour); + } + else if (d < c) { + RawSetPixel(x1, y1 += stepy, colour); + if (extras > 1) RawSetPixel(x1 += stepx, y1 += stepy, colour); - if (extras > 1) RawSetPixel(x1, y1 += stepy, colour); - if (extras > 2) RawSetPixel(x2 -= stepx, y2 -= stepy, colour); - } // else + if (extras > 2) + RawSetPixel(x2, y2 -= stepy, colour); + } + else { + RawSetPixel(x1 += stepx, y1 += stepy, colour); + if (extras > 1) + RawSetPixel(x1, y1 += stepy, colour); + if (extras > 2) + RawSetPixel(x2 -= stepx, y2 -= stepy, colour); + } // else } // if extras > 0 - } else { + } + else { int32 c = (dx - dy) << 1; int32 incr1 = c << 1; - int32 d = incr1 + dy; + int32 d = incr1 + dy; for (int32 i = 0; i < length; i++) { y1 += stepy; @@ -1275,13 +1323,15 @@ RawSetPixel(x2 -= stepx, y2, colour); RawSetPixel(x2 -= stepx, y2 -= stepy, colour); d += incr1; - } else { + } + else { if (d < c) { RawSetPixel(x1, y1, colour); RawSetPixel(x1 += stepx, y1 += stepy, colour); RawSetPixel(x2, y2, colour); RawSetPixel(x2 -= stepx, y2 -= stepy, colour); - } else { + } + else { RawSetPixel(x1 += stepx, y1, colour); RawSetPixel(x1, y1 += stepy, colour); RawSetPixel(x2 -= stepx, y2, colour); @@ -1294,23 +1344,29 @@ if (extras > 0) { if (d > 0) { RawSetPixel(x1 += stepx, y1 += stepy, colour); - if (extras > 1) RawSetPixel(x1 += stepx, y1 += stepy, colour); - if (extras > 2) RawSetPixel(x2 -= stepx, y2 -= stepy, colour); - } else - if (d < c) { - RawSetPixel(x1, y1 += stepy, colour); - if (extras > 1) RawSetPixel(x1 += stepx, y1 += stepy, colour); - if (extras > 2) RawSetPixel(x2, y2 -= stepy, colour); - } else { + if (extras > 1) RawSetPixel(x1 += stepx, y1 += stepy, colour); - if (extras > 1) RawSetPixel(x1, y1 += stepy, colour); - if (extras > 2) { - if (d > c) - RawSetPixel(x2 -= stepx, y2 -= stepy, colour); - else - RawSetPixel(x2, y2 -= stepy, colour); - } // if extras > 2 - } // else + if (extras > 2) + RawSetPixel(x2 -= stepx, y2 -= stepy, colour); + } + else if (d < c) { + RawSetPixel(x1, y1 += stepy, colour); + if (extras > 1) + RawSetPixel(x1 += stepx, y1 += stepy, colour); + if (extras > 2) + RawSetPixel(x2, y2 -= stepy, colour); + } + else { + RawSetPixel(x1 += stepx, y1 += stepy, colour); + if (extras > 1) + RawSetPixel(x1, y1 += stepy, colour); + if (extras > 2) { + if (d > c) + RawSetPixel(x2 -= stepx, y2 -= stepy, colour); + else + RawSetPixel(x2, y2 -= stepy, colour); + } // if extras > 2 + } // else } // if extras > 0 } // else } // else @@ -1325,338 +1381,337 @@ * private method; draws an unclipped line from (x1,y1) to (x2,y2) * */ - int32 tc; - if (!ogAvail()) return; - switch (BPP) { - case 8: - __asm__ __volatile__( - " mov $1, %%ecx \n" // mov ecx, 1 - " bt $15, %%eax \n" // bt eax, 15 - " jnc rlxPositive8 \n" - " or $-1, %%ecx \n" // or ecx, -1 - " neg %%eax \n" // neg eax -"rlxPositive8: \n" - " add %%eax, %%eax \n" // add eax, eax - " bt $15, %%ebx \n" // bt ebx, 15 - " jnc rlyPositive8 \n" - " neg %%edx \n" // neg edx - " neg %%ebx \n" // neg ebx -"rlyPositive8: \n" - " add %%ebx, %%ebx \n" // add ebx, ebx + int32 tc; + if (!ogAvail()) return; + switch (BPP) { + case 8: + __asm__ __volatile__( + " mov $1, %%ecx \n" // mov ecx, 1 + " bt $15, %%eax \n"// bt eax, 15 + " jnc rlxPositive8 \n" + " or $-1, %%ecx \n"// or ecx, -1 + " neg %%eax \n"// neg eax + "rlxPositive8: \n" + " add %%eax, %%eax \n"// add eax, eax + " bt $15, %%ebx \n"// bt ebx, 15 + " jnc rlyPositive8 \n" + " neg %%edx \n"// neg edx + " neg %%ebx \n"// neg ebx + "rlyPositive8: \n" + " add %%ebx, %%ebx \n"// add ebx, ebx - " cmp %%ebx, %%eax \n" // cmp eax, ebx - " jle rlyGreater8 \n" - " push %%ecx \n" // push ecx - " mov %%eax, %%ecx \n" // mov ecx, eax - " mov %%ebx, %6 \n" // mov tc, ebx - " shr $1, %%ecx \n" // shr ecx, 1 - " sub %%ecx, %6 \n" // sub tc, ecx - " pop %%ecx \n" // pop ecx -"rlxTop8: \n" - " push %%eax \n" // push eax - " mov %5, %%eax \n" // mov eax, colour - " mov %%al, (%%edi) \n" // mov [edi], al - " pop %%eax \n" // pop eax - " cmp %%edi, %%esi \n" // cmp esi, edi - " je rlDone8 \n" - " cmp $0, %6 \n" // cmp tc, 0 - " jl rlNoAddY8 \n" - " add %%edx, %%edi \n" // add edi, edx - " sub %%eax, %6 \n" // sub tc, eax -"rlNoAddY8: \n" - " add %%ecx, %%edi \n" // add edi, ecx - " add %%ebx, %6 \n" // add tc, ebx - " jmp rlxTop8 \n" + " cmp %%ebx, %%eax \n"// cmp eax, ebx + " jle rlyGreater8 \n" + " push %%ecx \n"// push ecx + " mov %%eax, %%ecx \n"// mov ecx, eax + " mov %%ebx, %6 \n"// mov tc, ebx + " shr $1, %%ecx \n"// shr ecx, 1 + " sub %%ecx, %6 \n"// sub tc, ecx + " pop %%ecx \n"// pop ecx + "rlxTop8: \n" + " push %%eax \n"// push eax + " mov %5, %%eax \n"// mov eax, colour + " mov %%al, (%%edi) \n"// mov [edi], al + " pop %%eax \n"// pop eax + " cmp %%edi, %%esi \n"// cmp esi, edi + " je rlDone8 \n" + " cmp $0, %6 \n"// cmp tc, 0 + " jl rlNoAddY8 \n" + " add %%edx, %%edi \n"// add edi, edx + " sub %%eax, %6 \n"// sub tc, eax + "rlNoAddY8: \n" + " add %%ecx, %%edi \n"// add edi, ecx + " add %%ebx, %6 \n"// add tc, ebx + " jmp rlxTop8 \n" -"rlyGreater8: \n" - " push %%ecx \n" // push ecx - " mov %%ebx, %%ecx \n" // mov ecx, ebx - " mov %%eax, %6 \n" // mov tc, eax - " shr $1, %%ecx \n" // shr ecx, 1 - " sub %%ecx, %6 \n" // sub tc, ecx - " pop %%ecx \n" -"rlyTop8: \n" - " push %%eax \n" // push eax - " mov %5, %%eax \n" // mov eax, colour - " mov %%al, (%%edi) \n" // mov [edi], al - " pop %%eax \n" // pop eax - " cmp %%edi, %%esi \n" // cmp esi, edi - " je rlDone8 \n" - " cmp $0, %6 \n" // cmp tc, 0 - " jl rlNoAddX8 \n" - " add %%ecx, %%edi \n" // add edi, ecx - " sub %%ebx, %6 \n" // sub tc, ebx -"rlNoAddX8: \n" - " add %%edx, %%edi \n" // add edi, edx - " add %%eax, %6 \n" // add tc, eax - " jmp rlyTop8 \n" -"rlDone8: \n" - : - : "D" ((uInt8 *)buffer+lineOfs[y1]+x1), // %0 - "S" ((uInt8 *)buffer+lineOfs[y2]+x2), // %1 - "a" (x2-x1), "b" (y2-y1), // %2, %3 - "d" (xRes), "m" (colour), // %4, %5 - "m" (tc) // %6 - ); - break; - case 15: - case 16: - __asm__ __volatile__( - " mov $1, %%ecx \n" // mov ecx, 1 - " bt $15, %%eax \n" // bt eax, 15 - " jnc rlxPositive16 \n" - " or $-1, %%ecx \n" // or ecx, -1 - " neg %%eax \n" // neg eax -"rlxPositive16: \n" - " add %%eax, %%eax \n" // add eax, eax - " bt $15, %%ebx \n" // bt ebx, 15 - " jnc rlyPositive16 \n" - " neg %%edx \n" // neg edx - " neg %%ebx \n" // neg ebx -"rlyPositive16: \n" - " add %%ebx, %%ebx \n" // add ebx, ebx + "rlyGreater8: \n" + " push %%ecx \n"// push ecx + " mov %%ebx, %%ecx \n"// mov ecx, ebx + " mov %%eax, %6 \n"// mov tc, eax + " shr $1, %%ecx \n"// shr ecx, 1 + " sub %%ecx, %6 \n"// sub tc, ecx + " pop %%ecx \n" + "rlyTop8: \n" + " push %%eax \n"// push eax + " mov %5, %%eax \n"// mov eax, colour + " mov %%al, (%%edi) \n"// mov [edi], al + " pop %%eax \n"// pop eax + " cmp %%edi, %%esi \n"// cmp esi, edi + " je rlDone8 \n" + " cmp $0, %6 \n"// cmp tc, 0 + " jl rlNoAddX8 \n" + " add %%ecx, %%edi \n"// add edi, ecx + " sub %%ebx, %6 \n"// sub tc, ebx + "rlNoAddX8: \n" + " add %%edx, %%edi \n"// add edi, edx + " add %%eax, %6 \n"// add tc, eax + " jmp rlyTop8 \n" + "rlDone8: \n" + : + : "D" ((uInt8 *)buffer+lineOfs[y1]+x1),// %0 + "S" ((uInt8 *)buffer+lineOfs[y2]+x2),// %1 + "a" (x2-x1), "b" (y2-y1),// %2, %3 + "d" (xRes), "m" (colour),// %4, %5 + "m" (tc)// %6 + ); + break; + case 15: + case 16: + __asm__ __volatile__( + " mov $1, %%ecx \n"// mov ecx, 1 + " bt $15, %%eax \n"// bt eax, 15 + " jnc rlxPositive16 \n" + " or $-1, %%ecx \n"// or ecx, -1 + " neg %%eax \n"// neg eax + "rlxPositive16: \n" + " add %%eax, %%eax \n"// add eax, eax + " bt $15, %%ebx \n"// bt ebx, 15 + " jnc rlyPositive16 \n" + " neg %%edx \n"// neg edx + " neg %%ebx \n"// neg ebx + "rlyPositive16: \n" + " add %%ebx, %%ebx \n"// add ebx, ebx - " cmp %%ebx, %%eax \n" // cmp eax, ebx - " jle rlyGreater16 \n" - " push %%ecx \n" // push ecx - " mov %%eax, %%ecx \n" // mov ecx, eax - " mov %%ebx, %6 \n" // mov tc, ebx - " shr $1, %%ecx \n" // shr ecx, 1 - " sub %%ecx, %6 \n" // sub tc, ecx - " pop %%ecx \n" // pop ecx -"rlxTop16: \n" - " push %%eax \n" // push eax - " mov %5, %%eax \n" // mov eax, colour - " mov %%ax, (%%edi) \n" // mov [edi], ax - " pop %%eax \n" // pop eax - " cmp %%edi, %%esi \n" // cmp esi, edi - " je rlDone16 \n" - " cmp $0, %6 \n" // cmp tc, 0 - " jl rlNoAddY16 \n" - " add %%edx, %%edi \n" // add edi, edx - " sub %%eax, %6 \n" // sub tc, eax -"rlNoAddY16: \n" - " add %%ecx, %%edi \n" // add edi, ecx - " add %%ecx, %%edi \n" // add edi, ecx - pix size - " add %%ebx, %6 \n" // add tc, ebx - " jmp rlxTop16 \n" + " cmp %%ebx, %%eax \n"// cmp eax, ebx + " jle rlyGreater16 \n" + " push %%ecx \n"// push ecx + " mov %%eax, %%ecx \n"// mov ecx, eax + " mov %%ebx, %6 \n"// mov tc, ebx + " shr $1, %%ecx \n"// shr ecx, 1 + " sub %%ecx, %6 \n"// sub tc, ecx + " pop %%ecx \n"// pop ecx + "rlxTop16: \n" + " push %%eax \n"// push eax + " mov %5, %%eax \n"// mov eax, colour + " mov %%ax, (%%edi) \n"// mov [edi], ax + " pop %%eax \n"// pop eax + " cmp %%edi, %%esi \n"// cmp esi, edi + " je rlDone16 \n" + " cmp $0, %6 \n"// cmp tc, 0 + " jl rlNoAddY16 \n" + " add %%edx, %%edi \n"// add edi, edx + " sub %%eax, %6 \n"// sub tc, eax + "rlNoAddY16: \n" + " add %%ecx, %%edi \n"// add edi, ecx + " add %%ecx, %%edi \n"// add edi, ecx - pix size + " add %%ebx, %6 \n"// add tc, ebx + " jmp rlxTop16 \n" -"rlyGreater16: \n" - " push %%ecx \n" // push ecx - " mov %%ebx, %%ecx \n" // mov ecx, ebx - " mov %%eax, %6 \n" // mov tc, eax - " shr $1, %%ecx \n" // shr ecx, 1 - " sub %%ecx, %6 \n" // sub tc, ecx - " pop %%ecx \n" -"rlyTop16: \n" - " push %%eax \n" // push eax - " mov %5, %%eax \n" // mov eax, colour - " mov %%ax, (%%edi) \n" // mov [edi], ax - " pop %%eax \n" // pop eax - " cmp %%edi, %%esi \n" // cmp esi, edi - " je rlDone16 \n" - " cmp $0, %6 \n" // cmp tc, 0 - " jl rlNoAddX16 \n" - " add %%ecx, %%edi \n" // add edi, ecx - " add %%ecx, %%edi \n" // add edi, ecx - pix size - " sub %%ebx, %6 \n" // sub tc, ebx -"rlNoAddX16: \n" - " add %%edx, %%edi \n" // add edi, edx - " add %%eax, %6 \n" // add tc, eax - " jmp rlyTop16 \n" -"rlDone16: \n" - : - : "D" ((uInt8 *)buffer+lineOfs[y1]+(x1 << 1)), // %0 - "S" ((uInt8 *)buffer+lineOfs[y2]+(x2 << 1)), // %1 - "a" (x2-x1), "b" (y2-y1), // %2, %3 - "d" (xRes), "m" (colour), // %4, %5 - "m" (tc) // %6 - ); - break; - case 24: - __asm__ __volatile__( - " mov $1, %%ecx \n" // mov ecx, 1 - " bt $15, %%eax \n" // bt eax, 15 - " jnc rlxPositive24 \n" - " or $-1, %%ecx \n" // or ecx, -1 - " neg %%eax \n" // neg eax -"rlxPositive24: \n" - " add %%eax, %%eax \n" // add eax, eax - " bt $15, %%ebx \n" // bt ebx, 15 - " jnc rlyPositive24 \n" - " neg %%edx \n" // neg edx - " neg %%ebx \n" // neg ebx -"rlyPositive24: \n" - " add %%ebx, %%ebx \n" // add ebx, ebx + "rlyGreater16: \n" + " push %%ecx \n"// push ecx + " mov %%ebx, %%ecx \n"// mov ecx, ebx + " mov %%eax, %6 \n"// mov tc, eax + " shr $1, %%ecx \n"// shr ecx, 1 + " sub %%ecx, %6 \n"// sub tc, ecx + " pop %%ecx \n" + "rlyTop16: \n" + " push %%eax \n"// push eax + " mov %5, %%eax \n"// mov eax, colour + " mov %%ax, (%%edi) \n"// mov [edi], ax + " pop %%eax \n"// pop eax + " cmp %%edi, %%esi \n"// cmp esi, edi + " je rlDone16 \n" + " cmp $0, %6 \n"// cmp tc, 0 + " jl rlNoAddX16 \n" + " add %%ecx, %%edi \n"// add edi, ecx + " add %%ecx, %%edi \n"// add edi, ecx - pix size + " sub %%ebx, %6 \n"// sub tc, ebx + "rlNoAddX16: \n" + " add %%edx, %%edi \n"// add edi, edx + " add %%eax, %6 \n"// add tc, eax + " jmp rlyTop16 \n" + "rlDone16: \n" + : + : "D" ((uInt8 *)buffer+lineOfs[y1]+(x1 << 1)),// %0 + "S" ((uInt8 *)buffer+lineOfs[y2]+(x2 << 1)),// %1 + "a" (x2-x1), "b" (y2-y1),// %2, %3 + "d" (xRes), "m" (colour),// %4, %5 + "m" (tc)// %6 + ); + break; + case 24: + __asm__ __volatile__( + " mov $1, %%ecx \n"// mov ecx, 1 + " bt $15, %%eax \n"// bt eax, 15 + " jnc rlxPositive24 \n" + " or $-1, %%ecx \n"// or ecx, -1 + " neg %%eax \n"// neg eax + "rlxPositive24: \n" + " add %%eax, %%eax \n"// add eax, eax + " bt $15, %%ebx \n"// bt ebx, 15 + " jnc rlyPositive24 \n" + " neg %%edx \n"// neg edx + " neg %%ebx \n"// neg ebx + "rlyPositive24: \n" + " add %%ebx, %%ebx \n"// add ebx, ebx - " cmp %%ebx, %%eax \n" // cmp eax, ebx - " jle rlyGreater24 \n" - " push %%ecx \n" // push ecx - " mov %%eax, %%ecx \n" // mov ecx, eax - " mov %%ebx, %6 \n" // mov tc, ebx - " shr $1, %%ecx \n" // shr ecx, 1 - " sub %%ecx, %6 \n" // sub tc, ecx - " pop %%ecx \n" // pop ecx -"rlxTop24: \n" - " push %%eax \n" // push eax - " mov %5, %%eax \n" // mov eax, colour - " mov %%ax, (%%edi) \n" // mov [edi], ax - " shr $16, %%eax \n" // shr eax, 16 - " mov %%al, 2(%%edi)\n" // mov [edi+2],al - " pop %%eax \n" // pop eax - " cmp %%edi, %%esi \n" // cmp esi, edi - " je rlDone24 \n" - " cmp $0, %6 \n" // cmp tc, 0 - " jl rlNoAddY24 \n" - " add %%edx, %%edi \n" // add edi, edx - " sub %%eax, %6 \n" // sub tc, eax -"rlNoAddY24: \n" - " add %%ecx, %%edi \n" // add edi, ecx - " add %%ecx, %%edi \n" // add edi, ecx - pix size - " add %%ecx, %%edi \n" // add edi, ecx - " add %%ebx, %6 \n" // add tc, ebx - " jmp rlxTop24 \n" + " cmp %%ebx, %%eax \n"// cmp eax, ebx + " jle rlyGreater24 \n" + " push %%ecx \n"// push ecx + " mov %%eax, %%ecx \n"// mov ecx, eax + " mov %%ebx, %6 \n"// mov tc, ebx + " shr $1, %%ecx \n"// shr ecx, 1 + " sub %%ecx, %6 \n"// sub tc, ecx + " pop %%ecx \n"// pop ecx + "rlxTop24: \n" + " push %%eax \n"// push eax + " mov %5, %%eax \n"// mov eax, colour + " mov %%ax, (%%edi) \n"// mov [edi], ax + " shr $16, %%eax \n"// shr eax, 16 + " mov %%al, 2(%%edi)\n"// mov [edi+2],al + " pop %%eax \n"// pop eax + " cmp %%edi, %%esi \n"// cmp esi, edi + " je rlDone24 \n" + " cmp $0, %6 \n"// cmp tc, 0 + " jl rlNoAddY24 \n" + " add %%edx, %%edi \n"// add edi, edx + " sub %%eax, %6 \n"// sub tc, eax + "rlNoAddY24: \n" + " add %%ecx, %%edi \n"// add edi, ecx + " add %%ecx, %%edi \n"// add edi, ecx - pix size + " add %%ecx, %%edi \n"// add edi, ecx + " add %%ebx, %6 \n"// add tc, ebx + " jmp rlxTop24 \n" -"rlyGreater24: \n" - " push %%ecx \n" // push ecx - " mov %%ebx, %%ecx \n" // mov ecx, ebx - " mov %%eax, %6 \n" // mov tc, eax - " shr $1, %%ecx \n" // shr ecx, 1 - " sub %%ecx, %6 \n" // sub tc, ecx - " pop %%ecx \n" -"rlyTop24: \n" - " push %%eax \n" // push eax - " mov %5, %%eax \n" // mov eax, colour - " mov %%ax, (%%edi) \n" // mov [edi], ax - " shr $16, %%eax \n" // shr eax, 16 - " mov %%al, 2(%%edi)\n" // mov [edi+2],al - " pop %%eax \n" // pop eax - " cmp %%edi, %%esi \n" // cmp esi, edi - " je rlDone24 \n" - " cmp $0, %6 \n" // cmp tc, 0 - " jl rlNoAddX24 \n" - " add %%ecx, %%edi \n" // add edi, ecx - " add %%ecx, %%edi \n" // add edi, ecx - pix size - " add %%ecx, %%edi \n" // add edi, ecx - " sub %%ebx, %6 \n" // sub tc, ebx -"rlNoAddX24: \n" - " add %%edx, %%edi \n" // add edi, edx - " add %%eax, %6 \n" // add tc, eax - " jmp rlyTop24 \n" -"rlDone24: \n" - : - : "D" ((uInt8 *)buffer+lineOfs[y1]+(x1*3)), // %0 - "S" ((uInt8 *)buffer+lineOfs[y2]+(x2*3)), // %1 - "a" (x2-x1), "b" (y2-y1), // %2, %3 - "d" (xRes), "m" (colour), // %4, %5 - "m" (tc) // %6 - ); - break; - case 32: - __asm__ __volatile__( - " mov $1, %%ecx \n" // mov ecx, 1 - " bt $15, %%eax \n" // bt eax, 15 - " jnc rlxPositive32 \n" - " or $-1, %%ecx \n" // or ecx, -1 - " neg %%eax \n" // neg eax -"rlxPositive32: \n" - " add %%eax, %%eax \n" // add eax, eax - " bt $15, %%ebx \n" // bt ebx, 15 - " jnc rlyPositive32 \n" - " neg %%edx \n" // neg edx - " neg %%ebx \n" // neg ebx -"rlyPositive32: \n" - " add %%ebx, %%ebx \n" // add ebx, ebx + "rlyGreater24: \n" + " push %%ecx \n"// push ecx + " mov %%ebx, %%ecx \n"// mov ecx, ebx + " mov %%eax, %6 \n"// mov tc, eax + " shr $1, %%ecx \n"// shr ecx, 1 + " sub %%ecx, %6 \n"// sub tc, ecx + " pop %%ecx \n" + "rlyTop24: \n" + " push %%eax \n"// push eax + " mov %5, %%eax \n"// mov eax, colour + " mov %%ax, (%%edi) \n"// mov [edi], ax + " shr $16, %%eax \n"// shr eax, 16 + " mov %%al, 2(%%edi)\n"// mov [edi+2],al + " pop %%eax \n"// pop eax + " cmp %%edi, %%esi \n"// cmp esi, edi + " je rlDone24 \n" + " cmp $0, %6 \n"// cmp tc, 0 + " jl rlNoAddX24 \n" + " add %%ecx, %%edi \n"// add edi, ecx + " add %%ecx, %%edi \n"// add edi, ecx - pix size + " add %%ecx, %%edi \n"// add edi, ecx + " sub %%ebx, %6 \n"// sub tc, ebx + "rlNoAddX24: \n" + " add %%edx, %%edi \n"// add edi, edx + " add %%eax, %6 \n"// add tc, eax + " jmp rlyTop24 \n" + "rlDone24: \n" + : + : "D" ((uInt8 *)buffer+lineOfs[y1]+(x1*3)),// %0 + "S" ((uInt8 *)buffer+lineOfs[y2]+(x2*3)),// %1 + "a" (x2-x1), "b" (y2-y1),// %2, %3 + "d" (xRes), "m" (colour),// %4, %5 + "m" (tc)// %6 + ); + break; + case 32: + __asm__ __volatile__( + " mov $1, %%ecx \n"// mov ecx, 1 + " bt $15, %%eax \n"// bt eax, 15 + " jnc rlxPositive32 \n" + " or $-1, %%ecx \n"// or ecx, -1 + " neg %%eax \n"// neg eax + "rlxPositive32: \n" + " add %%eax, %%eax \n"// add eax, eax + " bt $15, %%ebx \n"// bt ebx, 15 + " jnc rlyPositive32 \n" + " neg %%edx \n"// neg edx + " neg %%ebx \n"// neg ebx + "rlyPositive32: \n" + " add %%ebx, %%ebx \n"// add ebx, ebx - " cmp %%ebx, %%eax \n" // cmp eax, ebx - " jle rlyGreater32 \n" - " push %%ecx \n" // push ecx - " mov %%eax, %%ecx \n" // mov ecx, eax - " mov %%ebx, %6 \n" // mov tc, ebx - " shr $1, %%ecx \n" // shr ecx, 1 - " sub %%ecx, %6 \n" // sub tc, ecx - " pop %%ecx \n" // pop ecx -"rlxTop32: \n" - " push %%eax \n" // push eax - " mov %5, %%eax \n" // mov eax, colour - " mov %%eax, (%%edi)\n" // mov [edi], eax - " pop %%eax \n" // pop eax - " cmp %%edi, %%esi \n" // cmp esi, edi - " je rlDone32 \n" - " cmp $0, %6 \n" // cmp tc, 0 - " jl rlNoAddY32 \n" - " add %%edx, %%edi \n" // add edi, edx - " sub %%eax, %6 \n" // sub tc, eax -"rlNoAddY32: \n" - " add %%ecx, %%edi \n" // add edi, ecx - " add %%ecx, %%edi \n" // add edi, ecx - pix size - " add %%ecx, %%edi \n" // add edi, ecx - " add %%ecx, %%edi \n" // add edi, ecx - pix size - " add %%ebx, %6 \n" // add tc, ebx - " jmp rlxTop32 \n" + " cmp %%ebx, %%eax \n"// cmp eax, ebx + " jle rlyGreater32 \n" + " push %%ecx \n"// push ecx + " mov %%eax, %%ecx \n"// mov ecx, eax + " mov %%ebx, %6 \n"// mov tc, ebx + " shr $1, %%ecx \n"// shr ecx, 1 + " sub %%ecx, %6 \n"// sub tc, ecx + " pop %%ecx \n"// pop ecx + "rlxTop32: \n" + " push %%eax \n"// push eax + " mov %5, %%eax \n"// mov eax, colour + " mov %%eax, (%%edi)\n"// mov [edi], eax + " pop %%eax \n"// pop eax + " cmp %%edi, %%esi \n"// cmp esi, edi + " je rlDone32 \n" + " cmp $0, %6 \n"// cmp tc, 0 + " jl rlNoAddY32 \n" + " add %%edx, %%edi \n"// add edi, edx + " sub %%eax, %6 \n"// sub tc, eax + "rlNoAddY32: \n" + " add %%ecx, %%edi \n"// add edi, ecx + " add %%ecx, %%edi \n"// add edi, ecx - pix size + " add %%ecx, %%edi \n"// add edi, ecx + " add %%ecx, %%edi \n"// add edi, ecx - pix size + " add %%ebx, %6 \n"// add tc, ebx + " jmp rlxTop32 \n" -"rlyGreater32: \n" - " push %%ecx \n" // push ecx - " mov %%ebx, %%ecx \n" // mov ecx, ebx - " mov %%eax, %6 \n" // mov tc, eax - " shr $1, %%ecx \n" // shr ecx, 1 - " sub %%ecx, %6 \n" // sub tc, ecx - " pop %%ecx \n" -"rlyTop32: \n" - " push %%eax \n" // push eax - " mov %5, %%eax \n" // mov eax, colour - " mov %%eax, (%%edi)\n" // mov [edi], eax - " pop %%eax \n" // pop eax - " cmp %%edi, %%esi \n" // cmp esi, edi - " je rlDone32 \n" - " cmp $0, %6 \n" // cmp tc, 0 - " jl rlNoAddX32 \n" - " add %%ecx, %%edi \n" // add edi, ecx - pix size - " add %%ecx, %%edi \n" // add edi, ecx - " add %%ecx, %%edi \n" // add edi, ecx - pix size - " add %%ecx, %%edi \n" // add edi, ecx - " sub %%ebx, %6 \n" // sub tc, ebx -"rlNoAddX32: \n" - " add %%edx, %%edi \n" // add edi, edx - " add %%eax, %6 \n" // add tc, eax - " jmp rlyTop32 \n" -"rlDone32: \n" - : - : "D" ((uInt8 *)buffer+lineOfs[y1]+(x1 << 2)), // %0 - "S" ((uInt8 *)buffer+lineOfs[y2]+(x2 << 2)), // %1 - "a" (x2-x1), "b" (y2-y1), // %2, %3 - "d" (xRes), "m" (colour), // %4, %5 - "m" (tc) // %6 - ); - break; - } // switch + "rlyGreater32: \n" + " push %%ecx \n"// push ecx + " mov %%ebx, %%ecx \n"// mov ecx, ebx + " mov %%eax, %6 \n"// mov tc, eax + " shr $1, %%ecx \n"// shr ecx, 1 + " sub %%ecx, %6 \n"// sub tc, ecx + " pop %%ecx \n" + "rlyTop32: \n" + " push %%eax \n"// push eax + " mov %5, %%eax \n"// mov eax, colour + " mov %%eax, (%%edi)\n"// mov [edi], eax + " pop %%eax \n"// pop eax + " cmp %%edi, %%esi \n"// cmp esi, edi + " je rlDone32 \n" + " cmp $0, %6 \n"// cmp tc, 0 + " jl rlNoAddX32 \n" + " add %%ecx, %%edi \n"// add edi, ecx - pix size + " add %%ecx, %%edi \n"// add edi, ecx + " add %%ecx, %%edi \n"// add edi, ecx - pix size + " add %%ecx, %%edi \n"// add edi, ecx + " sub %%ebx, %6 \n"// sub tc, ebx + "rlNoAddX32: \n" + " add %%edx, %%edi \n"// add edi, edx + " add %%eax, %6 \n"// add tc, eax + " jmp rlyTop32 \n" + "rlDone32: \n" + : + : "D" ((uInt8 *)buffer+lineOfs[y1]+(x1 << 2)),// %0 + "S" ((uInt8 *)buffer+lineOfs[y2]+(x2 << 2)),// %1 + "a" (x2-x1), "b" (y2-y1),// %2, %3 + "d" (xRes), "m" (colour),// %4, %5 + "m" (tc)// %6 + ); + break; + } // switch return; } // ogSurface::RawLine #endif -bool -ogSurface::ogAlias(ogSurface& src, uInt32 x1, uInt32 y1, uInt32 x2, uInt32 y2) { +bool ogSurface::ogAlias(ogSurface& src, uInt32 x1, uInt32 y1, uInt32 x2, uInt32 y2) { uInt32 tmp; - if (dataState == ogOwner) { + if (dataState == ogOwner) { ogSetLastError(ogAlreadyOwner); return false; } // if if (x2 < x1) { - tmp= x2; + tmp = x2; x2 = x1; x1 = tmp; } // if if (y2 < y1) { - tmp= y2; + tmp = y2; y2 = y1; y1 = tmp; - } // if + } // if - maxX = (x2-x1); - maxY = (y2-y1); + maxX = (x2 - x1); + maxY = (y2 - y1); dataState = ogAliasing; @@ -1664,40 +1719,38 @@ lSize = 0; owner = &src; - buffer =((unsigned char *)(src.buffer)+x1*(src.bytesPerPix)); - lineOfs=((uInt32 *)src.lineOfs)+y1; + buffer = ((unsigned char *) (src.buffer) + x1 * (src.bytesPerPix)); + lineOfs = ((uInt32 *) src.lineOfs) + y1; attributes = src.attributes; - pal = src.pal; + pal = src.pal; xRes = src.xRes; yRes = src.yRes; - BPP = src.BPP; + BPP = src.BPP; bytesPerPix = src.bytesPerPix; pixFmtID = src.pixFmtID; - + // For 8bpp modes the next part doesn't matter - redFieldPosition = src.redFieldPosition; + redFieldPosition = src.redFieldPosition; greenFieldPosition = src.greenFieldPosition; - blueFieldPosition = src.blueFieldPosition; + blueFieldPosition = src.blueFieldPosition; alphaFieldPosition = src.alphaFieldPosition; // The next part is only used by 15/16bpp - redShifter = src.redShifter; + redShifter = src.redShifter; greenShifter = src.greenShifter; - blueShifter = src.blueShifter; + blueShifter = src.blueShifter; alphaShifter = src.alphaShifter; - + alphaMasker = src.alphaMasker; return true; } // ogSurface::ogAlias -void -ogSurface::ogArc(int32 xCenter, int32 yCenter, uInt32 radius, - uInt32 sAngle, uInt32 eAngle, uInt32 colour) { +void ogSurface::ogArc(int32 xCenter, int32 yCenter, uInt32 radius, uInt32 sAngle, uInt32 eAngle, uInt32 colour) { int32 p; uInt32 x, y, tmp; double alpha; - + if (radius == 0) { ogSetPixel(xCenter, yCenter, colour); return; @@ -1711,42 +1764,42 @@ sAngle = eAngle; eAngle = tmp; } // if - + x = 0; y = radius; - p = 3-2*radius; - + p = 3 - 2 * radius; + while (x <= y) { - alpha = (180.0/3.14159265358979)*atan((double)x/(double)y); + alpha = (180.0 / 3.14159265358979) * atan((double) x / (double) y); if ((alpha >= sAngle) && (alpha <= eAngle)) - ogSetPixel(xCenter-x, yCenter-y, colour); + ogSetPixel(xCenter - x, yCenter - y, colour); - if ((90-alpha >= sAngle) && (90-alpha <= eAngle)) - ogSetPixel(xCenter-y, yCenter-x, colour); + if ((90 - alpha >= sAngle) && (90 - alpha <= eAngle)) + ogSetPixel(xCenter - y, yCenter - x, colour); - if ((90+alpha >= sAngle) && (90+alpha <= eAngle)) - ogSetPixel(xCenter-y, yCenter+x, colour); + if ((90 + alpha >= sAngle) && (90 + alpha <= eAngle)) + ogSetPixel(xCenter - y, yCenter + x, colour); - if ((180-alpha >= sAngle) && (180-alpha <= eAngle)) - ogSetPixel(xCenter-x, yCenter+y, colour); + if ((180 - alpha >= sAngle) && (180 - alpha <= eAngle)) + ogSetPixel(xCenter - x, yCenter + y, colour); - if ((180+alpha >= sAngle) && (180+alpha <= eAngle)) - ogSetPixel(xCenter+x, yCenter+y, colour); + if ((180 + alpha >= sAngle) && (180 + alpha <= eAngle)) + ogSetPixel(xCenter + x, yCenter + y, colour); - if ((270-alpha >= sAngle) && (270-alpha <= eAngle)) - ogSetPixel(xCenter+y, yCenter+x, colour); + if ((270 - alpha >= sAngle) && (270 - alpha <= eAngle)) + ogSetPixel(xCenter + y, yCenter + x, colour); - if ((270+alpha >= sAngle) && (270+alpha <= eAngle)) - ogSetPixel(xCenter+y, yCenter-x, colour); + if ((270 + alpha >= sAngle) && (270 + alpha <= eAngle)) + ogSetPixel(xCenter + y, yCenter - x, colour); - if ((360-alpha >= sAngle) && (360-alpha <= eAngle)) - ogSetPixel(xCenter+x, yCenter-y, colour); + if ((360 - alpha >= sAngle) && (360 - alpha <= eAngle)) + ogSetPixel(xCenter + x, yCenter - y, colour); if (p < 0) - p += 4*x+6; + p += 4 * x + 6; else { - p += 4*(x-y)+10; + p += 4 * (x - y) + 10; --y; } // else ++x; @@ -1754,43 +1807,38 @@ return; } // ogSurface::ogArc -bool -ogSurface::ogAvail(void) { +bool ogSurface::ogAvail(void) { return ((buffer != NULL) && (lineOfs != NULL)); } // ogSurface::ogAvail -static int32 -calculate(float mu, int32 p0, int32 p1, int32 p2, int32 p3) { +static int32 calculate(float mu, int32 p0, int32 p1, int32 p2, int32 p3) { float mu2, mu3; - mu2 = mu*mu; - mu3 = mu2*mu; - return (int32)(0.5f+(1.0/6.0)*(mu3*(-p0+3.0*p1-3.0*p2+p3)+ - mu2*(3.0*p0-6.0*p1+3.0*p2)+ - mu*(-3.0*p0+3.0*p2)+(p0+4.0*p1+p2))); + mu2 = mu * mu; + mu3 = mu2 * mu; + return (int32) (0.5f + (1.0 / 6.0) * (mu3 * (-p0 + 3.0 * p1 - 3.0 * p2 + p3) + mu2 * (3.0 * p0 - 6.0 * p1 + 3.0 * p2) + mu * (-3.0 * p0 + 3.0 * p2) + (p0 + 4.0 * p1 + p2))); } // calculate - -void -ogSurface::ogBSpline(uInt32 numPoints, ogPoint2d* points, uInt32 segments, - uInt32 colour) { +void ogSurface::ogBSpline(uInt32 numPoints, ogPoint2d* points, uInt32 segments, uInt32 colour) { float mu, mudelta; int32 x1, y1, x2, y2; uInt32 n, h; - if (points == NULL) return; + if (points == NULL) + return; - if ((numPoints < 4) || (numPoints > 255) || (segments == 0)) return; + if ((numPoints < 4) || (numPoints > 255) || (segments == 0)) + return; - mudelta = 1.0/segments; - for (n=3; n= 0) { - ogSetPixel(xCenter+x, yCenter+y, colour); - ogSetPixel(xCenter+x, yCenter-y, colour); - ogSetPixel(xCenter-x, yCenter+y, colour); - ogSetPixel(xCenter-x, yCenter-y, colour); + ogSetPixel(xCenter + x, yCenter + y, colour); + ogSetPixel(xCenter + x, yCenter - y, colour); + ogSetPixel(xCenter - x, yCenter + y, colour); + ogSetPixel(xCenter - x, yCenter - y, colour); if (d + y > 0) { --y; - d -= 2*y+1; + d -= 2 * y + 1; } // if if (x > d) { ++x; - d += 2*x+1; + d += 2 * x + 1; } // if } // while return; } // ogSurface::ogCircle -void -ogSurface::ogClear(uInt32 colour) { +void ogSurface::ogClear(uInt32 colour) { uInt32 height = 0; uInt32 xx, yy; uInt8 r, g, b, a; - if (!ogAvail()) return; + if (!ogAvail()) + return; do { if (ogIsBlending()) { ogUnpack(colour, r, g, b, a); - if (a == 0) return; - if (a == 255) break; - for (yy = 0; yy <= maxY; yy++) - for (xx = 0; xx <= maxX; xx++) + if (a == 0) + return; + if (a == 255) + break; + for (yy = 0; yy <= maxY; yy++) + for (xx = 0; xx <= maxX; xx++) RawSetPixel(xx, yy, r, g, b, a); return; - } // if + } // if } while (false); __asm__ __volatile__("cld\n"); switch (bytesPerPix) { - case 4: + case 4: __asm__ __volatile__( - " add (%%esi), %%edi \n" // add edi, [esi] - " mov %%ecx, %%esi \n" // mov esi, ecx - " inc %%edx \n" // inc edx (maxX) - " inc %%ebx \n" // inc ebx (maxY) - " mov %%edx, %%ecx \n" // mov ecx, edx - " shl $2, %%ecx \n" // shl ecx, 2 - " sub %%ecx, %%esi \n" // sub esi, ecx // adjust for pix size - "loop32: \n" - " mov %%edx, %%ecx \n" // mov ecx, edx - " rep \n" - " stosl \n" - " add %%esi, %%edi \n" // add edi, esi - " dec %%ebx \n" - " jnz loop32 \n" - + " add (%%esi), %%edi \n" // add edi, [esi] + " mov %%ecx, %%esi \n"// mov esi, ecx + " inc %%edx \n"// inc edx (maxX) + " inc %%ebx \n"// inc ebx (maxY) + " mov %%edx, %%ecx \n"// mov ecx, edx + " shl $2, %%ecx \n"// shl ecx, 2 + " sub %%ecx, %%esi \n"// sub esi, ecx // adjust for pix size + "loop32: \n" + " mov %%edx, %%ecx \n"// mov ecx, edx + " rep \n" + " stosl \n" + " add %%esi, %%edi \n"// add edi, esi + " dec %%ebx \n" + " jnz loop32 \n" + : - : "D" (buffer), "S" (lineOfs), // %0, %1 - "a" (colour), "b" (maxY), // %2, %3 - "c" (xRes), "d" (maxX) // %4, %5 - ); - break; - case 3: - __asm__ __volatile__( - " add (%%esi), %%edi \n" // add edi, [esi] - " mov %%ecx, %%esi \n" // mov esi, ecx - " inc %%edx \n" // inc edx (maxX) - " inc %%ebx \n" // inc ebx (maxY) - " sub %%edx, %%esi \n" // sub esi, edx // adjust for pix size - " mov %%ebx, %6 \n" // mov height, ebx - " sub %%edx, %%esi \n" // sub esi, edx // adjust for pix size - " mov %%eax, %%ebx \n" // mov ebx, eax - " sub %%edx, %%esi \n" // sub esi, edx // adjust for pix size - " shr $16, %%ebx \n" // shr ebx, 16 - "oloop24: \n" - " mov %%edx, %%ecx \n" // mov ecx, edx - "iloop24: \n" - " mov %%ax,(%%edi) \n" // mov [edi],ax - " movb %%bl,2(%%edi) \n" // mov [edi+2],bl - " add $3, %%edi \n" // add edi, 3 - " dec %%ecx \n" // dec ecx - " jnz iloop24 \n" - " add %%esi, %%edi \n" // add edi, esi - " decl %6 \n" // dec height - " jnz oloop24 \n" - : - : "D" (buffer), "S" (lineOfs), // %0, %1 - "a" (colour), "b" (maxY), // %2, %3 - "c" (xRes), "d" (maxX), // %4, %5 - "m" (height) // %6 - ); - break; - case 2: - __asm__ __volatile__( - " add (%%esi), %%edi \n" // add edi, [esi] - " mov %%ecx, %%esi \n" // mov esi, ecx - " inc %%edx \n" // inc edx (maxX) - " inc %%ebx \n" // inc ebx (maxY) - " sub %%edx, %%esi \n" // sub esi, edx - " sub %%edx, %%esi \n" // sub esi, edx // adjust for pix size - " mov %%ax, %%cx \n" // mov cx, ax - " shl $16, %%eax \n" // shl eax, 16 - " mov %%cx, %%ax \n" // mov ax, cx - "loop16: \n" - " mov %%edx, %%ecx \n" // mov ecx, edx - " shr $1, %%ecx \n" // shr ecx, 1 - " rep \n" - " stosl \n" - " jnc noc16 \n" - " stosw \n" - "noc16: \n" - " add %%esi, %%edi \n" // add edi, esi - " dec %%ebx \n" - " jnz loop16 \n" - : - : "D" (buffer), "S" (lineOfs), // %0, %1 - "a" (colour), "b" (maxY), // %2, %3 - "c" (xRes), "d" (maxX) // %4, %5 + : "D" (buffer), "S" (lineOfs),// %0, %1 + "a" (colour), "b" (maxY),// %2, %3 + "c" (xRes), "d" (maxX)// %4, %5 ); - break; + break; + case 3: + __asm__ __volatile__( + " add (%%esi), %%edi \n" // add edi, [esi] + " mov %%ecx, %%esi \n"// mov esi, ecx + " inc %%edx \n"// inc edx (maxX) + " inc %%ebx \n"// inc ebx (maxY) + " sub %%edx, %%esi \n"// sub esi, edx // adjust for pix size + " mov %%ebx, %6 \n"// mov height, ebx + " sub %%edx, %%esi \n"// sub esi, edx // adjust for pix size + " mov %%eax, %%ebx \n"// mov ebx, eax + " sub %%edx, %%esi \n"// sub esi, edx // adjust for pix size + " shr $16, %%ebx \n"// shr ebx, 16 + "oloop24: \n" + " mov %%edx, %%ecx \n"// mov ecx, edx + "iloop24: \n" + " mov %%ax,(%%edi) \n"// mov [edi],ax + " movb %%bl,2(%%edi) \n"// mov [edi+2],bl + " add $3, %%edi \n"// add edi, 3 + " dec %%ecx \n"// dec ecx + " jnz iloop24 \n" + " add %%esi, %%edi \n"// add edi, esi + " decl %6 \n"// dec height + " jnz oloop24 \n" + : + : "D" (buffer), "S" (lineOfs),// %0, %1 + "a" (colour), "b" (maxY),// %2, %3 + "c" (xRes), "d" (maxX),// %4, %5 + "m" (height)// %6 + ); + break; + case 2: + __asm__ __volatile__( + " add (%%esi), %%edi \n" // add edi, [esi] + " mov %%ecx, %%esi \n"// mov esi, ecx + " inc %%edx \n"// inc edx (maxX) + " inc %%ebx \n"// inc ebx (maxY) + " sub %%edx, %%esi \n"// sub esi, edx + " sub %%edx, %%esi \n"// sub esi, edx // adjust for pix size + " mov %%ax, %%cx \n"// mov cx, ax + " shl $16, %%eax \n"// shl eax, 16 + " mov %%cx, %%ax \n"// mov ax, cx + "loop16: \n" + " mov %%edx, %%ecx \n"// mov ecx, edx + " shr $1, %%ecx \n"// shr ecx, 1 + " rep \n" + " stosl \n" + " jnc noc16 \n" + " stosw \n" + "noc16: \n" + " add %%esi, %%edi \n"// add edi, esi + " dec %%ebx \n" + " jnz loop16 \n" + : + : "D" (buffer), "S" (lineOfs),// %0, %1 + "a" (colour), "b" (maxY),// %2, %3 + "c" (xRes), "d" (maxX)// %4, %5 + ); + break; case 1: __asm__ __volatile__( - " add (%%esi), %%edi \n" // add edi, [esi] - " mov %%ecx, %%esi \n" // mov esi, ecx - " inc %%edx \n" // inc edx (maxY) - " inc %%ebx \n" // inc ebx (maxX) - " sub %%edx, %%esi \n" // sub esi, edx - " mov %%al, %%ah \n" // mov ah, al - " mov %%ax, %%cx \n" // mov cx, ax - " shl $16, %%eax \n" // shl eax, 16 - " mov %%cx, %%ax \n" // mov ax, cx - "loop8: \n" - " push %%edx \n" - " mov %%edx, %%ecx \n" // mov ecx, edx - " and $3, %%edx \n" // and edx, 3 - " shr $2, %%ecx \n" // shr ecx, 2 - " rep \n" - " stosl \n" - " mov %%edx, %%ecx \n" // mov ecx, edx - " rep \n" - " stosb \n" - " pop %%edx \n" - " add %%esi, %%edi \n" // add edi, esi - " dec %%ebx \n" - " jnz loop8 \n" + " add (%%esi), %%edi \n" // add edi, [esi] + " mov %%ecx, %%esi \n"// mov esi, ecx + " inc %%edx \n"// inc edx (maxY) + " inc %%ebx \n"// inc ebx (maxX) + " sub %%edx, %%esi \n"// sub esi, edx + " mov %%al, %%ah \n"// mov ah, al + " mov %%ax, %%cx \n"// mov cx, ax + " shl $16, %%eax \n"// shl eax, 16 + " mov %%cx, %%ax \n"// mov ax, cx + "loop8: \n" + " push %%edx \n" + " mov %%edx, %%ecx \n"// mov ecx, edx + " and $3, %%edx \n"// and edx, 3 + " shr $2, %%ecx \n"// shr ecx, 2 + " rep \n" + " stosl \n" + " mov %%edx, %%ecx \n"// mov ecx, edx + " rep \n" + " stosb \n" + " pop %%edx \n" + " add %%esi, %%edi \n"// add edi, esi + " dec %%ebx \n" + " jnz loop8 \n" : - : "D" (buffer), "S" (lineOfs), // %0, %1 - "a" (colour), "b" (maxY), // %2, %3 - "c" (xRes), "d" (maxX) // %4, %5 + : "D" (buffer), "S" (lineOfs),// %0, %1 + "a" (colour), "b" (maxY),// %2, %3 + "c" (xRes), "d" (maxX)// %4, %5 ); - break; + break; } // switch return; } // ogSurface::ogClear -bool -ogSurface::ogClone(ogSurface& src) { +bool ogSurface::ogClone(ogSurface& src) { bool created; ogPixelFmt pixFmt; @@ -1976,8 +2024,9 @@ } // if src.ogGetPixFmt(pixFmt); - created = ogCreate(src.maxX+1, src.maxY+1, pixFmt); - if (!created) return false; + created = ogCreate(src.maxX + 1, src.maxY + 1, pixFmt); + if (!created) + return false; *attributes = *src.attributes; @@ -1986,25 +2035,28 @@ return true; } // ogSurface::ogClone -void -ogSurface::ogCopy(ogSurface& src) { +void ogSurface::ogCopy(ogSurface& src) { uInt32 pixMap[256]; uInt32 count, xCount, yCount; uInt32 xx, yy; - uInt8 r, g, b, a; + uInt8 r, g, b, a; void * srcPtr; - - if (!ogAvail()) return; - if (!src.ogAvail()) return; - xCount = src.maxX+1; - if (xCount > maxX+1) xCount = maxX+1; - yCount = src.maxY+1; - if (yCount > maxY+1) yCount = maxY+1; + if (!ogAvail()) + return; + if (!src.ogAvail()) + return; + + xCount = src.maxX + 1; + if (xCount > maxX + 1) + xCount = maxX + 1; + yCount = src.maxY + 1; + if (yCount > maxY + 1) + yCount = maxY + 1; if (ogIsBlending()) { - for (yy = 0; yy < yCount; yy++) + for (yy = 0; yy < yCount; yy++) for (xx = 0; xx < xCount; xx++) { src.ogUnpack(src.RawGetPixel(xx, yy), r, g, b, a); RawSetPixel(xx, yy, r, g, b, a); @@ -2016,28 +2068,27 @@ if (pixFmtID != src.pixFmtID) { if (src.bytesPerPix == 1) { for (xx = 0; xx < 256; xx++) - pixMap[xx] = ogPack(src.pal[xx].red, - src.pal[xx].green, - src.pal[xx].blue, - src.pal[xx].alpha); + pixMap[xx] = ogPack(src.pal[xx].red, src.pal[xx].green, src.pal[xx].blue, src.pal[xx].alpha); - for (yy = 0; yy < yCount; yy++) - for (xx = 0; xx < xCount; xx++) + for (yy = 0; yy < yCount; yy++) + for (xx = 0; xx < xCount; xx++) RawSetPixel(xx, yy, pixMap[src.RawGetPixel(xx, yy)]); - } else { // if src.bytesPerPix == 1 + } + else { // if src.bytesPerPix == 1 ogPixelFmt srcPixFmt, dstPixFmt; src.ogGetPixFmt(srcPixFmt); ogGetPixFmt(dstPixFmt); ogPixCon * pc = new ogPixCon(srcPixFmt, dstPixFmt); - - for (yy = 0; yy < yCount; yy++) - for (xx = 0; xx < xCount; xx++) + + for (yy = 0; yy < yCount; yy++) + for (xx = 0; xx < xCount; xx++) RawSetPixel(xx, yy, pc->ConvPix(src.RawGetPixel(xx, yy))); delete pc; } // else - } else { + } + else { xCount *= bytesPerPix; @@ -2064,129 +2115,134 @@ free(srcPtr); #endif } // if srcPtr!=NULL - } else ogCopyLineTo(0, count, srcPtr, xCount); + } + else + ogCopyLineTo(0, count, srcPtr, xCount); } // else } // ogSurface::ogCopy -void -ogSurface::ogCopyBuf(int32 dX1, int32 dY1, - ogSurface& src, int32 sX1, int32 sY1, int32 sX2, int32 sY2) { +void ogSurface::ogCopyBuf(int32 dX1, int32 dY1, ogSurface& src, int32 sX1, int32 sY1, int32 sX2, int32 sY2) { uInt32 pixMap[256]; int32 xx, yy, count, xCount, yCount; uInt8 r, g, b, a; void *srcPtr; ogPixCon * pc; ogPixelFmt srcPixFmt, dstPixFmt; - - if (!ogAvail()) return; - if (!src.ogAvail()) return; - - if ((dX1 > (int32)maxX) || (dY1 > (int32)maxY)) return; - - // if any of the source buffer is out of bounds then do nothing - if (( (uInt32)sX1 > src.maxX) || ((uInt32)sX2 > src.maxX) || - ( (uInt32)sY1 > src.maxY) || ((uInt32)sY2 > src.maxY)) return; + + if (!ogAvail()) + return; + if (!src.ogAvail()) + return; + + if ((dX1 > (int32) maxX) || (dY1 > (int32) maxY)) + return; + + // if any of the source buffer is out of bounds then do nothing + if (((uInt32) sX1 > src.maxX) || ((uInt32) sX2 > src.maxX) || ((uInt32) sY1 > src.maxY) || ((uInt32) sY2 > src.maxY)) + return; if (sX1 > sX2) { xx = sX1; - sX1= sX2; - sX2= xx; + sX1 = sX2; + sX2 = xx; } // if if (sY1 > sY2) { yy = sY1; - sY1= sY2; - sY2= yy; + sY1 = sY2; + sY2 = yy; } // if - xCount = abs(sX2-sX1)+1; - yCount = abs(sY2-sY1)+1; - - if (dX1+xCount > (int32)maxX+1) xCount = maxX-dX1+1; - if (dY1+yCount > (int32)maxY+1) yCount = maxY-dY1+1; + xCount = abs(sX2 - sX1) + 1; + yCount = abs(sY2 - sY1) + 1; + + if (dX1 + xCount > (int32) maxX + 1) + xCount = maxX - dX1 + 1; + if (dY1 + yCount > (int32) maxY + 1) + yCount = maxY - dY1 + 1; if (dX1 < 0) { xCount += dX1; sX1 -= dX1; dX1 = 0; } // if - + if (dY1 < 0) { yCount += dY1; sY1 -= dY1; dY1 = 0; } // if - - if ((dX1+xCount < 0) || (dY1+yCount < 0)) return; + + if ((dX1 + xCount < 0) || (dY1 + yCount < 0)) + return; if (ogIsBlending()) { - for (yy = 0; yy < yCount; yy++) + for (yy = 0; yy < yCount; yy++) for (xx = 0; xx < xCount; xx++) { - src.ogUnpack(src.RawGetPixel(sX1+xx, sY1+yy), r, g, b, a); - RawSetPixel(dX1+xx, dY1+yy, r, g, b, a); + src.ogUnpack(src.RawGetPixel(sX1 + xx, sY1 + yy), r, g, b, a); + RawSetPixel(dX1 + xx, dY1 + yy, r, g, b, a); } // for xx } // if IsBlending if (pixFmtID != src.pixFmtID) { if (src.bytesPerPix == 1) { - for (xx = 0; xx < 256; xx++) - pixMap[xx] = ogPack(src.pal[xx].red, - src.pal[xx].green, - src.pal[xx].blue, - src.pal[xx].alpha); + for (xx = 0; xx < 256; xx++) + pixMap[xx] = ogPack(src.pal[xx].red, src.pal[xx].green, src.pal[xx].blue, src.pal[xx].alpha); - for (yy = 0; yy < yCount; yy++) + for (yy = 0; yy < yCount; yy++) for (xx = 0; xx < xCount; xx++) - RawSetPixel(dX1+xx,dY1+yy, - pixMap[src.ogGetPixel(sX1+xx,sY1+yy)]); - } else { - + RawSetPixel(dX1 + xx, dY1 + yy, pixMap[src.ogGetPixel(sX1 + xx, sY1 + yy)]); + } + else { + src.ogGetPixFmt(srcPixFmt); ogGetPixFmt(dstPixFmt); pc = new ogPixCon(srcPixFmt, dstPixFmt); // allocate the pixel converter - if (pc == NULL) return; + if (pc == NULL) + return; for (yy = 0; yy < yCount; yy++) for (xx = 0; xx < xCount; xx++) { - RawSetPixel(dX1+xx, dY1+yy, - pc->ConvPix(src.RawGetPixel(sX1+xx, sY1+yy))); + RawSetPixel(dX1 + xx, dY1 + yy, pc->ConvPix(src.RawGetPixel(sX1 + xx, sY1 + yy))); } // for xx delete pc; // destroy the pixel converter } // else - } else { + } + else { xCount *= bytesPerPix; for (count = 0; count < yCount; count++) - if ((srcPtr = src.ogGetPtr(sX1, sY1+count)) == NULL) { + if ((srcPtr = src.ogGetPtr(sX1, sY1 + count)) == NULL) { // if we are here then we couldn't get a direct memory pointer // from the source object. This means that it is not a normal // "memory" buffer and we have to use the implementation inspecific // interface. We let the source buffer fill a "temporary" buffer // and then we copy it to where it needs to go. - + #ifdef __UBIXOS_KERNEL__ srcPtr = kmalloc(xCount); // allocate space #else srcPtr = malloc(xCount); // allocate space #endif if (srcPtr != NULL) { - src.ogCopyLineFrom(sX1, sY1+count, srcPtr, xCount); - ogCopyLineTo(dX1, dY1+count, srcPtr, xCount); + src.ogCopyLineFrom(sX1, sY1 + count, srcPtr, xCount); + ogCopyLineTo(dX1, dY1 + count, srcPtr, xCount); #ifdef __UBIXOS_KERNEL__ kfree(srcPtr); #else free(srcPtr); #endif } // if srcPtr!=NULL - } else ogCopyLineTo(dX1,dY1+count,srcPtr,xCount); + } + else + ogCopyLineTo(dX1, dY1 + count, srcPtr, xCount); } // else } // ogSurface::ogCopyBuf -void -ogSurface::ogCopyLineTo(uInt32 dx, uInt32 dy, const void * src, uInt32 size) { +void ogSurface::ogCopyLineTo(uInt32 dx, uInt32 dy, const void * src, uInt32 size) { /* * CopyLineTo() * @@ -2207,16 +2263,15 @@ * methods that don't check to make sure you're hosing things. Don't * use this method unless YOU KNOW WHAT YOU'RE DOING!!!!!!!!! */ - - memcpy( (uint8_t *)buffer + lineOfs[dy] + (dx*bytesPerPix), // dest - src, // src - size); // size - + + memcpy((uint8_t *) buffer + lineOfs[dy] + (dx * bytesPerPix), // dest + src, // src + size); // size + return; } // ogSurface::ogCopyLineTo -void -ogSurface::ogCopyLineFrom(uInt32 sx, uInt32 sy, void * dst, uInt32 size) { +void ogSurface::ogCopyLineFrom(uInt32 sx, uInt32 sy, void * dst, uInt32 size) { /* * CopyLineFrom() * @@ -2238,52 +2293,53 @@ * use this method unless YOU KNOW WHAT YOU'RE DOING!!!!!!!!! */ - memcpy( dst, // dest - (uInt8*)buffer+lineOfs[sy]+sx*bytesPerPix, // src - size); // size + memcpy(dst, // dest + (uInt8*) buffer + lineOfs[sy] + sx * bytesPerPix, // src + size); // size return; } // ogSurface::ogCopyLineFrom -void -ogSurface::ogCopyPalette(ogSurface& src) { - if (src.pal == NULL) return; - if (pal == NULL) pal = new ogRGBA8[256]; - if (pal == NULL) return; +void ogSurface::ogCopyPalette(ogSurface& src) { + if (src.pal == NULL) + return; + if (pal == NULL) + pal = new ogRGBA8[256]; + if (pal == NULL) + return; src.ogGetPalette(pal); // memcpy(pal, src.pal, sizeof(ogRGBA8)*256); return; } // ogSurface::ogCopyPalette -bool -ogSurface::ogCreate(uInt32 _xRes, uInt32 _yRes, ogPixelFmt _pixFormat) { +bool ogSurface::ogCreate(uInt32 _xRes, uInt32 _yRes, ogPixelFmt _pixFormat) { /* * ogSurface::ogCreate() * Allocates memory for a buffer of size _xRes by _yRes with * the pixel format defined in _pixformat. Allocates memory * for pal and lineOfs. */ - void * newBuffer = NULL; - uInt32 * newLineOfs = NULL; - ogRGBA8 * newPal = NULL; + void * newBuffer = NULL; + uInt32 * newLineOfs = NULL; + ogRGBA8 * newPal = NULL; ogAttributes* newAttributes = NULL; - uInt32 newBSize; - uInt32 newLSize; - uInt32 yy; + uInt32 newBSize; + uInt32 newLSize; + uInt32 yy; - bool status = false; - + bool status = false; + switch (_pixFormat.BPP) { - case 8: - case 15: - case 16: - case 24: - case 32: + case 8: + case 15: + case 16: + case 24: + case 32: break; - default: - ogSetLastError(ogBadBPP); - return false; + default: + ogSetLastError(ogBadBPP); + return false; } // switch newBSize = _xRes * _yRes * ((_pixFormat.BPP + 7) >> 3); @@ -2300,11 +2356,10 @@ do { - if ((newBuffer == NULL) || (newLineOfs == NULL) || - (newPal == NULL) || (newAttributes == NULL)) { + if ((newBuffer == NULL) || (newLineOfs == NULL) || (newPal == NULL) || (newAttributes == NULL)) { ogSetLastError(ogMemAllocFail); - break; // break out of do {...} while(false) - } // if + break; // break out of do {...} while(false) + } // if // check to see if we have already allocated memory .. if so, free it @@ -2314,8 +2369,8 @@ #else free(buffer); #endif - delete [] lineOfs; - delete [] pal; + delete[] lineOfs; + delete[] pal; delete attributes; } // if dataState @@ -2324,22 +2379,22 @@ pal = newPal; attributes = newAttributes; bSize = newBSize; - lSize = newLSize; - - newBuffer = NULL; - newLineOfs = NULL; - newPal = NULL; + lSize = newLSize; + + newBuffer = NULL; + newLineOfs = NULL; + newPal = NULL; newAttributes = NULL; - + BPP = _pixFormat.BPP; bytesPerPix = (BPP + 7) >> 3; - ogSetPalette(DEFAULT_PALETTE); + ogSetPalette(DEFAULT_PALETTE); // memcpy(pal, DEFAULT_PALETTE, sizeof(ogRGBA8)*256); - maxX = _xRes -1; + maxX = _xRes - 1; xRes = _xRes * bytesPerPix; - maxY = _yRes -1; + maxY = _yRes - 1; yRes = _yRes; // in the pascal version we go from 1 to maxY .. here we use yy < yRes @@ -2347,23 +2402,23 @@ lineOfs[0] = 0; for (yy = 1; yy < yRes; yy++) - lineOfs[yy] = lineOfs[yy-1]+xRes; + lineOfs[yy] = lineOfs[yy - 1] + xRes; dataState = ogOwner; - // For 8bpp modes the next part doesn't matter + // For 8bpp modes the next part doesn't matter - redFieldPosition = _pixFormat.redFieldPosition; + redFieldPosition = _pixFormat.redFieldPosition; greenFieldPosition = _pixFormat.greenFieldPosition; - blueFieldPosition = _pixFormat.blueFieldPosition; + blueFieldPosition = _pixFormat.blueFieldPosition; alphaFieldPosition = _pixFormat.alphaFieldPosition; - // The next part is only used by 15/16hpp - redShifter = 8-_pixFormat.redMaskSize; - greenShifter = 8-_pixFormat.greenMaskSize; - blueShifter = 8-_pixFormat.blueMaskSize; - alphaShifter = 8-_pixFormat.alphaMaskSize; + // The next part is only used by 15/16hpp + redShifter = 8 - _pixFormat.redMaskSize; + greenShifter = 8 - _pixFormat.greenMaskSize; + blueShifter = 8 - _pixFormat.blueMaskSize; + alphaShifter = 8 - _pixFormat.alphaMaskSize; - if (_pixFormat.alphaMaskSize != 0) + if (_pixFormat.alphaMaskSize != 0) alphaMasker = ~(OG_MASKS[_pixFormat.alphaMaskSize] << alphaFieldPosition); else alphaMasker = ~0; @@ -2372,11 +2427,9 @@ pixFmtID = 0x08080808; // turn anti aliasing off by default for 8bpp modes ogSetAntiAliasing(false); - } else { - pixFmtID = (redFieldPosition) | - (greenFieldPosition << 8) | - (blueFieldPosition << 16) | - (alphaFieldPosition << 24); + } + else { + pixFmtID = (redFieldPosition) | (greenFieldPosition << 8) | (blueFieldPosition << 16) | (alphaFieldPosition << 24); ogSetAntiAliasing(true); } // else @@ -2384,47 +2437,50 @@ owner = this; status = true; - } while(false); + } while (false); #ifdef __UBIXOS_KERNEL__ if (newBuffer) kfree(newBuffer); #else - if (newBuffer) free(newBuffer); + if (newBuffer) + free(newBuffer); #endif - if (newLineOfs) delete [] newLineOfs; - if (newPal) delete [] newPal; - if (newAttributes) delete newAttributes; + if (newLineOfs) + delete[] newLineOfs; + if (newPal) + delete[] newPal; + if (newAttributes) + delete newAttributes; return status; } // ogSurface::ogCreate -void -ogSurface::ogCubicBezierCurve(int32 x1, int32 y1, int32 x2, int32 y2, - int32 x3, int32 y3, int32 x4, int32 y4, - uInt32 segments, uInt32 colour) { +void ogSurface::ogCubicBezierCurve(int32 x1, int32 y1, int32 x2, int32 y2, int32 x3, int32 y3, int32 x4, int32 y4, uInt32 segments, uInt32 colour) { float tX1, tY1, tX2, tY2, tX3, tY3, mu, mu2, mu3, mudelta; int32 xStart, yStart, xEnd, yEnd; uInt32 n; - if (segments < 1) return; - if (segments > 128) segments=128; - - mudelta = 1.0/segments; + if (segments < 1) + return; + if (segments > 128) + segments = 128; + + mudelta = 1.0 / segments; mu = mudelta; - tX1 =-x1+3*x2-3*x3+x4; - tY1 =-y1+3*y2-3*y3+y4; - tX2 =3*x1-6*x2+3*x3; - tY2 =3*y1-6*y2+3*y3; - tX3 =-3*x1+3*x2; - tY3 =-3*y1+3*y2; + tX1 = -x1 + 3 * x2 - 3 * x3 + x4; + tY1 = -y1 + 3 * y2 - 3 * y3 + y4; + tX2 = 3 * x1 - 6 * x2 + 3 * x3; + tY2 = 3 * y1 - 6 * y2 + 3 * y3; + tX3 = -3 * x1 + 3 * x2; + tY3 = -3 * y1 + 3 * y2; xStart = x1; yStart = y1; for (n = 1; n < segments; n++) { - mu2 = mu*mu; - mu3 = mu2*mu; - xEnd = static_cast(mu3*tX1+mu2*tX2+mu*tX3+x1 +0.5f); - yEnd = static_cast(mu3*tY1+mu2*tY2+mu*tY3+y1 +0.5f); + mu2 = mu * mu; + mu3 = mu2 * mu; + xEnd = static_cast(mu3 * tX1 + mu2 * tX2 + mu * tX3 + x1 + 0.5f); + yEnd = static_cast(mu3 * tY1 + mu2 * tY2 + mu * tY3 + y1 + 0.5f); ogLine(xStart, yStart, xEnd, yEnd, colour); mu += mudelta; xStart = xEnd; @@ -2433,54 +2489,53 @@ return; } // ogSurface::ogCubicBezierCurve -void -ogSurface::ogCurve(int32 x1, int32 y1, int32 x2, int32 y2, int32 x3, int32 y3, - uInt32 segments, uInt32 colour) { +void ogSurface::ogCurve(int32 x1, int32 y1, int32 x2, int32 y2, int32 x3, int32 y3, uInt32 segments, uInt32 colour) { int64 ex, ey, fx, fy; int64 t1, t2; - if (segments<2) segments=2; else if (segments>128) segments=128; - x2 = (x2*2)-((x1+x3)/2); - y2 = (y2*2)-((y1+y3)/2); + if (segments < 2) + segments = 2; + else if (segments > 128) + segments = 128; + x2 = (x2 * 2) - ((x1 + x3) / 2); + y2 = (y2 * 2) - ((y1 + y3) / 2); - ex = ((int64)(x2-x1) << 17) / segments; - ey = ((int64)(y2-y1) << 17) / (int64)segments; - fx = ((int64)(x3-(2*x2)+x1) << 16) / (segments*segments); - fy = ((int64)(y3-(2*y2)+y1) << 16) / (int64)(segments*segments); + ex = ((int64) (x2 - x1) << 17) / segments; + ey = ((int64) (y2 - y1) << 17) / (int64) segments; + fx = ((int64) (x3 - (2 * x2) + x1) << 16) / (segments * segments); + fy = ((int64) (y3 - (2 * y2) + y1) << 16) / (int64) (segments * segments); while (--segments > 0) { t1 = x3; t2 = y3; - x3 = ((int64)((fx*segments+ex)*segments) / 65536L)+x1; - y3 = ((int64)((fy*segments+ey)*segments) / 65536L)+y1; + x3 = ((int64) ((fx * segments + ex) * segments) / 65536L) + x1; + y3 = ((int64) ((fy * segments + ey) * segments) / 65536L) + y1; ogLine(t1, t2, x3, y3, colour); } // while ogLine(x3, y3, x1, y1, colour); return; - + } // ogSurface::ogCurve -void -ogSurface::ogFillCircle(int32 xCenter, int32 yCenter, - uInt32 radius, uInt32 colour) { +void ogSurface::ogFillCircle(int32 xCenter, int32 yCenter, uInt32 radius, uInt32 colour) { int32 x, y, d; x = 0; y = radius; - d = 4*(1-radius); + d = 4 * (1 - radius); while (y >= 0) { if (d + y > 0) { - ogHLine(xCenter-x, xCenter+x, yCenter-y, colour); - if (y != 0) ogHLine(xCenter-x, xCenter+x, yCenter+y, colour); - + ogHLine(xCenter - x, xCenter + x, yCenter - y, colour); + if (y != 0) + ogHLine(xCenter - x, xCenter + x, yCenter + y, colour); + --y; - d -= 4*y+1; + d -= 4 * y + 1; } // if - if (x > d) { ++x; - d += 4*x+1; + d += 4 * x + 1; } // if } // while return; @@ -2488,200 +2543,204 @@ #if 0 !-/* Scan converts an edge from (X1,Y1) to (X2,Y2), not including the -!- * point at (X2,Y2). This avoids overlapping the end of one line with -!- * the start of the next, and causes the bottom scan line of the -!- * polygon not to be drawn. If SkipFirst != 0, the point at (X1,Y1) -!- * isn't drawn. For each scan line, the pixel closest to the scanned -!- * line without being to the left of the scanned line is chosen -!- */ + !- * point at (X2,Y2). This avoids overlapping the end of one line with + !- * the start of the next, and causes the bottom scan line of the + !- * polygon not to be drawn. If SkipFirst != 0, the point at (X1,Y1) + !- * isn't drawn. For each scan line, the pixel closest to the scanned + !- * line without being to the left of the scanned line is chosen + !- */ !-static void index_forward(int32 & index, uInt32 numPoints) { -!- index = (index + 1) % numPoints; -!- return; -!-} // index_forward + !- index = (index + 1) % numPoints; + !- return; + !-} // index_forward !- !-static void index_backward(int32 & index, uInt32 numPoints) { -!- index = (index - 1 + numPoints) % numPoints; -!- return; -!-} // index_forward + !- index = (index - 1 + numPoints) % numPoints; + !- return; + !-} // index_forward !- !-static void index_move(int32 & index, uInt32 numPoints, int32 direction) { -!- if (direction > 0) -!- index_forward(index, numPoints); -!- else -!- index_backward(index, numPoints); -!- return; -!-} // index_move + !- if (direction > 0) + !- index_forward(index, numPoints); + !- + else + !- index_backward(index, numPoints); + !- return; + !-} // index_move !- !-static void scanEdge(int32 x1, int32 y1, int32 x2, int32 y2, -!- uInt32 & eIdx, int32 * xList) { -!- int32 y, deltaX, deltaY; -!- float inverseSlope; -!- -!- deltaX = x2 - x1; -!- deltaY = y2 - y1; -!- if (deltaY <= 0) return; -!- inverseSlope = deltaX / deltaY; -!- -!- // Store the X coordinate of the pixel closest to but not to the -!- // left of the line for each Y coordinate between Y1 and Y2, not -!- // including Y2 -!- y = y1; -!- do { -!- xList[eIdx] = x1+ (int32)(0.5f+((y-y1)*inverseSlope)); -!- y++; -!- eIdx++; -!- } while (y maxPointY) { -!- maxIndex = i; -!- maxPointY = polyPoints[i].y; // new bottom -!- } // else if -!- } // for -!- -!- if (minPointY == maxPointY) return; -!- -!- // scan in ascending order to find the last top-edge point -!- minIndexR = minIndexL; -!- while (polyPoints[minIndexR].y == minPointY) index_forward(minIndexR, numPoints); -!- index_backward(minIndexR, numPoints); // back up to last top-edge point -!- -!- // now scan in descending order to find the first top-edge point -!- while (polyPoints[minIndexL].y == minPointY) index_backward(minIndexL, numPoints); -!- index_forward(minIndexL, numPoints); -!- -!- // figure out which direction through the vertex list from the top -!- // vertex is the left edge and which is the right -!- leftEdgeDir = -1; -!- -!- topIsFlat = (polyPoints[minIndexL].x==polyPoints[minIndexR].x) ? 0 : 1; -!- if (topIsFlat==1) { -!- if (polyPoints[minIndexL].x > polyPoints[minIndexR].x) { -!- leftEdgeDir = 1; -!- temp = minIndexL; -!- minIndexL = minIndexR; -!- minIndexR = temp; -!- } -!- } else { -!- // Point to the downward end of the first line of each of the -!- // two edges down from the top -!- nextIndex = minIndexR; -!- index_forward(nextIndex, numPoints); -!- prevIndex = minIndexL; -!- index_forward(prevIndex, numPoints); -!- -!- deltaXN = polyPoints[nextIndex].x - polyPoints[minIndexL].x; -!- deltaYN = polyPoints[nextIndex].y - polyPoints[minIndexL].y; -!- deltaXP = polyPoints[prevIndex].x - polyPoints[minIndexL].x; -!- deltaYP = polyPoints[prevIndex].y - polyPoints[minIndexL].y; -!- if (deltaXN * deltaYP - deltaYN * deltaXP < 0) { -!- leftEdgeDir = 1; -!- temp = minIndexL; -!- minIndexL = minIndexR; -!- minIndexR = temp; -!- } // if -!- } // else -!- -!- /* Set the # of scan lines in the polygon, skipping the bottom edge -!- * and also skipping the top vertex if the top isn't flat because -!- * in that case the top vertex has a right edge component, and set -!- * the top scan line to draw, which is likewise the second line of -!- * the polygon unles the top if flat -!- */ -!- -!- workingHLineList.length = maxPointY - minPointY; -!- if (workingHLineList.length <= 0) return; -!- workingHLineList.yStart = minPointY; -!- -!- // get memory in which to srote the line list we generate -!- workingHLineList.xLeft = workingHLineList.xRight = NULL; -!- if ((workingHLineList.xLeft = new int32[workingHLineList.length]) == NULL) return; -!- if ((workingHLineList.xRight = new int32[workingHLineList.length]) == NULL) { -!- delete workingHLineList.xLeft; -!- return; -!- } -!- memset(workingHLineList.xLeft,0,workingHLineList.length*sizeof(int32)); -!- memset(workingHLineList.xRight,0,workingHLineList.length*sizeof(int32)); -!- -!- // scan the left edge and store the boundary points int he list -!- // Initial pointer for storing scan converted left-edge coords -!- edgePointIdx = 0; -!- -!- // start from the top of the left edge -!- curIndex = prevIndex = minIndexL; -!- -!- do { -!- index_move(curIndex, numPoints, leftEdgeDir); -!- scanEdge(polyPoints[prevIndex].x, -!- polyPoints[prevIndex].y, -!- polyPoints[curIndex].x, -!- polyPoints[curIndex].y, -!- edgePointIdx, -!- workingHLineList.xLeft); -!- prevIndex = curIndex; -!- } while (curIndex != maxIndex); -!- -!- edgePointIdx = 0; -!- curIndex = prevIndex = minIndexR; -!- // Scan convert the right edge, top to bottom. X coordinates are -!- // adjusted 1 to the left, effectively causing scan conversion of -!- // the nearest points to the left of but not exactly on the edge } -!- do { -!- index_move(curIndex, numPoints, -leftEdgeDir); -!- scanEdge(polyPoints[prevIndex].x, -!- polyPoints[prevIndex].y, -!- polyPoints[curIndex].x, -!- polyPoints[curIndex].y, -!- edgePointIdx, -!- workingHLineList.xRight); -!- prevIndex = curIndex; -!- } while (curIndex != maxIndex); -!- -!- ogPolygon(numPoints, polyPoints, colour); -!- -!- for (i = 0; i < workingHLineList.length; i++) { -!- HLine(workingHLineList.xLeft[i], workingHLineList.xRight[i], -!- workingHLineList.yStart+i, colour); -!- } // for -!- -!- ogPolygon(numPoints, polyPoints, colour); -!- -!- delete workingHLineList.xLeft; -!- delete workingHLineList.xRight; -!- -!- return; -!-} // ogSurface::FillConvexPolygon + !- int32 i, minIndexL, maxIndex, minIndexR, temp; + !- int32 minPointY, maxPointY, leftEdgeDir; + !- int32 topIsFlat, nextIndex, curIndex, prevIndex; + !- int32 deltaXN, deltaYN, deltaXP, deltaYP; + !- ogHLineList workingHLineList; + !- uInt32 edgePointIdx; + !- uInt32 vetexIdx; + !- + !- if (numPoints<2) return; + !- minIndexL = maxIndex = 0; + !- minPointY = maxPointY = polyPoints[0].y; + !- for (i = 1; i < (int32)numPoints; i++) { + !- if (polyPoints[i].y < minPointY) { + !- minIndexL = i; + !- minPointY = polyPoints[i].y; // new top + !-} + else if (polyPoints[i].y > maxPointY) { + !- maxIndex = i; + !- maxPointY = polyPoints[i].y; // new bottom + !-} // else if + !-} // for + !- + !- if (minPointY == maxPointY) return; + !- + !-// scan in ascending order to find the last top-edge point + !- minIndexR = minIndexL; + !- while (polyPoints[minIndexR].y == minPointY) index_forward(minIndexR, numPoints); + !- index_backward(minIndexR, numPoints);// back up to last top-edge point + !- + !-// now scan in descending order to find the first top-edge point + !- while (polyPoints[minIndexL].y == minPointY) index_backward(minIndexL, numPoints); + !- index_forward(minIndexL, numPoints); + !- + !-// figure out which direction through the vertex list from the top + !-// vertex is the left edge and which is the right + !- leftEdgeDir = -1; + !- + !- topIsFlat = (polyPoints[minIndexL].x==polyPoints[minIndexR].x) ? 0 : 1; + !- if (topIsFlat==1) { + !- if (polyPoints[minIndexL].x > polyPoints[minIndexR].x) { + !- leftEdgeDir = 1; + !- temp = minIndexL; + !- minIndexL = minIndexR; + !- minIndexR = temp; + !-} + !-} + else { + !- // Point to the downward end of the first line of each of the + !-// two edges down from the top + !- nextIndex = minIndexR; + !- index_forward(nextIndex, numPoints); + !- prevIndex = minIndexL; + !- index_forward(prevIndex, numPoints); + !- + !- deltaXN = polyPoints[nextIndex].x - polyPoints[minIndexL].x; + !- deltaYN = polyPoints[nextIndex].y - polyPoints[minIndexL].y; + !- deltaXP = polyPoints[prevIndex].x - polyPoints[minIndexL].x; + !- deltaYP = polyPoints[prevIndex].y - polyPoints[minIndexL].y; + !- if (deltaXN * deltaYP - deltaYN * deltaXP < 0) { + !- leftEdgeDir = 1; + !- temp = minIndexL; + !- minIndexL = minIndexR; + !- minIndexR = temp; + !-} // if + !-} // else + !- + !- /* Set the # of scan lines in the polygon, skipping the bottom edge + !- * and also skipping the top vertex if the top isn't flat because + !- * in that case the top vertex has a right edge component, and set + !- * the top scan line to draw, which is likewise the second line of + !- * the polygon unles the top if flat + !- */ + !- + !- workingHLineList.length = maxPointY - minPointY; + !- if (workingHLineList.length <= 0) return; + !- workingHLineList.yStart = minPointY; + !- + !- // get memory in which to srote the line list we generate + !- workingHLineList.xLeft = workingHLineList.xRight = NULL; + !- if ((workingHLineList.xLeft = new int32[workingHLineList.length]) == NULL) return; + !- if ((workingHLineList.xRight = new int32[workingHLineList.length]) == NULL) { + !- delete workingHLineList.xLeft; + !- return; + !-} + !- memset(workingHLineList.xLeft,0,workingHLineList.length*sizeof(int32)); + !- memset(workingHLineList.xRight,0,workingHLineList.length*sizeof(int32)); + !- + !- // scan the left edge and store the boundary points int he list + !-// Initial pointer for storing scan converted left-edge coords + !- edgePointIdx = 0; + !- + !-// start from the top of the left edge + !- curIndex = prevIndex = minIndexL; + !- + !- do { + !- index_move(curIndex, numPoints, leftEdgeDir); + !- scanEdge(polyPoints[prevIndex].x, + !- polyPoints[prevIndex].y, + !- polyPoints[curIndex].x, + !- polyPoints[curIndex].y, + !- edgePointIdx, + !- workingHLineList.xLeft); + !- prevIndex = curIndex; + !-}while (curIndex != maxIndex); + !- + !- edgePointIdx = 0; + !- curIndex = prevIndex = minIndexR; + !- // Scan convert the right edge, top to bottom. X coordinates are + !-// adjusted 1 to the left, effectively causing scan conversion of + !-// the nearest points to the left of but not exactly on the edge } + !- do { + !- index_move(curIndex, numPoints, -leftEdgeDir); + !- scanEdge(polyPoints[prevIndex].x, + !- polyPoints[prevIndex].y, + !- polyPoints[curIndex].x, + !- polyPoints[curIndex].y, + !- edgePointIdx, + !- workingHLineList.xRight); + !- prevIndex = curIndex; + !-}while (curIndex != maxIndex); + !- + !- ogPolygon(numPoints, polyPoints, colour); + !- + !- for (i = 0; i < workingHLineList.length; i++) { + !- HLine(workingHLineList.xLeft[i], workingHLineList.xRight[i], + !- workingHLineList.yStart+i, colour); + !-} // for + !- + !- ogPolygon(numPoints, polyPoints, colour); + !- + !- delete workingHLineList.xLeft; + !- delete workingHLineList.xRight; + !- + !- return; + !-} // ogSurface::FillConvexPolygon #endif -void -ogSurface::ogFillGouraudPolygon(uInt32 numPoints, ogPoint2d* polyPoints, ogRGBA8 * colours) { +void ogSurface::ogFillGouraudPolygon(uInt32 numPoints, ogPoint2d* polyPoints, ogRGBA8 * colours) { ogEdgeTable * edges; int32 currentY = ~0; - if (numPoints < 3) return; + if (numPoints < 3) + return; edges = new ogEdgeTable(); - if (edges == NULL) return; // sanity check + if (edges == NULL) + return; // sanity check edges->BuildGET_G(numPoints, polyPoints, colours); @@ -2694,25 +2753,28 @@ edges->AdvanceAET(); edges->XSortAET(); ++currentY; - if (currentY > (int32)maxY) break; // if we've gone past the bottom, stop + if (currentY > (int32) maxY) + break; // if we've gone past the bottom, stop } // while delete edges; return; } // ogSurface::ogFillGouraudPolygon -void -ogSurface::ogFillPolygon(uInt32 numPoints, ogPoint2d* polyPoints, uInt32 colour) { +void ogSurface::ogFillPolygon(uInt32 numPoints, ogPoint2d* polyPoints, uInt32 colour) { ogEdgeTable * edges; int32 currentY = ~0; - if (numPoints < 3) return; + if (numPoints < 3) + return; - if (!ogIsBlending()) ogPolygon(numPoints, polyPoints, colour); + if (!ogIsBlending()) + ogPolygon(numPoints, polyPoints, colour); edges = new ogEdgeTable(); - if (edges == NULL) return; // sanity check + if (edges == NULL) + return; // sanity check edges->BuildGET(numPoints, polyPoints); @@ -2725,37 +2787,39 @@ edges->AdvanceAET(); edges->XSortAET(); ++currentY; - if (currentY > (int32)maxY) break; // if we've gone past the bottom, stop + if (currentY > (int32) maxY) + break; // if we've gone past the bottom, stop } // while delete edges; return; } // ogSurface::ogFillPolygon -void -ogSurface::ogFillRect(int32 x1, int32 y1, int32 x2, int32 y2, uInt32 colour) { +void ogSurface::ogFillRect(int32 x1, int32 y1, int32 x2, int32 y2, uInt32 colour) { int32 yy, tmp; if (x2 < x1) { - tmp= x2; + tmp = x2; x2 = x1; x1 = tmp; } // if if (y2 < y1) { - tmp= y2; + tmp = y2; y2 = y1; y1 = tmp; - } // if + } // if - if ((y2 < 0) || (y1 > (int32)maxY)) return; - if (y1 < 0) y1 = 0; - if (y2 > (int32)maxY) y2 = maxY; + if ((y2 < 0) || (y1 > (int32) maxY)) + return; + if (y1 < 0) + y1 = 0; + if (y2 > (int32) maxY) + y2 = maxY; for (yy = y1; yy <= y2; yy++) ogHLine(x1, x2, yy, colour); } // ogSurface::ogFillRect -void ogSurface::ogFillTriangle(int32 x1, int32 y1, int32 x2, int32 y2, - int32 x3, int32 y3, uInt32 colour) { +void ogSurface::ogFillTriangle(int32 x1, int32 y1, int32 x2, int32 y2, int32 x3, int32 y3, uInt32 colour) { ogPoint2d points[3]; points[0].x = x1; points[0].y = y1; @@ -2769,16 +2833,14 @@ return; } // ogSurface::ogFillTriangle -uInt32 -ogSurface::ogGetAlpha(void) { - if (attributes != NULL) +uInt32 ogSurface::ogGetAlpha(void) { + if (attributes != NULL) return attributes->defaultAlpha; else return 255L; } // ogSurface::ogGetAlpha -ogErrorCode -ogSurface::ogGetLastError(void) { +ogErrorCode ogSurface::ogGetLastError(void) { ogErrorCode tmp = lastError; lastError = ogOK; return tmp; @@ -2786,84 +2848,84 @@ void ogSurface::ogGetPalette(ogRGBA8 _pal[256]) { memcpy(_pal, pal, sizeof(_pal)); - return; + return; } // ogSurface::ogGetPalette -void -ogSurface::ogGetPixFmt(ogPixelFmt& pixfmt) { +void ogSurface::ogGetPixFmt(ogPixelFmt& pixfmt) { pixfmt.BPP = BPP; - pixfmt.redFieldPosition = redFieldPosition; + pixfmt.redFieldPosition = redFieldPosition; pixfmt.greenFieldPosition = greenFieldPosition; - pixfmt.blueFieldPosition = blueFieldPosition; + pixfmt.blueFieldPosition = blueFieldPosition; pixfmt.alphaFieldPosition = alphaFieldPosition; - pixfmt.redMaskSize = 8-redShifter; - pixfmt.greenMaskSize = 8-greenShifter; - pixfmt.blueMaskSize = 8-blueShifter; - pixfmt.alphaMaskSize = 8-alphaShifter; + pixfmt.redMaskSize = 8 - redShifter; + pixfmt.greenMaskSize = 8 - greenShifter; + pixfmt.blueMaskSize = 8 - blueShifter; + pixfmt.alphaMaskSize = 8 - alphaShifter; return; } // ogSurface::ogGetPixFmt -uInt32 -ogSurface::ogGetPixel(int32 x, int32 y) { +uInt32 ogSurface::ogGetPixel(int32 x, int32 y) { uInt32 result; - if (!ogAvail()) return ogGetTransparentColor(); - - if (((uInt32)x > maxX) || ((uInt32)y > maxY)) return ogGetTransparentColor(); + if (!ogAvail()) + return ogGetTransparentColor(); + + if (((uInt32) x > maxX) || ((uInt32) y > maxY)) + return ogGetTransparentColor(); switch (bytesPerPix) { - case 4: - __asm__ __volatile__( - " shl $2, %%ecx \n" // shl ecx, 2 {adjust for pixel size} - " add %%esi, %%edi \n" // add edi, esi - " add %%ecx, %%edi \n" // add edi, ecx - " mov (%%edi),%%eax \n" // eax,word ptr [edi] - " mov %%eax, %3 \n" // mov result, eax - : - : "D" (buffer), "S" (lineOfs[y]), // %0, %1 - "c" (x), "m" (result) // %2, %3 - ); + case 4: + __asm__ __volatile__( + " shl $2, %%ecx \n" // shl ecx, 2 {adjust for pixel size} + " add %%esi, %%edi \n"// add edi, esi + " add %%ecx, %%edi \n"// add edi, ecx + " mov (%%edi),%%eax \n"// eax,word ptr [edi] + " mov %%eax, %3 \n"// mov result, eax + : + : "D" (buffer), "S" (lineOfs[y]),// %0, %1 + "c" (x), "m" (result)// %2, %3 + ); break; - case 3: - __asm__ __volatile__( - " leal (%%ecx, %%ecx, 2), %%ecx \n" // lea ecx, [ecx + ecx*2] -// " mov %%ecx, %%eax \n" // mov eax, ecx - adjust for pixel size + case 3: + __asm__ __volatile__( + " leal (%%ecx, %%ecx, 2), %%ecx \n" // lea ecx, [ecx + ecx*2] +// " mov %%ecx, %%eax \n" // mov eax, ecx - adjust for pixel size // " add %%ecx, %%ecx \n" // add ecx, ecx - adjust for pixel size // " add %%eax, %%ecx \n" // add ecx, eax - adjust for pixel size - " add %%esi, %%edi \n" // add edi, esi - " add %%ecx, %%edi \n" // add edi, ecx - " movzwl (%%edi),%%eax \n" // edx,word ptr [edi] - " xor %%eax, %%eax \n" - " mov 2(%%edi), %%al \n" // mov al, [edi+2] - " shl $16, %%eax \n" // shl eax, 16 - " mov (%%edi), %%ax \n" // mov ax, [edi] - " mov %%eax, %3 \n" // mov result, eax - : - : "D" (buffer), "S" (lineOfs[y]), // %0, %1 - "c" (x), "m" (result) // %2, %3 - ); + " add %%esi, %%edi \n"// add edi, esi + " add %%ecx, %%edi \n"// add edi, ecx + " movzwl (%%edi),%%eax \n"// edx,word ptr [edi] + " xor %%eax, %%eax \n" + " mov 2(%%edi), %%al \n"// mov al, [edi+2] + " shl $16, %%eax \n"// shl eax, 16 + " mov (%%edi), %%ax \n"// mov ax, [edi] + " mov %%eax, %3 \n"// mov result, eax + : + : "D" (buffer), "S" (lineOfs[y]),// %0, %1 + "c" (x), "m" (result)// %2, %3 + ); break; - case 2: - __asm__ __volatile__( - " add %%esi, %%edi \n" // add edi, esi - " add %%ecx, %%ecx \n" // add ecx, ecx {adjust for pixel size} - " add %%ecx, %%edi \n" // add edi, ecx - " movzwl (%%edi),%%eax \n" // movzx edx,word ptr [edi] - " mov %%eax, %0 \n" // mov result, eax - : "=m" (result) - : "D" (buffer), "S" (lineOfs[y]), // %0, %1 - "c" (x) // , "m" (result) // %2, %3 - ); + case 2: + __asm__ __volatile__( + " add %%esi, %%edi \n" // add edi, esi + " add %%ecx, %%ecx \n"// add ecx, ecx {adjust for pixel size} + " add %%ecx, %%edi \n"// add edi, ecx + " movzwl (%%edi),%%eax \n"// movzx edx,word ptr [edi] + " mov %%eax, %0 \n"// mov result, eax + : "=m" (result) + : "D" (buffer), "S" (lineOfs[y]),// %0, %1 + "c" (x)// , "m" (result) // %2, %3 + ); break; - case 1: - __asm__ __volatile__( - " add %%esi, %%edi \n" // add edi, esi - " add %%ecx, %%edi \n" // add edi, ecx - " movzbl (%%edi),%%eax \n" // movzx edx,byte ptr [edi] - " mov %%eax, %3 \n" // mov result, eax - : - : "D" (buffer), "S" (lineOfs[y]), // %0, %1 - "c" (x), "m" (result) // %2, %3 - ); + case 1: + __asm__ __volatile__( + " add %%esi, %%edi \n" // add edi, esi + " add %%ecx, %%edi \n"// add edi, ecx + " movzbl (%%edi),%%eax \n"// movzx edx,byte ptr [edi] + " mov %%eax, %3 \n"// mov result, eax + : + : "D" (buffer), "S" (lineOfs[y]),// %0, %1 + "c" (x), "m" (result)// %2, %3 + ); break; } // switch return result; @@ -2872,26 +2934,25 @@ void * ogSurface::ogGetPtr(uInt32 x, uInt32 y) { // return (Avail() ? ( (uInt8*)buffer+(lineOfs[y]+x*((BPP+7) >> 3)) ) : NULL ); - return ((uInt8*)buffer+(lineOfs[y]+x*bytesPerPix)); + return ((uInt8*) buffer + (lineOfs[y] + x * bytesPerPix)); } // ogSurface::ogGetPtr -uInt32 -ogSurface::ogGetTransparentColor(void) { +uInt32 ogSurface::ogGetTransparentColor(void) { if (attributes != NULL) return attributes->transparentColor; else - return 0; + return 0; } // ogSurface::ogGetTransparentColor -void -ogSurface::ogHFlip(void) { +void ogSurface::ogHFlip(void) { void * tmpBuf1; void * tmpBuf2; uInt32 xWidth, count; - if (!ogAvail()) return; + if (!ogAvail()) + return; - xWidth = (maxX+1)*bytesPerPix; + xWidth = (maxX + 1) * bytesPerPix; #ifdef __UBIXOS_KERNEL__ tmpBuf1 = kmalloc(xWidth); @@ -2902,16 +2963,16 @@ #endif if ((tmpBuf1 != NULL) && (tmpBuf2 != NULL)) - for (count = 0; count <= (maxY/2); count++) { + for (count = 0; count <= (maxY / 2); count++) { ogCopyLineFrom(0, count, tmpBuf1, xWidth); - ogCopyLineFrom(0, maxY-count,tmpBuf2, xWidth); - ogCopyLineTo(0, maxY-count,tmpBuf1, xWidth); + ogCopyLineFrom(0, maxY - count, tmpBuf2, xWidth); + ogCopyLineTo(0, maxY - count, tmpBuf1, xWidth); ogCopyLineTo(0, count, tmpBuf2, xWidth); } // for count #ifdef __UBIXOS_KERNEL__ - kfree(tmpBuf2); - kfree(tmpBuf1); + kfree(tmpBuf2); + kfree(tmpBuf1); #else free(tmpBuf2); free(tmpBuf1); @@ -2920,29 +2981,34 @@ return; } // ogSurface::ogHFlip -void -ogSurface::ogHLine(int32 x1, int32 x2, int32 y, uInt32 colour) { +void ogSurface::ogHLine(int32 x1, int32 x2, int32 y, uInt32 colour) { int32 tmp; uInt8 r, g, b, a; - if (!ogAvail()) return; - if ((uInt32)y > maxY) return; + if (!ogAvail()) + return; + if ((uInt32) y > maxY) + return; if (x1 > x2) { - tmp= x1; + tmp = x1; x1 = x2; x2 = tmp; } // if - if (x1 < 0) x1 = 0; - if (x2 > (int32)maxX) x2 = maxX; - if (x2 < x1) return; + if (x1 < 0) + x1 = 0; + if (x2 > (int32) maxX) + x2 = maxX; + if (x2 < x1) + return; if (ogIsBlending()) { ogUnpack(colour, r, g, b, a); - if (a == 0) return; + if (a == 0) + return; if (a == 255) { - for (tmp = x1; tmp <= x2; tmp++) + for (tmp = x1; tmp <= x2; tmp++) RawSetPixel(tmp, y, r, g, b, a); return; } // if a == 255 @@ -2950,135 +3016,131 @@ __asm__ __volatile__("cld \n"); switch (bytesPerPix) { - case 4: - __asm__ __volatile__( + case 4: + __asm__ __volatile__( " sub %%ebx, %%ecx \n" // sub ecx, ebx - " add %%esi, %%edi \n" // add edi, esi + " add %%esi, %%edi \n"// add edi, esi " inc %%ecx \n" - " shl $2, %%ebx \n" // shl ebx, 2 - " add %%ebx, %%edi \n" // add edi, ebx + " shl $2, %%ebx \n"// shl ebx, 2 + " add %%ebx, %%edi \n"// add edi, ebx " rep \n" - " stosl \n" + " stosl \n" : - : "D" (buffer), "S" (lineOfs[y]), // %0, %1 - "a" (colour), "b" (x1), // %2, %3 - "c" (x2) // %4 - ); + : "D" (buffer), "S" (lineOfs[y]),// %0, %1 + "a" (colour), "b" (x1),// %2, %3 + "c" (x2)// %4 + ); break; - case 3: - __asm__ __volatile__( + case 3: + __asm__ __volatile__( " sub %%ebx, %%ecx \n" // sub ecx, ebx - " add %%esi, %%edi \n" // add edi, esi - " add %%ebx, %%ebx \n" // add ebx, ebx - pix size - " inc %%ecx \n" // inc ecx - " add %%edx, %%ebx \n" // add ebx, edx - pix size - " add %%ebx, %%edi \n" // add edi, ebx - " mov %%eax, %%ebx \n" // mov ebx, eax - " shr $16, %%ebx \n" // shr ebx, 16 - "hLlop24: \n" - " mov %%ax, (%%edi) \n" // mov [edi], ax - " mov %%bl, 2(%%edi)\n" // mov [edi+2], bl - " add $3, %%edi \n" // add edi, 3 - " dec %%ecx \n" // dec ecx + " add %%esi, %%edi \n"// add edi, esi + " add %%ebx, %%ebx \n"// add ebx, ebx - pix size + " inc %%ecx \n"// inc ecx + " add %%edx, %%ebx \n"// add ebx, edx - pix size + " add %%ebx, %%edi \n"// add edi, ebx + " mov %%eax, %%ebx \n"// mov ebx, eax + " shr $16, %%ebx \n"// shr ebx, 16 + "hLlop24: \n" + " mov %%ax, (%%edi) \n"// mov [edi], ax + " mov %%bl, 2(%%edi)\n"// mov [edi+2], bl + " add $3, %%edi \n"// add edi, 3 + " dec %%ecx \n"// dec ecx " jnz hLlop24 \n" : - : "D" (buffer), "S" (lineOfs[y]), // %0, %1 - "a" (colour), "b" (x1), // %2, %3 - "c" (x2), "d" (x1) // %4, %5 - ); + : "D" (buffer), "S" (lineOfs[y]),// %0, %1 + "a" (colour), "b" (x1),// %2, %3 + "c" (x2), "d" (x1)// %4, %5 + ); break; - case 2: - __asm__ __volatile__( + case 2: + __asm__ __volatile__( " sub %%ebx, %%ecx \n" // sub ecx, ebx - " add %%ebx, %%ebx \n" // add ebx, ebx - pix size - " inc %%ecx \n" // inc ecx - " add %%ebx, %%edi \n" // add edi, ebx - " add %%esi, %%edi \n" // add edi, esi - " xor %%edx, %%edx \n" // xor edx, edx - " mov %%ax, %%dx \n" // mov dx, ax - " shl $16, %%eax \n" // shl eax, 16 - " add %%edx, %%eax \n" // add eax, edx + " add %%ebx, %%ebx \n"// add ebx, ebx - pix size + " inc %%ecx \n"// inc ecx + " add %%ebx, %%edi \n"// add edi, ebx + " add %%esi, %%edi \n"// add edi, esi + " xor %%edx, %%edx \n"// xor edx, edx + " mov %%ax, %%dx \n"// mov dx, ax + " shl $16, %%eax \n"// shl eax, 16 + " add %%edx, %%eax \n"// add eax, edx - " shr $1, %%ecx \n" // shr ecx, 1 + " shr $1, %%ecx \n"// shr ecx, 1 " rep \n" " stosl \n" " jnc hLnoc16 \n" " stosw \n" "hLnoc16: \n" : - : "D" (buffer), "S" (lineOfs[y]), // %0, %1 - "a" (colour), "b" (x1), // %2, %3 - "c" (x2) // %4 - ); + : "D" (buffer), "S" (lineOfs[y]),// %0, %1 + "a" (colour), "b" (x1),// %2, %3 + "c" (x2)// %4 + ); break; - case 1: - __asm__ __volatile__( + case 1: + __asm__ __volatile__( " add %%ebx, %%edi \n" // add edi, ebx - " add %%esi, %%edi \n" // add edi, esi - " and $0xff, %%eax \n" // and eax, 0ffh - " sub %%ebx, %%ecx \n" // sub ecx, ebx - " mov %%al, %%ah \n" // mov ah, al - " inc %%ecx \n" // inc ecx - " mov %%eax, %%ebx \n" // mov ebx, eax - " shl $16, %%ebx \n" // shl ebx, 16 - " add %%ebx, %%eax \n" // add eax, ebx + " add %%esi, %%edi \n"// add edi, esi + " and $0xff, %%eax \n"// and eax, 0ffh + " sub %%ebx, %%ecx \n"// sub ecx, ebx + " mov %%al, %%ah \n"// mov ah, al + " inc %%ecx \n"// inc ecx + " mov %%eax, %%ebx \n"// mov ebx, eax + " shl $16, %%ebx \n"// shl ebx, 16 + " add %%ebx, %%eax \n"// add eax, ebx - " mov %%ecx, %%edx \n" // mov edx, ecx - " mov $4, %%ecx \n" // mov ecx, 4 - " sub %%edi, %%ecx \n" // sub ecx, edi - " and $3, %%ecx \n" // and ecx, 3 - " sub %%ecx, %%edx \n" // sub edx, ecx + " mov %%ecx, %%edx \n"// mov edx, ecx + " mov $4, %%ecx \n"// mov ecx, 4 + " sub %%edi, %%ecx \n"// sub ecx, edi + " and $3, %%ecx \n"// and ecx, 3 + " sub %%ecx, %%edx \n"// sub edx, ecx " jle LEndBytes \n" - " rep \n" + " rep \n" " stosb \n" - " mov %%edx, %%ecx \n" // mov ecx, edx - " and $3, %%edx \n" // and edx, 3 - " shr $2, %%ecx \n" // shr ecx, 2 + " mov %%edx, %%ecx \n"// mov ecx, edx + " and $3, %%edx \n"// and edx, 3 + " shr $2, %%ecx \n"// shr ecx, 2 " rep \n" " stosl \n" - "LEndBytes: \n" - " add %%edx, %%ecx \n" // add ecx, edx + "LEndBytes: \n" + " add %%edx, %%ecx \n"// add ecx, edx " rep \n" " stosb \n" : - : "D" (buffer), "S" (lineOfs[y]), // %0, %1 - "a" (colour), "b" (x1), // %2, %3 - "c" (x2) - ); + : "D" (buffer), "S" (lineOfs[y]),// %0, %1 + "a" (colour), "b" (x1),// %2, %3 + "c" (x2) + ); break; } // switch return; } // ogSurface::ogHLine -bool -ogSurface::ogIsAntiAliasing(void) { +bool ogSurface::ogIsAntiAliasing(void) { if (attributes != NULL) return attributes->antiAlias; else return false; } // ogSurface::ogIsAntiAliasing -bool -ogSurface::ogIsBlending(void) { +bool ogSurface::ogIsBlending(void) { if (attributes != NULL) return attributes->blending; else return false; } // ogSurface::ogIsBlending -void -ogSurface::ogLine(int32 x1, int32 y1, int32 x2, int32 y2, uInt32 colour) { - if (ClipLine(x1,y1,x2,y2)) { - if (ogIsAntiAliasing()) - AARawLine(x1, y1, x2, y2, colour); - else +void ogSurface::ogLine(int32 x1, int32 y1, int32 x2, int32 y2, uInt32 colour) { + if (ClipLine(x1, y1, x2, y2)) { + if (ogIsAntiAliasing()) + AARawLine(x1, y1, x2, y2, colour); + else RawLine(x1, y1, x2, y2, colour); } // if clipLine return; } // ogSurface::ogLine -bool -ogSurface::ogLoadPalette(const char *palfile) { +bool ogSurface::ogLoadPalette(const char *palfile) { ogRGBA8 oldPalette[256]; #ifdef __UBIXOS_KERNEL__ fileDescriptor *f; @@ -3098,15 +3160,16 @@ if (pal == NULL) { ogSetLastError(ogMemAllocFail); return false; - } // if + } // if ogSetPalette(DEFAULT_PALETTE); - // memcpy(pal, DEFAULT_PALETTE, sizeof(ogRGBA8)*256); + // memcpy(pal, DEFAULT_PALETTE, sizeof(ogRGBA8)*256); } // if - + ogGetPalette(oldPalette); // memcpy(&oldPalette, pal, sizeof(ogRGBA8)*256); - if ((f = fopen(palfile, "rb")) == NULL) return false; + if ((f = fopen(palfile, "rb")) == NULL) + return false; lresult = fread(pal, sizeof(ogRGBA8), 256, f); result = (lresult == 256); @@ -3121,23 +3184,18 @@ return result; } // ogSurface::ogLoadPalette -void -ogSurface::ogPolygon(uInt32 numPoints, ogPoint2d* polyPoints, uInt32 colour) { +void ogSurface::ogPolygon(uInt32 numPoints, ogPoint2d* polyPoints, uInt32 colour) { uInt32 count; - - if (numPoints == 1) + + if (numPoints == 1) ogSetPixel(polyPoints[0].x, polyPoints[0].y, colour); else for (count = 0; count < numPoints; count++) - ogLine(polyPoints[count].x, polyPoints[count].y, - polyPoints[(count+1) % numPoints].x, - polyPoints[(count+1) % numPoints].y, - colour); + ogLine(polyPoints[count].x, polyPoints[count].y, polyPoints[(count + 1) % numPoints].x, polyPoints[(count + 1) % numPoints].y, colour); return; } // ogSurface::ogPolygon -void -ogSurface::ogRect(int32 x1, int32 y1, int32 x2, int32 y2, uInt32 colour) { +void ogSurface::ogRect(int32 x1, int32 y1, int32 x2, int32 y2, uInt32 colour) { int32 tmp; if ((x1 == x2) || (y1 == y2)) { @@ -3147,17 +3205,18 @@ else ogLine(x1, y1, x2, y2, colour); - } else { + } + else { if (y1 > y2) { - tmp= y1; + tmp = y1; y1 = y2; y2 = tmp; } // if ogHLine(x1, x2, y1, colour); // Horizline has built in clipping - ogVLine(x1, y1+1, y2-1, colour); // vertline has built in clipping too - ogVLine(x2, y1+1, y2-1, colour); + ogVLine(x1, y1 + 1, y2 - 1, colour); // vertline has built in clipping too + ogVLine(x2, y1 + 1, y2 - 1, colour); ogHLine(x1, x2, y2, colour); } // else @@ -3165,44 +3224,35 @@ return; } // ogSurface::ogRect -uInt32 -ogSurface::ogPack(uInt8 red, uInt8 green, uInt8 blue) { +uInt32 ogSurface::ogPack(uInt8 red, uInt8 green, uInt8 blue) { uInt32 idx, colour; uInt32 rd, gd, bd, dist, newdist; colour = 0; switch (bytesPerPix) { - case 4: - colour = ( (red << redFieldPosition) | - (green << greenFieldPosition) | - (blue << blueFieldPosition) | - (ogGetAlpha() << alphaFieldPosition) ); + case 4: + colour = ((red << redFieldPosition) | (green << greenFieldPosition) | (blue << blueFieldPosition) | (ogGetAlpha() << alphaFieldPosition)); break; - case 3: - colour = ( (red << redFieldPosition) | - (green << greenFieldPosition) | - (blue << blueFieldPosition) ); + case 3: + colour = ((red << redFieldPosition) | (green << greenFieldPosition) | (blue << blueFieldPosition)); break; - case 2: - colour = ((red >> redShifter) << redFieldPosition) | - ((green >> greenShifter) << greenFieldPosition) | - ((blue >> blueShifter) << blueFieldPosition) | - ((ogGetAlpha() >> alphaShifter) << alphaFieldPosition); + case 2: + colour = ((red >> redShifter) << redFieldPosition) | ((green >> greenShifter) << greenFieldPosition) | ((blue >> blueShifter) << blueFieldPosition) | ((ogGetAlpha() >> alphaShifter) << alphaFieldPosition); break; - case 1: - colour = 0; - dist = 255+255+255; - for (idx = 0; idx <= 255; idx++) { - rd = abs(red-pal[idx].red); - gd = abs(green-pal[idx].green); - bd = abs(blue-pal[idx].blue); - newdist = rd + gd + bd; + case 1: + colour = 0; + dist = 255 + 255 + 255; + for (idx = 0; idx <= 255; idx++) { + rd = abs(red - pal[idx].red); + gd = abs(green - pal[idx].green); + bd = abs(blue - pal[idx].blue); + newdist = rd + gd + bd; - if (newdist < dist) { - dist = newdist; - colour = idx; - } // if - } // for + if (newdist < dist) { + dist = newdist; + colour = idx; + } // if + } // for break; } // switch @@ -3210,52 +3260,42 @@ } // ogSurface::ogPack -uInt32 -ogSurface::ogPack(uInt8 red, uInt8 green, uInt8 blue, uInt8 alpha) { +uInt32 ogSurface::ogPack(uInt8 red, uInt8 green, uInt8 blue, uInt8 alpha) { uInt32 idx, colour; uInt32 rd, gd, bd, dist, newdist; colour = 0; switch (bytesPerPix) { - case 4: - colour = ( (red << redFieldPosition) | - (green << greenFieldPosition) | - (blue << blueFieldPosition) | - (alpha << alphaFieldPosition) ); + case 4: + colour = ((red << redFieldPosition) | (green << greenFieldPosition) | (blue << blueFieldPosition) | (alpha << alphaFieldPosition)); break; - case 3: - colour = ( (red << redFieldPosition) | - (green << greenFieldPosition) | - (blue << blueFieldPosition) ); + case 3: + colour = ((red << redFieldPosition) | (green << greenFieldPosition) | (blue << blueFieldPosition)); break; - case 2: - colour = ((red >> redShifter) << redFieldPosition) | - ((green >> greenShifter) << greenFieldPosition) | - ((blue >> blueShifter) << blueFieldPosition) | - ((alpha >> alphaShifter) << alphaFieldPosition); + case 2: + colour = ((red >> redShifter) << redFieldPosition) | ((green >> greenShifter) << greenFieldPosition) | ((blue >> blueShifter) << blueFieldPosition) | ((alpha >> alphaShifter) << alphaFieldPosition); break; - case 1: - colour = 0; - dist = 255+255+255; - for (idx = 0; idx <= 255; idx++) { - rd = abs(red-pal[idx].red); - gd = abs(green-pal[idx].green); - bd = abs(blue-pal[idx].blue); - newdist = rd + gd + bd; + case 1: + colour = 0; + dist = 255 + 255 + 255; + for (idx = 0; idx <= 255; idx++) { + rd = abs(red - pal[idx].red); + gd = abs(green - pal[idx].green); + bd = abs(blue - pal[idx].blue); + newdist = rd + gd + bd; - if (newdist < dist) { - dist = newdist; - colour = idx; - } // if - } // for + if (newdist < dist) { + dist = newdist; + colour = idx; + } // if + } // for break; } // switch return colour; } // ogSurface::ogPack -bool -ogSurface::ogSavePalette(const char *palfile) { +bool ogSurface::ogSavePalette(const char *palfile) { #ifdef __UBIXOS_KERNEL__ fileDescriptor *f; #else @@ -3268,11 +3308,12 @@ return false; } - if ((f = fopen(palfile, "wb"))==NULL) return false; - lresult = fwrite(pal,sizeof(ogRGBA8),256,f); + if ((f = fopen(palfile, "wb")) == NULL) + return false; + lresult = fwrite(pal, sizeof(ogRGBA8), 256, f); fclose(f); - if (lresult == 256) + if (lresult == 256) return true; else { ogSetLastError(ogFileWriteError); @@ -3281,16 +3322,12 @@ } // ogSurface::ogSavePal -void -ogSurface::ogScale(ogSurface& src) { +void ogSurface::ogScale(ogSurface& src) { ogScaleBuf(0, 0, maxX, maxY, src, 0, 0, src.maxX, src.maxY); return; } // ogSurface::ogScale -void -ogSurface::ogScaleBuf(int32 dX1, int32 dY1, int32 dX2, int32 dY2, - ogSurface& src, - int32 sX1, int32 sY1, int32 sX2, int32 sY2) { +void ogSurface::ogScaleBuf(int32 dX1, int32 dY1, int32 dX2, int32 dY2, ogSurface& src, int32 sX1, int32 sY1, int32 sX2, int32 sY2) { uInt32 sWidth, dWidth; uInt32 sHeight, dHeight; @@ -3304,70 +3341,74 @@ bool doCopyBuf; origdX1 = origdY1 = 0; // to keep the compiler from generating a warning - - if (!ogAvail()) return; - if (!src.ogAvail()) return; + + if (!ogAvail()) + return; + if (!src.ogAvail()) + return; if (sX1 > sX2) { xx = sX1; - sX1= sX2; - sX2= xx; + sX1 = sX2; + sX2 = xx; } if (sY1 > sY2) { yy = sY1; - sY1= sY2; - sY2= yy; + sY1 = sY2; + sY2 = yy; } // if any part of the source falls outside the buffer then don't do anything - if (((uInt32)sX1 > src.maxX) || ((uInt32)sX2 > src.maxX) || - ((uInt32)sY1 > src.maxY) || ((uInt32)sY2 > src.maxY)) return; + if (((uInt32) sX1 > src.maxX) || ((uInt32) sX2 > src.maxX) || ((uInt32) sY1 > src.maxY) || ((uInt32) sY2 > src.maxY)) + return; if (dX1 > dX2) { xx = dX1; - dX1= dX1; - dX2= xx; + dX1 = dX1; + dX2 = xx; } if (dY1 > dY2) { yy = dY1; - dY1= dY2; - dY2= yy; + dY1 = dY2; + dY2 = yy; } - dWidth = (dX2-dX1)+1; - if (dWidth <= 0) return; + dWidth = (dX2 - dX1) + 1; + if (dWidth <= 0) + return; - dHeight = (dY2-dY1)+1; - if (dHeight <= 0) return; + dHeight = (dY2 - dY1) + 1; + if (dHeight <= 0) + return; - sWidth = (sX2-sX1)+1; - sHeight = (sY2-sY1)+1; + sWidth = (sX2 - sX1) + 1; + sHeight = (sY2 - sY1) + 1; // convert into 16:16 fixed point ratio xInc = (sWidth << 16) / dWidth; yInc = (sHeight << 16) / dHeight; - if (dX2 > (int32)maxX) { - xx = (xInc*(dX1-maxX)) >> 16; + if (dX2 > (int32) maxX) { + xx = (xInc * (dX1 - maxX)) >> 16; sX1 -= xx; sWidth -= xx; - dWidth -= (dX1-maxX); + dWidth -= (dX1 - maxX); dX1 = maxX; } - if (dY2 > (int32)maxY) { - yy = (yInc*(dY2-maxY)) >> 16; + if (dY2 > (int32) maxY) { + yy = (yInc * (dY2 - maxY)) >> 16; sY2 -= yy; sHeight -= yy; - dHeight -= (dY2-maxY); + dHeight -= (dY2 - maxY); dY2 = maxY; } if (dX1 < 0) { - xx = (xInc*(-dX1)) >> 16; + xx = (xInc * (-dX1)) >> 16; sX1 += xx; sWidth -= xx; dWidth += dX1; @@ -3375,15 +3416,17 @@ } if (dY1 < 0) { - yy = (yInc*(-dY1)) >> 16; + yy = (yInc * (-dY1)) >> 16; sY1 += yy; sHeight -= yy; dHeight += dY1; dY1 = 0; } - if ((dWidth <= 0) || (dHeight <= 0)) return; - if ((sWidth <= 0) || (sHeight <= 0)) return; + if ((dWidth <= 0) || (dHeight <= 0)) + return; + if ((sWidth <= 0) || (sHeight <= 0)) + return; // Do a quick check to see if the scale is 1:1 .. in that case just copy // the image @@ -3413,12 +3456,14 @@ if (pixFmtID != src.pixFmtID) { tmpBuf = new ogSurface(); - if (tmpBuf == NULL) return; - if (sWidth*sHeight*src.bytesPerPix <= dWidth*dHeight*bytesPerPix) { + if (tmpBuf == NULL) + return; + if (sWidth * sHeight * src.bytesPerPix <= dWidth * dHeight * bytesPerPix) { // if the number of pixels in the source buffer is less than the // number of pixels in the dest buffer then... ogGetPixFmt(pixFmt); - if (!tmpBuf->ogCreate(sWidth, sHeight, pixFmt)) return; + if (!tmpBuf->ogCreate(sWidth, sHeight, pixFmt)) + return; tmpBuf->ogCopyPalette(src); tmpBuf->ogCopyBuf(0, 0, src, sX1, sY1, sX2, sY2); sX2 -= sX1; @@ -3428,9 +3473,11 @@ sBuf = tmpBuf; dBuf = this; doCopyBuf = false; // do we do a copyBuf later? - } else { + } + else { src.ogGetPixFmt(pixFmt); - if (!tmpBuf->ogCreate(dWidth,dHeight,pixFmt)) return; + if (!tmpBuf->ogCreate(dWidth, dHeight, pixFmt)) + return; tmpBuf->ogCopyPalette(*this); origdX1 = dX1; origdY1 = dY1; @@ -3442,7 +3489,8 @@ dBuf = tmpBuf; doCopyBuf = true; } // else - } else { + } + else { // pixel formats are identical sBuf = &src; dBuf = this; @@ -3454,13 +3502,12 @@ for (yy = dY1; yy <= dY2; yy++) { sx = 0; for (xx = dX1; xx <= dX2; xx++) { - dBuf->RawSetPixel(xx, yy, - sBuf->RawGetPixel(sX1+(sx >> 16),(sy>>16))); + dBuf->RawSetPixel(xx, yy, sBuf->RawGetPixel(sX1 + (sx >> 16), (sy >> 16))); sx += xInc; } // for xx sy += yInc; } // for yy - + if ((doCopyBuf) && (tmpBuf != NULL)) ogCopyBuf(origdX1, origdY1, *tmpBuf, 0, 0, tmpBuf->maxX, tmpBuf->maxY); @@ -3468,69 +3515,74 @@ return; } // ogSurface::ogScaleBuf -uInt32 -ogSurface::ogSetAlpha(uInt32 _newAlpha) { +uInt32 ogSurface::ogSetAlpha(uInt32 _newAlpha) { uInt32 tmp; if (attributes != NULL) { tmp = attributes->defaultAlpha; attributes->defaultAlpha = _newAlpha; return tmp; - } else return _newAlpha; + } + else + return _newAlpha; } // ogSurface::ogSetAlpha -bool -ogSurface::ogSetAntiAliasing(bool _antiAliasing) { +bool ogSurface::ogSetAntiAliasing(bool _antiAliasing) { bool tmp; if (attributes != NULL) { tmp = attributes->antiAlias; attributes->antiAlias = _antiAliasing; return tmp; - } else return _antiAliasing; + } + else + return _antiAliasing; } // ogSurface::ogSetAntiAliasing -bool -ogSurface::ogSetBlending(bool _blending) { +bool ogSurface::ogSetBlending(bool _blending) { bool tmp; if (attributes != NULL) { tmp = attributes->blending; attributes->blending = _blending; return tmp; - } else return _blending; + } + else + return _blending; } // ogSurface::ogSetBlending; -ogErrorCode -ogSurface::ogSetLastError(ogErrorCode latestError) { +ogErrorCode ogSurface::ogSetLastError(ogErrorCode latestError) { ogErrorCode tmp = lastError; lastError = latestError; return tmp; } // ogSurface::ogSetLastError -void -ogSurface::ogSetPalette(const ogRGBA8 newPal[256]) { - if (pal == NULL) return; +void ogSurface::ogSetPalette(const ogRGBA8 newPal[256]) { + if (pal == NULL) + return; memcpy(pal, newPal, sizeof(pal)); return; } // ogSurface::ogSetPalette -void -ogSurface::ogSetPixel(int32 x, int32 y, uInt32 colour) { +void ogSurface::ogSetPixel(int32 x, int32 y, uInt32 colour) { uInt32 newR, newG, newB, inverseA; uInt8 sR, sG, sB, sA; uInt8 dR, dG, dB; - if (!ogAvail()) return; + if (!ogAvail()) + return; - if (((uInt32)x > maxX) || ((uInt32)y > maxY)) return; + if (((uInt32) x > maxX) || ((uInt32) y > maxY)) + return; do { if (ogIsBlending()) { ogUnpack(colour, sR, sG, sB, sA); - if (sA == 0) return; - if (sA == 255) break; + if (sA == 0) + return; + if (sA == 255) + break; inverseA = 255 - sA; ogUnpack(RawGetPixel(x, y), dR, dG, dB); newR = (dR * inverseA + sR * sA) >> 8; @@ -3541,96 +3593,96 @@ } while (false); switch (bytesPerPix) { - case 4: - __asm__ __volatile__( - // { Calculate offset, prepare the pixel to be drawn } - " shl $2, %%ecx \n" // shl eax, 2 {adjust for pixel size} - " add %%esi, %%edi \n" // add edi, esi - " add %%ecx, %%edi \n" // add edi, ecx - // { Draw the pixel } - " mov %%eax, (%%edi) \n" // mov [edi], eax + case 4: + __asm__ __volatile__( + // { Calculate offset, prepare the pixel to be drawn } + " shl $2, %%ecx \n"// shl eax, 2 {adjust for pixel size} + " add %%esi, %%edi \n"// add edi, esi + " add %%ecx, %%edi \n"// add edi, ecx + // { Draw the pixel } + " mov %%eax, (%%edi) \n"// mov [edi], eax : - : "D" (buffer), "S" (lineOfs[y]), // %0, %1 - "c" (x), "a" (colour) // %2, %3 - ); + : "D" (buffer), "S" (lineOfs[y]),// %0, %1 + "c" (x), "a" (colour)// %2, %3 + ); break; - case 3: - __asm__ __volatile__( - // Calculate offset, prepare the pixel to be drawn - " leal (%%ecx, %%ecx, 2), %%ecx \n" // lea ecx, [ecx + ecx*2] - " add %%esi, %%edi \n" // add edi, esi - " add %%ecx, %%edi \n" // add edi, ecx - // { Draw the pixel } - " mov %%ax, (%%edi) \n" // mov [edi], ax - " shr $16, %%eax \n" // shr eax, 16 - " mov %%al, 2(%%edi)\n" // mov [edi+2],al + case 3: + __asm__ __volatile__( + // Calculate offset, prepare the pixel to be drawn + " leal (%%ecx, %%ecx, 2), %%ecx \n"// lea ecx, [ecx + ecx*2] + " add %%esi, %%edi \n"// add edi, esi + " add %%ecx, %%edi \n"// add edi, ecx + // { Draw the pixel } + " mov %%ax, (%%edi) \n"// mov [edi], ax + " shr $16, %%eax \n"// shr eax, 16 + " mov %%al, 2(%%edi)\n"// mov [edi+2],al : - : "D" (buffer), "S" (lineOfs[y]), // %0, %1 - "c" (x), "a" (colour) // %2, %3 - ); + : "D" (buffer), "S" (lineOfs[y]),// %0, %1 + "c" (x), "a" (colour)// %2, %3 + ); break; - case 2: - __asm__ __volatile__( - // { Calculate offset, prepare the pixel to be drawn } - " add %%ecx, %%ecx \n" // add ecx, ecx {adjust for pixel size} - " add %%esi, %%edi \n" // add edi, esi - // " mov %3, %%eax \n" // mov eax, colour - " add %%ecx, %%edi \n" // add edi, ecx - // { Draw the pixel } - " mov %%ax, (%%edi) \n" // mov [edi], ax + case 2: + __asm__ __volatile__( + // { Calculate offset, prepare the pixel to be drawn } + " add %%ecx, %%ecx \n"// add ecx, ecx {adjust for pixel size} + " add %%esi, %%edi \n"// add edi, esi + // " mov %3, %%eax \n" // mov eax, colour + " add %%ecx, %%edi \n"// add edi, ecx + // { Draw the pixel } + " mov %%ax, (%%edi) \n"// mov [edi], ax : - : "D" (buffer), "S" (lineOfs[y]), // %0, %1 - "c" (x), "a" (colour) // %2, %3 - ); - break; - case 1: - __asm__ __volatile__( - // { Calculate offset, prepare the pixel to be drawn } - // " add (%%esi,%%ebx,4), %%edi \n" // add edi, [esi + ebx * 4] - " add %%esi, %%edi \n" // add edi, esi - " add %%ecx, %%edi \n" // add edi, ecx - // { Draw the pixel } - " mov %%al, (%%edi) \n" // mov [edi], al + : "D" (buffer), "S" (lineOfs[y]),// %0, %1 + "c" (x), "a" (colour)// %2, %3 + ); + break; + case 1: + __asm__ __volatile__( + // { Calculate offset, prepare the pixel to be drawn } + // " add (%%esi,%%ebx,4), %%edi \n" // add edi, [esi + ebx * 4] + " add %%esi, %%edi \n"// add edi, esi + " add %%ecx, %%edi \n"// add edi, ecx + // { Draw the pixel } + " mov %%al, (%%edi) \n"// mov [edi], al : - : "D" (buffer), "S" (lineOfs[y]), // %0, %1 - "c" (x), "a" (colour) // %2, %3 - ); - break; + : "D" (buffer), "S" (lineOfs[y]),// %0, %1 + "c" (x), "a" (colour)// %2, %3 + ); + break; } // switch return; } // ogSurface::ogSetPixel -void -ogSurface::ogSetPixel(int32 x, int32 y, uInt8 r, uInt8 g, uInt8 b, uInt8 a) { - if (!ogAvail()) return; - if (((uInt32)x > maxX) || ((uInt32)y > maxY)) return; +void ogSurface::ogSetPixel(int32 x, int32 y, uInt8 r, uInt8 g, uInt8 b, uInt8 a) { + if (!ogAvail()) + return; + if (((uInt32) x > maxX) || ((uInt32) y > maxY)) + return; RawSetPixel(x, y, r, g, b, a); return; } // ogSurface::ogSetPixel -void -ogSurface::ogSetPalette(uInt8 colour, uInt8 red, uInt8 green, uInt8 blue, uInt8 alpha) { - if (pal == NULL) return; - pal[colour].red = red; +void ogSurface::ogSetPalette(uInt8 colour, uInt8 red, uInt8 green, uInt8 blue, uInt8 alpha) { + if (pal == NULL) + return; + pal[colour].red = red; pal[colour].green = green; - pal[colour].blue = blue; + pal[colour].blue = blue; pal[colour].alpha = alpha; return; } // ogSurface::ogSetPalette -void -ogSurface::ogSetPalette(uInt8 colour, uInt8 red, uInt8 green, uInt8 blue) { - if (pal == NULL) return; - pal[colour].red = red; +void ogSurface::ogSetPalette(uInt8 colour, uInt8 red, uInt8 green, uInt8 blue) { + if (pal == NULL) + return; + pal[colour].red = red; pal[colour].green = green; - pal[colour].blue = blue; + pal[colour].blue = blue; pal[colour].alpha = ogGetAlpha(); return; } // ogSurface::ogSetPalette -uInt32 -ogSurface::ogSetTransparentColor(uInt32 colour) { - uInt32 tmp = 0; +uInt32 ogSurface::ogSetTransparentColor(uInt32 colour) { + uInt32 tmp = 0; if (attributes != NULL) { tmp = attributes->transparentColor & ogGetAlphaMasker(); @@ -3640,11 +3692,11 @@ return tmp; } // ogSurface::ogSetTransparentColor -static double f(double g) { return g*g*g-g; } +static double f(double g) { + return g * g * g - g; +} -void -ogSurface::ogSpline(uInt32 numPoints, ogPoint2d* points, uInt32 segments, - uInt32 colour) { +void ogSurface::ogSpline(uInt32 numPoints, ogPoint2d* points, uInt32 segments, uInt32 colour) { int32 i, oldY, oldX, x, y, j; float part, t, xx, yy, tmp; float * zc; @@ -3658,438 +3710,455 @@ bool runOnce; - if ((numPoints < 2) || (points == NULL)) return; + if ((numPoints < 2) || (points == NULL)) + return; zc = new float[numPoints]; dx = new float[numPoints]; dy = new float[numPoints]; - u = new float[numPoints]; + u = new float[numPoints]; wndX1 = new float[numPoints]; wndY1 = new float[numPoints]; px = new float[numPoints]; py = new float[numPoints]; do { - if (zc == NULL) break; - if (dx == NULL) break; - if (dy == NULL) break; - if (wndX1 == NULL) break; - if (wndY1 == NULL) break; - if (px == NULL) break; - if (py == NULL) break; - - for (i = 0; (uInt32)i < numPoints; i++) { + if (zc == NULL) + break; + if (dx == NULL) + break; + if (dy == NULL) + break; + if (wndX1 == NULL) + break; + if (wndY1 == NULL) + break; + if (px == NULL) + break; + if (py == NULL) + break; + + for (i = 0; (uInt32) i < numPoints; i++) { zc[i] = dx[i] = dy[i] = u[i] = wndX1[i] = wndY1[i] = px[i] = py[i] = 0.0f; } - + runOnce = false; oldX = oldY = 0; x = points[0].x; y = points[0].y; - for (i = 1; (uInt32)i < numPoints; i++) { - xx = points[i-1].x - points[i].x; - yy = points[i-1].y - points[i].y; - t = sqrt(xx*xx + yy*yy); - zc[i] = zc[i-1]+t; + for (i = 1; (uInt32) i < numPoints; i++) { + xx = points[i - 1].x - points[i].x; + yy = points[i - 1].y - points[i].y; + t = sqrt(xx * xx + yy * yy); + zc[i] = zc[i - 1] + t; } // for - u[0] = zc[1] - zc[0] +1; - for (i = 1; (uInt32)i < numPoints-1; i++) { - u[i] = zc[i+1]-zc[i]+1; - tmp = 2*(zc[i+1]-zc[i-1]); + u[0] = zc[1] - zc[0] + 1; + for (i = 1; (uInt32) i < numPoints - 1; i++) { + u[i] = zc[i + 1] - zc[i] + 1; + tmp = 2 * (zc[i + 1] - zc[i - 1]); dx[i] = tmp; dy[i] = tmp; - wndY1[i] = 6.0f*((points[i+1].y-points[i].y)/u[i]- - (points[i].y-points[i-1].y)/u[i-1]); - wndX1[i] = 6.0f*((points[i+1].x-points[i].x)/u[i]- - (points[i].x-points[i-1].x)/u[i-1]); + wndY1[i] = 6.0f * ((points[i + 1].y - points[i].y) / u[i] - (points[i].y - points[i - 1].y) / u[i - 1]); + wndX1[i] = 6.0f * ((points[i + 1].x - points[i].x) / u[i] - (points[i].x - points[i - 1].x) / u[i - 1]); } // for - for (i = 1; (uInt32)i < numPoints-2; i++) { - wndY1[i+1] = wndY1[i+1]-wndY1[i]*u[i]/dy[i]; - dy[i+1] = dy[i+1]-u[i]*u[i]/dy[i]; - wndX1[i+1] = wndX1[i+1]-wndX1[i]*u[i]/dx[i]; - dx[i+1] = dx[i+1]-u[i]*u[i]/dx[i]; + for (i = 1; (uInt32) i < numPoints - 2; i++) { + wndY1[i + 1] = wndY1[i + 1] - wndY1[i] * u[i] / dy[i]; + dy[i + 1] = dy[i + 1] - u[i] * u[i] / dy[i]; + wndX1[i + 1] = wndX1[i + 1] - wndX1[i] * u[i] / dx[i]; + dx[i + 1] = dx[i + 1] - u[i] * u[i] / dx[i]; } // for - for (i = numPoints-2; i > 0; i--) { - py[i] = (wndY1[i]-u[i]*py[i+1])/dy[i]; - px[i] = (wndX1[i]-u[i]*px[i+1])/dx[i]; + for (i = numPoints - 2; i > 0; i--) { + py[i] = (wndY1[i] - u[i] * py[i + 1]) / dy[i]; + px[i] = (wndX1[i] - u[i] * px[i + 1]) / dx[i]; } // for - for (i = 0; (uInt32)i < numPoints-1; i++) { - for (j = 0; (uInt32)j <= segments; j++) { - part = zc[i]-(((zc[i]-zc[i+1])/segments)*j); - t = (part-zc[i])/u[i]; - part = t * points[i+1].y + - (1.0-t)*points[i].y + - u[i] * u[i] * ( f(t) * py[i+1] + f(1.0-t) * py[i]) /6.0; + for (i = 0; (uInt32) i < numPoints - 1; i++) { + for (j = 0; (uInt32) j <= segments; j++) { + part = zc[i] - (((zc[i] - zc[i + 1]) / segments) * j); + t = (part - zc[i]) / u[i]; + part = t * points[i + 1].y + (1.0 - t) * points[i].y + u[i] * u[i] * (f(t) * py[i + 1] + f(1.0 - t) * py[i]) / 6.0; // y = Round(part); - y = static_cast(part+0.5f); - part = zc[i]-(((zc[i]-zc[i+1])/segments)*j); - t = (part-zc[i])/u[i]; - part = t*points[i+1].x+(1.0-t)*points[i].x+u[i]*u[i]*(f(t)*px[i+1]+ - f(1.0-t)*px[i])/6.0; - + y = static_cast(part + 0.5f); + part = zc[i] - (((zc[i] - zc[i + 1]) / segments) * j); + t = (part - zc[i]) / u[i]; + part = t * points[i + 1].x + (1.0 - t) * points[i].x + u[i] * u[i] * (f(t) * px[i + 1] + f(1.0 - t) * px[i]) / 6.0; + // x = Round(part); - x = static_cast(part+0.5f); - if (runOnce) ogLine(oldX, oldY, x, y, colour); else runOnce = true; + x = static_cast(part + 0.5f); + if (runOnce) + ogLine(oldX, oldY, x, y, colour); + else + runOnce = true; oldX = x; oldY = y; } // for j } // for i } while (false); - delete [] py; - delete [] px; - delete [] wndY1; - delete [] wndX1; - delete [] u; - delete [] dy; - delete [] dx; - delete [] zc; + delete[] py; + delete[] px; + delete[] wndY1; + delete[] wndX1; + delete[] u; + delete[] dy; + delete[] dx; + delete[] zc; return; } // ogSurface::ogSpline +void ogSurface::ogTriangle(int32 x1, int32 y1, int32 x2, int32 y2, int32 x3, int32 y3, uInt32 colour) { -void -ogSurface::ogTriangle(int32 x1, int32 y1, int32 x2, int32 y2, int32 x3, - int32 y3, uInt32 colour) { - - ogLine(x1, y1, x2, y2,colour); - ogLine(x2, y2, x3, y3,colour); - ogLine(x3, y3, x1, y1,colour); + ogLine(x1, y1, x2, y2, colour); + ogLine(x2, y2, x3, y3, colour); + ogLine(x3, y3, x1, y1, colour); return; } // ogSurface::ogTriangle -void -ogSurface::ogUnpack(uInt32 colour, uInt8& red, uInt8& green, uInt8& blue) { +void ogSurface::ogUnpack(uInt32 colour, uInt8& red, uInt8& green, uInt8& blue) { switch (bytesPerPix) { - case 4: - case 3: - red = colour >> redFieldPosition; - green = colour >> greenFieldPosition; - blue = colour >> blueFieldPosition; + case 4: + case 3: + red = colour >> redFieldPosition; + green = colour >> greenFieldPosition; + blue = colour >> blueFieldPosition; break; - case 2: - red = ((colour >> redFieldPosition) << redShifter); - green = ((colour >> greenFieldPosition) << greenShifter); - blue = ((colour >> blueFieldPosition) << blueShifter); - if (red != 0) red += OG_MASKS[redShifter]; - if (green != 0) green += OG_MASKS[greenShifter]; - if (blue != 0) blue += OG_MASKS[blueShifter]; + case 2: + red = ((colour >> redFieldPosition) << redShifter); + green = ((colour >> greenFieldPosition) << greenShifter); + blue = ((colour >> blueFieldPosition) << blueShifter); + if (red != 0) + red += OG_MASKS[redShifter]; + if (green != 0) + green += OG_MASKS[greenShifter]; + if (blue != 0) + blue += OG_MASKS[blueShifter]; break; - case 1: + case 1: - if (pal == NULL) { - red = green = blue = 0; - return; - } // if pal == null + if (pal == NULL) { + red = green = blue = 0; + return; + } // if pal == null - if (colour > 255) colour &= 255; - red = pal[colour].red; - green = pal[colour].green; - blue = pal[colour].blue; + if (colour > 255) + colour &= 255; + red = pal[colour].red; + green = pal[colour].green; + blue = pal[colour].blue; break; - default: - red = 0; - green = 0; - blue = 0; + default: + red = 0; + green = 0; + blue = 0; } // switch return; } // ogSurface::ogUnpack -void -ogSurface::ogUnpack(uInt32 colour, uInt8& red, uInt8& green, uInt8& blue, uInt8& alpha) { +void ogSurface::ogUnpack(uInt32 colour, uInt8& red, uInt8& green, uInt8& blue, uInt8& alpha) { switch (bytesPerPix) { - case 4: - red = colour >> redFieldPosition; - green = colour >> greenFieldPosition; - blue = colour >> blueFieldPosition; - alpha = colour >> alphaFieldPosition; + case 4: + red = colour >> redFieldPosition; + green = colour >> greenFieldPosition; + blue = colour >> blueFieldPosition; + alpha = colour >> alphaFieldPosition; break; - case 3: - red = colour >> redFieldPosition; - green = colour >> greenFieldPosition; - blue = colour >> blueFieldPosition; - alpha = ogGetAlpha(); + case 3: + red = colour >> redFieldPosition; + green = colour >> greenFieldPosition; + blue = colour >> blueFieldPosition; + alpha = ogGetAlpha(); break; - case 2: - red = ((colour >> redFieldPosition) << redShifter); - green = ((colour >> greenFieldPosition) << greenShifter); - blue = ((colour >> blueFieldPosition) << blueShifter); - if (red != 0) red += OG_MASKS[redShifter]; - if (green != 0) green += OG_MASKS[greenShifter]; - if (blue != 0) blue += OG_MASKS[blueShifter]; + case 2: + red = ((colour >> redFieldPosition) << redShifter); + green = ((colour >> greenFieldPosition) << greenShifter); + blue = ((colour >> blueFieldPosition) << blueShifter); + if (red != 0) + red += OG_MASKS[redShifter]; + if (green != 0) + green += OG_MASKS[greenShifter]; + if (blue != 0) + blue += OG_MASKS[blueShifter]; - if (alphaShifter != 8) { - alpha = (colour >> alphaFieldPosition) << alphaShifter; - if (alpha != 0) alpha += OG_MASKS[alphaShifter]; - } else alpha = ogGetAlpha(); - - break; - case 1: + if (alphaShifter != 8) { + alpha = (colour >> alphaFieldPosition) << alphaShifter; + if (alpha != 0) + alpha += OG_MASKS[alphaShifter]; + } + else + alpha = ogGetAlpha(); - if (pal == NULL) { + break; + case 1: + + if (pal == NULL) { + red = green = blue = alpha = 0; + return; + } // if pal == null + + if (colour > 255) + colour &= 255; + red = pal[colour].red; + green = pal[colour].green; + blue = pal[colour].blue; + alpha = pal[colour].alpha; + break; + default: red = green = blue = alpha = 0; - return; - } // if pal == null - - if (colour > 255) colour &= 255; - red = pal[colour].red; - green = pal[colour].green; - blue = pal[colour].blue; - alpha = pal[colour].alpha; - break; - default: - red = green = blue = alpha = 0; } // switch return; } // ogSurface::ogUnpack -void -ogSurface::ogVFlip(void) { +void ogSurface::ogVFlip(void) { uInt32 height; - if (!ogAvail()) return; + if (!ogAvail()) + return; switch (bytesPerPix) { - case 4: - __asm__ __volatile__( + case 4: + __asm__ __volatile__( " add %%edi, %%esi \n" // add esi, edi "vf32lop: \n" - " push %%esi \n" // push esi - " push %%edi \n" // push edi + " push %%esi \n"// push esi + " push %%edi \n"// push edi "vf32lop2: \n" - " mov (%%edi),%%eax \n" // mov eax, [edi] - " mov (%%esi),%%ecx \n" // mov ecx, [esi] - " mov %%eax,(%%esi) \n" // mov [esi], eax - " mov %%ecx,(%%edi) \n" // mov [edi], ecx - " add $4, %%edi \n" // add edi, 4 - " sub $4, %%esi \n" // sub esi, 4 - " cmp %%esi, %%edi \n" // cmp edi, esi + " mov (%%edi),%%eax \n"// mov eax, [edi] + " mov (%%esi),%%ecx \n"// mov ecx, [esi] + " mov %%eax,(%%esi) \n"// mov [esi], eax + " mov %%ecx,(%%edi) \n"// mov [edi], ecx + " add $4, %%edi \n"// add edi, 4 + " sub $4, %%esi \n"// sub esi, 4 + " cmp %%esi, %%edi \n"// cmp edi, esi " jbe vf32lop2 \n" - " pop %%edi \n" // pop edi - " pop %%esi \n" // pop esi - " add %%ebx, %%esi \n" // add esi, ebx - " add %%ebx, %%edi \n" // add edi, ebx + " pop %%edi \n"// pop edi + " pop %%esi \n"// pop esi + " add %%ebx, %%esi \n"// add esi, ebx + " add %%ebx, %%edi \n"// add edi, ebx " dec %%edx \n" " jnz vf32lop \n" : - : "D" ((char *)buffer+lineOfs[0]), "S" (maxX*4), // %0, %1 - "b" (xRes), "d" (maxY+1) // %2, %3 - ); + : "D" ((char *)buffer+lineOfs[0]), "S" (maxX*4),// %0, %1 + "b" (xRes), "d" (maxY+1)// %2, %3 + ); break; - case 3: - height = maxY + 1; - __asm__ __volatile__( + case 3: + height = maxY + 1; + __asm__ __volatile__( " add %%edi, %%esi \n" // add esi, edi "vf24lop: \n" - " push %%esi \n" // push esi - " push %%edi \n" // push edi + " push %%esi \n"// push esi + " push %%edi \n"// push edi "vf24lop2: \n" - " mov (%%edi),%%ax \n" // mov ax, [edi] - " mov 2(%%edi),%%dl \n" // mov dl, [edi+2] - " mov (%%esi),%%cx \n" // mov cx, [esi] - " mov 2(%%esi),%%dh \n" // mov dh, [esi+2] - " mov %%ax,(%%esi) \n" // mov [esi], ax - " mov %%dl,2(%%esi) \n" // mov [esi+2], dl - " mov %%cx,(%%edi) \n" // mov [edi], cx - " mov %%dh,2(%%edi) \n" // mov [edi+2], dh - " add $3, %%edi \n" // add edi, 3 - " sub $3, %%esi \n" // sub esi, 3 - " cmp %%esi, %%edi \n" // cmp edi, esi + " mov (%%edi),%%ax \n"// mov ax, [edi] + " mov 2(%%edi),%%dl \n"// mov dl, [edi+2] + " mov (%%esi),%%cx \n"// mov cx, [esi] + " mov 2(%%esi),%%dh \n"// mov dh, [esi+2] + " mov %%ax,(%%esi) \n"// mov [esi], ax + " mov %%dl,2(%%esi) \n"// mov [esi+2], dl + " mov %%cx,(%%edi) \n"// mov [edi], cx + " mov %%dh,2(%%edi) \n"// mov [edi+2], dh + " add $3, %%edi \n"// add edi, 3 + " sub $3, %%esi \n"// sub esi, 3 + " cmp %%esi, %%edi \n"// cmp edi, esi " jbe vf24lop2 \n" - " pop %%edi \n" // pop edi - " pop %%esi \n" // pop esi - " add %%ebx, %%esi \n" // add esi, ebx - " add %%ebx, %%edi \n" // add edi, ebx - " decl %3 \n" // dec height + " pop %%edi \n"// pop edi + " pop %%esi \n"// pop esi + " add %%ebx, %%esi \n"// add esi, ebx + " add %%ebx, %%edi \n"// add edi, ebx + " decl %3 \n"// dec height " jnz vf24lop \n" : - : "D" ((char *)buffer+lineOfs[0]), "S" (maxX*3), // %0, %1 - "b" (xRes), "m" (height) // %2, %3 - ); + : "D" ((char *)buffer+lineOfs[0]), "S" (maxX*3),// %0, %1 + "b" (xRes), "m" (height)// %2, %3 + ); break; - case 2: - __asm__ __volatile__( + case 2: + __asm__ __volatile__( " add %%edi, %%esi \n" // add esi, edi "vf16lop: \n" - " push %%esi \n" // push esi - " push %%edi \n" // push edi + " push %%esi \n"// push esi + " push %%edi \n"// push edi "vf16lop2: \n" - " mov (%%edi),%%ax \n" // mov ax, [edi] - " mov (%%esi),%%cx \n" // mov cx, [esi] - " mov %%ax,(%%esi) \n" // mov [esi], ax - " mov %%cx,(%%edi) \n" // mov [edi], cx - " add $2, %%edi \n" // add edi, 2 - " sub $2, %%esi \n" // sub esi, 2 - " cmp %%esi, %%edi \n" // cmp edi, esi + " mov (%%edi),%%ax \n"// mov ax, [edi] + " mov (%%esi),%%cx \n"// mov cx, [esi] + " mov %%ax,(%%esi) \n"// mov [esi], ax + " mov %%cx,(%%edi) \n"// mov [edi], cx + " add $2, %%edi \n"// add edi, 2 + " sub $2, %%esi \n"// sub esi, 2 + " cmp %%esi, %%edi \n"// cmp edi, esi " jbe vf16lop2 \n" - " pop %%edi \n" // pop edi - " pop %%esi \n" // pop esi - " add %%ebx, %%esi \n" // add esi, ebx - " add %%ebx, %%edi \n" // add edi, ebx + " pop %%edi \n"// pop edi + " pop %%esi \n"// pop esi + " add %%ebx, %%esi \n"// add esi, ebx + " add %%ebx, %%edi \n"// add edi, ebx " dec %%edx \n" " jnz vf16lop \n" : - : "D" ((char *)buffer+lineOfs[0]), "S" (maxX*2), // %0, %1 - "b" (xRes), "d" (maxY+1) // %2, %3 - ); + : "D" ((char *)buffer+lineOfs[0]), "S" (maxX*2),// %0, %1 + "b" (xRes), "d" (maxY+1)// %2, %3 + ); break; - case 1: - __asm__ __volatile__( + case 1: + __asm__ __volatile__( " add %%edi, %%esi \n" // add esi, edi "vf8lop: \n" - " push %%esi \n" // push esi - " push %%edi \n" // push edi + " push %%esi \n"// push esi + " push %%edi \n"// push edi "vf8lop2: \n" - " mov (%%edi),%%al \n" // mov al, [edi] - " mov (%%esi),%%ah \n" // mov ah, [esi] - " mov %%al,(%%esi) \n" // mov [esi], al - " mov %%ah,(%%edi) \n" // mov [edi], ah - " inc %%edi \n" // inc edi - " dec %%esi \n" // dec esi - " cmp %%esi, %%edi \n" // cmp edi, esi + " mov (%%edi),%%al \n"// mov al, [edi] + " mov (%%esi),%%ah \n"// mov ah, [esi] + " mov %%al,(%%esi) \n"// mov [esi], al + " mov %%ah,(%%edi) \n"// mov [edi], ah + " inc %%edi \n"// inc edi + " dec %%esi \n"// dec esi + " cmp %%esi, %%edi \n"// cmp edi, esi " jbe vf8lop2 \n" - " pop %%edi \n" // pop edi - " pop %%esi \n" // pop esi - " add %%ebx, %%esi \n" // add esi, ebx - " add %%ebx, %%edi \n" // add edi, ebx + " pop %%edi \n"// pop edi + " pop %%esi \n"// pop esi + " add %%ebx, %%esi \n"// add esi, ebx + " add %%ebx, %%edi \n"// add edi, ebx " dec %%edx \n" " jnz vf8lop \n" : - : "D" ((char *)buffer+lineOfs[0]), "S" (maxX), // %0, %1 - "b" (xRes), "d" (maxY+1) // %2, %3 - ); + : "D" ((char *)buffer+lineOfs[0]), "S" (maxX),// %0, %1 + "b" (xRes), "d" (maxY+1)// %2, %3 + ); break; } // switch return; } // ogSurface::ogVFlip -void -ogSurface::ogVLine(int32 x, int32 y1, int32 y2, uInt32 colour) { +void ogSurface::ogVLine(int32 x, int32 y1, int32 y2, uInt32 colour) { int32 tmp; uInt8 r, g, b, a; - if (!ogAvail()) return; - if ((uInt32)x > maxX) return; + if (!ogAvail()) + return; + if ((uInt32) x > maxX) + return; if (y1 > y2) { - tmp= y1; + tmp = y1; y1 = y2; y2 = tmp; } // if - if (y1 < 0) y1 = 0; - if (y2 > (int32)maxY) y2 = maxY; - if (y2 < y1) return; + if (y1 < 0) + y1 = 0; + if (y2 > (int32) maxY) + y2 = maxY; + if (y2 < y1) + return; if (ogIsBlending()) { ogUnpack(colour, r, g, b, a); - if (a == 0) return; + if (a == 0) + return; if (a != 255) { - for (tmp = y1; tmp <= y2; tmp++) + for (tmp = y1; tmp <= y2; tmp++) RawSetPixel(x, tmp, r, g, b, a); return; - } // if - + } // if + } // if blending switch (bytesPerPix) { - case 4: - __asm__ __volatile__( + case 4: + __asm__ __volatile__( " add %%esi, %%edi \n" // add edi, esi - " shl $2, %%ebx \n" // shl ebx, 2 - pix size - " mov %6, %%esi \n" // mov esi, y1 - " sub %%esi, %%ecx \n" // sub ecx, esi - " add %%ebx, %%edi \n" // add edi, ebx - " inc %%ecx \n" // inc ecx + " shl $2, %%ebx \n"// shl ebx, 2 - pix size + " mov %6, %%esi \n"// mov esi, y1 + " sub %%esi, %%ecx \n"// sub ecx, esi + " add %%ebx, %%edi \n"// add edi, ebx + " inc %%ecx \n"// inc ecx "vLlop32: \n" - " mov %%eax, (%%edi)\n" // mov [edi], eax - " add %%edx, %%edi \n" // add edi, edx - " dec %%ecx \n" // dec ecx + " mov %%eax, (%%edi)\n"// mov [edi], eax + " add %%edx, %%edi \n"// add edi, edx + " dec %%ecx \n"// dec ecx " jnz vLlop32 \n" : - : "D" (buffer), "S" (lineOfs[y1]), // %0, %1 - "a" (colour), "b" (x), // %2, %3 - "c" (y2), "d" (xRes), // %4, %5 - "m" (y1) // %6 - ); + : "D" (buffer), "S" (lineOfs[y1]),// %0, %1 + "a" (colour), "b" (x),// %2, %3 + "c" (y2), "d" (xRes),// %4, %5 + "m" (y1)// %6 + ); break; - case 3: - __asm__ __volatile__( + case 3: + __asm__ __volatile__( " add %%esi, %%edi \n" // add edi, esi - " mov %%ebx, %%esi \n" // mov esi, ebx - pix size - " add %%ebx, %%ebx \n" // add ebx, ebx - pix size - " add %%esi, %%ebx \n" // add ebx, esi - pix size - " mov %6, %%esi \n" // mov esi, y1 - " sub %%esi, %%ecx \n" // sub ecx, esi - " add %%ebx, %%edi \n" // add edi, ebx - " inc %%ecx \n" // inc ecx - " mov %%eax, %%ebx \n" // mov ebx, eax - " shr $16, %%ebx \n" // shr ebx, 16 + " mov %%ebx, %%esi \n"// mov esi, ebx - pix size + " add %%ebx, %%ebx \n"// add ebx, ebx - pix size + " add %%esi, %%ebx \n"// add ebx, esi - pix size + " mov %6, %%esi \n"// mov esi, y1 + " sub %%esi, %%ecx \n"// sub ecx, esi + " add %%ebx, %%edi \n"// add edi, ebx + " inc %%ecx \n"// inc ecx + " mov %%eax, %%ebx \n"// mov ebx, eax + " shr $16, %%ebx \n"// shr ebx, 16 "vLlop24: \n" - " mov %%ax, (%%edi) \n" // mov [edi], eax - " mov %%bl, 2(%%edi)\n" // mov [edi+2], bl - " add %%edx, %%edi \n" // add edi, edx - " dec %%ecx \n" // dec ecx + " mov %%ax, (%%edi) \n"// mov [edi], eax + " mov %%bl, 2(%%edi)\n"// mov [edi+2], bl + " add %%edx, %%edi \n"// add edi, edx + " dec %%ecx \n"// dec ecx " jnz vLlop24 \n" : - : "D" (buffer), "S" (lineOfs[y1]), // %0, %1 - "a" (colour), "b" (x), // %2, %3 - "c" (y2), "d" (xRes), // %4, %5 - "m" (y1) // %6 - ); + : "D" (buffer), "S" (lineOfs[y1]),// %0, %1 + "a" (colour), "b" (x),// %2, %3 + "c" (y2), "d" (xRes),// %4, %5 + "m" (y1)// %6 + ); break; - case 2: - __asm__ __volatile__( + case 2: + __asm__ __volatile__( " add %%esi, %%edi \n" // add edi, esi - " add %%ebx, %%ebx \n" // add ebx, ebx - pix size - " mov %6, %%esi \n" // mov esi, y1 - " sub %%esi, %%ecx \n" // sub ecx, esi - " add %%ebx, %%edi \n" // add edi, ebx - " inc %%ecx \n" // inc ecx + " add %%ebx, %%ebx \n"// add ebx, ebx - pix size + " mov %6, %%esi \n"// mov esi, y1 + " sub %%esi, %%ecx \n"// sub ecx, esi + " add %%ebx, %%edi \n"// add edi, ebx + " inc %%ecx \n"// inc ecx "vLlop16: \n" - " mov %%ax, (%%edi) \n" // mov [edi], ax - " add %%edx, %%edi \n" // add edi, edx - " dec %%ecx \n" // dec ecx + " mov %%ax, (%%edi) \n"// mov [edi], ax + " add %%edx, %%edi \n"// add edi, edx + " dec %%ecx \n"// dec ecx " jnz vLlop16 \n" : - : "D" (buffer), "S" (lineOfs[y1]), // %0, %1 - "a" (colour), "b" (x), // %2, %3 - "c" (y2), "d" (xRes), // %4, %5 - "m" (y1) // %6 - ); + : "D" (buffer), "S" (lineOfs[y1]),// %0, %1 + "a" (colour), "b" (x),// %2, %3 + "c" (y2), "d" (xRes),// %4, %5 + "m" (y1)// %6 + ); break; - case 1: - __asm__ __volatile__( + case 1: + __asm__ __volatile__( " add %%esi, %%edi \n" // add edi, esi - " mov %6, %%esi \n" // mov esi, y1 - " sub %%esi, %%ecx \n" // sub ecx, esi - " add %%ebx, %%edi \n" // add edi, ebx - " inc %%ecx \n" // inc ecx - "vLlop8: \n" - " mov %%al, (%%edi) \n" // mov [edi], al - " add %%edx, %%edi \n" // add edi, edx - " dec %%ecx \n" // dec ecx + " mov %6, %%esi \n"// mov esi, y1 + " sub %%esi, %%ecx \n"// sub ecx, esi + " add %%ebx, %%edi \n"// add edi, ebx + " inc %%ecx \n"// inc ecx + "vLlop8: \n" + " mov %%al, (%%edi) \n"// mov [edi], al + " add %%edx, %%edi \n"// add edi, edx + " dec %%ecx \n"// dec ecx " jnz vLlop8 \n" : - : "D" (buffer), "S" (lineOfs[y1]), // %0, %1 - "a" (colour), "b" (x), // %2, %3 - "c" (y2), "d" (xRes), // %4, %5 - "m" (y1) // %6 - ); + : "D" (buffer), "S" (lineOfs[y1]),// %0, %1 + "a" (colour), "b" (x),// %2, %3 + "c" (y2), "d" (xRes),// %4, %5 + "m" (y1)// %6 + ); break; } // switch return; @@ -4098,8 +4167,8 @@ ogSurface::~ogSurface(void) { if (dataState == ogOwner) { - delete [] pal; - delete [] lineOfs; + delete[] pal; + delete[] lineOfs; delete attributes; #ifdef __UBIXOS_KERNEL__ kfree(buffer); @@ -4108,14 +4177,13 @@ #endif } // if datastate - pal = NULL; - lineOfs= NULL; + pal = NULL; + lineOfs = NULL; buffer = NULL; attributes = NULL; - bSize = 0; - lSize = 0; + bSize = 0; + lSize = 0; dataState = ogNone; return; } // ogSurface::~ogSurface - diff --git a/lib/objgfx40/ogFont.cpp b/lib/objgfx40/ogFont.cpp index b6af2ef..edbb24a 100644 --- a/lib/objgfx40/ogFont.cpp +++ b/lib/objgfx40/ogFont.cpp @@ -3,32 +3,29 @@ extern "C" { #ifdef __UBIXOS_KERNEL__ - #include - #include +#include #else - #include - #include - #include +#include +#include #endif - } + +#include +} //using namespace std; -typedef - struct { - char ID[3]; - uInt8 version; - uInt8 width, height; - uInt8 numOfChars; - uInt8 startingChar; - uInt8 colourType; - uInt8 paddington[7]; - } ogDPFHeader; +typedef struct { + char ID[3]; + uint8_t version; + uint8_t width, height; + uint8_t numOfChars; + uint8_t startingChar; + uint8_t colourType; + uint8_t paddington[7]; +} ogDPFHeader; -static -bool -fileExists(const char *file) -{ +static +bool fileExists(const char *file) { #ifdef __UBIXOS_KERNEL__ fileDescriptor *f = fopen(file, "rb"); #else @@ -50,33 +47,31 @@ numOfChars = 0; width = height = startingChar = 0; - BGColour.red = 0; + BGColour.red = 0; BGColour.green = 0; - BGColour.blue = 0; + BGColour.blue = 0; BGColour.alpha = 0; - - FGColour.red = 255; + + FGColour.red = 255; FGColour.green = 255; - FGColour.blue = 255; + FGColour.blue = 255; FGColour.alpha = 255; return; } // ogBitFont::ogBitFont -void -ogBitFont::SetBGColor(uInt32 red, uInt32 green, uInt32 blue, uInt32 alpha) { - BGColour.red = red; +void ogBitFont::SetBGColor(uInt32 red, uInt32 green, uInt32 blue, uInt32 alpha) { + BGColour.red = red; BGColour.green = green; - BGColour.blue = blue; + BGColour.blue = blue; BGColour.alpha = alpha; return; } // ogBitFont::SetBGColor -void -ogBitFont::SetFGColor(uInt32 red, uInt32 green, uInt32 blue, uInt32 alpha) { - FGColour.red = red; +void ogBitFont::SetFGColor(uInt32 red, uInt32 green, uInt32 blue, uInt32 alpha) { + FGColour.red = red; FGColour.green = green; - FGColour.blue = blue; + FGColour.blue = blue; FGColour.alpha = alpha; return; } // ogBitFont::SetFGColor @@ -85,59 +80,55 @@ memset(fontDataIdx, 0, sizeof(fontDataIdx)); memset(charWidthTable, 0, sizeof(charWidthTable)); memset(charHeightTable, 0, sizeof(charHeightTable)); - delete [] fontData; + delete[] fontData; fontData = NULL; fontDataSize = 0; width = height = startingChar = 0; return; } // ogBitFont::~ogBitFont; -void -ogBitFont::CenterTextX(ogSurface& dest, int32 y, const char * textString) { +void ogBitFont::CenterTextX(ogSurface& dest, int32 y, const char * textString) { int32 x; - x = ((dest.ogGetMaxX()+1) - TextWidth(textString)) / 2; + x = ((dest.ogGetMaxX() + 1) - TextWidth(textString)) / 2; PutString(dest, x, y, textString); return; } // ogBitFont::CenterTextX -void -ogBitFont::JustifyText(ogSurface& dest, ogTextAlign horiz, ogTextAlign vert, - const char * textString) { +void ogBitFont::JustifyText(ogSurface& dest, ogTextAlign horiz, ogTextAlign vert, const char * textString) { uInt32 x, y; switch (horiz) { - case leftText: - x = 0; + case leftText: + x = 0; break; - case centerText: - x = ((dest.ogGetMaxX())-TextWidth(textString)) / 2; + case centerText: + x = ((dest.ogGetMaxX()) - TextWidth(textString)) / 2; break; - case rightText: - x = (dest.ogGetMaxX())-TextWidth(textString); + case rightText: + x = (dest.ogGetMaxX()) - TextWidth(textString); break; - default: - return; + default: + return; } // switch switch (vert) { - case topText: - y = 0; + case topText: + y = 0; break; - case centerText: - y = ((dest.ogGetMaxY())-TextHeight(textString)) / 2; + case centerText: + y = ((dest.ogGetMaxY()) - TextHeight(textString)) / 2; break; - case bottomText: - y = (dest.ogGetMaxY())-TextHeight(textString); - default: - return; + case bottomText: + y = (dest.ogGetMaxY()) - TextHeight(textString); + default: + return; } // switch PutString(dest, x, y, textString); return; } // ogBitFont::JustifyText -bool -ogBitFont::Load(const char* fontFile, uInt32 offset = 0) { +bool ogBitFont::Load(const char* fontFile, uInt32 offset = 0) { #ifdef __UBIXOS_KERNEL__ fileDescriptor * infile; #else @@ -146,9 +137,10 @@ ogDPFHeader header; uInt32 lresult, size; - if (!fileExists(fontFile)) return false; + if (!fileExists(fontFile)) + return false; - delete [] fontData; + delete[] fontData; infile = fopen(fontFile, "rb"); fseek(infile, offset, SEEK_SET); @@ -156,20 +148,21 @@ width = header.width; height = header.height; numOfChars = header.numOfChars; - if (numOfChars == 0) numOfChars = 256; + if (numOfChars == 0) + numOfChars = 256; startingChar = header.startingChar; memset(fontDataIdx, 0, sizeof(fontDataIdx)); memset(charWidthTable, 0, sizeof(charWidthTable)); memset(charHeightTable, 0, sizeof(charHeightTable)); - - size = (((uInt32)width+7) / 8)*(uInt32)height; - fontDataSize = size* (uInt32)numOfChars; - for (int32 tmp = startingChar; tmp <= startingChar+numOfChars-1; tmp++) { + size = (((uInt32) width + 7) / 8) * (uInt32) height; + fontDataSize = size * (uInt32) numOfChars; + + for (int32 tmp = startingChar; tmp <= startingChar + numOfChars - 1; tmp++) { charWidthTable[tmp] = width; charHeightTable[tmp] = height; - fontDataIdx[tmp] = (size*(tmp-startingChar)); + fontDataIdx[tmp] = (size * (tmp - startingChar)); } // for tmp fontData = new uInt8[fontDataSize]; @@ -181,78 +174,72 @@ } // ogBitFont::Load /* -bool -ogFont::LoadFrom(const char* FontFile, uInt32 Offset) { - return true; -} // ogFont::LoadFrom + bool + ogFont::LoadFrom(const char* FontFile, uInt32 Offset) { + return true; + } // ogFont::LoadFrom -bool -ogFont::Save(const char* FontFile) { - return saveTo(FontFile,0); -} // ogFont::Save -*/ + bool + ogFont::Save(const char* FontFile) { + return saveTo(FontFile,0); + } // ogFont::Save + */ -uInt32 -ogBitFont::TextHeight(const char * textString) { +uInt32 ogBitFont::TextHeight(const char * textString) { uInt32 size, tmpsize; size = 0; - const unsigned char * text = (const unsigned char *)textString; + const unsigned char * text = (const unsigned char *) textString; if (text != NULL) while (*text) { tmpsize = charHeightTable[*text++]; - if (tmpsize>size) size = tmpsize; + if (tmpsize > size) + size = tmpsize; } // while return size; } // ogBitFont::TextHeight -uInt32 -ogBitFont::TextWidth(const char * textString) { +uInt32 ogBitFont::TextWidth(const char * textString) { uInt32 size = 0; - const unsigned char * text = (const unsigned char *)textString; + const unsigned char * text = (const unsigned char *) textString; if (text != NULL) - while (*text) + while (*text) size += charWidthTable[*text++]; return size; } // ogBitFont::TextWidth /* -bool -ogBitFont::SaveTo(const char * fontFile, int32 offset) { - return true; -} // TDPFont::SaveTo -*/ + bool + ogBitFont::SaveTo(const char * fontFile, int32 offset) { + return true; + } // TDPFont::SaveTo + */ -void -ogBitFont::PutChar(ogSurface& dest, int32 x, int32 y, const char ch) { +void ogBitFont::PutChar(ogSurface& dest, int32 x, int32 y, const char ch) { uInt32 xx, xCount, yCount; uInt32 BGC, FGC, tColour; uInt8 * offset; uInt8 bits = 0; - const unsigned char c = (const unsigned char)ch; + const unsigned char c = (const unsigned char) ch; - if (fontData == NULL) return; - if (!dest.ogAvail()) return; - - if (charWidthTable[c] != 0) { - BGC = dest.ogPack(BGColour.red, - BGColour.green, - BGColour.blue, - BGColour.alpha); + if (fontData == NULL) + return; + if (!dest.ogAvail()) + return; + + if (charWidthTable[c] != 0) { + BGC = dest.ogPack(BGColour.red, BGColour.green, BGColour.blue, BGColour.alpha); BGC &= dest.ogGetAlphaMasker(); tColour = dest.ogGetTransparentColor(); - FGC = dest.ogPack(FGColour.red, - FGColour.green, - FGColour.blue, - FGColour.alpha); - + FGC = dest.ogPack(FGColour.red, FGColour.green, FGColour.blue, FGColour.alpha); + offset = fontData; offset += fontDataIdx[c]; @@ -261,13 +248,12 @@ xx = 0; do { - if ((xx & 7) == 0) bits = *(offset++); + if ((xx & 7) == 0) + bits = *(offset++); if ((bits & 128) != 0) - dest.ogSetPixel(x + xx, y+yCount , FGColour.red, FGColour.green, - FGColour.blue, FGColour.alpha); - else - if (BGC != tColour) - dest.ogSetPixel(x + xx, y+yCount, BGC); + dest.ogSetPixel(x + xx, y + yCount, FGColour.red, FGColour.green, FGColour.blue, FGColour.alpha); + else if (BGC != tColour) + dest.ogSetPixel(x + xx, y + yCount, BGC); bits += bits; ++xx; @@ -277,23 +263,24 @@ return; } // ogBitFont::PutChar -void -ogBitFont::PutString(ogSurface& dest, int32 x, int32 y, - const char *textString) { +void ogBitFont::PutString(ogSurface& dest, int32 x, int32 y, const char *textString) { const unsigned char *text; unsigned char ch; - if (textString == NULL) return; - if (0 == strlen(textString)) return; - if (!dest.ogAvail()) return; + if (textString == NULL) + return; + if (0 == strlen(textString)) + return; + if (!dest.ogAvail()) + return; - text = (const unsigned char *)textString; + text = (const unsigned char *) textString; while ((ch = *text++) != 0) { PutChar(dest, x, y, ch); x += charWidthTable[ch]; } // while - + return; } // ogBitFont::PutString diff --git a/lib/objgfx40/ogPixCon.cpp b/lib/objgfx40/ogPixCon.cpp index 0e0473b..9f1801b 100644 --- a/lib/objgfx40/ogPixCon.cpp +++ b/lib/objgfx40/ogPixCon.cpp @@ -20,7 +20,7 @@ srcFieldSize[1] = srcPixFmt.redMaskSize; srcFieldSize[2] = srcPixFmt.greenMaskSize; srcFieldSize[3] = srcPixFmt.blueMaskSize; - + srcFieldPos[0] = srcPixFmt.alphaFieldPosition; srcFieldPos[1] = srcPixFmt.redFieldPosition; srcFieldPos[2] = srcPixFmt.greenFieldPosition; @@ -33,111 +33,106 @@ * the 32 will turn into a 0 and the shift will do nothing */ - dstShifters[0] = 32-(dstPixFmt.alphaFieldPosition+dstPixFmt.alphaMaskSize); - dstShifters[1] = 32-(dstPixFmt.redFieldPosition+dstPixFmt.redMaskSize); - dstShifters[2] = 32-(dstPixFmt.greenFieldPosition+dstPixFmt.greenMaskSize); - dstShifters[3] = 32-(dstPixFmt.blueFieldPosition+dstPixFmt.blueMaskSize); + dstShifters[0] = 32 - (dstPixFmt.alphaFieldPosition + dstPixFmt.alphaMaskSize); + dstShifters[1] = 32 - (dstPixFmt.redFieldPosition + dstPixFmt.redMaskSize); + dstShifters[2] = 32 - (dstPixFmt.greenFieldPosition + dstPixFmt.greenMaskSize); + dstShifters[3] = 32 - (dstPixFmt.blueFieldPosition + dstPixFmt.blueMaskSize); i = srcPixFmt.redMaskSize - dstPixFmt.redMaskSize; - if (i>0) - srcMasker = OG_MASKS[dstPixFmt.redMaskSize] << (srcPixFmt.redFieldPosition+i); + if (i > 0) + srcMasker = OG_MASKS[dstPixFmt.redMaskSize] << (srcPixFmt.redFieldPosition + i); else srcMasker = OG_MASKS[srcPixFmt.redMaskSize] << srcPixFmt.redFieldPosition; i = srcPixFmt.greenMaskSize - dstPixFmt.greenMaskSize; - if (i>0) - srcMasker+= OG_MASKS[dstPixFmt.greenMaskSize] << (srcPixFmt.greenFieldPosition+i); + if (i > 0) + srcMasker += OG_MASKS[dstPixFmt.greenMaskSize] << (srcPixFmt.greenFieldPosition + i); else - srcMasker+= OG_MASKS[srcPixFmt.greenMaskSize] << srcPixFmt.greenFieldPosition; + srcMasker += OG_MASKS[srcPixFmt.greenMaskSize] << srcPixFmt.greenFieldPosition; i = srcPixFmt.blueMaskSize - dstPixFmt.blueMaskSize; - if (i>0) - srcMasker+= OG_MASKS[dstPixFmt.blueMaskSize] << (srcPixFmt.blueFieldPosition+i); + if (i > 0) + srcMasker += OG_MASKS[dstPixFmt.blueMaskSize] << (srcPixFmt.blueFieldPosition + i); else - srcMasker+= OG_MASKS[srcPixFmt.blueMaskSize] << srcPixFmt.blueFieldPosition; + srcMasker += OG_MASKS[srcPixFmt.blueMaskSize] << srcPixFmt.blueFieldPosition; i = srcPixFmt.alphaMaskSize - dstPixFmt.alphaMaskSize; - if (i>0) - srcMasker+= OG_MASKS[dstPixFmt.alphaMaskSize] << (srcPixFmt.alphaFieldPosition+i); + if (i > 0) + srcMasker += OG_MASKS[dstPixFmt.alphaMaskSize] << (srcPixFmt.alphaFieldPosition + i); else - srcMasker+= OG_MASKS[srcPixFmt.alphaMaskSize] << srcPixFmt.alphaFieldPosition; + srcMasker += OG_MASKS[srcPixFmt.alphaMaskSize] << srcPixFmt.alphaFieldPosition; /* * sort in descending order based on srcFieldPos (oth field will hold * highest position value) */ - - for (i = 1; i < 4; i++ ) + + for (i = 1; i < 4; i++) for (j = 0; j < i; j++) { if (srcFieldPos[j] < srcFieldPos[i]) { tmpb = srcFieldPos[j]; srcFieldPos[j] = srcFieldPos[i]; srcFieldPos[i] = tmpb; - + tmpb = srcFieldSize[j]; srcFieldSize[j] = srcFieldSize[i]; srcFieldSize[i] = tmpb; - + tmpb = channelIdx[j]; channelIdx[j] = channelIdx[i]; channelIdx[i] = tmpb; } // if } // for j - srcShifter = ((srcFieldSize[0] << 24) | - (srcFieldSize[1] << 16) | - (srcFieldSize[2] << 8) | - (srcFieldSize[3])); + srcShifter = ((srcFieldSize[0] << 24) | (srcFieldSize[1] << 16) | (srcFieldSize[2] << 8) | (srcFieldSize[3])); - dstShifter = ((dstShifters[channelIdx[0]] << 24) | - (dstShifters[channelIdx[1]] << 16) | - (dstShifters[channelIdx[2]] << 8) | - (dstShifters[channelIdx[3]])); + dstShifter = ((dstShifters[channelIdx[0]] << 24) | (dstShifters[channelIdx[1]] << 16) | (dstShifters[channelIdx[2]] << 8) | (dstShifters[channelIdx[3]])); return; } // ogPixCon::ogPixCon -uInt32 -ogPixCon::ConvPix(uInt32 pixel) { +uInt32 ogPixCon::ConvPix(uInt32 pixel) { __asm__ __volatile__( - " xor %%ebx, %%ebx \n" // xor ebx, ebx - " xor %%edi, %%edi \n" // xor edi, edi - " \n" - " push %%eax \n" // push eax - " \n" - " and %%edx, %%esi \n" // and esi, edx - " xor %%eax, %%eax \n" // xor eax, eax - " xor %%edx, %%edx \n" // xor edx, edx - " \n" - " shrdl %%cl, %%esi, %%eax \n" // shrd eax, esi, cl - " shr %%cl, %%esi \n" // shr esi, cl - " mov %%ch, %%cl \n" // mov cl, ch - " shrdl %%cl, %%esi, %%ebx \n" // shrd ebx, esi, cl - " shr %%cl, %%esi \n" // shr esi, cl - " shr $16, %%ecx \n" // shr ecx, 16 - " shrdl %%cl, %%esi, %%edx \n" // shrd edx, esi, cl - " shr %%cl, %%esi \n" // shr esi, cl - " mov %%ch, %%cl \n" // mov cl, ch - " shrdl %%cl, %%esi, %%edi \n" // shrd edi, esi, cl - " \n" - " pop %%ecx \n" // pop ecx - " \n" - " shr %%cl, %%eax \n" // shr eax, cl - " shr $8, %%ecx \n" // shr ecx, 8 - " shr %%cl, %%ebx \n" // shr ebx, cl - " shr $8, %%ecx \n" // shr ecx, 8 - " shr %%cl, %%edx \n" // shr edx, cl - " shr $8, %%ecx \n" // shr ecx, 8 - " shr %%cl, %%edi \n" // shr edi, cl - " \n" - " or %%ebx, %%eax \n" // or eax, ebx - " or %%edi, %%edx \n" // or edx, edi - " nop \n" // nop - " or %%edx, %%eax \n" // or eax, edx + " xor %%ebx, %%ebx \n" // xor ebx, ebx + " xor %%edi, %%edi \n"// xor edi, edi + " \n" + " push %%eax \n"// push eax + " \n" + " and %%edx, %%esi \n"// and esi, edx + " xor %%eax, %%eax \n"// xor eax, eax + " xor %%edx, %%edx \n"// xor edx, edx + " \n" + " shrdl %%cl, %%esi, %%eax \n"// shrd eax, esi, cl + " shr %%cl, %%esi \n"// shr esi, cl + " mov %%ch, %%cl \n"// mov cl, ch + " shrdl %%cl, %%esi, %%ebx \n"// shrd ebx, esi, cl + " shr %%cl, %%esi \n"// shr esi, cl + " shr $16, %%ecx \n"// shr ecx, 16 + " shrdl %%cl, %%esi, %%edx \n"// shrd edx, esi, cl + " shr %%cl, %%esi \n"// shr esi, cl + " mov %%ch, %%cl \n"// mov cl, ch + " shrdl %%cl, %%esi, %%edi \n"// shrd edi, esi, cl + " \n" + " pop %%ecx \n"// pop ecx + " \n" + " shr %%cl, %%eax \n"// shr eax, cl + " shr $8, %%ecx \n"// shr ecx, 8 + " shr %%cl, %%ebx \n"// shr ebx, cl + " shr $8, %%ecx \n"// shr ecx, 8 + " shr %%cl, %%edx \n"// shr edx, cl + " shr $8, %%ecx \n"// shr ecx, 8 + " shr %%cl, %%edi \n"// shr edi, cl + " \n" + " or %%ebx, %%eax \n"// or eax, ebx + " or %%edi, %%edx \n"// or edx, edi + " nop \n"// nop + " or %%edx, %%eax \n"// or eax, edx - : "=a" (pixel) // %0 - : "S" (pixel), "d" (srcMasker), // %1, %2 - "c" (srcShifter), "a" (dstShifter) // %3, %4 - // "ecx" (srcShifter), "eax" (dstShifter) // %2, %3 + : "=a" (pixel)// %0 + : "S" (pixel), "d" (srcMasker),// %1, %2 + "c" (srcShifter), "a" (dstShifter)// %3, %4 + // "ecx" (srcShifter), "eax" (dstShifter) // %2, %3 ); return pixel; -}; // ogPixCon::ConvPix +} +; +// ogPixCon::ConvPix diff --git a/lib/objgfx40/ogPixelFmt.cpp b/lib/objgfx40/ogPixelFmt.cpp index 63d390b..4abb6e6 100644 --- a/lib/objgfx40/ogPixelFmt.cpp +++ b/lib/objgfx40/ogPixelFmt.cpp @@ -2,37 +2,30 @@ #include extern "C" { -#ifdef __UBIXOS_KERNEL__ #include -#else -#include -#endif } -ogPixelFmt::ogPixelFmt(void) : BPP(0), - redFieldPosition(0), greenFieldPosition(0), - blueFieldPosition(0), alphaFieldPosition(0), - redMaskSize(0), greenMaskSize(0), - blueMaskSize(0), alphaMaskSize(0) { - for (int i = 0; i < 7; i++) reserved[i] = 0; +ogPixelFmt::ogPixelFmt(void) : + BPP(0), redFieldPosition(0), greenFieldPosition(0), blueFieldPosition(0), alphaFieldPosition(0), redMaskSize(0), greenMaskSize(0), blueMaskSize(0), alphaMaskSize(0) { + for (int i = 0; i < 7; i++) + reserved[i] = 0; return; } -ogPixelFmt::ogPixelFmt(uInt8 bitsPerPix, - uInt8 RFP, uInt8 GFP, uInt8 BFP, uInt8 AFP, - uInt8 RMS, uInt8 GMS, uInt8 BMS, uInt8 AMS) { +ogPixelFmt::ogPixelFmt(uInt8 bitsPerPix, uInt8 RFP, uInt8 GFP, uInt8 BFP, uInt8 AFP, uInt8 RMS, uInt8 GMS, uInt8 BMS, uInt8 AMS) { BPP = bitsPerPix; - redFieldPosition = RFP; + redFieldPosition = RFP; greenFieldPosition = GFP; - blueFieldPosition = BFP; + blueFieldPosition = BFP; alphaFieldPosition = AFP; - redMaskSize = RMS; + redMaskSize = RMS; greenMaskSize = GMS; - blueMaskSize = BMS; + blueMaskSize = BMS; alphaMaskSize = AMS; - - for (int i = 0; i < 7; i++) reserved[i] = 0; - return; + for (int i = 0; i < 7; i++) + reserved[i] = 0; + + return; } // ogPixelFmt::ogPixelFmt() diff --git a/sys/lib/libcpp.cc b/sys/lib/libcpp.cc index 05e2950..ff6723a 100644 --- a/sys/lib/libcpp.cc +++ b/sys/lib/libcpp.cc @@ -31,25 +31,25 @@ #include #include -void __pure_virtual() { - while (1) - asm("nop"); -} + void __pure_virtual() { + while (1) + asm("nop"); + } -void __cxa_pure_virtual() { - while (1) - asm("nop"); -} + void __cxa_pure_virtual() { + while (1) + asm("nop"); + } -/* Don't plan on exiting the kernel...so do nothing. */ -int __cxa_atexit(void (*func)(void *), void * arg, void * d) { - return 0; -} + /* Don't plan on exiting the kernel...so do nothing. */ + int __cxa_atexit(void (*func)(void *), void * arg, void * d) { + return 0; + } -void __dso_handle() { - while (1) - asm("nop"); -} + void __dso_handle() { + while (1) + asm("nop"); + } } diff --git a/sys/lib/ogprintf.cc b/sys/lib/ogprintf.cc index 3d01814..4956823 100644 --- a/sys/lib/ogprintf.cc +++ b/sys/lib/ogprintf.cc @@ -74,41 +74,3 @@ } // ogPrintf } - -/*** - $Log: ogprintf.cc,v $ - Revision 1.1.1.1 2006/06/01 12:46:16 reddawg - ubix2 - - Revision 1.2 2005/10/12 00:13:37 reddawg - Removed - - Revision 1.1.1.1 2005/09/26 17:24:13 reddawg - no message - - Revision 1.7 2004/07/20 22:58:33 reddawg - retiring to the laptop for the night must sync in work to resume from there - - Revision 1.6 2004/07/17 14:24:22 reddawg - compile: changes to the way we link the kernel should prevent future errors - - Revision 1.5 2004/05/23 23:30:34 reddawg - Fixens - - Revision 1.4 2004/05/23 01:40:19 reddawg - Spinlock - - Revision 1.3 2004/05/19 17:09:50 flameshadow - chg: Undid previous renaming. This now restores me as the EOOUIAD. - - Revision 1.2 2004/04/26 12:56:01 reddawg - Made src/sys/sde Copy and Make the ogPixelFormat.cpp - - Revision 1.1.1.1 2004/04/15 12:07:10 reddawg - UbixOS v1.0 - - Revision 1.19 2004/04/13 16:36:33 reddawg - Changed our copyright, it is all now under a BSD-Style license - - END - ***/ diff --git a/sys/sde/main.cc b/sys/sde/main.cc index a8712d2..a456f04 100644 --- a/sys/sde/main.cc +++ b/sys/sde/main.cc @@ -51,13 +51,11 @@ font->SetFGColor(255, 255, 255, 255); font->SetBGColor(0, 0, 0, 255); - printOff = 0x1; screen->ogCreate(800, 600, OG_PIXFMT_16BPP); screen->ogClear(screen->ogPack(122, 140, 163)); - systemVitals->screen = screen; systemVitals->font = font; diff --git a/sys/sde/sde.cc b/sys/sde/sde.cc index 2c06de3..375b271 100644 --- a/sys/sde/sde.cc +++ b/sys/sde/sde.cc @@ -29,7 +29,6 @@ extern "C" { #include #include -//#include #include #include #include