void GUIDrawBorder(SDL_Surface *dst, int x1, int y1, int x2, int y2, Uint32 outLeft, Uint32 inLeft, Uint32 outRight, Uint32 inRight, bool topLeft){ if(outLeft!=0){ vlineColor(dst,x1,y1,y2-1,outLeft); hlineColor(dst,x1,x2-1,y1,outLeft); } if(inLeft!=0){ vlineColor(dst,x1+1,y1+1,y2-2,inLeft); hlineColor(dst,x1+1,x2-2,y1+1,inLeft); } if(outRight!=0){ vlineColor(dst,x2,y1+1,y2,outRight); hlineColor(dst,x1+1,x2-1,y2,outRight); } if(inRight!=0){ vlineColor(dst,x2-1,y1+2,y2-1,inRight); hlineColor(dst,x1+2,x2-2,y2-1,inRight); } if(topLeft){ outRight=outLeft; inRight=inLeft; } pixelColor(dst,x2,y1,outRight); pixelColor(dst,x1,y2,outRight); pixelColor(dst,x1+1,y2-1,inRight); pixelColor(dst,x2-1,y1+1,inRight); }
void GUICheckBox::Draw(SDL_Surface *dst){ if(isCircle){ int rad = ((posX2-posX1<posY2-posY1)?(posX2-posX1):(posY2-posY1))-7; filledCircleColor(dst,(posX1+posX2)/2,(posY1+posY2)/2,rad,0xFFFFFFFF); arcColor(dst,(posX1+posX2)/2,(posY1+posY2)/2,rad,135,315,0x000000FF); arcColor(dst,(posX1+posX2)/2,(posY1+posY2)/2,rad+1,135,315,0x808080FF); arcColor(dst,(posX1+posX2)/2,(posY1+posY2)/2,rad,315,135,0xD4D0C8FF); arcColor(dst,(posX1+posX2)/2,(posY1+posY2)/2,rad+1,315,135,0xFFFFFFFF); if(isChecked)filledCircleColor(dst,(posX1+posX2)/2,(posY1+posY2)/2,rad-3,0x000000FF); }else{ boxColor(dst,posX1,posY1,posX2,posY2,0xFFFFFFFF); GUIDrawBorder(dst,posX1,posY1,posX2,posY2,0x808080FF,0x404040FF,0xFFFFFFFF,0xD4D0C8FF); if(isChecked){ int tickX=((posX2+posX1)/2)-2,tickY=((posY2+posY1)/2)-3; Uint32 clr=0x000000FF; boxColor(dst,tickX+1,tickY+4,tickX+3,tickY+5,clr); boxColor(dst,tickX+4,tickY+2,tickX+5,tickY+3,clr); vlineColor(dst,tickX,tickY+2,tickY+4,clr); vlineColor(dst,tickX+6,tickY,tickY+2,clr); pixelColor(dst,tickX+1,tickY+3,clr); pixelColor(dst,tickX+3,tickY+3,clr); pixelColor(dst,tickX+4,tickY+4,clr); pixelColor(dst,tickX+5,tickY+1,clr); pixelColor(dst,tickX+2,tickY+6,clr); } } }
void Surface::blendAdd(Surface *target, int x, int y) { RGBAColor targetcol, blendcol; for (int iy=0; iy<raw->h; iy++) if (iy+y >= 0 && iy+y < target->raw->h) for (int ix=0; ix<raw->w; ix++) { if (ix+x >= 0 && ix+x < target->raw->w) { blendcol = pixelColor(ix,iy); targetcol = target->pixelColor(ix+x,iy+y); targetcol.r = min(targetcol.r+blendcol.r, 255); targetcol.g = min(targetcol.g+blendcol.g, 255); targetcol.b = min(targetcol.b+blendcol.b, 255); target->putPixel(ix+x,iy+y,targetcol); } } /* Uint32 bcol, tcol; char *pPos, *tpPos; for (int iy=0; iy<raw->h; iy++) if (iy+y >= 0 && iy+y < target->raw->h) { pPos = (char*)raw->pixels + raw->pitch*iy; tpPos = (char*)target->raw->pixels + target->raw->pitch*(iy+y); for (int ix=0; ix<raw->w; ix++) { memcpy(&bcol, pPos, raw->format->BytesPerPixel); memcpy(&tcol, tpPos, target->raw->format->BytesPerPixel); //memcpy(tpPos, &bcol, target->raw->format->BytesPerPixel); pPos += raw->format->BytesPerPixel; tpPos += target->raw->format->BytesPerPixel; target->putPixel(ix+x,iy+y,bcol); } } */ }
void Renderer::render() const { Ray ray; P2d pp; Random rnd(3141592); C3f *image = new C3f[ _vp.width * _vp.height]; double invNumSample = 1.0 / _vp.numSamples; // OpenMP #pragma omp parallel for schedule(dynamic, 1) num_threads(4) for (int y = 0; y < _vp.height; y++) { std::cerr << "Rendering (y = " << y << ") " << (100.0 * y / (_vp.height - 1)) << "%" << std::endl; for (int x = 0; x < _vp.width; x++) { const int imageIndex = (_vp.height - y - 1) * _vp.width + x; C3f pixelColor(0.0f, 0.0f, 0.0f); for (int j = 0; j < _vp.numSamples; j++) { pp.x = _vp.s*(- x + 0.5 * _vp.width); pp.y = _vp.s*(y - 0.5 * _vp.height); ray = _camera->getRay(pp); pixelColor = pixelColor + radiance(ray, &rnd, 0) / _vp.numSamples; } image[imageIndex] = C3f(pixelColor); } } savePPM("output.ppm", image, _vp.width, _vp.height); delete[] image; }
bool kpFloodFill::shouldGoTo (int x, int y) const { bool beenThere; const kpColor col = pixelColor (x, y, &beenThere); return (!beenThere && col.isSimilarTo (m_colorToChange, m_processedColorSimilarity)); }
CAMLprim value ml_pixelColor(value dst,value x,value y, value col) { SDL_Surface *sur= SDL_SURFACE(dst); int r; r=pixelColor(sur,Int_val(x),Int_val(y),Int32_val(col)); return Val_bool(r); }
int GeoLayer::pixel(int16_t x, int16_t y, uint32_t col) { if(!surf) { error("%s can't run: layer not initialized", __PRETTY_FUNCTION__); return -1; } res = pixelColor(surf, x, y, col); if(res < 0) error("error in %s", __PRETTY_FUNCTION__); return(res); }
void ImageBuffer::putByteArray(Multiply multiplied, ByteArray* source, const IntSize& sourceSize, const IntRect& sourceRect, const IntPoint& destPoint, CoordinateSystem) { ASSERT(cairo_surface_get_type(m_data.m_surface) == CAIRO_SURFACE_TYPE_IMAGE); unsigned char* dataDst = cairo_image_surface_get_data(m_data.m_surface); ASSERT(sourceRect.width() > 0); ASSERT(sourceRect.height() > 0); int originx = sourceRect.x(); int destx = destPoint.x() + sourceRect.x(); ASSERT(destx >= 0); ASSERT(destx < m_size.width()); ASSERT(originx >= 0); ASSERT(originx <= sourceRect.maxX()); int endx = destPoint.x() + sourceRect.maxX(); ASSERT(endx <= m_size.width()); int numColumns = endx - destx; int originy = sourceRect.y(); int desty = destPoint.y() + sourceRect.y(); ASSERT(desty >= 0); ASSERT(desty < m_size.height()); ASSERT(originy >= 0); ASSERT(originy <= sourceRect.maxY()); int endy = destPoint.y() + sourceRect.maxY(); ASSERT(endy <= m_size.height()); int numRows = endy - desty; unsigned srcBytesPerRow = 4 * sourceSize.width(); int stride = cairo_image_surface_get_stride(m_data.m_surface); unsigned char* srcRows = source->data() + originy * srcBytesPerRow + originx * 4; for (int y = 0; y < numRows; ++y) { unsigned* row = reinterpret_cast<unsigned*>(dataDst + stride * (y + desty)); for (int x = 0; x < numColumns; x++) { int basex = x * 4; unsigned* pixel = row + x + destx; Color pixelColor(srcRows[basex], srcRows[basex + 1], srcRows[basex + 2], srcRows[basex + 3]); if (multiplied == Unmultiplied) *pixel = premultipliedARGBFromColor(pixelColor); else *pixel = pixelColor.rgb(); } srcRows += srcBytesPerRow; } cairo_surface_mark_dirty_rectangle(m_data.m_surface, destx, desty, numColumns, numRows); }
void putImageData(ImageData*& source, const IntRect& sourceRect, const IntPoint& destPoint, ImageBufferData& data, const IntSize& size) { ASSERT(cairo_surface_get_type(data.m_surface) == CAIRO_SURFACE_TYPE_IMAGE); unsigned char* dataDst = cairo_image_surface_get_data(data.m_surface); ASSERT(sourceRect.width() > 0); ASSERT(sourceRect.height() > 0); int originx = sourceRect.x(); int destx = destPoint.x() + sourceRect.x(); ASSERT(destx >= 0); ASSERT(destx < size.width()); ASSERT(originx >= 0); ASSERT(originx <= sourceRect.right()); int endx = destPoint.x() + sourceRect.right(); ASSERT(endx <= size.width()); int numColumns = endx - destx; int originy = sourceRect.y(); int desty = destPoint.y() + sourceRect.y(); ASSERT(desty >= 0); ASSERT(desty < size.height()); ASSERT(originy >= 0); ASSERT(originy <= sourceRect.bottom()); int endy = destPoint.y() + sourceRect.bottom(); ASSERT(endy <= size.height()); int numRows = endy - desty; unsigned srcBytesPerRow = 4 * source->width(); int stride = cairo_image_surface_get_stride(data.m_surface); unsigned char* srcRows = source->data()->data()->data() + originy * srcBytesPerRow + originx * 4; for (int y = 0; y < numRows; ++y) { unsigned* row = reinterpret_cast<unsigned*>(dataDst + stride * (y + desty)); for (int x = 0; x < numColumns; x++) { int basex = x * 4; unsigned* pixel = row + x + destx; Color pixelColor(srcRows[basex], srcRows[basex + 1], srcRows[basex + 2], srcRows[basex + 3]); if (multiplied == Unmultiplied) *pixel = premultipliedARGBFromColor(pixelColor); else *pixel = pixelColor.rgb(); } srcRows += srcBytesPerRow; } }
QRgb PhongPixelProcessor::reallyFastIlluminatePixel(quint32 posup, quint32 posdown, quint32 posleft, quint32 posright) { qreal temp; const int totalChannels = 3; qreal computation[] = {0, 0, 0}; QColor pixelColor(0, 0, 0); normal_vector.setX(- heightmap[posright] + heightmap[posleft]); normal_vector.setY(- heightmap[posup] + heightmap[posdown]); normal_vector.setZ(8); normal_vector.normalize(); /* foreach (Illuminant illuminant, lightSources) { temp = Kd * QVector3D::dotProduct(normal_vector, illuminant.lightVector); for (int channel = 0; channel < totalChannels; channel++) { //I = each RGB value Id = illuminant.RGBvalue[channel] * temp; if (Id < 0) Id = 0; if (Id > 1) Id = 1; computation[channel] += Id; } } */ temp = QVector3D::dotProduct(normal_vector, fastLight.lightVector); for (int channel = 0; channel < totalChannels; channel++) { //I = each RGB value Id = fastLight.RGBvalue[channel] * temp; if (Id < 0) Id = 0; if (Id > 1) Id = 1; computation[channel] += Id; } temp = QVector3D::dotProduct(normal_vector, fastLight2.lightVector); for (int channel = 0; channel < totalChannels; channel++) { //I = each RGB value Id = fastLight2.RGBvalue[channel] * temp; if (Id < 0) Id = 0; if (Id > 1) Id = 1; computation[channel] += Id; } for (int i = 0; i < 3; i++) if (computation[i] > 1) computation[i] = 1; pixelColor.setRedF(computation[0]); pixelColor.setGreenF(computation[1]); pixelColor.setBlueF(computation[2]); return pixelColor.rgb(); }
void draw_func_densite(SDL_Surface *ecran, SDL_Surface *rectangle, double a) { int t; double tmp; double tmp2; SDL_Rect position; Sint16 vx[1000]; Sint16 vy[1000]; Sint16 vz[1000]; double total = 0; for (t = 0; t < 1000; t++) { position.x = 50 + t; vx[t] = 50 + t; tmp = f(a, (t * 0.01)); position.y = (WIN_HEIGHT - 166) - tmp * 600; vy[t] = (WIN_HEIGHT - 166) - tmp * 600; total += vy[t]; pixelColor(ecran, vx[t], vy[t], 0xff3a2aff); if (t > 0) lineColor(ecran, vx[t - 1], vy[t - 1], vx[t], vy[t], 0xff3a2aff); SDL_FillRect(rectangle, NULL, SDL_MapRGB(ecran->format, 255, 100, 25)); // polygonColor(ecran, vx, vy, 1000, 0xffa02aff); // SDL_BlitSurface(rectangle, NULL, ecran, &position); } for (t = 0; t < 1000; t++) { vx[t] = 50 + t; // tmp2 = fonc_test(0, 1000, 1, 1000, a, total); tmp2 = fonc_rep(0, t, a); vz[t] = (WIN_HEIGHT - 166) - tmp2 * 600; pixelColor(ecran, vx[t], vz[t], 0x3a3affff); if (t > 0) lineColor(ecran, vx[t - 1], vz[t - 1], vx[t], vz[t], 0x3a3affff); } SDL_Flip(ecran); }
void EnergyPoint::hide() { Uint32 color = 0xffffffff; for (Sint16 xColor = _xCenterPixel - Sint16(_radius) ; xColor < _xCenterPixel + Sint16(_radius) ; xColor++) { for (Sint16 yColor = _yCenterPixel - Sint16(_radius) ; yColor < _yCenterPixel + Sint16 (_radius); yColor ++) { if ((sqrt ( pow (xColor-_xCenterPixel,2) + pow (yColor - _yCenterPixel,2))) < _radius) { pixelColor(gBackgroundImage, xColor, yColor, color); } } } }
// TODO I could make this much faster by using an array or vector of vectors - the index is the group void ParticleSystem::draw(int group) { for(unsigned int i = 0; i < particles.size(); i++) if(particles[i].group == group) switch(particles[i].type) { case PIXEL: pixelColor(display, (int)particles[i].x, (int)particles[i].y, particles[i].color); break; case CIRCLE: circleColor(display, (int)particles[i].x, (int)particles[i].y, particles[i].size, particles[i].color); break; case SQUARE: FillRect(particles[i].x, particles[i].y, particles[i].size, particles[i].size, particles[i].color >> 8); break; } }
void Effect::Draw(SDL_Renderer *rnd) { Uint32 x, y; for(Uint32 i = 0; i < _particles.size(); ++i) { Converter::GameWorldToPixel(_particles[i].pos.x, _particles[i].pos.y, &x, &y); pixelColor(rnd, x, y, 0xFF000000 | (150 << 16) | 150); } Uint32 a = rand()% _particles.size(), b = rand() % _particles.size(), x2, y2; Converter::GameWorldToPixel(_particles[a].pos.x, _particles[a].pos.y, &x, &y); Converter::GameWorldToPixel(_particles[b].pos.x, _particles[b].pos.y, &x2, &y2); lineColor(rnd, x, y, x2, y2, (40 << 24) | (150 << 16) | (150 << 8)); }
void HWPlottingArea::plotFromImage(const QImage &image) { clearBins(); for (int y = 0; y < image.height(); y++) { for (int x = 0; x < image.width(); x++) { QColor pixelColor(image.pixel(x, y)); bins[0][pixelColor.red()]++; bins[1][pixelColor.green()]++; bins[2][pixelColor.blue()]++; } } update(); }
void CurveDrawer::fillCircle(const QPointF& center, qreal diameter) { qreal radius = diameter / 2; for (int sy = -1; sy <= 1; sy += 2) { qreal d; for (QPoint p(Utils::roundPoint(center)); (d = qSqrt(Utils::normSquared(p - center)) - radius) <= 0; p.ry() += sy) { for (int sx = -1; sx <= 1; sx += 2) { for (QPoint pp(p); (d = qSqrt(Utils::normSquared(pp - center)) - radius) <= 0; pp.rx() += sx) { setPixel(pp, pixelColor(d, 0.)); } } } } }
void Image::overwriteMask(const Color& maskedColor, const Color& insideColor, const Color& outsideColor) { assert(m_bpp == 4); for(int p=0;p<getPixelCount();p++) { uint8& r = m_pixels[p*4 + 0]; uint8& g = m_pixels[p*4 + 1]; uint8& b = m_pixels[p*4 + 2]; uint8& a = m_pixels[p*4 + 3]; Color pixelColor(r,g,b,a); Color writeColor = (pixelColor == maskedColor) ? insideColor : outsideColor; r = writeColor.r(); g = writeColor.g(); b = writeColor.b(); a = writeColor.a(); } }
static PyObject* _gfx_pixelcolor (PyObject *self, PyObject* args) { PyObject *surface, *color, *pt; int x, y; pguint32 c; ASSERT_VIDEO_INIT (NULL); if (!PyArg_ParseTuple (args, "OOO:pixel", &surface, &pt, &color)) { PyErr_Clear (); if (!PyArg_ParseTuple (args, "OiiO:pixel", &surface, &x, &y, &color)) return NULL; } else { if (!PointFromObj (pt, &x, &y)) return NULL; } if (!PySDLSurface_Check (surface)) { PyErr_SetString (PyExc_TypeError, "surface must be a Surface"); return NULL; } if (!ColorFromObj (color, &c)) return NULL; if (pixelColor (((PySDLSurface*)surface)->surface, (Sint16)x, (Sint16)y, (Uint32)c)== -1) { PyErr_SetString (PyExc_PyGameError, SDL_GetError ()); return NULL; } Py_RETURN_NONE; }
inline void DrawPixel(int x, int y, uint color) { pixelColor(screen, x, y, color); }
void render_line(slide *sl, displayline *out, DrawMode *dm, SDL_Surface *surface) { style *st = sl->st; int single_line; int textshift, x, shift; int xmargin = st->leftmargin; int xbase = st->leftmargin + st->foldmargin; TTF_Font *font; if(dm != NULL) { // Store initial draw mode to make future individual line redraws easy: out->initial_dm = *dm; single_line = 0; } else { // Just drawing this line (not whole slide), so use saved draw mode: dm = new DrawMode; *dm = out->initial_dm; single_line = 1; } shift = 0; if(out->bullet == -1) { shift = dm->lastshift; } else if(out->bullet > 0) { shift = 10 + 30 * out->bullet; bullet(out->bullet, xbase + shift - 20, out->y + (st->text_ascent - st->text_descent) / 2, surface, st); } if(out->centred) { int text_area = sl->des_w - st->leftmargin - st->foldmargin - st->rightmargin; shift = (sl->des_w - out->width) / 2 - st->leftmargin - st->foldmargin; /* Force long lines into the text area, even if that means they end up off-centre within the slide itself due to different left/fold and right margins: */ if(shift + out->width > text_area) // Too far right shift = text_area - out->width; if(shift < 0) // Too far left shift = 0; } if(out->exposed > 0) exposeicon(out->exposed, xmargin, out->y, out->height, surface, st); if(out->type == TYPE_FOLDED) { textshift = 0; if(dm->ttmode) textshift += (st->text_ascent - st->fixed_ascent) / 2; else if(dm->italicmode) textshift += (st->text_ascent - st->italic_ascent) / 2; else if(dm->boldmode) textshift += (st->text_ascent - st->bold_ascent) / 2; foldicon(1, out->exposed, xmargin, out->y, out->height, out->y + (st->text_ascent - st->text_descent) / 2 + textshift, surface, st, out->highlighted); } else if(out->type == TYPE_EXPANDED) { textshift = 0; if(dm->ttmode) textshift += (st->text_ascent - st->fixed_ascent) / 2; else if(dm->italicmode) textshift += (st->text_ascent - st->italic_ascent) / 2; else if(dm->boldmode) textshift += (st->text_ascent - st->bold_ascent) / 2; foldicon(0, out->exposed, xmargin, out->y, out->height, out->y + (st->text_ascent - st->text_descent) / 2 + textshift, surface, st, out->highlighted); } x = xbase + shift; if(out->bullet == 0 && out->prespace > 0) { x += out->prespace * (dm->ttmode ? st->fixed_space_width : st->text_space_width); } if(out->import != NULL) { SDL_Rect dst; dst.x = x; dst.y = out->y + st->latexspaceabove; SDL_BlitSurface(out->import, NULL, surface, &dst); } else if(out->rule) { int width; SDL_Rect dst; width = sl->des_w * st->rulewidth / 100; dst.x = (sl->des_w - width) / 2; dst.y = out->y + st->rulespaceabove; dst.w = width; dst.h = st->ruleheight; SDL_FillRect(surface, &dst, colour->fills->item(st->rulecolour)); } else if(out->line == NULL) error("Impossible out->line in render.cpp"); else if(out->heading && strlen(out->line) > 0) { x = render_text(out->line, st->heading_font, st->headingcolour, surface, x, out->y + st->headspaceabove, 0); } else if(strlen(out->line) > 0) { svector *codes; char code; svector *v = split_string(out->line, &codes); const char *s; int link_text_colour_index; if(out->highlighted) link_text_colour_index = st->highlightcolour; else link_text_colour_index = st->linkcolour; for(int j = 0; j < v->count(); j++) { s = v->item(j); code = codes->item(j)[0]; if(strlen(s) > 0) { textshift = 0; if(dm->italicmode) { font = st->italic_font; textshift += st->text_ascent - st->italic_ascent; } else if(dm->boldmode) { font = st->bold_font; textshift += st->text_ascent - st->bold_ascent; } else if(dm->ttmode) { font = st->fixed_font; textshift += st->text_ascent - st->fixed_ascent; } else { font = st->text_font; } x = render_text(s, font, out->link == NULL ? dm->current_text_colour_index : link_text_colour_index, surface, x, out->y + textshift, out->link == NULL || !st->underlinelinks ? 0 : st->textsize); } if(code == '$') dm->ttmode = 1 - dm->ttmode; else if(code == '%') { if(codes->item(j)[1] == '\0') { dm->current_text_colour_index = st->textcolour; // Default } else { int colour_index; if(codes->item(j)[1] == '#') { colour_index = colour->search_add(codes->item(j) + 2); if(colour_index == -1) error("Incorrect hex colour %s", codes->item(j) + 1); } else { colour_index = colour->names->find(codes->item(j) + 1); if(colour_index == -1) error("Unknown colour <%s>", codes->item(j) + 1); } dm->current_text_colour_index = colour_index; } } else if(code == '*') { if(dm->ttmode == 0) dm->boldmode = 1 - dm->boldmode; else x = render_text("*", st->fixed_font, out->link == NULL ? dm->current_text_colour_index : link_text_colour_index, surface, x, out->y + st->text_ascent - st->fixed_ascent, out->link == NULL || !st->underlinelinks ? 0 : st->textsize); } else if(code == '/') { if(dm->ttmode == 0) dm->italicmode = 1 - dm->italicmode; else x = render_text("/", st->fixed_font, out->link == NULL ? dm->current_text_colour_index : link_text_colour_index, surface, x, out->y + st->text_ascent - st->fixed_ascent, out->link == NULL || !st->underlinelinks ? 0 : st->textsize); } } delete v; delete codes; } if(debug & DEBUG_BASELINES) { pixelColor(surface, xbase, out->y, colour->red_pen); pixelColor(surface, xbase - 1, out->y - 1, colour->red_pen); pixelColor(surface, xbase + 1, out->y + 1, colour->red_pen); pixelColor(surface, xbase - 1, out->y + 1, colour->red_pen); pixelColor(surface, xbase + 1, out->y - 1, colour->red_pen); } if(single_line) delete dm; else dm->lastshift = shift; }
void CurveDrawer::drawLine(QPointF p0, QPointF p1, qreal thickness) { //draw line with thickness and squared ends struct DrawHelper { QPointF p0; QPointF p1; QPointF dp; qreal ed; DrawHelper(const QPointF& p0, const QPointF& p1) { this->p0 = p0; this->p1 = p1; dp = p1 - p0; ed = Utils::norm(dp); } double dist(const QPointF& p) { return qAbs((p.x() - p0.x()) * dp.y() - (p.y() - p0.y()) * dp.x()) / ed; } bool inside(const QPointF& p) { qreal v = (p.y() - p0.x()) * dp.y() + (p.x() - p1.y()) * dp.x(); return v + (p1.y() - p0.x()) * dp.x() + (p0.x() - p0.y()) * dp.y() >= 0 && v + (p1.y() - p1.x()) * dp.x() + (p0.x() - p1.y()) * dp.y() <= 0; } static QPointF makePoint(const QPointF& p) { return p; } static QPointF makePointSwap(const QPointF& p) { return QPointF(p.y(), p.x()); } } drawHelper(p0, p1); QPointF (*pointMaker)(const QPointF& p) = DrawHelper::makePoint; if (qAbs(drawHelper.dp.y()) > qAbs(drawHelper.dp.x())) { p0 = DrawHelper::makePointSwap(p0); p1 = DrawHelper::makePointSwap(p1); pointMaker = DrawHelper::makePointSwap; } if (p1.x() < p0.x()) { qSwap(p0, p1); qSwap(drawHelper.p0, drawHelper.p1); drawHelper.dp *= -1; } qreal xOffset = thickness * qAbs(p0.y() - p1.y()) / drawHelper.ed; QPointF dStep(1, (p1.y() - p0.y()) / (p1.x() - p0.x())); for (QPointF p(p0 - xOffset * dStep); p.x() <= p1.x() + xOffset; p += dStep) { for (int sy = -1; sy <= 1; sy += 2) { qreal dist; for (QPoint pp(Utils::roundPoint(p)); (dist = drawHelper.dist(pointMaker(pp))) <= thickness; pp.ry() += sy) { if (drawHelper.inside(pointMaker(pp))) { setPixel(Utils::roundPoint(pointMaker(pp)), pixelColor(dist, thickness)); } } } } }
void WBFilter::adjustWhiteBalance(uchar* data, int width, int height, bool sixteenBit) { uint size = (uint)(width*height); uint i, j; int progress; if (!sixteenBit) // 8 bits image. { uchar red, green, blue; uchar* ptr = data; for (j = 0 ; runningFlag() && (j < size) ; ++j) { int v, rv[3]; blue = ptr[0]; green = ptr[1]; red = ptr[2]; rv[0] = (int)(blue * d->mb); rv[1] = (int)(green * d->mg); rv[2] = (int)(red * d->mr); v = qMax(rv[0], rv[1]); v = qMax(v, rv[2]); if (d->clipSat) { v = qMin(v, (int)d->rgbMax-1); } i = v; ptr[0] = (uchar)pixelColor(rv[0], i, v); ptr[1] = (uchar)pixelColor(rv[1], i, v); ptr[2] = (uchar)pixelColor(rv[2], i, v); ptr += 4; progress = (int)(((double)j * 100.0) / size); if ( progress%5 == 0 ) { postProgress( progress ); } } } else // 16 bits image. { unsigned short red, green, blue; unsigned short* ptr = (unsigned short*)data; for (j = 0 ; runningFlag() && (j < size) ; ++j) { int v, rv[3]; blue = ptr[0]; green = ptr[1]; red = ptr[2]; rv[0] = (int)(blue * d->mb); rv[1] = (int)(green * d->mg); rv[2] = (int)(red * d->mr); v = qMax(rv[0], rv[1]); v = qMax(v, rv[2]); if (d->clipSat) { v = qMin(v, (int)d->rgbMax-1); } i = v; ptr[0] = pixelColor(rv[0], i, v); ptr[1] = pixelColor(rv[1], i, v); ptr[2] = pixelColor(rv[2], i, v); ptr += 4; progress = (int)(((double)j * 100.0) / size); if ( progress%5 == 0 ) { postProgress( progress ); } } } }
void PixEditor::addMenu() { //Fichier precedent_action=new QAction(tr("&Precedent"),this); precedent_action->setIcon(QIcon("./icones/precedent.jpg")); precedent_action->setStatusTip(tr("Precedent")); QObject::connect(precedent_action,SIGNAL(triggered()),&widgetcentral,SLOT(precedent())); // nouveau_action = new QAction(tr("&Nouveau"), this); nouveau_action->setIcon(QIcon("./icones/window-new-3.png")); nouveau_action->setShortcut(tr("Ctrl+N")); nouveau_action->setStatusTip(tr("Nouvelle image")); QObject::connect(nouveau_action, SIGNAL(triggered()), &widgetcentral, SLOT(nouveau())); ouvrir_action = new QAction(tr("&Ouvrir"), this); ouvrir_action->setShortcut(tr("Ctrl+O")); ouvrir_action->setIcon(QIcon("./icones/OpenButton.png")); ouvrir_action->setStatusTip(tr("Charger une image")); QObject::connect(ouvrir_action, SIGNAL(triggered()), &widgetcentral, SLOT(ouvrir())); sauver_action = new QAction(tr("&Sauvegarder"), this); sauver_action->setShortcut(tr("Ctrl+S")); sauver_action->setIcon(QIcon("./icones/enregistrer.png")); sauver_action->setStatusTip(tr("Sauvegarder l'image")); QObject::connect(sauver_action, SIGNAL(triggered()), &widgetcentral, SLOT(sauvegarder())); sauversous_action = new QAction(tr("S&auvegarder sous..."), this); sauversous_action->setShortcut(tr("Ctrl+Shift+S")); sauversous_action->setIcon(QIcon("./icones/enregistrer-sous.png")); sauversous_action->setStatusTip(tr("Sauvegarder l'image sous...")); connect(sauversous_action, SIGNAL(triggered()), &widgetcentral, SLOT(sauvegarderSous())); quitter_action = new QAction(tr("&Quitter"), this); quitter_action->setStatusTip(tr("Quitter le programme")); quitter_action->setIcon(QIcon("./icones/icone-infos.png")); QObject::connect(quitter_action, SIGNAL(triggered()), &widgetcentral, SLOT(quitter())); menu_fichier = new QMenu(tr("&Fichier"), this); menu_fichier->addAction(precedent_action); menu_fichier->addAction(nouveau_action); menu_fichier->addAction(ouvrir_action); menu_fichier->addAction(sauver_action); menu_fichier->addAction(sauversous_action); menu_fichier->addAction(quitter_action); // Filtre flou_action = new QAction(tr("&F&lou"), this); flou_action->setStatusTip(tr("Appliquer un flou l'image")); flou_action->setIcon(QIcon("./icones/flou.gif")); QObject::connect(flou_action, SIGNAL(triggered()), &widgetcentral, SLOT(loadflou())); fusion_action = new QAction(tr("&F&usion"), this); fusion_action->setStatusTip(tr("Fusionner l'image avec une autre")); QObject::connect(fusion_action, SIGNAL(triggered()), &widgetcentral, SLOT(loadfusion())); gris_action = new QAction(tr("&Gris"),this); gris_action->setStatusTip("Appliquer un gris l'image"); QObject::connect(gris_action,SIGNAL(triggered()),&widgetcentral,SLOT(gris())); rehaussement_action = new QAction(tr("&Rehaussement de contraste"),this); rehaussement_action->setStatusTip("Rehausser le contraste"); QObject::connect(rehaussement_action,SIGNAL(triggered()),&widgetcentral,SLOT(loadrehausseur())); detection_action = new QAction(tr("&Detecter les contours"),this); detection_action->setStatusTip("Detection de contour"); QObject::connect(detection_action,SIGNAL(triggered()),&widgetcentral,SLOT(loaddetection())); gradient_action = new QAction(tr("&Gradient"),this); gradient_action->setStatusTip("Gradient"); QObject::connect(gradient_action,SIGNAL(triggered()),&widgetcentral,SLOT(loadgradient())); perso_action = new QAction(tr("&Personnaliser"),this); perso_action->setStatusTip("Personnaliser le filtre"); QObject::connect(perso_action,SIGNAL(triggered()),&widgetcentral,SLOT(loadperso())); accent_action = new QAction(tr("&Accentuer"),this); accent_action->setStatusTip("Accentuer l'image"); QObject::connect(accent_action,SIGNAL(triggered()),&widgetcentral,SLOT(loadaccentuer())); menu_outils = new QMenu(tr("&F&iltre"), this); menu_outils->addAction(flou_action); menu_outils->addAction(fusion_action); menu_outils->addAction(gris_action); menu_outils->addAction(rehaussement_action); menu_outils->addAction(detection_action); menu_outils->addAction(gradient_action); menu_outils->addAction(perso_action); menu_outils->addAction(accent_action); //histogramme histo_menu=new QMenu(tr("&Histogramme"),this); histoRGB_action = new QAction(tr("&RGB"),this); QObject::connect(histoRGB_action, SIGNAL(triggered()), &widgetcentral, SLOT(histogrammeRGB())); histo_menu->addAction(histoRGB_action); histoHSV_action = new QAction(tr("&HSV"),this); QObject::connect(histoHSV_action, SIGNAL(triggered()), &widgetcentral, SLOT(histogrammeHSV())); histo_menu->addAction(histoHSV_action); egalise_action = new QAction(tr("&Egaliser"),this); QObject::connect(egalise_action, SIGNAL(triggered()), &widgetcentral, SLOT(egalisation())); histo_menu->addAction(egalise_action); linearise_action = new QAction(tr("&Lineariser"),this); QObject::connect(linearise_action, SIGNAL(triggered()), &widgetcentral, SLOT(linearisation())); histo_menu->addAction(linearise_action); negatif_action = new QAction(tr("&Negatif"),this); QObject::connect(negatif_action, SIGNAL(triggered()), &widgetcentral, SLOT(negatif())); histo_menu->addAction(negatif_action); seuillage_action = new QAction(tr("&Seuillage"),this); QObject::connect(seuillage_action, SIGNAL(triggered()), &widgetcentral, SLOT(seuillage())); histo_menu->addAction(seuillage_action); //color_picker picker_action = new QAction(tr("&P&i&xelColor"),this); picker_action->setStatusTip("Pixel valeur"); picker_action->setIcon(QIcon("./icones/icones/pixelcolor.jpg")); QObject::connect(picker_action, SIGNAL(triggered()), widgetcentral.affichage, SLOT(pixelColor())); color_picker = new QMenu(tr("&Picolor"),this); color_picker->addAction(picker_action); //Selection menu_selection = new QMenu(tr("&Se&lection"),this); selection_action=new QAction(tr("&selection"),this); QObject::connect(selection_action, SIGNAL(triggered()), widgetcentral.affichage, SLOT(selection())); menu_selection->addAction(selection_action); //redimension redim_action = new QAction(tr("&R&edimension"),this); redim_action->setStatusTip("Appliquer le redimensionnement l'image"); QObject::connect(redim_action,SIGNAL(triggered()),&widgetcentral,SLOT(redimension())); seam_action = new QAction(tr("&Seam Carving"),this); seam_action->setStatusTip("Redimensionnement intelligent"); QObject::connect(seam_action,SIGNAL(triggered()),&widgetcentral,SLOT(loadseam())); menu_redimension = new QMenu (tr ("&R&e&dimension"), this); menu_redimension->addAction(redim_action); menu_redimension->addAction(seam_action); barre_menu = new QMenuBar(this); barre_menu->addMenu(menu_fichier); barre_menu->addMenu(menu_outils); barre_menu->addMenu(histo_menu); barre_menu->addMenu(color_picker); barre_menu->addMenu(menu_selection); barre_menu->addMenu(menu_redimension); setMenuBar(barre_menu); }
void graphics_draw_pixel(GContext *ctx, GPoint point) { GPoint topOffset=getTopOffset (); pixelColor(getTopScreen(), topOffset.x+point.x, topOffset.y+point.y, getRawColor(ctx->stroke_color)); }
void MedeaAltUtilityBattleAgentObserver::step() { _iterationCount++; if ( _wm->_agentId == 0 ) { if ( MedeaAltUtilitySharedData::gExperimentNumber == 2 ) { if (_wm->_agentId == gAgentIndexFocus ) // && gVerbose ) // debug { std::cout << std::endl << "#### Experiment no.2 starts now. ####" << std::endl; } // * remove energy points. for(std::vector<EnergyPoint>::iterator it = gEnergyPoints.begin(); it != gEnergyPoints.end(); it++) { it->hide(); } gEnergyPoints.clear(); // * setup new energy zone Uint32 colorShown = 0xeab71fff; Uint32 colorZone = 0xAAAAAAFF; // for floor sensor. for (Sint16 xColor = MedeaAltUtilitySharedData::g_xStart_EnergyZone ; xColor < MedeaAltUtilitySharedData::g_xEnd_EnergyZone ; xColor++) { for (Sint16 yColor = Sint16 (MedeaAltUtilitySharedData::g_yStart_EnergyZone) ; yColor < Sint16 (MedeaAltUtilitySharedData::g_yEnd_EnergyZone) ; yColor ++) { pixelColor(gBackgroundImage, xColor, yColor, colorShown); pixelColor(gZoneImage, xColor, yColor, colorZone); } } } } // std::cout << "robot #" << _wm->_agentId << "\n" ; MedeaAltUtilityPerceptronControlArchitecture* currentBehavior = dynamic_cast<MedeaAltUtilityPerceptronControlArchitecture*>(gWorld->getAgent(_wm->_agentId)->getBehavior()); if ( ! currentBehavior ) { std::cerr << "Error from robot " << _wm->_agentId << " : the behavior architecture of this robot isn't a MedeaAltUtilityPerceptronControlArchitecture" << std::endl; exit(1); } /*if (_wm->_agentId == 1) { std::cout << _key <<std::endl; }*/ if ( gVerbose && gInspectAgent && gAgentIndexFocus == _wm->_agentId ) { //std::cout << "target: " << _wm->getEnergyPointDirectionAngleValue() << std::endl;// " (" << _wm->_agentAbsoluteOrientation << "," << angleToClosestEnergyPoint << ")" << std::endl; } if ( MedeaAltUtilitySharedData::gExperimentNumber == 1 ) { // * update the energy of the robot (if needed) Point2d posRobot(_wm->_xReal,_wm->_yReal); if ( gEnergyMode ) { for(std::vector<EnergyPoint>::iterator it = gEnergyPoints.begin(); it != gEnergyPoints.end(); it++) { if( (getEuclidianDistance (posRobot,it->getPosition()) < gEnergyPointRadius) && (it->getActiveStatus())) { float loadingEnergy = gEnergyPointValue; // test? //float loadingEnergy = 5*(1.0/(2.0*sqrt(2.0*M_PI)))*gEnergyPointValue; // test? //float loadingEnergy = 5*(1.0/(2.0*sqrt(2.0*M_PI)))*exp(-(pow((_key - it->getKey()),2.0)/(pow(2.0,2.0))))*gEnergyPointValue; // update energy level _wm->setEnergyLevel(_wm->getEnergyLevel() + loadingEnergy); _wm->setDeltaEnergy(_wm->getDeltaEnergy() + loadingEnergy); //saturate if ( _wm->getEnergyLevel() > MedeaAltUtilitySharedData::gEnergyMax ) // should be at least one lifetime _wm->setEnergyLevel(MedeaAltUtilitySharedData::gEnergyMax); if ( _wm->getDeltaEnergy() > MedeaAltUtilitySharedData::gEnergyMax ) _wm->setDeltaEnergy(MedeaAltUtilitySharedData::gEnergyMax); gLogFile << "Info(" << gWorld->getIterations() << ") : " << _wm->_agentId << "(" << posRobot.x << "," << posRobot.y << ")" << " get an energy point at " << it->getPosition().x << "," << it->getPosition().y << " :: Value : " << loadingEnergy << std::endl; it->setActiveStatus(false); } } } } else { if ( MedeaAltUtilitySharedData::gExperimentNumber == 2 ) { // * once per world update (TODO: move to worldobserver) if (_wm->_agentId == 0 ) // debug { int agentsOnZone = 0; for ( int i = 0 ; i != gAgentCounter ; i++ ) { int x = (int)(gWorld->getAgent(i)->getWorldModel()->getXReal()); int y = (int)(gWorld->getAgent(i)->getWorldModel()->getYReal()); // std::cout << "x =" << x << " , y = " << y << std::endl; if ( x >= MedeaAltUtilitySharedData::g_xStart_EnergyZone && y >= MedeaAltUtilitySharedData::g_yStart_EnergyZone && x <= MedeaAltUtilitySharedData::g_xEnd_EnergyZone && y <= MedeaAltUtilitySharedData::g_yEnd_EnergyZone ) agentsOnZone++; } // update MedeaAltUtilitySharedData::gZoneEnergy_harvestValue //MedeaAltUtilitySharedData::gZoneEnergy_harvestValue = 10; // TODO :: TEMPORARY !!!!!!!!!!TEMPORARY !!!!!!!!!!TEMPORARY !!!!!!!!!!TEMPORARY !!!!!!!!!!TEMPORARY !!!!!!!!!! if ( gVerbose ) std::cout << "There are " << agentsOnZone << " agents on the energy zone" << std::endl; /**/ if ( agentsOnZone <= MedeaAltUtilitySharedData::gZoneEnergy_maxFullCapacity ) { // best case MedeaAltUtilitySharedData::gZoneEnergy_harvestValue = MedeaAltUtilitySharedData::gZoneEnergy_maxHarvestValue; } else { if ( agentsOnZone <= MedeaAltUtilitySharedData::gZoneEnergy_saturateCapacityLevel ) { double energyValueSpan = MedeaAltUtilitySharedData::gZoneEnergy_maxHarvestValue - MedeaAltUtilitySharedData::gZoneEnergy_minHarvestValue; int agentsOverheadCount = MedeaAltUtilitySharedData::gZoneEnergy_saturateCapacityLevel - MedeaAltUtilitySharedData::gZoneEnergy_maxFullCapacity; double costPerAgents = energyValueSpan / (double)agentsOverheadCount; MedeaAltUtilitySharedData::gZoneEnergy_harvestValue = MedeaAltUtilitySharedData::gZoneEnergy_maxHarvestValue - costPerAgents * ( agentsOnZone- MedeaAltUtilitySharedData::gZoneEnergy_maxFullCapacity ) ; } else { // worst case MedeaAltUtilitySharedData::gZoneEnergy_harvestValue = MedeaAltUtilitySharedData::gZoneEnergy_minHarvestValue; } } /**/ // debug : MedeaAltUtilitySharedData::gZoneEnergy_harvestValue = MedeaAltUtilitySharedData::gZoneEnergy_maxHarvestValue; } // * for each agent -- TODO: could be optimized by merging with previous block in the worldobserve if ( _wm->_xReal >= MedeaAltUtilitySharedData::g_xStart_EnergyZone && _wm->_xReal <= MedeaAltUtilitySharedData::g_xEnd_EnergyZone && _wm->_yReal >= MedeaAltUtilitySharedData::g_yStart_EnergyZone && _wm->_yReal <= MedeaAltUtilitySharedData::g_yEnd_EnergyZone ) { float loadingEnergy = MedeaAltUtilitySharedData::gZoneEnergy_harvestValue; // update energy level _wm->setEnergyLevel(_wm->getEnergyLevel() + loadingEnergy); _wm->setDeltaEnergy(_wm->getDeltaEnergy() + loadingEnergy); // saturate if ( _wm->getEnergyLevel() > MedeaAltUtilitySharedData::gEnergyMax ) // assume: need MedeaAltUtilitySharedData::gEvaluationTime to live full life _wm->setEnergyLevel(MedeaAltUtilitySharedData::gEnergyMax); if ( _wm->getDeltaEnergy() > MedeaAltUtilitySharedData::gEnergyMax ) // assume: need MedeaAltUtilitySharedData::gEvaluationTime to live full life _wm->setDeltaEnergy(MedeaAltUtilitySharedData::gEnergyMax); Point2d posRobot(_wm->_xReal,_wm->_yReal); gLogFile << "Info(" << gWorld->getIterations() << ") : " << _wm->_agentId << "(" << posRobot.x << "," << posRobot.y << ")" << " get an energy point at 0,0 :: Value : " << loadingEnergy << std::endl; // hack to comply with python log analyser } } } // * check energy level if ( MedeaAltUtilitySharedData::gExperimentNumber == 1 || MedeaAltUtilitySharedData::gExperimentNumber == 2 ) { if ( _wm->getEnergyLevel() <= 0 ) { _wm->setDeltaEnergy(0); // must be set to zero to avoid broadcasting. _wm->setActiveStatus(false); } } // * broadcast the genome (current agent writes its genome to all neighbors // broadcast only if agent is active (ie. not just revived) and deltaE>0. if ( /*( _wm->getDeltaEnergy()>0.0 && _wm->getActiveStatus() == true ) || ( MedeaAltUtilitySharedData::gExperimentNumber == 0 && _wm->getActiveStatus() == true )*/ _wm->getActiveStatus() == true ) { for (int i = 0 ; i < gAgentCounter ; i++) { if ( ( i != _wm->_agentId ) && ( gRadioNetworkArray[_wm->_agentId][i] ) ) //&& (_wm->getEnergyLevel() > 0.0) ) --> always true as status is active { MedeaAltUtilityBattleAgentObserver* agentObserver = dynamic_cast<MedeaAltUtilityBattleAgentObserver*>(gWorld->getAgent(i)->getObserver()); if ( ! agentObserver ) { std::cerr << "Error from robot " << _wm->_agentId << " : the observer of robot " << i << " isn't a MedeaAltUtilityBattleAgentObserver" << std::endl; exit(1); } agentObserver->writeGenome(_currentGenome, _wm->_agentId); } } } // * handle genome renewal //"restart" the robot in case it runs out of energy -- case: no synchronisation /* if ( ( _wm->getEnergyLevel() <= 0.0 ) && ( MedeaAltUtilitySharedData::gSynchronization == false ) ){ logStatus(); //resetActiveGenome(); _wm->setEnergyLevel( currentBehavior->getInitialEnergy()); _wm->setDeltaEnergy(0.0); gLogFile << "Info(" << gWorld->getIterations() << ") : Human intervention on robot " << _wm->_agentId << " (Energy)" << std::endl; _iterationCount = 0; _wm->setActiveStatus(false); // !N.20100407 : inactive robot should get a new genome and move until it imports one from neighbors. } */ // case: default for Medea, synchronised if( _iterationCount >= MedeaAltUtilitySharedData::gEvaluationTime ) { /**/ if (_wm->_agentId == gAgentIndexFocus && gVerbose) // debug { std::cout << "agent #" << gAgentIndexFocus << " is renewed" << std::endl; std::cout << "agent #" << gAgentIndexFocus << " imported " << _genomesList.size() << " genomes. Energy is " << _wm->getEnergyLevel() << ". Status is " << _wm->getActiveStatus() << "." <<std::endl; } /**/ logStatus(); //"revive" the robot in case it runs out of energy if ( MedeaAltUtilitySharedData::gExperimentNumber == 1 || MedeaAltUtilitySharedData::gExperimentNumber == 2 ) { if ( _wm->getEnergyLevel() <= 0.0 ) { gLogFile << "Info(" << gWorld->getIterations() << ") : Human intervention on robot " << _wm->_agentId << " (Energy)" << std::endl; // reformulate (check python script compatibility before): gLogFile << "Info(" << gWorld->getIterations() << ") : robot " << _wm->_agentId << " was revived (human intervention)" << std::endl; if (_wm->_agentId == gAgentIndexFocus && gVerbose) // debug { std::cout << "agent #" << gAgentIndexFocus << " is revived (energy was 0)." << std::endl; } logStatus(); //resetActiveGenome(); _wm->setEnergyLevel(MedeaAltUtilitySharedData::gEnergyRevive); // !n : too few? _wm->setActiveStatus(false); // true: restart, false: no-restart _genomesList.empty(); } } //else // uncomment if restart // note: at this point, agent got energy, wether because it was revived or because of remaining energy. // case: genome(s) imported, random pick. if (_genomesList.size() > 0) { pickRandomGenome(); _wm->setActiveStatus(true); // !N.20100407 : revive takes imported genome if any } // case: no imported genome - wait for new genome. else { gLogFile << "Info(" << gWorld->getIterations() << ") : robot nb." << _wm->_agentId // << " is trying a whole new genome" << std::endl; << " is waiting for a new genome" << std::endl; //resetActiveGenome(); // optional -- could be set to zeroes. _wm->setActiveStatus(false); // !N.20100407 : inactive robot must import a genome from others. } //log the genome gLogFile << "get active status" << std::endl ; if ( _wm->getActiveStatus() == true ) { gLogFile << "Info("<< gWorld->getIterations() <<") : robot nb."<< _wm->_agentId << " use genome :"; for(unsigned int i=0; i<_wm->_genome.size(); i++) { gLogFile << std::fixed << std::showpoint<< _wm->_genome[i] << " "; } gLogFile << std::endl; } //Re-initialize the main parameters if ( MedeaAltUtilitySharedData::gExperimentNumber == 1 || MedeaAltUtilitySharedData::gExperimentNumber == 2 ) { _wm->setDeltaEnergy(0.0); // !n : avant: 10.0 } _iterationCount = 0; _generationCount ++; if ( _wm->_agentId == 0 ) { if ( !gVerbose ) { //std::cout << "."; int activeCount = 0; for ( int i = 0 ; i != gAgentCounter ; i++ ) { if ( _wm->getActiveStatus() == true ) activeCount++; } std::cout << "[" << activeCount << "]"; } } } }
/* Show the frame stat */ void make_stat() { int percent_y, percent_u, percent_v, percent_fy, percent_fu, percent_fv; long long num_pixels_y, num_pixels_u, num_pixels_v; long long f_pixels_y, f_pixels_u, f_pixels_v; int peak_y, peak_u, peak_v, peak_fy, peak_fu, peak_fv; int i,j; peak_y = 0; peak_u = 0; peak_v = 0; peak_fy = 0; peak_fu = 0; peak_fv = 0; num_pixels_y = y_stats[0]; num_pixels_u = u_stats[0]; num_pixels_v = v_stats[0]; f_pixels_y = fy_stats[0]; f_pixels_u = fu_stats[0]; f_pixels_v = fv_stats[0]; /* geting the maimal number for all frames */ for (i = 0; i < 255; i++) { /* getting the maximal numbers for Y, U, V for all frames */ if (num_pixels_y < y_stats[i]) { num_pixels_y = y_stats[i]; peak_y = i; } if (num_pixels_u < u_stats[i]) { num_pixels_u = u_stats[i]; peak_u = i; } if (num_pixels_v < v_stats[i]) { num_pixels_v = v_stats[i]; peak_v = i; } /* getting the maximal numbers for Y, U, V for the current frame */ fy_stats[i]= y_stats[i] - ly_stats[i]; ly_stats[i] = y_stats[i]; if (f_pixels_y < fy_stats[i]) { f_pixels_y = fy_stats[i]; peak_fy = i; } fu_stats[i]= u_stats[i] - lu_stats[i]; lu_stats[i] = u_stats[i]; if (f_pixels_u < fu_stats[i]) { f_pixels_u = fu_stats[i]; peak_fu = i; } fv_stats[i]= v_stats[i] - lv_stats[i]; lv_stats[i] = v_stats[i]; if (f_pixels_v < fv_stats[i]) { f_pixels_v = fv_stats[i]; peak_fv = i; } } num_pixels_y = (num_pixels_y /100); num_pixels_u = (num_pixels_u /100); num_pixels_v = (num_pixels_v /100); f_pixels_y = (f_pixels_y /100); f_pixels_u = (f_pixels_u /100); f_pixels_v = (f_pixels_v /100); /* The description for the histogram */ make_histogram_desc(number_of_frames); number_of_frames++; make_vectorscope_layout(); /*draw the vectorscope basic layout*/ clear_histogram_area(); /* Here we delete the old histograms */ make_histogram_stat(peak_y, peak_u, peak_v, sum1_x, stat); make_histogram_stat(peak_fy, peak_fu, peak_fv, frm1_x , stat); for (i = 0; i < 255; i++) { percent_y = (y_stats[i] / num_pixels_y); percent_u = (u_stats[i] / num_pixels_u); percent_v = (v_stats[i] / num_pixels_v); percent_fy = (fy_stats[i] / f_pixels_y); percent_fu = (fu_stats[i] / f_pixels_u); percent_fv = (fv_stats[i] / f_pixels_v); if ((i < 16) || (i > 235)) /* Y luma */ { /* Red means out of the allowed range */ vlineColor(screen,(sum1_x+i),sum1_y+100, ((sum1_y+100)-percent_y),red); vlineColor(screen,(frm1_x+i),frm1_y+100, ((frm1_y+100)-percent_fy),red); } else { vlineColor(screen,(sum1_x+i),sum1_y+100, ((sum1_y+100)-percent_y),gray); vlineColor(screen,(frm1_x+i),frm1_y+100, ((frm1_y+100)-percent_fy),gray); } if ((i < 16) || (i > 240)) /* U V chroma */ { /* Red means out of the allowed range */ vlineColor(screen,(sum2_x+i),sum2_y+100, ((sum2_y+100)-percent_u),red); vlineColor(screen,(sum3_x+i),sum3_y+100, ((sum3_y+100)-percent_v),red); vlineColor(screen,(frm2_x+i),frm2_y+100, ((frm2_y+100)-percent_fu),red); vlineColor(screen,(frm3_x+i),frm3_y+100, ((frm3_y+100)-percent_fv),red); } else { vlineColor(screen,(sum2_x+i),sum2_y+100, ((sum2_y+100)-percent_u),gray); vlineColor(screen,(sum3_x+i),sum3_y+100, ((sum3_y+100)-percent_v),gray); vlineColor(screen,(frm2_x+i),frm2_y+100, ((frm2_y+100)-percent_fu),gray); vlineColor(screen,(frm3_x+i),frm3_y+100, ((frm3_y+100)-percent_fv),gray); } } for (i=0; i < 260; i++) for (j=0; j < 260; j++) if (vectorfield[i][j]== 1) pixelColor(screen, (vector_x+ i- 127), (vector_y+ j- 132) ,red); SDL_UpdateRect(screen,0,0,0,0); }
QRgb PhongPixelProcessor::testingSpeedIlluminatePixel(quint32 posup, quint32 posdown, quint32 posleft, quint32 posright) { qreal temp; quint8 channel = 0; const quint8 totalChannels = 3; qreal computation[] = {0, 0, 0}; QColor pixelColor(0, 0, 0); if (lightSources.size() == 0) return pixelColor.rgb(); // Algorithm begins, Phong Illumination Model normal_vector.setX(- heightmap[posright] + heightmap[posleft]); normal_vector.setY(- heightmap[posup] + heightmap[posdown]); normal_vector.setZ(8); normal_vector.normalize(); /* for (int i = 0; i < size; i++) { temp = QVector3D::dotProduct(normal_vector, lightSources.at(i).lightVector); for (int channel = 0; channel < totalChannels; channel++) { // I = each RGB value Id = fastLight.RGBvalue[channel] * temp; if (Id < 0) Id = 0; if (Id > 1) Id = 1; computation[channel] += Id; } } */ // PREPARE ALGORITHM HERE for (int i = 0; i < size; i++) { light_vector = lightSources.at(i).lightVector; for (channel = 0; channel < totalChannels; channel++) { Ia = lightSources.at(i).RGBvalue.at(channel) * Ka; computation[channel] += Ia; } if (diffuseLightIsEnabled) { temp = Kd * QVector3D::dotProduct(normal_vector, light_vector); for (channel = 0; channel < totalChannels; channel++) { Id = lightSources.at(i).RGBvalue.at(channel) * temp; if (Id < 0) Id = 0; if (Id > 1) Id = 1; computation[channel] += Id; } } if (specularLightIsEnabled) { reflection_vector = (2 * pow(QVector3D::dotProduct(normal_vector, light_vector), shiny_exp)) * normal_vector - light_vector; temp = Ks * QVector3D::dotProduct(vision_vector, reflection_vector); for (channel = 0; channel < totalChannels; channel++) { Is = lightSources.at(i).RGBvalue.at(channel) * temp; if (Is < 0) Is = 0; if (Is > 1) Is = 1; computation[channel] += Is; } } } for (channel = 0; channel < totalChannels; channel++) { if (computation[channel] > 1) computation[channel] = 1; if (computation[channel] < 0) computation[channel] = 0; } pixelColor.setRedF(computation[0]); pixelColor.setGreenF(computation[1]); pixelColor.setBlueF(computation[2]); return pixelColor.rgb(); }
/** * Desenhador de RectNoScrolling retirado da SDL_gfx mais nova. */ int Sprite::drawRoundRectNoScrolling(Rectangle rect, int r, int g, int b, int a, int rad, Screen *screen) { SDL_Surface * dst; Sint16 x1, y1, x2, y2; Uint32 color; int result; dst = screen->getTopScreen(); x1 = rect.x; x2 = rect.x + rect.w; y1 = rect.y; y2 = rect.y + rect.h; color = ((Uint32) r << 24) | ((Uint32) g << 16) | ((Uint32) b << 8) | (Uint32) a; Sint16 w, h, tmp; Sint16 xx1, xx2, yy1, yy2; /* * Check destination surface */ if (dst == NULL) { return -1; } /* * Check radius vor valid range */ if (rad < 0) { return -1; } /* * Special case - no rounding */ if (rad == 0) { return rectangleColor(dst, x1, y1, x2, y2, color); } /* * Check visibility of clipping rectangle */ if ((dst->clip_rect.w==0) || (dst->clip_rect.h==0)) { return 0; } /* * Test for special cases of straight lines or single point */ if (x1 == x2) { if (y1 == y2) { return (pixelColor(dst, x1, y1, color)); } else { return (vlineColor(dst, x1, y1, y2, color)); } } else { if (y1 == y2) { return (hlineColor(dst, x1, x2, y1, color)); } } /* * Swap x1, x2 if required */ if (x1 > x2) { tmp = x1; x1 = x2; x2 = tmp; } /* * Swap y1, y2 if required */ if (y1 > y2) { tmp = y1; y1 = y2; y2 = tmp; } /* * Calculate width&height */ w = x2 - x1; h = y2 - y1; /* * Maybe adjust radius */ if ((rad * 2) > w) { rad = w / 2; } if ((rad * 2) > h) { rad = h / 2; } /* * Draw corners */ result = 0; xx1 = x1 + rad; xx2 = x2 - rad; yy1 = y1 + rad; yy2 = y2 - rad; result |= arcColor(dst, xx1, yy1, rad, 180, 270, color); result |= arcColor(dst, xx2, yy1, rad, 270, 360, color); result |= arcColor(dst, xx1, yy2, rad, 90, 180, color); result |= arcColor(dst, xx2, yy2, rad, 0, 90, color); /* * Draw lines */ if (xx1 <= xx2) { result |= hlineColor(dst, xx1, xx2, y1, color); result |= hlineColor(dst, xx1, xx2, y2, color); } if (yy1 <= yy2) { result |= vlineColor(dst, x1, yy1, yy2, color); result |= vlineColor(dst, x2, yy1, yy2, color); } return 1; }