Ejemplo n.º 1
0
void Night::printAlt (int year, int month, int day, XmlRpc::HttpParams *params, const char* &response_type, char* &response, size_t &response_length)
{
	response_type = "image/jpeg";

	AltPlot ap (params->getInteger ("w", 800), params->getInteger ("h", 600));
	Magick::Geometry size (params->getInteger ("w", 800), params->getInteger ("h", 600));

	time_t from;
	int64_t duration;

	getNightDuration (year, month, day, from, duration);

	time_t end = from + duration;

	rts2db::ImageSetDate is = rts2db::ImageSetDate (from, end);
	is.load ();

	Magick::Image mimage (size, "white");
	ap.getPlot (from, end, &is, &mimage);

	Magick::Blob blob;
	mimage.write (&blob, "jpeg");

	response_length = blob.length();
	response = new char[response_length];
	memcpy (response, blob.data(), response_length);
}
Ejemplo n.º 2
0
//----------------------------------------------------------------------------------------------------------------------
// Image Magick Image loading routines
//----------------------------------------------------------------------------------------------------------------------
bool Image::load( const std::string &_fname  ) noexcept
{
  #ifdef IMAGE_DEBUG_ON
  std::cerr<<"loading with ImageMagick"<<std::endl;
  #endif
  Magick::Image image;
  Magick::Blob blob;

  try
  {
    image.read(_fname);
    // need to flip image as OpenGL uses textures starting the other way round.
    image.flip();
    image.write(&blob, "RGBA");
  }
  catch (Magick::Error& Error)
  {
  std::cout << "Error loading texture '" << _fname << "': " << Error.what() << std::endl;
  return false;
  }
  m_width=image.columns();
  m_height=image.rows();
  m_channels=4;
  m_format=GL_RGBA;
  m_data.reset(new unsigned char[ m_width*m_height*m_channels]);
  // simple memcpy of the blob data to our internal data, not worrying about RGB/RGBA
  // here (as OpenGL doesn't really either).
  memcpy(m_data.get(),blob.data(),blob.length());
  return true;
}
Ejemplo n.º 3
0
void Targets::plotTarget (rts2db::Target *tar, XmlRpc::HttpParams *params, const char* &response_type, char* &response, size_t &response_length)
{
	response_type = "image/jpeg";

	AltPlot ap (params->getInteger ("w", 800), params->getInteger ("h", 600));
	Magick::Geometry size (params->getInteger ("w", 800), params->getInteger ("h", 600));

	double from = params->getDouble ("from", 0);
	double to = params->getDouble ("to", 0);

	if (from < 0 && to == 0)
	{
		// just fr specified - from
		to = time (NULL);
		from += to;
	}
	else if (from == 0 && to == 0)
	{
		// default - one day
		to = time (NULL);
		from = to - 86400;
	}

	Magick::Image mimage (size, "white");
	ap.getPlot (from, to, tar, &mimage);

	Magick::Blob blob;
	mimage.write (&blob, "jpeg");

	response_length = blob.length();
	response = new char[response_length];
	memcpy (response, blob.data(), response_length);
}
Ejemplo n.º 4
0
char osra_cuneiform_ocr(Magick::Image &cuneiform_img, const string &char_filter)
{
  Magick::Blob blob;
  cuneiform_img.write(&blob, "DIB");
  size_t data_size = blob.length();
  char *dib = new char[data_size];
  memcpy(dib, blob.data(), data_size);

  char str[256];
  memset(str, 0, sizeof(str));

  if (!PUMA_XOpen(dib, NULL) || !PUMA_XFinalRecognition() || !PUMA_SaveToMemory(NULL, PUMA_TOTEXT, PUMA_CODE_ASCII, str, sizeof(str) - 1))
    {
      //if (verbose)
      //  cout << "Cuneiform recognition failed." << endl;

      PUMA_XClose();
      delete []dib;

      return UNKNOWN_CHAR;
    }

  PUMA_XClose();
  delete []dib;

  // As we have initialized the image with two identical samples, it is expected that they go in the string
  // one after another, or separated by space (e.g. "ZZ\n" or "Z Z\n").
  if (((str[0] == str[1] && isspace(str[2])) || (str[0] == str[2] && str[1] == ' ')) && isalnum(str[0])
      && (char_filter.empty() || char_filter.find(str[0], 0) != string::npos))
    return str[0];

  return UNKNOWN_CHAR;
}
Ejemplo n.º 5
0
Archivo: edit.cpp Proyecto: cran/magick
// [[Rcpp::export]]
Rcpp::RawVector magick_image_write( XPtrImage input, Rcpp::CharacterVector format, Rcpp::IntegerVector quality,
                                    Rcpp::IntegerVector depth, Rcpp::CharacterVector density, Rcpp::CharacterVector comment){
  if(!input->size())
    return Rcpp::RawVector(0);
  XPtrImage image = copy(input);
#if MagickLibVersion >= 0x691
  //suppress write warnings see #74 and #116
  image->front().quiet(true);
#endif
  if(format.size())
    for_each ( image->begin(), image->end(), Magick::magickImage(std::string(format[0])));
  if(quality.size())
    for_each ( image->begin(), image->end(), Magick::qualityImage(quality[0]));
  if(depth.size())
    for_each ( image->begin(), image->end(), Magick::depthImage(depth[0]));
  if(density.size()){
    for_each ( image->begin(), image->end(), Magick::resolutionUnitsImage(Magick::PixelsPerInchResolution));
    for_each ( image->begin(), image->end(), Magick::densityImage(Point(density[0])));
  }
  if(comment.size())
    for_each ( image->begin(), image->end(), Magick::commentImage(std::string(comment.at(0))));
  Magick::Blob output;
  writeImages( image->begin(), image->end(),  &output );
  Rcpp::RawVector res(output.length());
  std::memcpy(res.begin(), output.data(), output.length());
  return res;
}
Ejemplo n.º 6
0
  void PipelineStabDetect::onInput(InputImageInfo info, Magick::Image image) {
    try {
      if (!initialized) {
        init(image);
      }
      if (image.rows() != height || image.columns() != width) {
        throw runtime_error(QString("Not uniform image size! %").arg(info.file.fileName()).toStdString());
      }


      Magick::Blob blob;
      // set raw RGBS output format & convert it into a Blob  
      if (image.depth() > 8)
        *err << "Warning: we lost some information by converting to 8bit depth (now " << image.depth() << ")" << endl;
      image.depth(8);
      image.magick("RGB");
      image.write(&blob);

      LocalMotions localmotions;
      VSFrame frame;
      size_t dataLen = blob.length();

      Q_ASSERT(fi.planes == 1);
      Q_ASSERT(dataLen == image.baseColumns() * image.baseRows() * 3);

      if (stabConf->mdConf.show > 0) { // create copy of blob
        frame.data[0] = new uint8_t[dataLen];
        memcpy(frame.data[0], blob.data(), dataLen);
      } else {
        frame.data[0] = (uint8_t*) blob.data();
      }
      frame.linesize[0] = image.baseColumns() * 3;

      if (vsMotionDetection(&md, &localmotions, &frame) != VS_OK) {
        throw runtime_error("motion detection failed");
      } else {
        if (vsWriteToFile(&md, f, &localmotions) != VS_OK) {
          throw runtime_error("cannot write to transform file");
        }
        vs_vector_del(&localmotions);
      }

      if (stabConf->mdConf.show > 0) {
        // if we want to store transformations, we have to create new image...
        Magick::Geometry g(width, height);
        Magick::Blob oblob(frame.data[0], dataLen);

        Magick::Image oimage;
        oimage.read(oblob, g, 8, "RGB");
        delete[] frame.data[0];
        emit input(info, oimage);
      } else {
        emit input(info, image);
      }

    } catch (exception &e) {
      emit error(e.what());
    }
  }
Ejemplo n.º 7
0
    void FsImgStorage::Write(ImgInfo& img) const {
        Utils::Contract::Assert(img.GetId() != IMGID_UNDEFINED);
        Utils::Contract::Assert(!img.GetFileExtension().empty());

        boost::filesystem::path uploadFilePath = GetImgPath(img.GetId(), img.GetFileExtension());

        Magick::Blob magickBlob;
        img.GetMagickImage().write(&magickBlob);

        Utils::FileSystem::WriteAllBytes((const char*)magickBlob.data(), magickBlob.length(), uploadFilePath);
    }
int main ( int argc, char **argv )
{
    int i;                      /* loop iterator            */
    int height, width;          /* image dimensions         */
    string param;               /* passed parameter         */
    void *raw_data;             /* raw image data           */
    Magick::Blob blob;          /* image in blob format     */
    vector <string> qr_data;    /* decoded qr codes         */

    /* Check that a file was passed - provide usage statement if not */
    if( argc != 2 )
    {
        error( TRUE, "Usage: read_img (imagefile | 'webcam')" );
    }

    /* get command line arg as c++ style string */
    param = argv[ 1 ];

    /* process the image into the raw data */
    if( param == "webcam" )
    {
        /* obtain the image from the webcam */
        dbg_msg( "Attempting to get data from webcam using OpenCV" );
        get_cam_img( raw_data, width, height );
    }
    else
    {
        /* initalize image magick c++ library and use it to get image data */
        dbg_msg( "Using ImageMagick to read QR codes from image file %s", param.c_str() );
        Magick::InitializeMagick( NULL );
        read_img( param, blob, width, height );
        raw_data = (void *) blob.data();
    }

    /* process the qr codes */
    if( raw_data == NULL )
    {
        error( TRUE, "Could not read image data" );
    }
    get_codes( qr_data, raw_data, width, height );

    /* output all of the recognized codes */
    for( i = 0; i < qr_data.size(); i++ )
    {
        printf( "symbol %d - data: %s\n", i, qr_data[ i ].c_str() );
    }

    /* be tidy -- don't leak memory */
    if( raw_data != NULL && param == "webcam" ) free( raw_data );

    return 0;
}
Ejemplo n.º 9
0
void Targets::processForm (XmlRpc::HttpParams *params, const char* &response_type, char* &response, size_t &response_length)
{
#ifdef RTS2_HAVE_LIBJPEG
	if (!strcmp (params->getString ("plot", "xxx"), "Plot target altitude"))
	{
		response_type = "image/jpeg";

		AltPlot ap (params->getInteger ("w", 800), params->getInteger ("h", 600));
		Magick::Geometry size (params->getInteger ("w", 800), params->getInteger ("h", 600));
	
		double from = params->getDouble ("from", 0);
		double to = params->getDouble ("to", 0);
	
		if (from < 0 && to == 0)
		{
			// just fr specified - from
			to = time (NULL);
			from += to;
		}
		else if (from == 0 && to == 0)
		{
			// default - one hour
			to = time (NULL);
			from = to - 86400;
		}


		std::list < int > ti;

		for (XmlRpc::HttpParams::iterator iter = params->begin (); iter != params->end (); iter++)
		{
			if (!strcmp (iter->getName (), "tid"))
				ti.push_back (atoi (iter->getValue ()));
		}

		rts2db::TargetSet ts = rts2db::TargetSet ();
		ts.load (ti);
	
		Magick::Image mimage (size, "white");
		ap.getPlot (from, to, &ts, &mimage);
	
		Magick::Blob blob;
		mimage.write (&blob, "jpeg");
	
		response_length = blob.length();
		response = new char[response_length];
		memcpy (response, blob.data(), response_length);
		return;
	}
#endif // RTS2_HAVE_LIBJPEG
}
Ejemplo n.º 10
0
Archivo: edit.cpp Proyecto: cran/magick
// [[Rcpp::export]]
Rcpp::IntegerVector magick_image_write_integer(XPtrImage input){
  if(input->size() != 1)
    throw std::runtime_error("Image must have single frame to write a native raster");
  Frame frame = input->front();
  Magick::Geometry size(frame.size());
  size_t width = size.width();
  size_t height = size.height();
  Magick::Blob output;
  frame.write(&output, "RGBA", 8L);
  Rcpp::IntegerVector res(output.length() / 4);
  memcpy(res.begin(), output.data(), output.length());
  res.attr("class") = Rcpp::CharacterVector::create("nativeRaster");
  res.attr("dim") = Rcpp::NumericVector::create(height, width);
  return res;
}
Ejemplo n.º 11
0
bool CubemapTexture::load() {
    Magick::Image *img;
    Magick::Blob blob;

    glGenTextures(1, &_tex);
    glBindTexture(GL_TEXTURE_CUBE_MAP, _tex);
    for (uint i=0; i < sizeof(types) / sizeof(types[0]); i++) {
        img = new Magick::Image(_fs[i]);
        try {
            img->write(&blob, "RGBA");
        } catch (Magick::Error &err) {
            std::cerr << "Could not load texture " << _fs[i] << ": " << err.what() << std::endl;
            delete (img);
            return false;
        }
        std::cout << "Cubemap texture loaded: " << _fs[i] << std::endl;
        glTexImage2D(types[i], 0, GL_RGB, img->columns(), img->rows(), 0, GL_RGBA, GL_UNSIGNED_BYTE, blob.data());
        glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
        glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
        glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
        glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
        glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_R, GL_CLAMP_TO_EDGE);
        delete img;
    }
    return true;
}
Ejemplo n.º 12
0
ItemSequence_t
FormatFunction::evaluate(
  const ExternalFunction::Arguments_t& aArgs,
  const StaticContext*                          aSctxCtx,
  const DynamicContext*                         aDynCtx) const
{
  Magick::Image lImage;
  ImageFunction::getOneImageArg(aDynCtx, aArgs, 0, lImage);
  Magick::Blob lBlob;
  lImage.write(&lBlob); 
  long lBlobLength = (long) lBlob.length();
  std::string lImageType = GetImageType(lBlob.data(), &lBlobLength);
  String lResult(lImageType);
  return ItemSequence_t(new SingletonItemSequence(
      theModule->getItemFactory()->createString(lResult)));
}
Ejemplo n.º 13
0
bool CubemapTexture::Load()
{
    glGenTextures(1, &m_textureObj);
    glBindTexture(GL_TEXTURE_CUBE_MAP, m_textureObj);

    Magick::Image* pImage = NULL;
    Magick::Blob blob;

    for (unsigned int i = 0 ; i < ARRAY_SIZE_IN_ELEMENTS(types) ; i++) {
        pImage = new Magick::Image(m_fileNames[i]);
        
        try {            
            pImage->write(&blob, "RGBA");
        }
        catch (Magick::Error& Error) {
            cout << "Error loading texture '" << m_fileNames[i] << "': " << Error.what() << endl;
            delete pImage;
            return false;
        }

        glTexImage2D(types[i], 0, GL_RGB, pImage->columns(), pImage->rows(), 0, GL_RGBA, GL_UNSIGNED_BYTE, blob.data());
        
        delete pImage;
    }    
    
    glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
    glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
    glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
    glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
    glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_R, GL_CLAMP_TO_EDGE);           
    
    return true;
}
Ejemplo n.º 14
0
void updateNoCopy_wrapper(Magick::Blob& blob, std::string& data) {
    std::string str;
    char* w = new char[data.size() + 1];
    std::copy(str.begin(), str.end(), w);
    w[str.size()] = '\0';
    blob.updateNoCopy(w,data.size(),Magick::Blob::NewAllocator);
}
Ejemplo n.º 15
0
 ResizeTest(std::string fileName) {
     source.loadFile(fileName);
     for (int i=1; i<99; ++i) {
         Magick::Image image = source.getImage();
         image.magick("JPEG");
         image.quality(50);
         Magick::Geometry resizeGeometry;
         resizeGeometry.percent(true);
         resizeGeometry.width(i);
         resizeGeometry.height(i);
         image.resize(resizeGeometry);
         Magick::Blob blob;
         image.write(&blob);
         imghash::Source target((char*)blob.data(), blob.length());
         images.push_back(target);
     }
 }
Ejemplo n.º 16
0
void photoalbum::api::map::map_tile_km(
        const jsonrpc::request& request,
        jsonrpc::result&        result,
        sqlite::connection&     conn
        )
{
    const std::string region = request.params().get<std::string>(0);
    const int eastings = request.params().get<int>(1);
    const int northings = request.params().get<int>(2);

    photoalbum::map::tile_data_db data_db;
    db::get(
            conn,
            region,
            eastings/10,
            northings/10,
            data_db
            );
    try
    {
        Magick::Image image(Magick::Blob(
            reinterpret_cast<const void*>(&(data_db.data[0])),
            data_db.data.size()
            )
            );
        Magick::Geometry out_size(
            image.size().width()/5,
            image.size().height()/5
            );
        Magick::Image out_image(out_size, Magick::Color(255,255,255));

        int off_x = -(out_size.width() * (eastings%5));
        int off_y = -(out_size.height() * (4 - (northings%5)));
        out_image.composite(image, off_x, off_y);

        Magick::Blob blob;
        out_image.write(&blob, "PNG");
        png_data(result.data()).data() = base64::encode(
            reinterpret_cast<const unsigned char*>(blob.data()),
            blob.length()
            );
    }
    catch(const std::exception& e)
    {
    }
}
Ejemplo n.º 17
0
std::unique_ptr<Image> loadImageFromFile(const std::string& fname)
{
    try {
        Magick::Image image(config().imagesPath + fname);
        Magick::Blob blob;
        image.write(&blob, "RGBA");
        std::vector<uint8_t> data(blob.length());
        memcpy(&data.front(), blob.data(), blob.length());
        std::cout << "Loaded image " << fname << std::endl;
        return std::unique_ptr<Image>(new Image(std::move(data),
            Size(image.size().width(), image.size().height())));
    } catch (const Magick::Exception& ex) {
        std::cerr << "Error while trying to load image: " << fname
            << ", reason: " << ex.what() << std::endl;
        return defaultImage();
    }
}
Ejemplo n.º 18
0
void ImageItem::rotate(short degrees)
{
  if (!degrees)
    return;

  QString file = absoluteFilePath();
  Magick::Image image;
  image.read(file.toStdString());
  image.rotate(degrees);
  image.write(file.toStdString());

  Magick::Blob buffer;
  image.write(&buffer);

  QImage thumbnail;
  thumbnail.loadFromData((const uchar*) buffer.data(), buffer.length());
  thumbnail.save(absoluteThumbPath(), "JPEG");
}
Ejemplo n.º 19
0
Glib::RefPtr<Gdk::Pixbuf> createCoverPixBufWithOverlay(const AlbumArt& albumArt, int32_t size)
{
    try
    {
        std::stringstream finalGeometry;
        finalGeometry << size << "x" << size;

        std::stringstream intermediateGeometry;
        intermediateGeometry << overlayWidth << "x" << overlayHeight << "!";
        
        std::stringstream albumArtGeometry;
        albumArtGeometry << coverWidth << "x" << coverHeight << "!";

        Magick::Blob coverImageBlob(&(albumArt.getData().front()), albumArt.getData().size());
        Magick::Image coverImage(coverImageBlob);
        coverImage.scale(Magick::Geometry(albumArtGeometry.str()));

        Magick::Blob cdCaseBlob(cdCaseData, sizeof(cdCaseData));
        Magick::Image cdCase(cdCaseBlob, Magick::Geometry(intermediateGeometry.str()), "PNG");

        Magick::Quantum maxRgb;
        {using namespace Magick; maxRgb = MaxRGB;} // Magick::MaxRGB; quits with the compile-time error "'Quantum' was not declared in this scope"
        Magick::Image result(Magick::Geometry(intermediateGeometry.str()), Magick::Color(0, 0, 0, maxRgb));
        result.composite(coverImage, coverImageOffsetX, coverImageOffsetY, Magick::CopyCompositeOp);
        result.composite(cdCase, 0, 0, Magick::OverCompositeOp);
        result.scale(Magick::Geometry(finalGeometry.str()));

        Magick::Blob data;
        result.write(&data, "PNG");

        Glib::RefPtr<Gdk::PixbufLoader> loader = Gdk::PixbufLoader::create();
        loader->set_size(size, size);
        loader->write((guint8*)data.data(), data.length());
        Glib::RefPtr<Gdk::Pixbuf> pixBuf = loader->get_pixbuf();
        loader->close();

        return pixBuf;
    }
    catch (Magick::Exception& e)
    {
        log::warn("Creating cover with overlay failed: %s", e.what());
        return createCoverPixBuf(albumArt, size);
    }
}
Ejemplo n.º 20
0
void loadTexture(const char* name, GLuint &textID) 
{
    Magick::Image* myImage = new Magick::Image( name );
    Magick::Blob myBlob;

    myImage->write(&myBlob, "RGBA");
    
    glGenTextures(1, &textID);
    glBindTexture(GL_TEXTURE_2D, textID);
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); //or GL_NEAREST
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); //or GL_NEAREST
    glTexImage2D(GL_TEXTURE_2D, 
                 0, 
                 GL_RGBA,
                 myImage->columns(),
                 myImage->rows(), 0,
                 GL_RGBA,
                 GL_UNSIGNED_BYTE, myBlob.data());    
}
Ejemplo n.º 21
0
QImage ImageFactoryThumbnail::image()
{
    // try loading cached thumbnail of exported image
    Magick::Image thumbnail = m_config->db()->cache().retrieve(m_config->config(),true);
    if( !thumbnail.isValid() )
    {
        // fallback to loading cached thumbnail embedded in RAW image
        thumbnail = m_config->db()->cache().retrieve(m_config->raw(),true);
        if( !thumbnail.isValid() )
        {
            qDebug() << "ImageFactoryThumbnail::image() invalid" << m_config->raw();
            return QImage();
        }
    }

    Magick::Blob blob;
    thumbnail.write( &blob );
    qDebug() << "ImageFactoryThumbnail::image()" << thumbnail.size().width() << "x" << thumbnail.size().height();
    return QImage::fromData( QByteArray( static_cast<const char*>(blob.data()), blob.length() ) );
}
Ejemplo n.º 22
0
ItemSequence_t
ExifFunction::evaluate(
  const ExternalFunction::Arguments_t& aArgs,
  const StaticContext*                          aSctxCtx,
  const DynamicContext*                         aDynCtx) const
{
  Magick::Image lImage;
  ImageFunction::getOneImageArg(aDynCtx, aArgs, 0, lImage);
  String lTag = ImageFunction::getOneStringArg(aArgs, 1);
  std::string lTagWithExif("EXIF:");
  lTagWithExif += lTag.c_str(); 
  Magick::Blob lBlob;
  lImage.write(&lBlob); 
  long lBlobLength = (long) lBlob.length();
  std::string lExifValue = GetExifValue(lBlob.data(), &lBlobLength, lTagWithExif);
  if (lExifValue == "") {
    return ItemSequence_t(new EmptySequence());
  }
  return ItemSequence_t(new SingletonItemSequence(
      theModule->getItemFactory()->createString(String(lExifValue)))); 
}
Ejemplo n.º 23
0
void Night::printAltAz (int year, int month, int day, XmlRpc::HttpParams *params, const char* &response_type, char* &response, size_t &response_length)
{
	response_type = "image/jpeg";

	time_t from;
	int64_t duration;

	getNightDuration (year, month, day, from, duration);

	time_t end = from + duration;

	rts2db::ImageSetDate is = rts2db::ImageSetDate (from, end);
	is.load ();

	int s = params->getInteger ("s", 250);
	AltAz altaz = AltAz (s, s);
	altaz.plotAltAzGrid ();

	for (rts2db::ImageSetDate::iterator iter = is.begin (); iter != is.end (); iter++)
	{
		struct ln_hrz_posn hrz;
		try
		{
			(*iter)->getCoordBestAltAz (hrz, rts2core::Configuration::instance ()->getObserver ());
			(*iter)->closeFile ();
			altaz.plotCross (&hrz, NULL, "green");
		}
		catch (rts2core::Error &er)
		{
			(*iter)->closeFile ();
		}
	}

	Magick::Blob blob;
	altaz.write (&blob, "jpeg");

	response_length = blob.length();
	response = new char[response_length];
	memcpy (response, blob.data(), response_length);
}
Ejemplo n.º 24
0
bool Texture::Load() {
    // generating a texture name
    glGenTextures(1, &mTextureObj);
    // binding the name
    glBindTexture(mTextureTarget, mTextureObj);

    Magick::Image* image = nullptr;
    Magick::Blob blob;


    try {
        image = new Magick::Image("mFilename");
        image->write(&blob, "RGBA");
    } catch (Magick::Error& error) {
        cerr << "Error Loading texture '" << mFilename << "': " << error.what() << endl;
        delete image;
        return false;
    }

    glTexImage2D(mTextureTarget,
                    0,
                    GL_RGB,
                    image->columns(),
                    image->rows(),
                    0, 
                    GL_RGBA,
                    GL_UNSIGNED_BYTE, blob.data());


    // setting parameters
    glTexParameteri(mTextureTarget, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
    glTexParameteri(mTextureTarget, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
    glTexParameteri(mTextureTarget, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
    glTexParameteri(mTextureTarget, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);

    delete image;
    return true;
}
Ejemplo n.º 25
0
QByteArray ApplicationHelper::getCaptcha(const QString& text, const int width, const int height)
{
    qsrand(QTime::currentTime().msec());

    Magick::InitializeMagick(NULL);

    Magick::Image image( QString("%1x%2").arg(width).arg(height).toStdString().c_str(), "white" );

    image.addNoise(Magick::GaussianNoise);

    image.fontPointsize(25);
    image.strokeColor("black");

    image.floodFillColor(Magick::Geometry(0, 0, 1, 1), Magick::ColorRGB(qrand() % 200, qrand() % 150, qrand() % 10 + 200));

    const QList<int> v{10, 10,10, 5,10, height - 20,10, height - 5,width - 10, 10,width - 10, 20,width - 10, height - 10,width - 10, height - 30};

    double * controlPoints = new double[v.size()];
    std::copy(v.begin(), v.end(), controlPoints);

    image.distort(Magick::PerspectiveDistortion, v.size(), controlPoints);

    image.annotate("\n" + text.toStdString(), Magick::Geometry(150, 110), Magick::NorthGravity);

    image.blur(1, 5);
    image.addNoise(Magick::GaussianNoise);
    image.opacity(0.3);

    //image.randomThreshold(Magick::Geometry(4,4));

    Magick::Blob blob;

    image.write(&blob, "PNG");

    delete[] controlPoints;

    return QByteArray((char *) blob.data(), blob.length());
}
Ejemplo n.º 26
0
void AltAzTarget::authorizedExecute (XmlRpc::XmlRpcSource *source, std::string path, XmlRpc::HttpParams *params, const char* &response_type, char* &response, size_t &response_length)
{
	// get new AltAz graph
	rts2json::AltAz altaz = rts2json::AltAz ();

	// plot its AltAz grid
	altaz.plotAltAzGrid ();

	struct ln_hrz_posn hrz;

	// retrieve from database set of all targets..
	rts2db::TargetSet ts = rts2db::TargetSet ();
	ts.load ();

	// iterate through the set, plot location of each target
	for (rts2db::TargetSet::iterator iter = ts.begin (); iter != ts.end (); iter++)
	{
	  	// retrieve target AltAz coordinates
		(*iter).second->getAltAz (&hrz);

		// and plot them with proper caption
		if (hrz.alt > -2)
			altaz.plotCross (&hrz, (*iter).second->getTargetName ());
	}

	// write image to blob as JPEG
	Magick::Blob blob;
	altaz.write (&blob, "JPEG");

	// set MIME response type
	response_type = "image/jpeg";

	// lenght of response
	response_length = blob.length();
	// create and fill response buffer
	response = new char[response_length];
	memcpy (response, blob.data(), response_length);
}
Ejemplo n.º 27
0
void CMagicKHelper::GetPhotoBinval( const tstring& strPhotoName, tstring& strBinval )
{
	try
	{
		CLogger::GetInstance()->PrintErrLog("begin getphotoBinval");
		Magick::Image imgSrc(strPhotoName);
		CLogger::GetInstance()->PrintErrLog("imgSrc()");
		Magick::Blob blob;

//		EnterCriticalSection(cs_);
		imgSrc.write(&blob);
//		LeaveCriticalSection(cs_);

		CLogger::GetInstance()->PrintErrLog("write()");
		unsigned int len = blob.length();
		strBinval.assign((const char*)blob.data(), blob.length());
		CLogger::GetInstance()->PrintErrLog("write()");
	}
	catch (std::exception &ex)
	{
		CLogger::GetInstance()->PrintErrLog("resize image failure  %s", ex.what());
	}
}
Ejemplo n.º 28
0
QImage ImageItem::previewRotate(short degrees)
{
  Magick::Image image;
  if (m_tempImage) {
    m_tempImage->open();
    image.read(m_tempImage->fileName().toStdString());
    image.magick("jpg");
  } else {
    image.read(absoluteFilePath().toStdString());
    m_tempImage = new QTemporaryFile(qApp);
    m_tempImage->open();
  }

  image.rotate(degrees);
  Magick::Blob buffer;
  image.write(&buffer);

  QImage output;
  output.loadFromData((const uchar*) buffer.data(), buffer.length());
  output.save(m_tempImage, "JPEG");
  m_tempImage->close();
  return output;
}
Ejemplo n.º 29
0
ImagePtr MagickImageLoader::load(std::istream& stream) {
    if (stream.fail())
        throw Exception("[MagickImageLoader::load] invalid stream given");

    long int stream_size = streamSize(stream);
    if (stream_size < 1)
        throw Exception("[MagickImageLoader::load] empty stream given");

    boost::scoped_array<char> tmp(new char[stream_size]);
    Magick::Blob blob;
    blob.updateNoCopy(tmp.get(), stream_size);
    try {
        Magick::Image image;
        image.density("10");
        image.ping(blob);
        convertImageDpi(image);
        image.read(blob);

        return load(image);
    } catch (Magick::Exception &e) {
        cfError(MODULE_RDIB) << e.what();
        throw Exception("[MagickImageLoader::load] failed");
    }
}
Ejemplo n.º 30
0
CTexture::CTexture(const std::string& filename)
   : texture(GL_TEXTURE_2D)
{
   Log::msg("loading texture from ", filename);
   Magick::Image img;
   Magick::Blob blob;
   img.read(std::string("aersy-res/") + filename);
   mHasAlpha = !img.isOpaque();
   img.write(&blob, mHasAlpha ? "RGBA" : "RGB");
   bind();
   const GLenum format = mHasAlpha ? GL_RGBA : GL_RGB;
   glTexImage2D(GL_TEXTURE_2D, 0, format, img.columns(), img.rows(), 0, format, GL_UNSIGNED_BYTE, blob.data());
   glGenerateMipmap(_target);
   glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
   glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
   unbind();
}