예제 #1
0
파일: STL.cpp 프로젝트: 0xPr0xy/ImageMagick
// Frame image
Magick::frameImage::frameImage( const Magick::Geometry &geometry_ )
  : _width( geometry_.width() ),
    _height( geometry_.height() ),
    _outerBevel( geometry_.xOff() ),
    _innerBevel( geometry_.yOff() )
{
}
예제 #2
0
 Magick::Geometry scale (const Magick::Geometry& geometry) const
 {
   return Magick::Geometry (x_scale_ * geometry.width (),
                            y_scale_ * geometry.height (),
                            x_scale_ * geometry.xOff (),
                            y_scale_ * geometry.yOff ());
 }
예제 #3
0
파일: STL.cpp 프로젝트: 0xPr0xy/ImageMagick
Magick::floodFillColorImage::floodFillColorImage( const Magick::Geometry &point_,
                                                  const Magick::Color &fillColor_ )
  : _x(point_.xOff()),
    _y(point_.yOff()),
    _fillColor(fillColor_),
    _borderColor()
{
}
예제 #4
0
파일: STL.cpp 프로젝트: 0xPr0xy/ImageMagick
Magick::floodFillTextureImage::floodFillTextureImage( const Magick::Geometry &point_,
                                                      const Magick::Image &texture_ )
  : _x(point_.xOff()),
    _y(point_.yOff()),
    _texture(texture_),
    _borderColor()
{
}
예제 #5
0
파일: STL.cpp 프로젝트: 0xPr0xy/ImageMagick
Magick::compositeImage::compositeImage( const Magick::Image &compositeImage_,
                                        const Magick::Geometry &offset_,
                                        Magick::CompositeOperator compose_  )
  : _compositeImage( compositeImage_ ),
    _xOffset ( offset_.xOff() ),
    _yOffset ( offset_.yOff() ),
    _compose ( compose_ )
{
}
예제 #6
0
int Magick::operator <  ( const Magick::Geometry& left_,
			  const Magick::Geometry& right_ )
{
  return (
	  ( left_.width() * left_.height() )
	  <
	  ( right_.width() * right_.height() )
	  );
}
예제 #7
0
Magick::floodFillTextureImage::floodFillTextureImage(
  const Magick::Geometry &point_,const Magick::Image &texture_,
  const Magick::Color &borderColor_,const bool invert_)
  : _x(point_.xOff()),
    _y(point_.yOff()),
    _texture(texture_),
    _borderColor(borderColor_),
    _invert(invert_)
{
}
	//==============================================================================================
	const Magick::Geometry* MagickGeometry::CreateGeometry()
	{
		Magick::Geometry* result = new Magick::Geometry(Width, Height, Math::Abs(X), Math::Abs(Y), X < 0, Y < 0);
		result->percent(IsPercentage);
		result->aspect(IgnoreAspectRatio);
		result->less(Less);
		result->greater(Greater);

		return result;
	}
예제 #9
0
	void KBuild::Symbol::Frame::getGeometry(Magick::Geometry& geo) const {
		using namespace Magick;

		const Image atlas = parent->parent->atlases[getAtlasIdx()].second;

		float_type w0 = atlas.columns();
		float_type h0 = atlas.rows();

		geo.xOff(size_t( floor(w0*atlas_bbox.x()) ));
		geo.yOff(size_t( floor(h0*atlas_bbox.y()) ));
		geo.width(size_t( floor(w0*atlas_bbox.w() + 0.5) ));
		geo.height(size_t( floor(h0*atlas_bbox.h() + 0.5) ));
	}
예제 #10
0
파일: main.cpp 프로젝트: robotology/yarp
void copyImage(Magick::Image& src,
               yarp::sig::ImageOf<yarp::sig::PixelRgb>& dest) {
    Magick::Geometry g = src.size();
    int h = g.height();
    int w = g.width();
    src.depth(8);
    dest.resize(w,h);
    for (int i=0; i<h; i++) {
        // must transfer row by row, since YARP may use padding in representation
        Magick::PixelPacket *packet = src.getPixels(0,i,w,1);
        src.writePixels(Magick::RGBQuantum,(unsigned char *)(&dest.pixel(0,i)));
    }
    src.syncPixels();
}
예제 #11
0
void Magick::Options::page ( const Magick::Geometry &pageSize_ )
{
  if ( !pageSize_.isValid() )
    _imageInfo->page=(char *) RelinquishMagickMemory(_imageInfo->page);
  else
    Magick::CloneString( &_imageInfo->page, pageSize_ );
}
예제 #12
0
void Magick::Options::density ( const Magick::Geometry &density_ )
{
  if ( !density_.isValid() )
    _imageInfo->density=(char *) RelinquishMagickMemory(_imageInfo->density);
  else
    Magick::CloneString( &_imageInfo->density, density_ );
}
예제 #13
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);
     }
 }
예제 #14
0
bool convert::resize( long numOfPix, const string &fIN, const string &fOUT ) {
  string outf;
  if ( fOUT == "" ) outf = fIN;
  else outf = fOUT;
#ifdef HAVE_MAGICK
  Magick::Image img;
  try {
    img.ping( fIN );
    Magick::Geometry sz = img.size();
    uint w = sz.width(), h = sz.height();
    if ( w*h <= numOfPix ) return true;
    double factor = sqrt((double)numOfPix/(double)(w*h));
    stringstream ss;
    ss << floor(w*factor) << "x" << floor(h*factor) << ">";   
    img.read( fIN );
    img.scale( ss.str() );
    img.write( outf );
    return true;
  } catch ( Magick::Exception &ex ) {
    cerr << " Exception while reading/resizing image: " << ex.what() << endl;
    return false;
  }
#else // ! HAVE_MAGICK++
  string cmd("-resize");
  stringstream ss;
  ss << numOfPix << "@> ";
  
  int pid = fork();
  int status;
  switch( pid ) { 
    case 0:
      execl( pathToConvert.c_str(), fIN.c_str(), cmd.c_str(), ss.str().c_str(), outf.c_str(), (char *) NULL );
      return false;
      break;
    default:
      waitpid( pid, &status, 0 );
      return WIFEXITED( status );
  }
#endif // HAVE_MAGICK
}
예제 #15
0
MagickPPExport int Magick::operator == (const Magick::Geometry& left_,
  const Magick::Geometry& right_)
{
  return((left_.aspect() == right_.aspect()) &&
    (left_.fillArea() == right_.fillArea()) &&
    (left_.greater() == right_.greater()) &&
    (left_.height() == right_.height()) &&
    (left_.isValid() == right_.isValid()) &&
    (left_.less() == right_.less()) &&
    (left_.limitPixels() == right_.limitPixels()) &&
    (left_.percent() == right_.percent()) &&
    (left_.width() == right_.width()) &&
    (left_.xNegative() == right_.xNegative()) &&
    (left_.xOff() == right_.xOff()) &&
    (left_.yNegative() == right_.yNegative()) &&
    (left_.yOff() == right_.yOff()));
}
예제 #16
0
  void TimeLapseCapture::imageCaptured(QString format, Magick::Blob blob, Magick::Geometry sizeHint) {
    bool readRawFromFile = false;

    QString framePath = output.path() + QDir::separator()
      + leadingZeros(capturedCnt, FRAME_FILE_LEADING_ZEROS) + "_" + leadingZeros(capturedSubsequence, 2);

    if (format == "RGB") {
      if (storeRawImages) {
        // store RAW RGB data in PPM format
        QString pgmHeader = QString("P6\n%1 %2\n255\n").arg(sizeHint.width()).arg(sizeHint.height());
        std::string headerStr = pgmHeader.toStdString();
        const char *headerBytes = headerStr.c_str();
        size_t headerLen = strlen(headerBytes);

        if (shutterSpdAlg != NULL && capturedSubsequence == 0) {
          Magick::Image capturedImage;
          capturedImage.read(blob, sizeHint, 8, "RGB");
          shutterSpdAlg->update(capturedImage);
        }

        framePath += ".ppm";
        QFile file(framePath);
        file.open(QIODevice::WriteOnly);
        file.write(headerBytes, headerLen);
        file.write((char*) blob.data(), blob.length());
        file.close();
      } else {
        // convert RGB data to JPEG
        Magick::Image capturedImage;
        capturedImage.read(blob, sizeHint, 8, "RGB");

        if (shutterSpdAlg != NULL && capturedSubsequence == 0) {
          shutterSpdAlg->update(capturedImage);
        }

        QDateTime now = QDateTime::currentDateTime();
        QString exifDateTime = now.toString("yyyy:MM:dd HH:mm:ss");\

        // ImageMagick don't support writing of exif data
        // TODO: setup exif timestamp correctly
        capturedImage.attribute("EXIF:DateTime", exifDateTime.toStdString());
        //capturedImage.defineValue("EXIF", "DateTime", exifDateTime.toStdString());

        capturedImage.compressType(Magick::JPEGCompression);
        capturedImage.magick("JPEG");
        framePath += ".jpeg";
        capturedImage.write(framePath.toStdString());

      }
    } else {

      if (shutterSpdAlg != NULL && capturedSubsequence == 0) {
        try {
          Magick::Image capturedImage;
          capturedImage.read(blob, format.toStdString());
          shutterSpdAlg->update(capturedImage);
        } catch (const std::exception &e) {
          err << "Failed to decode captured image (" << format << "): " << QString::fromUtf8(e.what()) << endl;
          readRawFromFile = true;
        }
      }

      // store other formats in device specific format 
      framePath += "." + format;
      QFile file(framePath);
      file.open(QIODevice::WriteOnly);
      file.write((char*) blob.data(), blob.length());
      file.close();

      if (readRawFromFile && shutterSpdAlg != NULL && capturedSubsequence == 0) {
        /* I don't understand ImageMagick correctly, but it fails with reading RAW files
         * from memory blob, but reading from file works (sometimes). 
         * Maybe, it don't support delegating (dcraw, ufraw...) with memory data...
         */
        try {
          Magick::Image capturedImage;
          capturedImage.read(framePath.toStdString());
          shutterSpdAlg->update(capturedImage);
        } catch (const std::exception &e) {
          err << "Failed to decode captured image (" << framePath << "): " << QString::fromUtf8(e.what()) << endl;
        }
      }
    }

    verboseOutput << "Captured frame saved to " << framePath << endl;

    capturedSubsequence++;
  }
		Initialize(x, y, (int)percentageWidth, (int)percentageHeight, true);
	}
	//==============================================================================================
	MagickGeometry::MagickGeometry(Rectangle rectangle)
	{
		Initialize(rectangle.X, rectangle.Y, rectangle.Width, rectangle.Height, false);
	}
	//==============================================================================================
	MagickGeometry::MagickGeometry(String^ value)
	{
		Throw::IfNullOrEmpty("value", value);

		std::string geometrySpec;
		Marshaller::Marshal(value, geometrySpec);

		Magick::Geometry geometry = Magick::Geometry(geometrySpec);
		Throw::IfFalse("geometry", geometry.isValid(), "Invalid geometry specified.");

		Initialize(geometry);
	}
	//==============================================================================================
	bool MagickGeometry::operator == (MagickGeometry^ left, MagickGeometry^ right)
	{
		return Object::Equals(left, right);
	}
	//==============================================================================================
	bool MagickGeometry::operator != (MagickGeometry^ left, MagickGeometry^ right)
	{
		return !Object::Equals(left, right);
	}
	//==============================================================================================
DefinitionFile * ResourcePackerScreen::ProcessPSD(const String & processDirectoryPath, const String & psdPathname, const String & psdName)
{
	int32 maxTextureSize = 1024;
	if (CommandLineParser::Instance()->IsFlagSet("--tsize2048"))
	{
		maxTextureSize = 2048;
	}
	
	// TODO: Check CRC32
	std::vector<Magick::Image> layers;
	
	String psdNameWithoutExtension = FileSystem::ReplaceExtension(psdName, "");
	
	try 
	{
		Magick::readImages(&layers, psdPathname);
		
		if (layers.size() == 0)
		{
			Logger::Error("Number of layers is too low: %s", psdPathname.c_str());
			return 0;
		}
		
		if (layers.size() == 1)
		{
			layers.push_back(layers[0]);
		}
		
		//Logger::Debug("psd file: %s wext: %s", psdPathname.c_str(), psdNameWithoutExtension.c_str());
		
		int width = (int)layers[0].columns();
		int height = (int)layers[0].rows();
		
		for(int k = 1; k < (int)layers.size(); ++k)
		{
			Magick::Image & currentLayer = layers[k];
			
			
			/* 
			MagickCore::ResetImagePropertyIterator(currentLayer.image());
			const char * property = MagickCore::GetNextImageProperty(currentLayer.image());
			if (property != (const char *) NULL)
			{
				printf("  Properties:\n");
				while (property != (const char *) NULL)
				{
					printf("    %c",*property);
					if (strlen(property) > 1)
						printf("%s: ",property+1);
					if (strlen(property) > 80)
						printf("\n");

					const char * value = MagickCore::GetImageProperty(currentLayer.image(), property);
					if (value != (const char *) NULL)
						printf("%s\n",value);
					property = MagickCore::GetNextImageProperty(currentLayer.image());
				}
			} */
			
			
			
			currentLayer.crop(Magick::Geometry(width,height, 0, 0));
			currentLayer.magick("PNG");
			String outputFile = processDirectoryPath + String("/") + psdNameWithoutExtension;
			outputFile += String(Format("%d.png", k - 1));
			currentLayer.write(outputFile);
		}
		
		
		DefinitionFile * defFile = new DefinitionFile;
		defFile->filename = processDirectoryPath + String("/") + psdNameWithoutExtension + String(".txt");
		// Logger::Debug("filename: %s", defFile->filename.c_str());
		defFile->spriteWidth = width;
		defFile->spriteHeight = height;
		defFile->frameCount = (int)layers.size() -1;
		defFile->frameRects = new Rect2i[defFile->frameCount];
		
		for(int k = 1; k < (int)layers.size(); ++k)
		{
			Magick::Image & currentLayer = layers[k];
			Magick::Geometry bbox = currentLayer.page();
			int xOff = (int)bbox.xOff();
			if (bbox.xNegative())
				xOff = -xOff;
			int yOff = (int)bbox.yOff();
			if (bbox.yNegative())
				yOff = -yOff;
			
			defFile->frameRects[k - 1] = Rect2i(xOff, yOff, (int32)bbox.width(), (int32)bbox.height());
			
			//printf("Percent: %d Aspect: %d Greater: %d Less: %d\n", (int)bbox.percent(), (int)bbox.aspect(), (int)bbox.greater(), (int)bbox.less());
			
			if ((defFile->frameRects[k - 1].dx >= maxTextureSize) || (defFile->frameRects[k - 1].dy >= maxTextureSize))
			{
				
				printf("* WARNING * - frame of %s layer %d is bigger than maxTextureSize(%d) layer exportSize (%d x %d) FORCE REDUCE TO (%d x %d). Bewarned!!! Results not guaranteed!!!\n", psdName.c_str(), k - 1, maxTextureSize
					   , defFile->frameRects[k - 1].dx, defFile->frameRects[k - 1].dy, width, height);
				defFile->frameRects[k - 1].dx = width;
				defFile->frameRects[k - 1].dy = height;
			}
				
			
			
			if (CommandLineParser::Instance()->IsFlagSet("--add0pixel"))
			{
				
			}else if (CommandLineParser::Instance()->IsFlagSet("--add1pixel"))
			{
				defFile->frameRects[k - 1].dx++;
				defFile->frameRects[k - 1].dy++;
			}
			else if (CommandLineParser::Instance()->IsFlagSet("--add2pixel"))
			{
				defFile->frameRects[k - 1].dx+=2;
				defFile->frameRects[k - 1].dy+=2;
			}
			else if (CommandLineParser::Instance()->IsFlagSet("--add4pixel"))
			{
				defFile->frameRects[k - 1].dx+=4;
				defFile->frameRects[k - 1].dy+=4;
			}
			else if(CommandLineParser::Instance()->IsFlagSet("--add2sidepixel"))
			{
				defFile->frameRects[k - 1].dx+=2;
				defFile->frameRects[k - 1].dy+=2;
			}
			else
			{
				defFile->frameRects[k - 1].dx++;
				defFile->frameRects[k - 1].dy++;	
			}
		}
		
		return defFile;
	}
	catch( Magick::Exception &error_ )
    {
		std::cout << "Caught exception: " << error_.what() << " file: "<< psdPathname << std::endl;
		return 0;
    }
	return 0;
}
예제 #19
0
파일: STL.cpp 프로젝트: 0xPr0xy/ImageMagick
// Roll image (rolls image vertically and horizontally) by specified
// number of columnms and rows)
Magick::rollImage::rollImage( const Magick::Geometry &roll_ )
  : _columns( roll_.width() ),
    _rows( roll_.height() )
{
}