void Picture::paintTriangle(const Triangle& triangle) { Edge edges[3]; for(int i = 0; i < 3; ++i) { edges[i] = Edge(triangle.vertex(i), triangle.vertex((i+1)%3)); } std::vector<int> lineEndpoints; bool onRightSide = gatherEndPoints(edges, lineEndpoints); int i = 0; i = scanLine(edges[0], triangle.color(), lineEndpoints, onRightSide, i); scanLine(edges[1], triangle.color(), lineEndpoints, onRightSide, i); }
void SceneCuller::setVisibleExtrema(const EdgeIt &start, const EdgeIt &end) { for (EdgeIt it = start; it != end; ++it) { assert(it->first.y < it->second.y); if (it->first.x < it->second.x) { line_mirrored = false; scanLine(it->first.x, it->first.y, it->second.x, it->second.y); } else { line_mirrored = true; mirror_x = it->first.x; int mx = it->first.x * 2 - it->second.x; scanLine(it->first.x, it->first.y, mx, it->second.y); } } }
static void scanSpan(edge _e0, edge _e1, int _yMin, int _yMax, int _z, std::set<TileID>& _tiles) { // _e1 has a shorter y-span, so we'll use it to limit our y coverage int y0 = fmax(_yMin, floor(_e1.y0)); int y1 = fmin(_yMax, ceil(_e1.y1)); // sort edges by x-coordinate if (_e0.x0 == _e1.x0 && _e0.y0 == _e1.y0) { if (_e0.x0 + _e1.dy / _e0.dy * _e0.dx < _e1.x1) { std::swap(_e0, _e1); } } else { if (_e0.x1 - _e1.dy / _e0.dy * _e0.dx < _e1.x0) { std::swap(_e0, _e1); } } // scan lines! double m0 = _e0.dx / _e0.dy; double m1 = _e1.dx / _e1.dy; double d0 = _e0.dx > 0 ? 1.0 : 0.0; double d1 = _e1.dx < 0 ? 1.0 : 0.0; for (int y = y0; y < y1; y++) { double x0 = m0 * fmax(0.0, fmin(_e0.dy, y + d0 - _e0.y0)) + _e0.x0; double x1 = m1 * fmax(0.0, fmin(_e1.dy, y + d1 - _e1.y0)) + _e1.x0; scanLine(floor(x1), ceil(x0), y, _z, _tiles); } }
void scanFile(Options& opts, istream& in) { do { string line; getline(in, line); scanLine(opts, line); } while(!!in); }
Color Picture::getAverageColor(const ivec2& v1, const ivec2& v2, const ivec2& v3) const { // This algorithm is basically the same algorithm as in rasterization Edge edges[3]; edges[0] = Edge(v1, v2); edges[1] = Edge(v3, v2); edges[2] = Edge(v1, v3); std::vector<int> lineEndpoints; bool onRightSide = gatherEndPoints(edges, lineEndpoints); int i = 0; size_t rgb[4] = {0}, pix = 0; i = scanLine(edges[0], lineEndpoints, onRightSide, i, rgb, pix); scanLine(edges[1], lineEndpoints, onRightSide, i, rgb, pix); if(pix == 0) return Color(0,0,0,0); for(int i = 0; i < 3; ++i) rgb[i] /= pix; rgb[3] = 255; return Color(rgb); }
task main() { float error; scanLine(); while (true) { error = SensorValue[colour] - grey; motor[leftwheel] = nMotorSpeedSetting - round(error * nPfactor); motor[rightwheel] = nMotorSpeedSetting + round(error * nPfactor); wait1Msec(50); } }
void VMsgLog::runCmd( WString &cmd ) { static char buff[MAX_BUFF+1]; addLine( cmd ); blength = 0; buffer[blength] = '\0'; if( !_batserv ) { #ifdef __WINDOWS__ VxDPut( cmd.gets(), cmd.size() + 1 ); for(;;) { int len = VxDGet( buff, MAX_BUFF ); buff[len] = '\0'; if( streq( buff, TERMINATE_COMMAND_STR ) ) { break; } else if( len > 0 ) { scanLine( buff, len ); } } #endif } else { unsigned maxlen; maxlen = BatchMaxCmdLine(); cmd.truncate( maxlen ); BatchSpawn( cmd ); for( ;; ) { WSystemService::sysYield(); //allow other tasks to run unsigned long stat; int len = BatchCollect( buff, MAX_BUFF, &stat ); if( len < 0 ) { break; } else if( len > 0 ) { scanLine( buff, len ); } } } if( strlen( buffer ) > 0 ) { addLine( buffer ); } }
void scanSourceLineByLine(FILE *source, FILE *result) { int line_no = 1; char line[128]; while (fgets(line, sizeof(line), source) != NULL) { scanLine(line_no, line, result); line_no++; } if (mlc_f == 1) printf("%d\\%d\\%s\n", line_no - 1, -1, "Expected: */"); }
std::vector<cv::Mat> InputWidget::evaluate(){ auto img = image.scaled(28,28,Qt::IgnoreAspectRatio,Qt::SmoothTransformation); cv::Mat mat(28,28,cv::DataType<float>::type); for(int i=0;i<28;++i){ auto l = (QRgb*)img.scanLine(i); for(int j=0;j<28;++j){ auto val = qGray(l[j])/256.0; mat.at<float>(i,j) = val; } } return std::vector<cv::Mat>({mat}); }
int scanLineForAllMacros(char *buffer, MACRO_STRUCT **m) { int i; for (i=0; ; i++) { if (macroDefs[i].macroName==0) return 0; if (scanLine(¯oDefs[i], buffer, m)==1) return 1; } return 0; }
void main43(void) { char chArr[C_SIZE_OF_TARGET_ARR]; int wordIndex = -1; char *chArrPtr; // Testdata fdom labb-assignment: // char* temp; // temp = getWord("Hej på dej", 1); // temp = getWord("en sträng", 0); // temp = getWord("ett ord", 2); printf_s("Welcome Word Finder!\n"); do { printf_s("\nPlease enter a sentence: "); scanLine(chArr, C_SIZE_OF_TARGET_ARR); printf_s("chArr = \"%s\"\n", chArr); // printf_s("\nThe first word is: \n"); // printFirstWord(chArr); // printf_s("\n"); printf_s("Which word index do you want to print? "); scanf_s("%d", &wordIndex); flushRestOfLine(); chArrPtr = getWord(chArr, wordIndex); if (NULL != chArrPtr) { printf_s("The word at index %d is: \"", wordIndex); printFirstWord(chArrPtr); printf_s("\"\n"); } else { printFirstWord(chArrPtr); printf_s("\n"); } } while (1 == yesNoRepeater("Would you like to run the Word Finder again?")); printf_s("\nThank you for using Word Finder\n\n"); } // main
BresenhamLineScan::BresenhamLineScan(const Vector2<int>& start, const double& direction, const CameraInfo& cameraInfo) { const Vector2<int> frameUpperLeft(0,0); const Vector2<int> frameLowerRight(cameraInfo.resolutionWidth-1, cameraInfo.resolutionHeight-1); Geometry::Line scanLine(start, Vector2<double>(cos(direction), sin(direction))); Vector2<int> lineStart, lineEnd; Geometry::getIntersectionPointsOfLineAndRectangle( frameUpperLeft, frameLowerRight, scanLine, lineStart, lineEnd); Vector2<double> delta((lineEnd - start).x, (lineEnd - start).y); Vector2<double> directionVector(cos(direction), sin(direction)); if (delta*directionVector >= 0) setup(lineEnd-start); else setup(lineStart-start); }
void render() { vx = cosang + sinang + incvx * 0.5f; vy = sinang - cosang + incvy * 0.5f; int d = height - width/2; vx += d*incvx; vy += d*incvy; for(sx=0; sx < width; sx++) { incx = fabsf(vx); incy = fabsf(vy); scanLine(); vx += incvx; vy += incvy; } }
void ScanForAxes::execute() { const QImage img = m_doc->processedImage(); if ((img.width() > 2) && (img.height() > 2)) { QColor scanLineColor = PointSetStyles::instance().pointSetColor( DefaultSettings::instance().getScanForAxesLineColor()); int scanLineWidth = DefaultSettings::instance().getScanForAxesLineWidth(); Q3CanvasLine scanLine(m_doc->canvas()); Q3CanvasLine bestXLine(m_doc->canvas()); // best x scan line so far Q3CanvasLine bestYLine(m_doc->canvas()); // best y scan line so far scanLine.setBrush(QBrush(scanLineColor)); bestXLine.setBrush(QBrush(scanLineColor)); bestYLine.setBrush(QBrush(scanLineColor)); scanLine.setPen(QPen(scanLineColor, scanLineWidth)); bestXLine.setPen(QPen(scanLineColor, scanLineWidth)); bestYLine.setPen(QPen(scanLineColor, scanLineWidth)); scanLine.setZ(ZScanForAxesLines); bestXLine.setZ(ZScanForAxesLines); bestYLine.setZ(ZScanForAxesLines); scanLine.show(); int xAxisRow, xAxisColMin, xAxisColMax; int yAxisCol, yAxisRowMin, yAxisRowMax; scanXAxis(img, scanLine, bestXLine, xAxisRow, xAxisColMin, xAxisColMax); scanYAxis(img, scanLine, bestYLine, yAxisCol, yAxisRowMin, yAxisRowMax); double yForXAxis = 0.0; double xForYAxis = 0.0; m_doc->addAxisPoint(xAxisColMin, xAxisRow, m_xMinG, yForXAxis); m_doc->addAxisPoint(xAxisColMax, xAxisRow, m_xMaxG, yForXAxis); m_doc->addAxisPoint(yAxisCol, yAxisRowMin, xForYAxis, m_yMaxG); // remember, lowest row is at top so use yAxisRowMin! } }
// quickly finds user-specified layer before first render void scanLines() { printf("Indexing lines...\n"); layerCount = 0; // preallocate for 128 layers, we double the size later if it's not enough layerSize = (128 * sizeof(layerData)); layer = malloc(layerSize); layer[0].startX = NAN; layer[0].startY = NAN; layer[0].index = NULL; ZstackIndex = 0; while ((busy & BUSY_SCANFILE) && ((layerCount - 2) <= currentLayer)) { scanLine(); } printf("found layer %d\n", currentLayer); }
int main(int argc, char* argv[]) { msgbuf = malloc(256); msgbuf[0] = 0; currentLayer = 0; cache = true; int longIndex; int opt; do { opt = getopt_long(argc, argv, optString, longOpts, &longIndex); if (opt != -1) { switch( opt ) { case 'l': currentLayer = strtol(optarg, NULL, 10); break; case 'w': extrusionWidth = strtof(optarg, NULL); break; case 'n': printf("DISABLING CACHE\n"); cache = false; break; case 'h': /* fall-through is intentional */ case '?': display_usage(); break; case 0: /* long option without a short arg */ //if( strcmp( "randomize", longOpts[longIndex].name ) == 0 ) { // globalArgs.randomized = 1; //} break; default: /* You won't actually get here. */ break; } } } while (opt != -1); if (optind >= argc) display_usage(); int fd = open(argv[optind], 0); if (fd == -1) die("Open ", argv[optind]); struct stat filestats; if (fstat(fd, &filestats) == -1) die("fstat ", argv[optind]); filesz = filestats.st_size; printf("File is %d long\n", filesz); #ifdef __linux__ gcodefile = mmap(NULL, filesz, PROT_READ, MAP_PRIVATE | MAP_POPULATE, fd, 0); #elif defined __APPLE__ gcodefile = mmap(NULL, filesz, PROT_READ, MAP_PRIVATE, fd, 0); #else #error "don't know how to mmap on this system!" #endif if (gcodefile == MAP_FAILED) die("mmap ", argv[optind]); gcodefile_end = &gcodefile[filesz]; busy = BUSY_SCANFILE; scanLines(); if (currentLayer >= layerCount) currentLayer = layerCount - 1; //for (int i = 0; i < layerCount; i++) // printf("Layer %3d starts at %7d and is %7d bytes long\n", i, layer[i].index - gcodefile, layer[i].size); Running = true; Surf_Display = NULL; if (SDL_Init(SDL_INIT_EVERYTHING) < 0) die("SDL_init", ""); if (FcInitLoadConfigAndFonts() == ((void *) FcTrue)) die("FontConfig Init",""); // from http://www.spinics.net/lists/font-config/msg03050.html FcPattern *pat, *match; FcResult result; char *file; int index; pat = FcPatternCreate(); FcPatternAddString(pat, FC_FAMILY, (FcChar8 *) "Mono"); FcConfigSubstitute(NULL, pat, FcMatchPattern); FcDefaultSubstitute(pat); match = FcFontMatch(NULL, pat, &result); FcPatternGetString(match, FC_FILE, 0, (FcChar8 **) &file); FcPatternGetInteger(match, FC_INDEX, 0, &index); font = ftglCreateExtrudeFont(file); if (!font) die("FTGL createFont", ""); FcPatternDestroy (match); FcPatternDestroy (pat); #ifdef OPENGL transX = transY = 0.0; zoomFactor = 1.0; resize(600, 600); #else viewPortL = viewPortT = 0.0; viewPortR = viewPortB = 200.0; zoomFactor = 3.0; resize(viewPortR * zoomFactor, viewPortB * zoomFactor); #endif SDL_WM_SetCaption("gcodeview", 0); drawLayer(currentLayer); layerVelocity = 0; timerIdle = SDL_AddTimer(20, &timerCallback, (void *) TIMER_IDLE); SDL_Event Event; while(Running != false) { if (busy) { Event.type = SDL_NOEVENT; SDL_PollEvent(&Event); } else { if (SDL_WaitEvent(&Event) == 0) die("SDL_WaitEvent", ""); } //SDL_RemoveTimer(timerIdle); switch (Event.type) { case SDL_NOEVENT: if (busy & BUSY_SCANFILE) { // TODO: scan next layer scanLine(); if ((busy & BUSY_SCANFILE) == 0) { if (cache) { printf("File scanned, rendering...\n"); busy = BUSY_RENDER; } else { printf("File scanned.\n"); busy = 0; } } } else if ((busy & BUSY_RENDER) && cache) { bool allRendered = true; int i; // TODO: render next layer in background for (i = 0; i < layerCount; i++) { if (layer[i].glList == 0) { layer[i].glList = glGenLists(1); glNewList(layer[i].glList, GL_COMPILE); glBegin(GL_QUADS); for (int j = SHADOW_LAYERS; j >= 1; j--) { if (i - j > 0) render_layer(i - j, SHADOW_ALPHA - (j - 1) * (SHADOW_ALPHA / SHADOW_LAYERS)); } render_layer(i, 1.0); glEnd(); glEndList(); layer[i].flags |= LD_LISTGENERATED; allRendered = false; break; } } if (allRendered) { printf("All %d layers rendered\n", i); busy &= ~BUSY_RENDER; } } break; case SDL_QUIT: Running = false; break; case SDL_VIDEORESIZE: resize(Event.resize.w, Event.resize.h); break; case SDL_VIDEOEXPOSE: render(); break; case SDL_MOUSEBUTTONDOWN: handle_mousedown(Event.button); break; case SDL_MOUSEBUTTONUP: handle_mouseup(Event.button); break; case SDL_MOUSEMOTION: handle_mousemove(Event.motion); break; case SDL_ACTIVEEVENT: // lose or gain focus break; case SDL_KEYDOWN: handle_keydown(Event.key); break; case SDL_KEYUP: handle_keyup(Event.key); break; case SDL_USEREVENT: handle_userevent(Event.user); break; default: printf("SDL Event %d\n", Event.type); break; } //idle code //if (busy) // timerIdle = SDL_AddTimer(20, &timerCallback, (void *) TIMER_IDLE); } if (timerKeyRepeat) SDL_RemoveTimer(timerKeyRepeat); if (timerDragRender) SDL_RemoveTimer(timerDragRender); free(layer); SDL_FreeSurface(Surf_Display); SDL_Quit(); return 0; }
int GzPutTriangle(GzRender *render, int numParts, GzToken *nameList, GzPointer *valueList) /* numParts : how many names and values */ { /* - pass in a triangle description with tokens and values corresponding to GZ_POSITION:3 vert positions in model space - Xform positions of verts using matrix on top of stack - Clip - just discard any triangle with any vert(s) behind view plane - optional: test for triangles with all three verts off-screen (trivial frustum cull) - invoke triangle rasterizer */ if (render == NULL || nameList == NULL) return GZ_FAILURE; float *n1 = new float[3], *v1 = new float[3], *t1 = new float[2]; float *n2 = new float[3], *v2 = new float[3], *t2 = new float[2]; float *n3 = new float[3], *v3 = new float[3], *t3 = new float[2]; float color1[3]; float color2[3]; float color3[3]; for (int i = 0; i < numParts; ++i) { // iterates through number of parts if (nameList[i] == GZ_NULL_TOKEN) // do nothing ; if (nameList[i] == GZ_TEXTURE_INDEX) { GzTextureIndex *tex = (GzTextureIndex*)valueList[i]; for (int num = 0; num < 2; ++num) { t1[num] = tex[0][num]; t2[num] = tex[1][num]; t3[num] = tex[2][num]; } for (int num = 0; num < 2; ++num) { t1[num] /= ((v1[2] / ((float)MAXINT - v1[2])) + 1.0); t2[num] /= ((v2[2] / ((float)MAXINT - v2[2])) + 1.0); t3[num] /= ((v3[2] / ((float)MAXINT - v3[2])) + 1.0); } if (render->tex_fun != NULL) { // for Gourad Shading float dummy[3] = { 1, 1, 1 }; colorPixelTex(render, n1, color1, dummy, dummy, dummy); colorPixelTex(render, n2, color2, dummy, dummy, dummy); colorPixelTex(render, n3, color3, dummy, dummy, dummy); } } if (nameList[i] == GZ_NORMAL) { GzCoord *normal = (GzCoord*)valueList[i]; for (int num = 0; num < 3; ++num) { n1[num] = normal[0][num]; n2[num] = normal[1][num]; n3[num] = normal[2][num]; } float matrix[4][4]; for (int i = 0; i < 4; ++i) // get matrix based on normals for (int j = 0; j < 4; ++j) matrix[i][j] = render->Xnorm[render->matlevel - 1][i][j]; float n_v1[4] = { 0.0f, 0.0f, 0.0f, 0.0f }; float n_v2[4] = { 0.0f, 0.0f, 0.0f, 0.0f }; float n_v3[4] = { 0.0f, 0.0f, 0.0f, 0.0f }; for (int y = 0; y < 4; ++y) { // does matrix multiplication for (int x = 0; x < 4; ++x) { if (x != 3) { n_v1[y] += matrix[y][x] * n1[x]; n_v2[y] += matrix[y][x] * n2[x]; n_v3[y] += matrix[y][x] * n3[x]; } else { n_v1[y] += matrix[y][x] * 1; n_v2[y] += matrix[y][x] * 1; n_v3[y] += matrix[y][x] * 1; } } } for (int x = 0; x < 3; ++x) { // converts the vertices from 4D to 3D n_v1[x] /= n_v1[3]; n_v2[x] /= n_v2[3]; n_v3[x] /= n_v3[3]; } // Reassign n1, n2, n3 for (int num = 0; num < 3; ++num) { n1[num] = n_v1[num]; n2[num] = n_v2[num]; n3[num] = n_v3[num]; } // gets the color based on vertices colorPixel(render, n1, color1); colorPixel(render, n2, color2); colorPixel(render, n3, color3); } if (nameList[i] == GZ_POSITION) { // Executes GzCoord *coord = (GzCoord*)valueList[i]; for (int num = 0; num < 3; ++num) { v1[num] = coord[0][num]; v2[num] = coord[1][num]; v3[num] = coord[2][num]; } // Transform the coords based on the current matrix float matrix[4][4]; for (int i = 0; i < 4; ++i) for (int j = 0; j < 4; ++j) matrix[i][j] = render->Ximage[render->matlevel - 1][i][j]; float n_v1[4] = { 0.0f, 0.0f, 0.0f, 0.0f }; float n_v2[4] = { 0.0f, 0.0f, 0.0f, 0.0f }; float n_v3[4] = { 0.0f, 0.0f, 0.0f, 0.0f }; for (int y = 0; y < 4; ++y) { // does matrix multiplication for (int x = 0; x < 4; ++x) { if (x != 3) { n_v1[y] += matrix[y][x] * v1[x]; n_v2[y] += matrix[y][x] * v2[x]; n_v3[y] += matrix[y][x] * v3[x]; } else { n_v1[y] += matrix[y][x] * 1; n_v2[y] += matrix[y][x] * 1; n_v3[y] += matrix[y][x] * 1; } } } for (int x = 0; x < 3; ++x) { // converts the vertices from 4D to 3D n_v1[x] /= n_v1[3]; n_v2[x] /= n_v2[3]; n_v3[x] /= n_v3[3]; } // Reassign v1, v2, v3 for (int num = 0; num < 3; ++num) { v1[num] = n_v1[num]; v2[num] = n_v2[num]; v3[num] = n_v3[num]; } // Offsets for Anti-aliasing { v1[0] -= render->xOff; v1[1] -= render->yOff; v2[0] -= render->xOff; v2[1] -= render->yOff; v3[0] -= render->xOff; v3[1] -= render->yOff; } } } // GZ_FLAT -> same // GZ_COLOR -> find color first then interpolate // GZ_NORMAL -> interpolate then find normals float *v_sub; float *n_sub; float c_sub; float *t_sub; for (int v = 0; v < 2; ++v) { // selection sort vertices by y from lowest to highest if (v1[1] > v2[1]) { v_sub = v2; v2 = v1; v1 = v_sub; if (render->interp_mode == GZ_NORMALS){ n_sub = n2; n2 = n1; n1 = n_sub; } else if (render->interp_mode == GZ_COLOR) { for (int c = 0; c < 3; ++c) { c_sub = color2[c]; color2[c] = color1[c]; color1[c] = c_sub; } } if (render->tex_fun != NULL) { t_sub = t1; t1 = t2; t2 = t_sub; } } if (v2[1] > v3[1]) { v_sub = v3; v3 = v2; v2 = v_sub; if (render->interp_mode == GZ_NORMALS){ n_sub = n3; n3 = n2; n2 = n_sub; } else if (render->interp_mode == GZ_COLOR) { for (int c = 0; c < 3; ++c) { c_sub = color3[c]; color3[c] = color2[c]; color2[c] = c_sub; } } if (render->tex_fun != NULL) { t_sub = t2; t2 = t3; t3 = t_sub; } } } // vectors that are based off the y-axis from low to high float vect1[3]; float vect2[3]; float vect3[3]; int lr; // 0 = left, 1 = right, 2 = special traingle case for (int num = 0; num < 3; ++num) { // DEFAULT is set to L vect1[num] = v2[num] - v1[num]; // To v2 from v1 vect2[num] = v3[num] - v2[num]; // To v3 from v2 vect3[num] = v3[num] - v1[num]; // To v3 from v1 } // Normalize the vectors normalize(vect1); normalize(vect2); normalize(vect3); // determines if the line is left or right if (v2[1] == v3[1] || v2[1] == v1[1]) // Checks if mid-vertex has same y-coord lr = 2; else { // looks at the edge vector opposite the vertex: v1 -> v3 // based on y-intercept for v2 float time, x; time = (v2[1] - v1[1]) / vect3[1]; x = v1[0] + time * vect3[0]; // find x and compare with v2 x-coordinate if (x < v2[0]) { // if the intersection occurs on the right lr = 1; // midpoint is on R } else lr = 0; // midpoint is on L } float norm[3], d; crossProduct(vect1, vect2, norm); // Calculates the cross product for the plane // Calculates d using vertex 1 d = -((norm[0] * v1[0]) + (norm[1] * v1[1]) + (norm[2] * v1[2])); // variables for finding the bounds for coloring in triangle float x_sol; float x_begin; int y_begin; float x_end, y_end; // clamps the boundaries for y if (ceilf(v1[1]) < 0) y_begin = 0; else y_begin = ceilf(v1[1]); if (v3[1] > render->display->yres - 1) y_end = render->display->yres - 1; else y_end = v3[1]; float t; float GouraudColor1[3]; float GouraudColor2[3]; float PhongNormal1[3]; float PhongNormal2[3]; float TexPoint1[3]; float TexPoint2[3]; // Computes rasterization using scan line if (lr == 0) { // vect 1 & vect 2 are on the left for (int y = y_begin; y <= y_end; ++y) { // cycles from top vertex to bottom vertex // finds the start point and the endpoint from v1 to v3 in y-coord // computes x_begin for v1 -> v2 if (y < v2[1]) { t = ((float)y - v1[1]) / vect1[1]; x_sol = (vect1[0] * t + v1[0]); x_begin = x_sol; if (render->interp_mode == GZ_COLOR) interpolate(y, v1[1], v2[1], color1, color2, GouraudColor1); else if (render->interp_mode == GZ_NORMALS) interpolate(y, v1[1], v2[1], n1, n2, PhongNormal1); if (render->tex_fun != NULL) interpolateTex(y, v1[1], v2[1], t1, t2, TexPoint1); } else { // compute for v2 -> v3 t = ((float)y - v2[1]) / vect2[1]; x_sol = (vect2[0] * t + v2[0]); x_begin = x_sol; if (render->interp_mode == GZ_COLOR) interpolate(y, v2[1], v3[1], color2, color3, GouraudColor1); else if (render->interp_mode == GZ_NORMALS) interpolate(y, v2[1], v3[1], n2, n3, PhongNormal1); if (render->tex_fun != NULL) interpolateTex(y, v2[1], v3[1], t2, t3, TexPoint1); } // computes x_end: v1 -> v3 t = ((float)y - v1[1]) / vect3[1]; x_sol = (vect3[0] * t + v1[0]); x_end = x_sol; if (render->interp_mode == GZ_COLOR) interpolate(y, v1[1], v3[1], color1, color3, GouraudColor2); else if (render->interp_mode == GZ_NORMALS) interpolate(y, v1[1], v3[1], n1, n3, PhongNormal2); if (render->tex_fun != NULL) interpolateTex(y, v1[1], v3[1], t1, t3, TexPoint2); if (render->interp_mode == GZ_FLAT) scanLine(render, x_begin, x_end, y, norm, d); // Spans line for y_value else if (render->interp_mode == GZ_COLOR) { scanLineGouraud(render, x_begin, x_end, y, norm, d, GouraudColor1, GouraudColor2, TexPoint1, TexPoint2); // Gouraud Shading } else if (render->interp_mode == GZ_NORMALS) { scanLinePhong(render, x_begin, x_end, y, norm, d, PhongNormal1, PhongNormal2, TexPoint1, TexPoint2); // Phong Shading } else scanLine(render, x_begin, x_end, y, norm, d); // Spans line for y_value } } else if (lr == 1) { // RIGHT for (int y = y_begin; y <= y_end; ++y) { // cycles from top vertex to bottom vertex // finds the start point and the endpoint from v1 to v3 in y-coord // computes x_begin for v1 -> v3 t = ((float)y - v1[1]) / vect3[1]; x_sol = (vect3[0] * t + v1[0]); x_begin = x_sol; if (render->interp_mode == GZ_COLOR) interpolate(y, v1[1], v3[1], color1, color3, GouraudColor1); else if (render->interp_mode == GZ_NORMALS) interpolate(y, v1[1], v3[1], n1, n3, PhongNormal1); if (render->tex_fun != NULL) interpolateTex(y, v1[1], v3[1], t1, t3, TexPoint1); // computes x_end v1 -> v2 if (y < v2[1]) { t = ((float)y - v1[1]) / vect1[1]; x_sol = (vect1[0] * t + v1[0]); x_end = x_sol; if (render->interp_mode == GZ_COLOR) interpolate(y, v1[1], v2[1], color1, color2, GouraudColor2); else if (render->interp_mode == GZ_NORMALS) interpolate(y, v1[1], v2[1], n1, n2, PhongNormal2); if (render->tex_fun != NULL) interpolateTex(y, v1[1], v2[1], t1, t2, TexPoint2); } else { // compute for v2 -> v3 t = ((float)y - v2[1]) / vect2[1]; x_sol = (vect2[0] * t + v2[0]); x_end = x_sol; if (render->interp_mode == GZ_COLOR) interpolate(y, v2[1], v3[1], color2, color3, GouraudColor2); else if (render->interp_mode == GZ_NORMALS) interpolate(y, v2[1], v3[1], n2, n3, PhongNormal2); if (render->tex_fun != NULL) interpolateTex(y, v2[1], v3[1], t2, t3, TexPoint2); } if (render->interp_mode == GZ_FLAT) scanLine(render, x_begin, x_end, y, norm, d); // Spans line for y_value else if (render->interp_mode == GZ_COLOR) { scanLineGouraud(render, x_begin, x_end, y, norm, d, GouraudColor1, GouraudColor2, TexPoint1, TexPoint2); // Gouraud Shading } else if (render->interp_mode == GZ_NORMALS) { scanLinePhong(render, x_begin, x_end, y, norm, d, PhongNormal1, PhongNormal2, TexPoint1, TexPoint2); // Phong Shading } else scanLine(render, x_begin, x_end, y, norm, d); // Spans line for y_value } } // special case of horizontal triangles else if (lr == 2) { // compare x float *vleft, *vright; float *vleftend, *vrightend; float *cleft, *cright; float *cleftend, *crightend; float *nleft, *nright; float *nleftend, *nrightend; float *tleft, *tright; float *tleftend, *trightend; float* vect_l; float* vect_r; if (v2[1] == v3[1]) { // bottom line triangle vleft = v1; vright = v1; if (render->interp_mode == GZ_COLOR) { cleft = color1; cright = color1; } else if (render->interp_mode == GZ_NORMALS) { nleft = n1; nright = n1; } if (render->tex_fun != NULL) { tleft = t1; tright = t1; } if (v2[0] > v3[0]) { // v2 is on the right; v1->v2 is on left, v1->v3 is on right vect_l = vect3; vect_r = vect1; vleftend = v2; vrightend = v3; if (render->interp_mode == GZ_COLOR) { cleftend = color2; crightend = color3; } else if (render->interp_mode == GZ_NORMALS) { nleftend = n2; nrightend = n3; } if (render->tex_fun != NULL) { tleftend = t2; trightend = t3; } } else { // v2 is on the left; v1->v2 is on right, v1->v3 is on left vect_l = vect1; vect_r = vect3; vleftend = v3; vrightend = v2; if (render->interp_mode == GZ_COLOR) { cleftend = color3; crightend = color2; } else if (render->interp_mode == GZ_NORMALS) { nleftend = n3; nrightend = n2; } if (render->tex_fun != NULL) { tleftend = t3; trightend = t2; } } } else if (v1[1] == v2[1]) { // top line triangle if (y_begin == v1[1]) // if top horizontal line lies on y_coord for row of pixels ++y_begin; // prevents top and bottom triangle from overwriting same line for integer y if (v1[0] > v2[0]) { // v2 is on the left; v1 is on right vleft = v2; vright = v1; vect_l = vect2; vect_r = vect3; if (render->interp_mode == GZ_COLOR) { cleft = color2; cright = color1; } else if (render->interp_mode == GZ_NORMALS) { nleft = n2; nright = n3; } if (render->tex_fun != NULL) { tleft = t2; tright = t3; } } else { // v2 is on the right; v1 is on left vleft = v1; vright = v2; vect_l = vect3; vect_r = vect2; if (render->interp_mode == GZ_COLOR) { cleft = color1; cright = color2; } else if (render->interp_mode == GZ_NORMALS) { nleft = n1; nright = n2; } if (render->tex_fun != NULL) { tleft = t1; tright = t2; } } vleftend = v3; vrightend = v3; if (render->interp_mode == GZ_COLOR) { cleftend = color3; crightend = color3; } else if (render->interp_mode == GZ_NORMALS) { nleftend = n3; nrightend = n3; } if (render->tex_fun != NULL) { tleftend = t3; trightend = t3; } } for (int y = y_begin; y <= y_end; ++y) { // cycles from top vertex to bottom vertex // computes x_begin for left t = ((float)y - vleft[1]) / vect_l[1]; x_sol = (vect_l[0] * t + vleft[0]); x_begin = x_sol; if (render->interp_mode == GZ_COLOR) interpolate(y, vleft[1], vleftend[1], cleft, cleftend, GouraudColor1); else if (render->interp_mode == GZ_NORMALS) interpolate(y, vleft[1], vleftend[1], nleft, nleftend, PhongNormal1); if (render->tex_fun != NULL) interpolateTex(y, vleft[1], vleftend[1], tleft, tleftend, TexPoint1); // computes x_end for right t = ((float)y - vright[1]) / vect_r[1]; x_sol = (vect_r[0] * t + vright[0]); x_end = x_sol; if (render->interp_mode == GZ_COLOR) interpolate(y, vright[1], vrightend[1], cright, crightend, GouraudColor2); else if (render->interp_mode == GZ_NORMALS) interpolate(y, vright[1], vrightend[1], nright, nrightend, PhongNormal2); if (render->tex_fun != NULL) interpolateTex(y, vright[1], vrightend[1], tright, trightend, TexPoint2); if (render->interp_mode == GZ_FLAT) scanLine(render, x_begin, x_end, y, norm, d); // Spans line for y_value else if (render->interp_mode == GZ_COLOR) { scanLineGouraud(render, x_begin, x_end, y, norm, d, GouraudColor1, GouraudColor2, TexPoint1, TexPoint2); // Spans line for y_value } else if (render->interp_mode == GZ_NORMALS) { scanLinePhong(render, x_begin, x_end, y, norm, d, PhongNormal1, PhongNormal2, TexPoint1, TexPoint2); // Spans line for y_value } else scanLine(render, x_begin, x_end, y, norm, d); // Spans line for y_value } } delete t1; delete t2; delete t3; delete n1; delete n2; delete n3; delete v1; delete v2; delete v3; return GZ_SUCCESS; }
QImage QPatchedPixmap::convertToImage() const { QImage image; if ( isNull() ) { #if defined(CHECK_NULL) qWarning( "QPixmap::convertToImage: Cannot convert a null pixmap" ); #if defined(NASTY) abort(); #endif #endif return image; } int w = qt_screen->mapToDevice( QSize(width(), height()) ).width(); int h = qt_screen->mapToDevice( QSize(width(), height()) ).height(); int d = depth(); bool mono = d == 1; if( d == 15 || d == 16 ) { #ifndef QT_NO_QWS_DEPTH_16 d = 32; // Convert here because we may not have a 32bpp gfx image.create( w,h,d,0, QImage::IgnoreEndian ); for ( int y=h-1; y>=0; y-- ) { // for each scan line... register uint *p = (uint *)image.scanLine(y); ushort *s = (ushort*)scanLine(y); for (int i=w;i>0;i--) *p++ = qt_conv16ToRgb( *s++ ); } const QBitmap *mymask = mask(); if(mymask!=NULL) { QImage maskedimage(width(), height(), 32); maskedimage.fill(0); QGfx * mygfx=maskedimage.graphicsContext(); if(mygfx) { mygfx->setAlphaSource(mymask->scanLine(0), mymask->bytesPerLine()); mygfx->setSource(&image); mygfx->setAlphaType(QGfx::LittleEndianMask); mygfx->setLineStep(maskedimage.bytesPerLine()); mygfx->blt(0,0,width(),height(),0,0); } else { qWarning("No image gfx for convertToImage!"); } delete mygfx; maskedimage.setAlphaBuffer(TRUE); image.reset(); image=maskedimage; } #endif } else { // We can only create little-endian pixmaps if ( d == 4 ) image.create(w,h,8,0, QImage::IgnoreEndian ); else if ( d == 24 ) image.create(w,h,32,0, QImage::IgnoreEndian ); else image.create(w,h,d,0, mono ? QImage::LittleEndian : QImage::IgnoreEndian );//####### endianness QGfx * mygfx=image.graphicsContext(); const QBitmap *mymask = mask(); if(mygfx) { QGfx::AlphaType at = QGfx::IgnoreAlpha; if(mymask!=NULL) { at = QGfx::LittleEndianMask; mygfx->setAlphaSource(mymask->scanLine(0), mymask->bytesPerLine()); image.fill(0); } mygfx->setSource(this); mygfx->setAlphaType(at); mygfx->setLineStep(image.bytesPerLine()); mygfx->blt(0,0,width(),height(),0,0); } else { qWarning("No image gfx for convertToImage!"); } delete mygfx; image.setAlphaBuffer(mymask==NULL?data->hasAlpha:TRUE); } if ( mono ) { // bitmap image.setNumColors( 2 ); image.setColor( 0, qRgb(255,255,255) ); image.setColor( 1, qRgb(0,0,0) ); } else if ( d <= 8 ) { image.setNumColors( numCols() ); for ( int i = 0; i < numCols(); i++ ) image.setColor( i, clut()[i] ); } image = qt_screen->mapFromDevice( image ); return image; }
void chamaScanLine() { scanLine(NUM_PONTOS, points); }
void myMain() { promptInput(); deBlank(scanLine(input, LINE), output, (int)strlen(input) + 1); printf("%s", output); }
void inPut() { printf("Please enter a line of text --> "); scanLine(line, LINE); }