int main() { ImageLoader loader; auto f = loader.LoadImage("../Resource/Fig0310(a)(Moon Phobos).jpg"); auto low_high(HW::strechlim(f)); //auto hist(HW::imhist(f,255)); auto g = HW::imadjust(f, low_high, 0,1); ImageWriter writer; writer.WritePNGImage(g, "imadjustTest.png"); return 0; }
int EntropyEncoder::writeTables(ImageWriter &writer) { int bits = 0; if (!_using_basic) { writer.writeBit(1); bits += _az.writeTable(writer); bits += _bz.writeTable(writer); } else { writer.writeBit(0); bits += _basic.writeTable(writer); } return bits; }
/* * Demonstrates the minimum amount of metadata * necessary to write out an image plane. */ bool minWrite(int argc, const char *argv[]) { if (argc < 2) { cout << "Please specify an output file name." << endl; return -1; } string id = argv[1]; // create blank 512x512 image cout << "Creating random image..." << endl; int w = 512, h = 512; int pixelType = FormatTools::UINT16(); //byte[] img = new byte[w * h * FormatTools.getBytesPerPixel(pixelType)]; int planeSize = w * h * FormatTools::getBytesPerPixel(pixelType); ByteArray img(planeSize); // pre-allocate buffer // fill with random data for (int i=0; i<planeSize; i++) img[i] = rand(); // create metadata object with minimum required metadata fields cout << "Populating metadata..." << endl; IMetadata meta = MetadataTools::createOMEXMLMetadata(); meta.createRoot(); meta.setImageID("Image:0", 0); meta.setPixelsID("Pixels:0", 0); meta.setPixelsBinDataBigEndian(Boolean(1), 0, 0); meta.setPixelsDimensionOrder(DimensionOrder::XYZCT(), 0); meta.setPixelsType( PixelType::fromString(FormatTools::getPixelTypeString(pixelType)), 0); meta.setPixelsSizeX(PositiveInteger(Integer(w)), 0); meta.setPixelsSizeY(PositiveInteger(Integer(h)), 0); meta.setPixelsSizeZ(PositiveInteger(Integer(1)), 0); meta.setPixelsSizeC(PositiveInteger(Integer(1)), 0); meta.setPixelsSizeT(PositiveInteger(Integer(1)), 0); meta.setChannelID("Channel:0:0", 0, 0); meta.setChannelSamplesPerPixel(Integer(1), 0, 0); // write image plane to disk cout << "Writing image to '" << id << "'..." << endl; ImageWriter writer; writer.setMetadataRetrieve(meta); writer.setId(id); writer.saveBytes(img, true); writer.close(); cout << "Done." << endl; }
void CDPWizard::variableDone(QString theFileNameString) { std::cout << " ---------------- Variable " << theFileNameString << " written! " << std::endl; QFileInfo myQFileInfo(theFileNameString); //convert the completed variable layer to an image file ImageWriter myImageWriter; if (cbxPseudoColour->isChecked()) { QString myImageFileNameString = myQFileInfo.dirPath()+"/"+myQFileInfo.baseName()+".png"; myImageWriter.writeImage(theFileNameString,myImageFileNameString); //set the image label on the calculating variables screen to show the last //variable calculated QPixmap myPixmap(myImageFileNameString); pixmapLabel2->setScaledContents(true); pixmapLabel2->setPixmap(myPixmap); } if (cbxMeridianSwitch->isChecked()) { //spit the filename up so we can rename it for the meridian shift QString myMSFileNameString = myQFileInfo.dirPath()+"/"+myQFileInfo.baseName()+"MS."+myQFileInfo.extension(); //perform the meridian shift (hard coding for now but we should have a class member //boolean that stores whether this is needed MeridianSwitcher mySwitcher; mySwitcher.doSwitch(theFileNameString,myMSFileNameString); if (cbxPseudoColour->isChecked()) { //make an image for the shifted file too QFileInfo myQFileInfo2(myMSFileNameString); QString myImageFileNameString = myQFileInfo2.dirPath()+"/"+myQFileInfo2.baseName()+".png"; myImageWriter.writeImage(myMSFileNameString,myImageFileNameString); //set the image label on the calculating variables screen to show the last //variable calculated QPixmap myPixmap(myImageFileNameString); pixmapLabel2->setScaledContents(true); pixmapLabel2->setPixmap(myPixmap); } } progressTotalJob->setProgress(progressTotalJob->progress()+1); //update the elapsed time QString myLabelString; myLabelString.sprintf("<p align=\"right\">Time elapsed: %d s</p>", startTime.elapsed()/1000); lblElapsedTime->setText(myLabelString); qApp->processEvents(); }
static PyObject * image_save_footer(PyObject *self,PyObject *args) { PyObject *pyimwriter; if(!PyArg_ParseTuple(args,"O",&pyimwriter)) { return NULL; } ImageWriter *i = (ImageWriter *)PyCObject_AsVoidPtr(pyimwriter); if(!i || !i->save_footer()) { PyErr_SetString(PyExc_IOError, "Couldn't save image footer"); return NULL; } Py_INCREF(Py_None); return Py_None; }
void setPixel(float x, float y, GLfloat r, GLfloat g, GLfloat b) { if (imageWriter.drawing) { unsigned char color[3]; color[0] = min((int)floor(r*255), 255); color[1] = min((int)floor(g*255), 255); color[2] = min((int)floor(b*255), 255); imageWriter.setPixel(x, y, color); } else { glColor3f(r, g, b); glVertex2f(x, y); } }
void processArgs(int argc, char* argv[]) { if (argc < 3) { Usage(); } int i=1; string filename = argv[i++]; string p = argv[i++]; if (DEBUG) cout << "Parsing scene " << filename << endl; if (DEBUG) cout << "Parameter: " << atof(p.c_str()) << endl; bool adaptive = false; string arg; if (argc >= 4) { for ( ; i<argc; i++) { arg = argv[i]; if (arg.compare("-a") == 0) { adaptive = true; //scene->build(filename, atof(p.c_str())); if (DEBUG) cout << "Using adaptive subdivision." << endl; } else if (arg.compare("-pr")==0) { imageWriter.init(viewport.w, viewport.h); imageWriter.glOn = false; imageWriter.fileName = argv[++i]; } else if (arg.compare("-px")==0) { int width = atoi(argv[++i]); int height = atoi(argv[++i]); viewport.w = width; viewport.h = height; imageWriter.setSize(width, height); } } } scene = new Scene(filename, atof(p.c_str()), adaptive); }
int EntropyEncoder::writeZeroRun(int run, ImageWriter &writer) { if (run <= 0) { return 0; } int bits; if (run < _zrle_syms) { bits = _bz.writeSymbol(_num_syms + run - 1, writer); } else { bits = _bz.writeSymbol(_bz_tail_sym, writer); writer.write255255(run - _zrle_syms); } return bits; }
//*************************************************** // Function what actually draws to screen //*************************************************** void myDisplay() { glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT); // clear the color buffer (sets everything to black) glMatrixMode(GL_MODELVIEW); glLoadIdentity(); vec3 t = scene->translation; glTranslatef(t[0] ,t[1], t[2]); vec3 r = scene->rotation; glRotatef(r[0],1,0,0); glRotatef(r[1],0,1,0); glRotatef(r[2],0,0,1); for (int i=0; i<scene->meshes.size(); i++) { Mesh* mesh = scene->meshes[i]; //Mesh* mesh = scene->meshes[patch]; glColor3f(.1,.1,0); glVertexPointer(3, GL_FLOAT, 0, mesh->verts); glNormalPointer(GL_FLOAT, 0, mesh->norms); if (scene->wireframe) { glPolygonMode(GL_FRONT_AND_BACK, GL_LINE); } else { glPolygonMode(GL_FRONT_AND_BACK, GL_FILL); } if (scene->adaptiveSub) { glDrawElements(GL_TRIANGLES, 3*mesh->n_poly, GL_UNSIGNED_INT, mesh->indices); } else { glDrawElements(GL_QUADS, 4*mesh->n_poly, GL_UNSIGNED_INT, mesh->indices); } } glFlush(); glutSwapBuffers(); // swap buffers (we earlier set double buffer) if (imageWriter.drawing) { imageWriter.printScreen(); quitProgram(); } }
//Deals with normal keydowns void processNormalKeys(unsigned char key, int x, int y) { //escape, q, spacebar quit string name; switch(key) { case 32: case 27: case 'q': quitProgram(); break; case '0': case '1': case '2': case '3': case '4': case '5': case '6': case '7': case '8': case '9': name = "pic"; name += key; name += ".png"; imageWriter.fileName = name; imageWriter.init(viewport.w, viewport.h); break; case 's': if(scene->smoothShading) { glShadeModel(GL_FLAT); } else { glShadeModel(GL_SMOOTH); } scene->smoothShading = !scene->smoothShading; break; case 'w': scene->wireframe = !scene->wireframe; break; case '-': case '_': scene->translating[2] = -TRANSPEED; break; case '=': case '+': scene->translating[2] = TRANSPEED; break; case 'a': patch = (patch + 1) % scene->meshes.size(); break; } }
void VideoThumbnailer::generateThumbnail(const QString& videoFile, ImageWriter& imageWriter, QImage &image) { MovieDecoder movieDecoder(videoFile, NULL); if (movieDecoder.getInitialized()) { movieDecoder.decodeVideoFrame(); //before seeking, a frame has to be decoded if ((!m_WorkAroundIssues) || (movieDecoder.getCodec() != QLatin1String("h264"))) { //workaround for bug in older ffmpeg (100% cpu usage when seeking in h264 files) int secondToSeekTo = m_SeekTime.isEmpty() ? movieDecoder.getDuration() * m_SeekPercentage / 100 : timeToSeconds(m_SeekTime); movieDecoder.seek(secondToSeekTo); } VideoFrame videoFrame; if (m_SmartFrameSelection) { generateSmartThumbnail(movieDecoder, videoFrame); } else { movieDecoder.getScaledVideoFrame(m_ThumbnailSize, m_MaintainAspectRatio, videoFrame); } applyFilters(videoFrame); imageWriter.writeFrame(videoFrame, image); } }
int ImageRGBAWriter::writeTables(ImageWriter &writer) { CAT_INANE("RGBA") << "Writing tables..."; CAT_DEBUG_ENFORCE(MAX_FILTERS <= 32); CAT_DEBUG_ENFORCE(SF_COUNT <= 128); CAT_DEBUG_ENFORCE(_tile_bits_x <= 8); writer.writeBits(_tile_bits_x - 1, 3); int basic_bits = 3; DESYNC_TABLE(); CAT_DEBUG_ENFORCE(_sf_count > 0); // Write filter choices writer.writeBits(_sf_count - 1, 5); int choice_bits = 5; for (int ii = 0; ii < _sf_count; ++ii) { u16 sf = _sf_indices[ii]; writer.writeBits(sf, 7); choice_bits += 7; } DESYNC_TABLE(); int sf_table_bits = _sf_encoder.writeTables(writer); DESYNC_TABLE(); int cf_table_bits = _cf_encoder.writeTables(writer); DESYNC_TABLE(); int a_table_bits = _a_encoder.writeTables(writer); DESYNC_TABLE(); #ifdef CAT_COLLECT_STATS Stats.y_table_bits = 0; Stats.u_table_bits = 0; Stats.v_table_bits = 0; #endif // CAT_COLLECT_STATS writer.writeBits(_encoders->chaos.getBinCount() - 1, 4); basic_bits += 4; for (int jj = 0; jj < _encoders->chaos.getBinCount(); ++jj) { int y_table_bits = _encoders->y[jj].writeTables(writer); DESYNC_TABLE(); int u_table_bits = _encoders->u[jj].writeTables(writer); DESYNC_TABLE(); int v_table_bits = _encoders->v[jj].writeTables(writer); DESYNC_TABLE(); #ifdef CAT_COLLECT_STATS Stats.y_table_bits += y_table_bits; Stats.u_table_bits += u_table_bits; Stats.v_table_bits += v_table_bits; #endif // CAT_COLLECT_STATS } int lz_table_bits = _lz.writeTables(writer); DESYNC_TABLE(); #ifdef CAT_COLLECT_STATS Stats.basic_overhead_bits = basic_bits; Stats.sf_choice_bits = choice_bits; Stats.sf_table_bits = sf_table_bits; Stats.cf_table_bits = cf_table_bits; Stats.a_table_bits = a_table_bits; Stats.lz_table_bits = lz_table_bits; #endif // CAT_COLLECT_STATS return GCIF_WE_OK; }
void lrfExample(ImageWriter& iw) { iw.setLabel("lrf-example"); // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - WorldModel2D wm; // wm.addEntity(createBox(geo::Vec2(), geo::Vec2())); wm.addEntity(createBox(7.63, 4.09, true), fromXYADegrees(0.085, 0.065, 0)); wm.addEntity(createBox(0.691667, 1.45833), fromXYADegrees(-0.529166, 0.404165, 0)); wm.addEntity(createBox(0.45833, 0.6), fromXYADegrees(-1.69583, 0.375, 0)); wm.addEntity(createBox(0.95833, 0.516667), fromXYADegrees(-1.72917, -0.616667, 0)); wm.addEntity(createBox(0.96666, 0.50833), fromXYADegrees(-1.75, 1.37084, 0)); wm.addEntity(createBox(1.6, 0.30834), fromXYADegrees(-0.45, -1.8375, 0)); wm.addEntity(createBox(0.65, 0.95), fromXYADegrees(1.6, 0.4, 0)); wm.addEntity(createBox(0.55, 1.28333), fromXYADegrees(3.54167, 0.558333, 0)); wm.addEntity(createCircle(0.1), fromXYA(0.358333, 1.81667, 0)); wm.addEntity(createCircle(0.1), fromXYA(-1.73333, -1.78333, 0)); wm.addEntity(createCircle(0.1), fromXYA(3.18333, 1.68333, 0)); Model2D model; Contour2D& c = model.addContour(); c.addPoint(-3.73333 + 3.3, -1 + 1.6); c.addPoint(-3.15 + 3.3, -1 + 1.6); c.addPoint(-3.15 + 3.3, -1.46 + 1.6); c.addPoint(-2.36 + 3.3, -1.46 + 1.6); c.addPoint(-2.36 + 3.3, -1.97 + 1.6); c.addPoint(-3.73333 + 3.3, -1.97 + 1.6); wm.addEntity(model, fromXYADegrees(-3.3, -1.6, 0)); // wm.addEntity(createBox(geo::Vec2(0, -4), geo::Vec2(8, 0), true), fromXYA(-4, 2, 0)); // 0 // wm.addEntity(createBox(1.6, 0.8), fromXYA(2, -1, 0)); // 1 table // wm.addEntity(createCircle(0.1), fromXYA(2.6, -0.8, 0)); // 2 small object // wm.addEntity(createCircle(0.5), fromXYA(-3.2, -1.2, 0)); // 3 // wm.addEntity(createCircle(0.3), fromXYA(-2.2, -1.4, 0)); // 4 // wm.addEntity(createCircle(0.3), fromXYA(3.3, 1.0, 0)); // 5 // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - geo::LaserRangeFinder lrf; lrf.setNumBeams(50); lrf.setAngleLimits(-1.0, 1.0); lrf.setRangeLimits(0, 10); // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // Draw world model without extra object Canvas canvas = iw.nextCanvas(); drawImage(canvas, iw.image_path() + "/livingroom.jpg", 0.9); iw.setLabel("livingroom"); iw.process(canvas); iw.setLabel("lrf-example"); iw.process(canvas); // canvas = iw.nextCanvas(); // drawWorld(canvas, wm); // iw.process(canvas); // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // Render world model (LRF) without extra object (virtual data) geo::Transform2 lrf_pose = fromXYADegrees(0.533333, -1.24167, 145); drawLRFPose(canvas, lrf_pose, Color(0, 150, 0, 2)); iw.process(canvas); std::vector<double> ranges_virtual = renderLRF(lrf, lrf_pose, wm); drawRanges(canvas, lrf, lrf_pose, ranges_virtual, Color(255, 0, 0, 3), Color(50, 50, 50)); drawLRFPose(canvas, lrf_pose, Color(0, 150, 0, 2)); iw.process(canvas); drawWorld(canvas, wm); drawRanges(canvas, lrf, lrf_pose, ranges_virtual, Color(255, 0, 0, 3), Color(50, 50, 50)); drawLRFPose(canvas, lrf_pose, Color(0, 150, 0, 2)); iw.process(canvas); canvas = iw.nextCanvas(); drawWorld(canvas, wm); drawRanges(canvas, lrf, lrf_pose, ranges_virtual, Color(255, 0, 0, 3), Color(50, 50, 50)); drawLRFPose(canvas, lrf_pose, Color(0, 150, 0, 2)); iw.process(canvas); }
int main() { IFractalSite doNothingSite; ListColorMap *cmap = new ListColorMap(); cmap->init(256); for(int i = 0; i < 256; ++i) { int x = (i % 2) ? 179 : 49; cmap->set(i,i/256.0, 255, x, x, 255); } pf_obj *pfo = pf_new(); s_param *pfoParams = new s_param[7]; pfoParams[0].gradient = cmap; //gradient pfoParams[1].doubleval = 4.0; //bailout pfoParams[2].doubleval = 1.0; //cf0 density pfoParams[3].doubleval = 1.0; //cf0 offset pfoParams[4].doubleval = 4.0; //cf0 bailout pfoParams[5].doubleval = 1.0; //cf1 density pfoParams[6].doubleval = 1.0; // offset double params[] = { 0.0, 0.0, 0.0, 0.0, 4.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0}; pfo->vtbl->init( pfo,2.0e-9, params, pfoParams, 7); image *im = new image(); im->set_resolution(1024,1024,-1,-1); calc( params, AA_FAST, 32767, 1, pfo, cmap, true, false, true, true, DEBUG_QUICK_TRACE | DEBUG_DRAWING_STATS, RENDER_TWO_D, -1, im, &doNothingSite); FILE *outfile = fopen("prof.tga", "wb"); ImageWriter *iw = ImageWriter::create(FILE_TYPE_TGA, outfile, im); iw->save_header(); iw->save_tile(); iw->save_footer(); fclose(outfile); }
void relativeSection(ImageWriter& iw) { iw.setLabel("relative"); // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - WorldModel2D wm; // wm.addEntity(createBox(geo::Vec2(), geo::Vec2())); // wm.addEntity(createBox(7.63, 4.09, true), fromXYADegrees(0.085, 0.065, 0)); wm.addEntity(createBox(geo::Vec2(0, -4.09), geo::Vec2(7.63, 0), true), fromXYADegrees(-3.75, 2.1, 0)); int idx_couch = wm.entities.size(); wm.addEntity(createBox(0.691667, 1.45833), fromXYADegrees(-0.529166, 0.404165, 0)); wm.addEntity(createBox(0.45833, 0.6), fromXYADegrees(-1.69583, 0.375, 0)); wm.addEntity(createBox(0.95833, 0.516667), fromXYADegrees(-1.72917, -0.616667, 0)); wm.addEntity(createBox(0.96666, 0.50833), fromXYADegrees(-1.75, 1.37084, 0)); wm.addEntity(createBox(1.6, 0.30834), fromXYADegrees(-0.45, -1.8375, 0)); int idx_table = wm.entities.size(); wm.addEntity(createBox(0.65, 0.95), fromXYADegrees(1.6, 0.4, 0)); int idx_cabinet = wm.entities.size(); wm.addEntity(createBox(0.55, 1.28333), fromXYADegrees(3.54167, 0.558333, 0)); wm.addEntity(createCircle(0.1), fromXYA(0.358333, 1.81667, 0)); wm.addEntity(createCircle(0.1), fromXYA(-1.73333, -1.78333, 0)); int idx_plant = wm.entities.size(); wm.addEntity(createCircle(0.1), fromXYA(3.18333, 1.68333, 0)); Model2D model; Contour2D& c = model.addContour(); c.addPoint(-3.73333 + 3.3, -1 + 1.6); c.addPoint(-3.15 + 3.3, -1 + 1.6); c.addPoint(-3.15 + 3.3, -1.46 + 1.6); c.addPoint(-2.36 + 3.3, -1.46 + 1.6); c.addPoint(-2.36 + 3.3, -1.97 + 1.6); c.addPoint(-3.73333 + 3.3, -1.97 + 1.6); wm.addEntity(model, fromXYADegrees(-3.3, -1.6, 0)); // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Canvas canvas = iw.nextCanvas(); drawImage(canvas, iw.image_path() + "/livingroom.jpg", 0.9); iw.process(canvas); // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - drawWorld(canvas, wm); iw.process(canvas); // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - int idx_lrf = wm.entities.size(); wm.addEntity(createLRFPose(), fromXYADegrees(0.533333, -1.24167, 145), Color(0, 150, 0, 2)); drawWorld(canvas, wm); iw.process(canvas); int idx_target = wm.entities.size(); wm.addEntity(createTarget(), fromXYADegrees(-0.533333, -0.725, 0), Color(255, 0, 0, 2)); drawWorld(canvas, wm); iw.process(canvas); // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // Moved couch canvas = iw.nextCanvas(); drawImage(canvas, iw.image_path() + "/livingroom2.jpg", 0.9); drawWorld(canvas, wm); iw.process(canvas); // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // canvas = iw.nextCanvas(); drawWorldModelAbsolute(canvas, wm, wm.entities[0].pose.t); iw.process(canvas); // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - canvas = iw.nextCanvas(); drawImage(canvas, iw.image_path() + "/livingroom2.jpg", 0.9); drawWorld(canvas, wm); iw.process(canvas); std::vector<Link> links; links.push_back(Link(0, idx_target)); links.push_back(Link(0, idx_lrf)); // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - drawWorldModelSceneGraph(canvas, wm, links); iw.process(canvas); canvas = iw.nextCanvas(); drawImage(canvas, iw.image_path() + "/livingroom2.jpg", 0.9); drawWorld(canvas, wm); iw.process(canvas); links.clear(); links.push_back(Link(idx_couch, idx_target)); drawWorldModelSceneGraph(canvas, wm, links); iw.process(canvas); links.push_back(Link(idx_lrf, idx_couch)); drawWorldModelSceneGraph(canvas, wm, links); iw.process(canvas); // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - WorldModel2D wm2; wm2.entities.push_back(wm.entities[idx_lrf]); wm2.entities.push_back(wm.entities[idx_couch]); wm2.entities.push_back(wm.entities[idx_target]); links.clear(); links.push_back(Link(0, 1)); links.push_back(Link(1, 2)); canvas = iw.nextCanvas(); drawWorldModelSceneGraph(canvas, wm2, links); iw.process(canvas); canvas = iw.nextCanvas(); drawImage(canvas, iw.image_path() + "/livingroom2.jpg", 0.9); wm.entities[idx_target].pose.t.y += 0.7; wm.entities[idx_couch].pose.t.y += 0.7; links.clear(); links.push_back(Link(idx_couch, idx_target)); links.push_back(Link(idx_lrf, idx_couch)); drawWorldModelSceneGraph(canvas, wm, links); iw.process(canvas); links.push_back(Link(idx_couch, 2)); links.push_back(Link(2, 3)); links.push_back(Link(2, 4)); links.push_back(Link(idx_lrf, idx_table)); links.push_back(Link(idx_table, idx_cabinet)); links.push_back(Link(idx_cabinet, idx_plant)); drawWorldModelSceneGraph(canvas, wm, links); iw.process(canvas); // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // Soccer field iw.setLabel("relative-soccer"); //Click: [ -2.0125 -0.0125 ] //Click: [ 0.8375 -1.1 ] //Click: [ 2.075 0.025 ] //Click: [ 2 1.7125 ] ball wm.entities.clear(); wm.addEntity(createSoccerFieldModel(), geo::Transform2::identity(), Color(255, 255, 255, 2)); wm.addEntity(createCircle(0.2), fromXYA(2, 1.7125, 0), Color(255, 220, 0, 2)); wm.addEntity(createTurtleModel(), fromXYADegrees(0.8375, -1.1 , 60), Color(0, 0, 0, 2)); // wm.addEntity(createTurtleModel(), fromXYADegrees(-1.1, -0.15, -90), Color(0, 0, 0, 2)); // wm.addEntity(createTurtleModel(), fromXYADegrees(2.275, 0.025, 105), Color(0, 0, 0, 2)); canvas = iw.nextCanvas(); drawSoccerField(canvas); drawWorld(canvas, wm); iw.process(canvas); // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - drawWorldModelAbsolute(canvas, wm, geo::Vec2(-4, 2.67)); iw.process(canvas); // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - links.clear(); links.push_back(Link(2, 1)); canvas = iw.nextCanvas(); drawSoccerField(canvas); drawWorldModelSceneGraph(canvas, wm, links); iw.process(canvas); // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - wm.addEntity(createTurtleModel(), fromXYADegrees(-1.5, -0.15, -10), Color(0, 0, 0, 2)); canvas = iw.nextCanvas(); drawSoccerField(canvas); drawWorldModelSceneGraph(canvas, wm, links); iw.process(canvas); links.push_back(Link(3, 2)); drawWorldModelSceneGraph(canvas, wm, links); iw.process(canvas); drawArrow(canvas, wm.entities[3].pose.t, wm.entities[1].pose.t, Color(150, 150, 150, 2), true); iw.process(canvas); // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - canvas = iw.nextCanvas(); drawSoccerField(canvas); geo::Vec2 ball_pos_rel = wm.entities[2].pose.inverse() * wm.entities[1].pose.t; geo::Transform2 offset = geo::Transform2::identity(); offset.setRotation(-0.3); wm.entities[2].pose = wm.entities[2].pose * offset; wm.entities[1].pose.t = wm.entities[2].pose * ball_pos_rel; drawWorldModelSceneGraph(canvas, wm, links); drawArrow(canvas, wm.entities[3].pose.t, wm.entities[1].pose.t, Color(150, 150, 150, 2), true); iw.process(canvas); // Turn back wm.entities[2].pose = wm.entities[2].pose * offset.inverse(); wm.entities[1].pose.t = wm.entities[2].pose * ball_pos_rel; // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - canvas = iw.nextCanvas(); drawSoccerField(canvas); drawWorld(canvas, wm); iw.process(canvas); // wm.addEntity(createTurtleModel(), fromXYADegrees(2.275, 0.025, 105), Color(0, 0, 0, 2)); wm.addEntity(createTurtleModel(), fromXYADegrees(0.375, 0.65, -105), Color(0, 0, 0, 2)); drawWorld(canvas, wm); iw.process(canvas); // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - links.clear(); links.push_back(Link(2, 1)); links.push_back(Link(2, 4)); drawWorldModelSceneGraph(canvas, wm, links); iw.process(canvas); // links.push_back(Link(4, 1)); // drawWorldModelSceneGraph(canvas, wm, links); // iw.process(canvas); links.push_back(Link(3, 2)); links.push_back(Link(3, 4)); drawWorldModelSceneGraph(canvas, wm, links); iw.process(canvas); cv::Mat temp = canvas.image.clone(); // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - canvas = iw.nextCanvas(); canvas.image = temp.clone(); drawTriangle(canvas, wm.entities[1].pose.t, wm.entities[2].pose.t, wm.entities[4].pose.t, Color(0, 255, 255, 2)); iw.process(canvas); // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // Replace 3th turtle by field feature wm.entities[4] = Entity2D(Model2D(), fromXYA(0, 0.7, 0), Color()); canvas = iw.nextCanvas(); drawSoccerField(canvas); drawWorldModelSceneGraph(canvas, wm, links); iw.process(canvas); drawTriangle(canvas, wm.entities[1].pose.t, wm.entities[2].pose.t, wm.entities[4].pose.t, Color(0, 255, 255, 2)); iw.process(canvas); }
int ForceRGBCommand::run(const char** args, unsigned int numArgs) { if ( numArgs < 2 ) { fprintf(stderr, "Usage: ImageTool forcergb <input> <output> [-filequality 0-100] [-pad N,N,N]\n"); fprintf(stderr, "\te.g. ImageTool forcergb input.jpg output.jpg\n"); return IMAGECORE_INVALID_USAGE; } int ret = open(args[0], args[1]); if (ret != IMAGECORE_SUCCESS) { return ret; } // Defaults unsigned int compressionQuality = 75; // Optional args unsigned int numOptional = numArgs - 2; if ( numOptional > 0 ) { unsigned int numPairs = numOptional / 2; for ( unsigned int i = 0; i < numPairs; i++ ) { const char* argName = args[2 + i * 2 + 0]; const char* argValue = args[2 + i * 2 + 1]; if( strcmp(argName, "-filequality") == 0 ) { compressionQuality = clamp(0, 100, atoi(argValue)); } else if( strcmp(argName, "-pad") == 0 ) { int ret = populateBuckets(argValue); if (ret != IMAGECORE_SUCCESS) { return ret; } } } } ImageReader* reader = ImageReader::create(m_Source); if( reader == NULL ) { fprintf(stderr, "error: unknown or corrupt image format for '%s'\n", m_InputFilePath); return IMAGECORE_INVALID_FORMAT; } EImageFormat outputFormat = ImageWriter::formatFromExtension(args[1], reader->getFormat()); unsigned int colorProfileSize = 0; reader->getColorProfile(colorProfileSize); if( colorProfileSize != 0 && reader->getFormat() == kImageFormat_JPEG ) { reader->setReadOptions(ImageReader::kReadOption_ApplyColorProfile); ImageRGBA* image = ImageRGBA::create(reader->getWidth(), reader->getHeight()); if( reader->readImage(image) ) { ImageWriter* writer = ImageWriter::createWithFormat(kImageFormat_JPEG, m_Output); if (writer == NULL) { fprintf(stderr, "error: unable to create ImageWriter\n"); return IMAGECORE_OUT_OF_MEMORY; } writer->setWriteOptions(ImageWriter::kWriteOption_WriteDefaultColorProfile); writer->setSourceReader(reader); writer->setQuality(compressionQuality); if( !writer->writeImage(image) ) { ret = IMAGECORE_WRITE_ERROR; } delete writer; } else { fprintf(stderr, "error unable to read input image"); ret = IMAGECORE_READ_ERROR; } delete image; } else { ImageWriter* imageWriter = ImageWriter::createWithFormat(outputFormat, m_Output); unsigned int writeOptions = 0; writeOptions |= ImageWriter::kWriteOption_WriteExifOrientation; writeOptions |= ImageWriter::kWriteOption_WriteDefaultColorProfile; if( imageWriter != NULL ) { imageWriter->setWriteOptions(writeOptions); if( imageWriter->copyLossless(reader) ) { ret = IMAGECORE_SUCCESS; } else { fprintf(stderr, "error: unable to perform lossless copy.\n"); ret = IMAGECORE_INVALID_OPERATION; } delete imageWriter; } } delete reader; reader = NULL; close(); return ret; }