void PropPC::update() { Prop::update(); if (age % (60 / 10) == 0) { if (crashed) { for (int x = 0; x < 320 / 16 + 1; x++) { for (int y = 0; y < 200 / 16 + 1; y++) { Pixel p = Pixel(Util::random() * 0xFF, Util::random() * 0xFF, Util::random() * 0xFF, 0xFF); for (int px = 0; px < 16; px++) { for (int py = 0; py < 16; py++) { setPixel(x * 16 + px, y * 16 + py, p); } } } } } else { if (age % (60/4) == 0) { caret = !caret; GLubyte carCol = caret ? 0xFF : 0x0; renderString("_", (text.size() + 1) * 8, lineHeight * 8, Pixel(carCol, carCol, carCol, 0xFF)); } } redraw(); } }
void main(int argc,String *argv) { ArgParser a=ArgParser(argc,argv); int as=a.intafter("-as","angles examined",16); bool showpp=a.argexists("-spp","show winning projection profile"); bool showpps=a.argexists("-spps","show all projection profiles"); String bname=a.getarg("binary image"); a.done(); Map2d<bool> binimg=*Map2d<bool>::readfile(bname)->threshold(0.5); ProjectionProfiler pp=ProjectionProfiler(as,binimg); pp.showpps=showpps; pp.showpp=showpp; float ang=pp.getlineangle(); Pixel cen=Pixel(binimg.width/2,binimg.height/2); Pixel diff=Pixel(V2d::angle(ang)*binimg.width); binimg.line(cen-diff,cen+diff,true); #ifdef USINGJFONT jfont.writeString(Sformat("entropy=%.5f",lowestent),&binimg,0,10,8.0,true); #endif binimg.writefile("result.bmp"); }
static List<Pixel> line(Pixel a,Pixel b) { //printf("a\n"); List<Pixel> ls; if (a==b) { ls.add(a); //printf("b\n"); return ls; } Pixel diff=b-a; if (abs(diff.x)>abs(diff.y)) { int diffm=abs(diff.x); for (int i=0;i<=diffm;i++) { // printf("%i/%i\n",i,diffm); // Pixel p=a+diff*((float)i/(float)diffm); Pixel p=Pixel(a.x+mysgn(diff.x)*i,a.y+diff.y*((float)i/(float)diffm)); ls.add(p); } } else { int diffm=abs(diff.y); for (int i=0;i<=diffm;i++) { // printf(" %i/%i\n",i,diffm); // Pixel p=a+diff*((float)i/(float)diffm); Pixel p=Pixel(a.x+diff.x*((float)i/(float)diffm),a.y+mysgn(diff.y)*i); ls.add(p); } } //printf("c\n"); return ls; }
void World::build() { //a sample scene with 5 spheres Sphere *sph1 = new Sphere(); sph1->set_color(Pixel(123, 255, 45)); sph1->set_center(Point3d(-400, 200, -300)); sph1->set_radius(250); add_object(sph1); Sphere *sph2 = new Sphere(); sph2->set_color(Pixel(255, 123, 45)); sph2->set_center(Point3d(400, -200,-100)); sph2->set_radius(200); add_object(sph2); Sphere *sph3 = new Sphere(); sph3->set_color(Pixel(45, 123, 255)); sph3->set_center(Point3d(400, 200,-100)); sph3->set_radius(150); add_object(sph3); Sphere *sph4 = new Sphere(); sph4->set_color(Pixel(123, 123, 45)); sph4->set_center(Point3d(-600, -200,-100)); sph4->set_radius(150); add_object(sph4); Sphere *sph5 = new Sphere(); sph5->set_color(Pixel(235, 34, 45)); sph5->set_center(Point3d(0, 0,-100)); sph5->set_radius(50); add_object(sph5); }
Image::Pixel Image::getPixelLI(const float &x, const float &y) const { #if HYDRAX_IMAGE_CHECK_PIXELS == 1 if (x < 0 || x > mSize.Width || y < 0 || y > mSize.Height) { HydraxLOG("Error in Image::getPixel, x = " + Ogre::StringConverter::toString(x) + " y = " + Ogre::StringConverter::toString(y)); return Pixel(0); } #endif float v[4]; for(int k = 0; k < 4; k++) { if (mChannels >= k) { v[k] = getValueLI(x, y, k); } else { v[k] = 0; } } return Pixel(v[0], v[1], v[2], v[3]); }
void main(){ //すべての画素を書き換える *background = Pixel(255); //ImageClass#setPosのテスト if(frame == 100){ img->setPos(0,100); } //biImageClass#Sizeのテスト if(frame == 200){ load->Height(-load->Height()); } if(frame == 250){ load->Width(-load->Width()); } //biImageClass#Rotateのテスト if(frame >= 300){ angle += 10; *load = base.Rotate(angle); } //biImageClass#Clearのテスト if(frame == 500){ load->Clear(Pixel(255,0,0)); } //biImageClass#Pasteのテスト background->Paste(0,0,*load); frame++; img->Paste(0,0,*background); }
Pixel getPixel( Im::Position, BrightnessType br ) const { unsigned char part = br & 0xFF; return inv( ( br < 0x100 ) ? Pixel( part, 0, 0 ) : ( br < 0x200 ) ? Pixel( 0xFF, part, 0 ) : Pixel( 0xFF, 0xFF, part ) ); }
int extract_cc_(Pixel p, std::vector<Pixel> &cc, ImageGray<BYTE> &img) { std::stack<Pixel> s; BYTE *pColor; if (img.pixelInside(p.x, p.y)) pColor = &img.pixel(p.x, p.y); else return 0; while (*pColor == 0 || !s.empty()) { if (*pColor == 0) { cc.push_back(p); *pColor = 255; s.push(Pixel(p.x+1, p.y)); s.push(Pixel(p.x-1, p.y)); s.push(Pixel(p.x, p.y+1)); s.push(Pixel(p.x, p.y-1)); } p = s.top(); s.pop(); if (img.pixelInside(p.x, p.y)) pColor = &img.pixel(p.x, p.y); else *pColor = 255; } return cc.size(); }
void RayTracer::trace_rays(){ int i,j; SbVec3f pix_pos, d_vec; double a,b,c; float color_scale; SbVec3f color; std::vector<Pixel> image_row; std::cout << "Tracing rays"<<std::endl; color[0] = 0.0; color[1] = 0.0; color[2] = 0.0; for (i=0; i < y_resolution; i++){ image_row.clear(); for (j=0; j < x_resolution; j++) { pix_pos = calculate_pixel_location(i,j); d_vec = pix_pos - camera->position; d_vec.normalize(); bool should_color = shade(&(camera->position), &d_vec, &color, 1); if(should_color) { image_row.push_back(Pixel(min(color[0]), min(color[1]), min(color[2]))); } else image_row.push_back(Pixel(0,0,0)); } image.push_back(image_row); } open_file(); write_to_file(image); close_file(); std::cout<<"Done Tracing"<<std::endl; return; }
void Calibration::init(){ if(device){ cam = VideoCapture(idCam); for(int i = 0 ; i < 30 ; i++){ cam >> inputImage; } } rotation = 0; for(int i = 0 ; i < 3 ; i++){ staticVisionColorHelper[i] = 0; staticVisionColorHelper[i+3] = 255; staticVisionColor.min = Pixel(0, 0, 0); staticVisionColor.max = Pixel(0, 0, 0); } // Se o estágio de calibragem é uma cor if(calibrationStage >= 0 && calibrationStage <= 7){ calibrationVisionColor(); }else{ if(calibrationStage == ROTATION){ calibrationRotation(); }else if(calibrationStage == CUT){ calibrationCut(); } } }
Uint8 WgSDLSurface::Alpha( WgCoord coord ) const { // All pixels are transparent if we don't have any surface... if( !m_pSurface ) return 0; // Opacity tests below done in order to match SDL blitting rules (hopefully). // First, if surface has SDL_SRCALPHA + alpha channel we ignore everything // else. if( m_pSurface->flags & SDL_SRCALPHA && m_pSurface->format->Amask ) return ((Pixel(coord) & m_pSurface->format->Amask) >> m_pSurface->format->Ashift) << m_pSurface->format->Aloss; // Secondly, check for colorkey, return transparent if match. if( m_pSurface->flags & SDL_SRCCOLORKEY ) { if( Pixel( coord ) == 0 ) return 0; } // Third, if surface has SDL_SRCALPHA we return the surace alpha value. if( m_pSurface->flags & SDL_SRCALPHA ) return 0;//m_pSurface->format->alpha; // Fourth, all tests passed, pixel is opaque. return 255; }
/******************************************************************************* * Function Name : TP_DrawPoint * Description : ÔÚÖ¸¶¨×ù±ê»µã * Input : - Xpos: Row Coordinate * - Ypos: Line Coordinate * Output : None * Return : None * Attention : None *******************************************************************************/ void TP_DrawPoint(uint16_t Xpos,uint16_t Ypos) { Pixel(Xpos,Ypos,0xf800); /* ÖÐÐĵã */ Pixel(Xpos+1,Ypos,0xf800); Pixel(Xpos,Ypos+1,0xf800); Pixel(Xpos+1,Ypos+1,0xf800); }
Vnd *summarise(List<Pixel> *ps) { printf("X\n"); Vnd *nv=new Vnd(nummeasures); printf("Y0\n"); float f=measureedgeanglecancelling(ps); printf("Y1\n"); nv->setaxis(1,f); printf("Y2\n"); nv->setaxis(2,sqrt(measureglvariance(ps))); printf("Y3\n"); nv->setaxis(3,measurehiststability(ps)); printf("Y4\n"); nv->setaxis(4,measureedgecount(ps)); // nv->setaxis(5,measureoldedgeanglecancelling(ps)); printf("Z\n"); if (show) for (int i=1;i<=nummeasures;i++) if (ps->len>1) for (int j=1;j<=ps->len;j++) measmaps.num(i)->setpos(ps->num(j),nv->getaxis(i)); else { for (int x=0;x<windres;x++) for (int y=0;y<windres;y++) measmaps.num(i)->setpos(ps->num(1)-Pixel(windres/2,windres/2)+Pixel(x,y),nv->getaxis(i)); } printf("Z1\n"); return nv; }
void main(int argc,String *argv) { ArgParser a=ArgParser(argc,argv); int as=a.intafter("-as","angles examined",16); String bname=a.getarg("binary image"); a.done(); Map2d<bool> binimg=*Map2d<bool>::readfile(bname)->threshold(0.5); List<float> angs; for (float a=0;a<=pi;a+=pi/(float)as) angs.add(a); List<Map1d<int> > pps=getprojprofiles(binimg,angs); float lowestent=0.0; int lowestind=-1; for (int i=1;i<=pps.len;i++) { // Map2d<bool> d=pps.p2num(i)->draw(); float ent=pps.p2num(i)->entropy(); if (ent<lowestent) { lowestent=ent; lowestind=i; } // jfont.writeString(Sformat("%.5f",ent),&d,0,12,10.0,true); // d.writefile(getnextfilename("pp","bmp")); // d.freedom(); } float ang=lowestind*pi/(float)as; Pixel cen=Pixel(binimg.width/2,binimg.height/2); Pixel diff=Pixel(V2d::angle(ang)*binimg.width); binimg.line(cen-diff,cen+diff,true); jfont.writeString(Sformat("entropy=%.5f",lowestent),&binimg,0,10,8.0,true); binimg.writefile("result.bmp"); printf("Lowest was %i with %.5f\n",lowestind,lowestent); }
void Image::Shift(double sx, double sy) { for(int y = 0; y < height; y++) { int y_ = (0 < sy) ? height - 1 - y : y; for(int x = 0; x < width; x++) { int x_ = (0 < sx) ? width - 1 - x : x; if(sx == floor(sx) && sy == floor(sy)) GetPixel(x_, y_) = (ValidCoord(x_ - (int) sx, y_ - (int) sy)) ? GetPixel(x_ - (int) sx, y_ - (int) sy) : Pixel(0, 0, 0); else { if(sampling_method == IMAGE_SAMPLING_HAT) { if(ValidCoord(x_ - (int) sx, y_ - (int) sy)) { float h_r, h_g, h_b, h_all, h_tmp; h_r = h_g = h_b = h_all = 0.0f; for(int c = -1; c < 2; c++) { for(int r = -1; r < 2; r++) { if(ValidCoord(x_ - (int) sx + r, y_ - (int) sy + c)) { h_tmp = hat(-((int) sx) + r + (float) sx) * hat(-((int) sy) + c + (float) sy); h_all += h_tmp; h_r += (float) GetPixel(x_ - (int) sx + r, y_ - (int) sy + c).r * h_tmp; h_g += (float) GetPixel(x_ - (int) sx + r, y_ - (int) sy + c).g * h_tmp; h_b += (float) GetPixel(x_ - (int) sx + r, y_ - (int) sy + c).b * h_tmp; } } } GetPixel(x_, y_).SetClamp(h_r / h_all, h_g / h_all, h_b / h_all); } else GetPixel(x_, y_) = Pixel(0, 0, 0); } else if (sampling_method == IMAGE_SAMPLING_MITCHELL) { if (ValidCoord(x_ - (int) sx, y_ - (int) sy)) { float h_r, h_g, h_b, h_all, h_tmp; h_r = h_g = h_b = h_all = 0.0f; for(int c = -4; c < 5; c++) { for(int r = -4; r < 5; r++) { if(ValidCoord(x_ - (int) sx + r, y_ - (int) sy + c)) { h_tmp = mitchell(-((int) sx) + r + (float) sx) * mitchell(-((int) sy) + c + (float) sy); h_all += h_tmp; h_r += (float) GetPixel(x_ - (int) sx + r, y_ - (int) sy + c).r * h_tmp; h_g += (float) GetPixel(x_ - (int) sx + r, y_ - (int) sy + c).g * h_tmp; h_b += (float) GetPixel(x_ - (int) sx + r, y_ - (int) sy + c).b * h_tmp; } } } GetPixel(x_, y_).SetClamp(h_r / h_all, h_g / h_all, h_b / h_all); } else GetPixel(x_, y_) = Pixel(0, 0, 0); } } } } }
virtual void arrow(Pixel a,Pixel b,myRGB c) { this->line(a,b,c); V2d diff=V2d(b-a); V2d perp=V2d(diff.y,-diff.x); V2d l=V2d(a)+0.9*diff+perp*0.1*diff.mag(); V2d r=V2d(a)+0.9*diff-perp*0.1*diff.mag(); this->line(b,Pixel(l),c); this->line(b,Pixel(r),c); }
void opencircle(int x,int y,float r,CT c) { Pixel last=Pixel(x,y+r); int steps=4+r/2; for (int i=1;i<=steps;i++) { float a=2.0*pi*(float)i/(float)steps; Pixel next=Pixel(x+r*sin(a),y+r*cos(a)); line(last,next,c); last=next; } }
void IPLCanny::trace( int x, int y, double lowThreshold, IPLOrientedImage* dI, IPLImagePlane* image ) { int width = dI->width(); int height = dI->height(); Queue queue; queue.push_back( Pixel( x,y ) ); while( ! queue.empty() ) { Pixel c = queue.front(); queue.pop_front(); if( c.x<width && c.x >=0 && c.y<height && c.y>=0 ) { if( dI->magnitude(c.x,c.y)>lowThreshold && (! image->p(c.x,c.y)) ) { image->p(c.x,c.y) = 255; queue.push_back( Pixel( c.x+1, c.y ) ); queue.push_back( Pixel( c.x, c.y+1 ) ); queue.push_back( Pixel( c.x-1, c.y ) ); queue.push_back( Pixel( c.x, c.y-1 ) ); queue.push_back( Pixel( c.x+1, c.y+1 ) ); queue.push_back( Pixel( c.x-1, c.y+1 ) ); queue.push_back( Pixel( c.x-1, c.y-1 ) ); queue.push_back( Pixel( c.x+1, c.y-1 ) ); } } } }
/******************************************************************************* * Function Name : DrawCross * Description : ÔÚÖ¸¶¨×ù±ê»Ê®×Ö×¼ÐÇ * Input : - Xpos: Row Coordinate * - Ypos: Line Coordinate * Output : None * Return : None * Attention : None *******************************************************************************/ void DrawCross(uint16_t Xpos,uint16_t Ypos) { LCD_DrawUniLine(Xpos-12,Ypos,Xpos+13,Ypos); LCD_DrawUniLine(Xpos,Ypos-12,Xpos,Ypos+13); Pixel(Xpos+2,Ypos+2,BLUE); Pixel(Xpos-2,Ypos+2,BLUE); Pixel(Xpos+2,Ypos-2,BLUE); Pixel(Xpos-2,Ypos-2,BLUE); LCD_Circle(Xpos, Ypos, 6, 1, BLUE); }
void Object::Circle(u32 X, u32 Y, u32 r, u32 Color){ u32 rr = r*r; for(u32 y=0;y<r;y++){ u32 width=sqrt(rr-y*y); for(u32 x=0;x<width;x++){ Pixel(X+x, Y+y, Color); Pixel(X+x, Y-y, Color); Pixel(X-x, Y+y, Color); Pixel(X-x, Y-y, Color); } } }
void R2Image:: Brighten(double factor) { // Brighten the image by multiplying each pixel component by the factor. // This is implemented for you as an example of how to access and set pixels for (int i = 0; i < width; i++) { for (int j = 0; j < height; j++) { Pixel(i,j) *= factor; Pixel(i,j).Clamp(); } } }
namespace Colors { const Pixel RadarColor(10, 25, 10, 0); const Pixel RadarEnd(132, 132, 132, 0); const Pixel RadarBorder(132, 132, 132, 0); const Pixel RadarWall(90, 90, 90, 0); const Pixel SafeColor(24, 82, 24, 0); const Pixel EnemyColor[2] = { Pixel(82, 82, 214, 0), Pixel(165,165,255,0) }; const Pixel EnemyBallColor(255, 57, 74, 0); const Pixel EnergyColor[2] = { Pixel(181, 181, 255, 0), Pixel(99, 99, 206, 0) }; const Pixel XRadarOn(41, 107, 41, 0); const Pixel XRadarOff(24, 82, 24, 0); }
virtual void Get(RGBA *span, int x, int y, unsigned len) { interpolator.Begin(x, y, len); fixed = hstyle && vstyle; while(len--) { Point h = interpolator.Get(); // h -= 128; Point l = h >> 8; if(hstyle == FILL_HREPEAT) l.x = (l.x + ax) % cx; if(vstyle == FILL_VREPEAT) l.y = (l.y + ay) % cy; if(fast) { if(l.x > 0 && l.x < maxx && l.y > 0 && l.y < maxy) *span = Pixel(l.x, l.y); else if(style == 0 && (l.x < -1 || l.x > cx || l.y < -1 || l.y > cy)) *span = RGBAZero(); else *span = GetPixel(l.x, l.y); } else { RGBAV v; v.Set(0); // v.Set(256 * 256 / 2); h.x &= 255; h.y &= 255; Point u = -h + 256; if(l.x > 0 && l.x < maxx && l.y > 0 && l.y < maxy) { v.Put(u.x * u.y, Pixel(l.x, l.y)); v.Put(h.x * u.y, Pixel(l.x + 1, l.y)); v.Put(u.x * h.y, Pixel(l.x, l.y + 1)); v.Put(h.x * h.y, Pixel(l.x + 1, l.y + 1)); } else if(style == 0 && (l.x < -1 || l.x > cx || l.y < -1 || l.y > cy)) v.Set(0); else { v.Put(u.x * u.y, GetPixel(l.x, l.y)); v.Put(h.x * u.y, GetPixel(l.x + 1, l.y)); v.Put(u.x * h.y, GetPixel(l.x, l.y + 1)); v.Put(h.x * h.y, GetPixel(l.x + 1, l.y + 1)); } span->r = byte(v.r >> 16); span->g = byte(v.g >> 16); span->b = byte(v.b >> 16); span->a = byte(v.a >> 16); } ++span; } }
void Showpoint(unsigned int PointY,unsigned char PointX,uint8 Mode) { uint8 y,x; PointY-=1; PointX-=1; for(y=0;y<3;y++) { for(x=0;x<3;x++) { Pixel(PointY+y, PointX+x, Mode) ; } } Pixel(PointY+1, PointX+1, !Mode) ; }
void PropPC::input(SDL_Event e) { if (crashed) return; renderString("_", (text.size() + 1) * 8, lineHeight * 8, Pixel(0x0, 0x0, 0x0, 0xFF)); char key = e.key.keysym.sym; if (key == SDLK_BACKSPACE) { if (!text.empty()) { for (int x = 0; x < 16; x++) { for (int y = 0; y < 8; y++) { setPixel(text.size()*8 + x, lineHeight * 8 + y, Pixel(0x0, 0x0, 0x0, 0xFF)); } } text.pop_back(); } } else if (key == SDLK_RETURN) { std::string command = text.substr(0, text.find(" ")); if (command == "crash") { crashed = true; } else if (command == "camera") { this->texture = this->cameraTexture; } else if (command == "help") { renderString("crash\ncamera\necho <text>", 0, (lineHeight + 1)*8, Pixel(0xFF, 0xFF, 0xFF, 0xFF)); lineHeight += 4; } else if (command == "echo") { renderString(text.substr(text.find(" ") + 1, text.length() - 1), 0, (lineHeight + 1) * 8, Pixel(0xFF, 0xFF, 0xFF, 0xFF)); lineHeight += 2; } lineHeight++; text = ""; renderString(">", 0, 0 + lineHeight * 8, Pixel(0xFF, 0xFF, 0xFF, 0xFF)); } else { if (key >= '0' && key <= '9' || key >= 'a' && key <= 'z' || key == ' ' || key == ',' || key == '.') { if (key >= 'a' && key <= 'z') { if (e.key.keysym.mod & (KMOD_SHIFT | KMOD_CAPS)) { key -= 32; } } else if (key >= '0' && key <= '9') { if (e.key.keysym.mod & (KMOD_SHIFT | KMOD_CAPS)) { key -= 16; } } text += key; } renderString(text, 8, 0 + lineHeight * 8, Pixel(0xFF, 0xFF, 0xFF, 0xFF)); } if ((text.size()) % (300 / 8) + 1 == 0) { text += "\n"; } }
//========= void x_line(unsigned int y1, unsigned char x1, unsigned char x2, uint8 Mode) { if(abs(x2-x1)>1) { if(x1<x2) { for(x1++;x1<x2;x1++) Pixel(y1, x1, Mode) ; } else { for(x2++;x2<x1;x2++) Pixel(y1, x2, Mode) ; } } }
//============= void y_line(unsigned int y1, unsigned char x1, unsigned int y2, uint8 Mode) { if(abs(y2-y1)>1) {if(y1<y2) { for(y1++;y1<y2;y1++) Pixel(y1, x1, Mode) ; } else { for(y2++;y2<y1;y2++) Pixel(y2, x1, Mode) ; } } }
List<Pixel> *p2pixelsinrectangle(int l,int t,int r,int b) { List<Pixel> *ps=new List<Pixel>(); for (int i=l;i<=r;i++) for (int j=t;j<=b;j++) ps->add(Pixel(i,j)); return ps; }
Image Renderer::render() { Raycaster rc(task_.scene); #pragma omp parallel for collapse(2) for (int x=0; x<task_.resolution.x; ++x) { for (int y=0; y<task_.resolution.y; ++y) { glm::dvec2 view_plane_coords( (double) x / task_.resolution.x, (double) y / task_.resolution.y ); auto r = task_.camera->generateRay(view_plane_coords, RAY_DEPTH); auto cl = rc.shade(r, rc.trace(r)); img_.setPixel(Pixel(x,y,cl)); } } return img_; /*const std::size_t checkersize = 20; for (unsigned y = 0; y < height_; ++y) { for (unsigned x = 0; x < width_; ++x) { Pixel p(x,y); if ( ((x/checkersize)%2) != ((y/checkersize)%2)) { p.color = Color(0.0, 1.0, float(x)/height_); } else { p.color = Color(1.0, 0.0, float(y)/width_); } write(p); } } ppm_.save(filename_);*/ }
Pixel R8Image::pixel(size_t row, size_t column) const { int idx = index(row, column); const Byte *data = pixelData(); return Pixel(data[idx], 255, 255); }