Beispiel #1
0
    void WriteImage(
            // source image data in RGB24 format
            uint8_t *srcData, int srcWidth, int srcHeight, 
            // offset
            int offsetX, int offsetY,
            // resize
            int tgtWidth, int tgtHeight)
    {
        typedef boost::shared_ptr<cairo_surface_t> SurfacePtr;

        cairo_save(ctx_);
        cairo_translate(ctx_, offsetX, offsetY);
        cairo_scale(ctx_, 
                static_cast<double>(tgtWidth)/srcWidth, 
                static_cast<double>(tgtHeight)/srcHeight);

        {
            int stride = cairo_format_stride_for_width(CAIRO_FORMAT_RGB24, srcWidth);
            SurfacePtr srcSurface(
                    cairo_image_surface_create_for_data(
                        srcData, CAIRO_FORMAT_RGB24, srcWidth, srcHeight, stride),
                    cairo_surface_destroy);
            cairo_set_source_surface(ctx_, srcSurface.get(), 0, 0);
        }

        cairo_paint(ctx_);
        cairo_restore(ctx_);
    }
Beispiel #2
0
M4Surface *OrionMenuView::createThumbnail() {
	M4Surface srcSurface(_vm->_screen->width(), _vm->_screen->height());
	M4Surface *result = new M4Surface(_vm->_screen->width() / 3, _vm->_screen->height() / 3);

	// Translate the scene data

	_vm->_scene->onRefresh(NULL, &srcSurface);
	byte *srcP = (byte *)srcSurface.pixels;
	byte *destP = (byte *)result->pixels;

	for (int yCtr = 0; yCtr < _vm->_scene->height() / 3; ++yCtr, srcP += g_system->getWidth() * 3) {
		byte *src0P = srcP;
		byte *src1P = srcP + _vm->_screen->width();
		byte *src2P = src1P + _vm->_screen->width();

		for (int xCtr = 0; xCtr < result->width(); ++xCtr) {
			*destP = (byte)((uint32)((
				*src0P + *(src0P + 1) + *(src0P + 2) +
				*src1P + *(src1P + 1) + *(src1P + 2) +
				*src2P + *(src2P + 1) + *(src2P + 2)) / 9));
			if (*destP == 0)
				*destP = 21;

			++destP;
			src0P += 3;
			src1P += 3;
			src2P += 3;
		}
	}

	// Translate the game interface view - since it's using standard colors that can't be
	// averaged, simply take the top left pixel of every 3x3 pixel block

	_vm->_interfaceView->onRefresh(NULL, &srcSurface);
	destP = (byte *)result->pixels + (_vm->_screen->width() / 3) * (_vm->_interfaceView->bounds().top / 3);

	int yStart = _vm->_interfaceView->bounds().top;
	int yEnd = MIN(_vm->_screen->height() - 1, (int) _vm->_interfaceView->bounds().bottom - 1);
	for (int yCtr = yStart; yCtr <= yEnd; yCtr += 3) {
		srcP = (byte *)srcSurface.pixels + (yCtr * _vm->_screen->width());

		for (int xCtr = 0; xCtr < result->width(); ++xCtr, srcP += 3)
			*destP++ = *srcP;
	}

	return result;
}