static void convertImages(FILE * const ofP, struct cmdlineInfo const cmdline, struct jpeg_decompress_struct * const cinfoP, struct sourceManager * const sourceManagerP) { if (cmdline.multiple) { unsigned int imageSequence; for (imageSequence = 0; dsDataLeft(sourceManagerP); ++imageSequence) { if (cmdline.verbose) pm_message("Reading Image %u", imageSequence); convertImage(ofP, cmdline, cinfoP); } } else { if (dsDataLeft(sourceManagerP)) { convertImage(ofP, cmdline, cinfoP); } else pm_error("Input stream is empty"); } if (dsPrematureEof(sourceManagerP)) { if (cmdline.repair) pm_message("Premature EOF on input; repaired by padding end " "of image."); else pm_error("Premature EOF on input. Use -repair to salvage."); } }
void ImageTest::testShortImage() { debug(LOG_DEBUG, DEBUG_LOG, 0, "testShortImage() begin"); Image<unsigned short> image2(640, 480); convertImage(image2, *image); CPPUNIT_ASSERT(image2.pixel(13, 15) == ((13 + 15 * 640) % 160) * 256); Image<unsigned char> image3(640,480); convertImage(image3, image2); CPPUNIT_ASSERT(image3 == *image); image3.pixel(14, 15) = 1; CPPUNIT_ASSERT(!(image3 == *image)); debug(LOG_DEBUG, DEBUG_LOG, 0, "testShortImage() end"); }
void BlobDetectorNode::update() { // if more than 2 seconds have passed and no messages have been received, // stop sending if((ros::Time::now()-t_depth).toSec()>1.0) { return; } //convert image to openCV image cv_bridge::CvImagePtr cv_ptr = convertImage(); //normalize image, remove max values // cv_ptr = normalize(cv_ptr); //if(1) return; //detect blobs in image vector<KeyPoint> points = detectBlobs(cv_ptr); //pick the closest blob KeyPoint kp = getClosestBlob(points,cv_ptr); ROS_INFO_STREAM("x cor: " << kp.pt.x << " distance: " << kp.pt.y); // calculate kinematics and send twist to robot simulation node geometry_msgs::Twist twist_msg; twist_msg.linear.x = kp.pt.x; twist_msg.linear.y = 0.0; twist_msg.linear.z = kp.pt.y; twist_msg.angular.x = 0.0; twist_msg.angular.y = 0.0; twist_msg.angular.z = 0.0; blob_publisher.publish(twist_msg); }
int Converter::convert(std::string filename, std::function<void(float)> progress_callback) { if (!this->isOpened()) { return -1; } int fourcc = static_cast<int>(videoCapture.get(CV_CAP_PROP_FOURCC)); VideoWriter writer(filename, fourcc, this->fps(), Size(dst_width, dst_height)); videoCapture.set(CAP_PROP_POS_FRAMES, _start_frame); Mat frame; while (1) { double current_frame = videoCapture.get(CAP_PROP_POS_FRAMES); // std::cout << "fram:" << videoCapture.get(CAP_PROP_POS_FRAMES) // << " / msec:" << videoCapture.get(CAP_PROP_POS_MSEC) << std::endl; if (current_frame > _end_frame) { break; } videoCapture >> frame; if( frame.empty() ) return -1; Mat new_frame = Mat(dst_height, dst_width, frame.type()); convertImage(frame, new_frame); writer << new_frame; float progress = (current_frame - _start_frame) / (_end_frame - _start_frame); progress_callback(progress); } return 0; }
int Converter::makeConvertedPreviewImage(unsigned char* dst_array, int width, int height) { if (!this->isOpened()) { return -1; } Mat dst_img(height, width, CV_8UC4, dst_array); convertImage(previewImage, dst_img); return 0; }
int main(int argc, char *argv[]) { struct cmdlineInfo cmdline; const char * inputFileDescription; FILE* ifP; TIFF* tifP; bool eof; unsigned int imageSeq; pnm_init(&argc, argv); parseCommandLine(argc, argv, &cmdline); ifP = pm_openr_seekable(cmdline.input_filespec); if (streq(cmdline.input_filespec, "-")) inputFileDescription = "Standard Input"; else inputFileDescription = cmdline.input_filespec; if (cmdline.append) validateReadableStdout(); createTiffGenerator(STDOUT_FILENO, "Standard Output", cmdline.append, &tifP); eof = FALSE; /* initial assumption */ imageSeq = 0; while (!eof) { bool success; if (cmdline.verbose) pm_message("Converting Image %u", imageSeq); pnm_nextimage(ifP, &eof); if (!eof) { if (imageSeq > 0) validateReadableStdout(); convertImage(ifP, tifP, inputFileDescription, cmdline); success = TIFFWriteDirectory(tifP); if (!success) pm_error("Unable to write TIFF image %u to file. " "tifWriteDirectory() failed.", imageSeq); ++imageSeq; } } destroyTiffGenerator(tifP); pm_close(ifP); return 0; }
void PadArtist::drawImage(Leap::Image pict) { auto converted = convertImage(pict); image.draw_image( min_x+(WINDOW_WIDTH/2)-(converted.width()/2), min_y+(WINDOW_HEIGHT/2)-(converted.height()/2), 0, 0, converted ); }
static void convertImages(FILE * const ofP, struct cmdlineInfo const cmdline, struct jpeg_decompress_struct * const cinfoP, struct sourceManager * const sourceManagerP) { if (cmdline.multiple) { unsigned int imageSequence; for (imageSequence = 0; dsDataLeft(sourceManagerP); ++imageSequence) { if (cmdline.verbose) pm_message("Reading Image %u", imageSequence); convertImage(ofP, cmdline, cinfoP); } } else { if (dsDataLeft(sourceManagerP)) convertImage(ofP, cmdline, cinfoP); else pm_error("Input stream is empty"); } }
void ImagePreview::paintEvent(TQPaintEvent*){ QImage tmpImage = convertImage(image_,hue_,(bw_ ? 0 : saturation_),brightness_,gamma_); int x = (width()-tmpImage.width())/2, y = (height()-tmpImage.height())/2; TQPixmap buffer(width(), height()); buffer.fill(parentWidget(), 0, 0); TQPainter p(&buffer); p.drawImage(x,y,tmpImage); p.end(); bitBlt(this, TQPoint(0, 0), &buffer, buffer.rect(), TQt::CopyROP); }
void ImageTest::testYUYVImage() { debug(LOG_DEBUG, DEBUG_LOG, 0, "testYUYVImage() begin"); // test the conversion of an individual pixel YUYV<unsigned char> p((unsigned char)47, 11); unsigned char v; convertPixel(v, p); CPPUNIT_ASSERT(47 == v); // convert a complete image Image<YUYV<unsigned char> > image2(640, 480); convertImage(image2, *image); CPPUNIT_ASSERT(image2.pixel(13, 15).y == (13 + 15 * 640) % 160); // convert to an unsigned short image Image<unsigned char> image3(640, 480); convertImage(image3, image2); CPPUNIT_ASSERT(image3 == *image); image3.pixel(14,15) = 1; CPPUNIT_ASSERT(!(image3 == *image)); debug(LOG_DEBUG, DEBUG_LOG, 0, "testYUYVImage() end"); }
char *convert (char* originalFilename, user_agent UserAgent, int Quality, char* Extensions) { char* imageSpecs= (char*) malloc (200); char* targetFilename= (char*) malloc (200); char* midFilename= (char*) malloc (200); char* command = (char*) malloc (1000); imageSpecs = generatePrefix( originalFilename, UserAgent, Quality); midFilename = createNewFilename( originalFilename, UserAgent.format, Extensions); targetFilename = strcat(imageSpecs,midFilename); command = generateCommand(originalFilename, targetFilename, UserAgent, Quality); return convertImage(targetFilename, command); }
TextCache::TextCache(std::string text, const TextParams ¶ms) : params(params) { // Render text SDL_Color white = {255,255,255,0}; SDL_Surface *renderedText = convertImage(TTF_RenderText_Blended(params.font, text.c_str(), white)); // Copy the text onto a new surface with a meaningful size int sizeX, sizeY; SDL_SetAlpha(renderedText, 0, 255); textureSize(renderedText->w, renderedText->h, sizeX, sizeY); SDL_Surface *image = SDL_CreateRGBSurface(SDL_SWSURFACE, sizeX, sizeY, 32, textureFormat.Rmask, textureFormat.Gmask, textureFormat.Bmask, textureFormat.Amask); SDL_FillRect(image, NULL, 0); SDL_BlitSurface(renderedText, NULL, image, NULL); GLuint textureID = 0; glGenTextures(1, &textureID); glBindTexture(GL_TEXTURE_2D, textureID); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); glTexImage2D(GL_TEXTURE_2D, //type of texture 0, //level of detail (mipmap) 4, //components per pixel image->w, image->h, //dimensions 0, //image border GL_RGBA, //colors order GL_UNSIGNED_BYTE, //components data type image->pixels); //pixel data /* gluBuild2DMipmaps(GL_TEXTURE_2D, //type of texture 4, // image->w, image->h, //dimensions GL_RGBA, //format GL_UNSIGNED_BYTE, //channel type image->pixels); //data */ this->text = text; this->w = image->w; this->h = image->h; this->texID = textureID; this->preserve = false; SDL_FreeSurface(renderedText); SDL_FreeSurface(image); }
void showBootLogo() { uint8_t *bootImageData = NULL; uint8_t *appleBootLogo = (uint8_t *) decodeRLE(appleLogoRLE, 686, 16384); setVideoMode(GRAPHICS_MODE); // Fill the background to 75% grey (same as BootX). drawColorRectangle(0, 0, VIDEO(width), VIDEO(height), 0x01); convertImage(APPLE_LOGO_WIDTH, APPLE_LOGO_HEIGHT, appleBootLogo, &bootImageData); drawDataRectangle(APPLE_LOGO_X, APPLE_LOGO_Y, APPLE_LOGO_WIDTH, APPLE_LOGO_HEIGHT, bootImageData); free(bootImageData); free(appleBootLogo); }
inline int ReadImage(const char * path, Image<RGBColor> * im) { std::vector<unsigned char> ptr; int w, h, depth; int res = ReadImage(path, &ptr, &w, &h, &depth); if (res == 1) { if(depth == 3) { (*im) = Image<RGBColor>(w, h, (const RGBColor*) &ptr[0]); } else if(depth == 1) { Image<unsigned char> gray(w, h, &ptr[0]); convertImage(gray, im); } else res = 0; // Do not know how to convert to color } return res; }
bool LoadImageFile(const char *filename, CByteImage &image) { // Load the query image. printf("%s\n", filename); Fl_Shared_Image *fl_image = Fl_Shared_Image::get(filename); if (fl_image == NULL) { printf("TGA\n"); ReadFile(image, filename); return true; } else { printf("Not TGA\n"); CShape sh(fl_image->w(), fl_image->h(), 4); image = CByteImage(sh); // Convert the image to the CImage format. if (!convertImage(fl_image, image)) { printf("couldn't convert image to RGB format\n"); return false; } /* Set the alpha channel to 1 everywhere */ int w = sh.width; int h = sh.height; sh = image.Shape(); // printf("shape: %d, %d, %d\n", sh.width, sh.height, sh.nBands); for (int y = 0; y < h; y++) { for (int x = 0; x < w; x++) { image.Pixel(x, y, 3) = 255; } } return true; } }
VideoFrame::VideoFrame::Data::Data(const QImage &image) : mpi(nullptr), image(convertImage(image)), format(this->image) { data[0] = this->image.bits(); }
/* ================== Add main (All public Add use this) ================== */ bool IND_SurfaceManager::addMain(IND_Surface *pNewSurface, IND_Image *pImage, int pBlockSizeX, int pBlockSizeY, IND_Type pType, IND_Quality pQuality) { g_debug->header("Creating surface", 5); if (!_ok || !pNewSurface || !pImage) { writeMessage(); return 0; } g_debug->header("From image:", 3); g_debug->dataChar(pImage->getName(), 1); //Convert image if needed convertImage(pImage,pType,pQuality); if (_textureBuilder->createNewTexture(pNewSurface, pImage, pBlockSizeX, pBlockSizeY)) { //TODO: ERROR DEBUG FILE } assert(pNewSurface); // ----- Puts the object into the manager ----- addToList(pNewSurface); // ----- g_debug ----- g_debug->header("Type:", 3); g_debug->dataChar(pNewSurface->getTypeString(), 1); g_debug->header("Quality:", 3); g_debug->dataChar(pNewSurface->getQualityString(), 1); g_debug->header("Image size:", 3); g_debug->dataInt(pNewSurface->_surface->_attributes._width, 0); g_debug->dataChar("x", 0); g_debug->dataInt(pNewSurface->_surface->_attributes._height, 1); g_debug->header("Block size:", 3); g_debug->dataInt(pNewSurface->_surface->_attributes._widthBlock, 0); g_debug->dataChar("x", 0); g_debug->dataInt(pNewSurface->_surface->_attributes._heightBlock, 1); g_debug->header("Number of blocks:", 3); g_debug->dataInt(pNewSurface->_surface->_attributes._blocksX, 0); g_debug->dataChar("x", 0); g_debug->dataInt(pNewSurface->_surface->_attributes._blocksY, 1); g_debug->header("Spare (Right | Down):", 3); g_debug->dataInt(pNewSurface->_surface->_attributes._spareX, 0); g_debug->dataChar("x", 0); g_debug->dataInt(pNewSurface->_surface->_attributes._spareY, 1); //TODO: LOG % NOT USED //g_debug->Header ("Not used percentage:", 3); //g_debug->DataFloat (pNewSurface->_surface->_attributes., 0); //g_debug->DataChar ("%", 1); g_debug->header("Surface created", 6); return 1; }
void AGOSEngine::dumpBitmap(const char *filename, const byte *offs, uint16 w, uint16 h, int flags, const byte *palette, byte base) { byte *imageBuffer = (byte *)malloc(w * h); assert(imageBuffer); VC10_state state; state.depack_cont = -0x80; state.srcPtr = offs; state.dh = h; state.height = h; state.width = w / 16; if (getFeatures() & GF_PLANAR) { state.srcPtr = convertImage(&state, (getGameType() == GType_PN || (flags & 0x80) != 0)); flags &= ~0x80; } const byte *src = state.srcPtr; byte *dst = imageBuffer; int i, j; if (w > _screenWidth) { for (i = 0; i < w; i += 8) { decodeColumn(dst, src + readUint32Wrapper(src), h, w); dst += 8; src += 4; } } else if (h > _screenHeight) { for (i = 0; i < h; i += 8) { decodeRow(dst, src + readUint32Wrapper(src), w, w); dst += 8 * w; src += 4; } } else if (getGameType() == GType_FF || getGameType() == GType_PP) { if ((flags & 0x80)) { for (i = 0; i != w; i++) { byte *c = vc10_depackColumn(&state); for (j = 0; j != h; j++) { dst[j * w + i] = c[j]; } } } else { for (j = 0; j != h; j++) { for (i = 0; i != w; i++) { dst[i] = src[i]; } } dst += w; src += w; } } else if ((getGameType() == GType_SIMON1 || getGameType() == GType_SIMON2) && w == 320 && (h == 134 || h == 200)) { for (j = 0; j != h; j++) { uint16 count = w / 8; byte *dstPtr = dst; do { uint32 bits = (src[0] << 24) | (src[1] << 16) | (src[2] << 8) | (src[3]); dstPtr[0] = (byte)((bits >> (32 - 5)) & 31); dstPtr[1] = (byte)((bits >> (32 - 10)) & 31); dstPtr[2] = (byte)((bits >> (32 - 15)) & 31); dstPtr[3] = (byte)((bits >> (32 - 20)) & 31); dstPtr[4] = (byte)((bits >> (32 - 25)) & 31); dstPtr[5] = (byte)((bits >> (32 - 30)) & 31); bits = (bits << 8) | src[4]; dstPtr[6] = (byte)((bits >> (40 - 35)) & 31); dstPtr[7] = (byte)((bits) & 31); dstPtr += 8; src += 5; } while (--count); dst += w; } } else if (flags & 0x80) {
int main(int argc, const char *argv[]) { CmdlineInfo cmdline; const char * inputFileDescription; FILE * ifP; TIFF * tifP; int ofd; int eof; unsigned int imageSeq; pm_proginit(&argc, argv); parseCommandLine(argc, argv, &cmdline); ifP = pm_openr_seekable(cmdline.inputFileName); if (streq(cmdline.inputFileName, "-")) inputFileDescription = "Standard Input"; else inputFileDescription = cmdline.inputFileName; switch (cmdline.writeMethod) { case DIRECT_APPEND: createTiffGeneratorDirect(cmdline.output, MUST_EXIST, &tifP, &ofd); break; case DIRECT_CREATE: createTiffGeneratorDirect(cmdline.output, MAY_CREATE, &tifP, &ofd); break; case TMPFILE: createTiffGeneratorTmpfile(&tifP, &ofd); break; } eof = FALSE; /* initial assumption */ imageSeq = 0; while (!eof) { bool success; pnm_nextimage(ifP, &eof); if (!eof) { if (imageSeq > 0) validateReadableOutputFile(ofd); if (cmdline.verbose) pm_message("Converting Image %u", imageSeq); convertImage(ifP, tifP, inputFileDescription, cmdline); success = TIFFWriteDirectory(tifP); if (!success) pm_error("Unable to write TIFF image %u to file. " "tifWriteDirectory() failed.", imageSeq); ++imageSeq; } } destroyTiffGenerator(cmdline.writeMethod, tifP, ofd); pm_close(ifP); return 0; }