Ejemplo n.º 1
0
static Magick::Image* ImageCtor_layer(iTJSDispatch2* lay) {
	unsigned int w, h;
	unsigned char *p;
	long s;
	if (!lay || TJS_FAILED(lay->IsInstanceOf(0, 0, 0, TJS_W("Layer"), lay)))
		TVPThrowExceptionMessage(TJS_W("Magick::Image: _layer method needs Layer-instance param."));

	// レイヤサイズ取得
	tTJSVariant tmp[2];
	lay->PropGet(0, TJS_W("imageWidth"),  0, &tmp[0], lay);
	lay->PropGet(0, TJS_W("imageHeight"), 0, &tmp[1], lay);
	w = static_cast<unsigned int>((tTVInteger)tmp[0]);
	h = static_cast<unsigned int>((tTVInteger)tmp[1]);

	// バッファ取得
	lay->PropGet(0, TJS_W("mainImageBuffer"),         0, &tmp[0], lay);
	lay->PropGet(0, TJS_W("mainImageBufferPitch"),    0, &tmp[1], lay);
	p = reinterpret_cast<unsigned char*>((tTVInteger)tmp[0]);
	s = static_cast<long               >((tTVInteger)tmp[1]);

	typedef Magick::PixelPacket PixelT;
	typedef Magick::Color ColorT;
	Magick::Image *image = new Magick::Image(Magick::Geometry(w, h), ColorT());
	image->modifyImage();
	image->type(Magick::TrueColorMatteType);
	// コピー
	if (sizeof(Magick::Quantum) == 1) {
		// 8bit quantum 専用
		for (unsigned int y = 0; y < h; y++, p+=s) {
			unsigned char *cp = p;
			PixelT *q = image->getPixels(0, y, w, 1); 
			for (int i = w; i > 0; i--, cp+=4) {
				*q++ = ColorT(static_cast<Magick::Quantum>(cp[2]),
							  static_cast<Magick::Quantum>(cp[1]),
							  static_cast<Magick::Quantum>(cp[0]),
							  ~static_cast<Magick::Quantum>(cp[3]));
			}
			image->syncPixels();
		}
	} else {
		// それ以外はdouble経由なので重い
		for (unsigned int y = 0; y < h; y++, p+=s) {
			unsigned char *cp = p;
			PixelT *q = image->getPixels(0, y, w, 1); 
			for (int i = w; i > 0; i--, cp+=4) {
				Magick::ColorRGB col(cp[2]/255.0, cp[1]/255.0, cp[0]/255.0);
				col.alpha(cp[3]/255.0);
				*q++ = col;
			}
			image->syncPixels();
		}
	}
	return image;
}
Ejemplo n.º 2
0
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();
}
Ejemplo n.º 3
0
void DrvSDL::WriteGif() {
    std::list<Magick::Image> gif;

    int num = 0;
    for(std::list<Magick::Blob>::iterator it = image_.begin(); it != image_.end(); it++) {
        Magick::Image image;
        image.magick("RGB");
        image.depth(32);
        image.size(Magick::Geometry(cols_ * pixels.x, rows_ * pixels.y));
        Magick::PixelPacket *pixel_cache = image.getPixels(0, 0, cols_ * pixels.x, rows_ * pixels.y);
        for(int n = 0; n < rows_ * pixels.y * cols_ * pixels.x; n++) {
            int col = ((int *)(*it).data())[n];
            uint8_t *rgb = (uint8_t *) &col;
            Magick::PixelPacket *gif_pixel = pixel_cache + n;
            *gif_pixel = Magick::ColorRGB(rgb[0] / 256.0, rgb[1] / 256.0, rgb[2] / 256.0);
        }
        image.syncPixels();
        gif.push_back(image);
        LCDInfo("Image %d", num++);
    }
    LCDInfo("Writing GIF image...");
    for_each(gif.begin(), gif.end(), Magick::animationDelayImage(ani_speed_ / 10));
    Magick::writeImages(gif.begin(), gif.end(), gif_file_);
}
Ejemplo n.º 4
0
void imageToPixmap() {
	image.flip();
	pixmap = image.getPixels(0, 0, image.columns(), image.rows());
}
Ejemplo n.º 5
0
Image::Image(GLuint filter, string filename, string alphaFilename) :
    filter(filter)
{

#if IMAGE_PRINT
	cout << "Loading image " << filename << "..." << endl;
#endif

	Magick::Image image;
	image.read(filename);
	Magick::PixelPacket* data = image.getPixels(0, 0, image.columns(), image.rows());
	width = image.columns();
	height = image.rows();

#if IMAGE_PRINT
	cout << "  Width: " << width << endl;
	cout << "  Height: " << height << endl;
#endif

	// Convert to floats and flip vertically
	pixels = new Color[width * height];
	for (int x = 0; x < width; x++) {
		for (int y = 0; y < height; y++) {
			int idest = x + y * width;
			int isrc = x + (height - 1 - y) * width;
			pixels[idest] = {
				(float)data[isrc].red / USHRT_MAX,
				(float)data[isrc].green / USHRT_MAX,
				(float)data[isrc].blue / USHRT_MAX,
				1.f - (float)data[isrc].opacity / USHRT_MAX
			};
		}
	}

	// Load alpha map
	if (alphaFilename != "") {

#if IMAGE_PRINT
		cout << "  Alpha map found: " << alphaFilename << endl;
#endif

		Magick::Image aImage;
		aImage.read(alphaFilename);
		Magick::PixelPacket* aData = aImage.getPixels(0, 0, aImage.columns(), aImage.rows());
		int aWidth = aImage.columns();
		int aHeight = aImage.rows();

		for (int x = 0; x < width; x++) {
			for (int y = 0; y < height; y++) {
				if (x >= aWidth || y >= aHeight)
					continue;
				int idest = x + y * width;
				int isrc = x + (aHeight - 1 - y) * aWidth;
				pixels[idest].a((float)aData[isrc].red / USHRT_MAX);
			}
		}

	}

	createTexture();

}