Image *flattenImages(const Image *image, ExceptionInfo *exception) { #ifdef _MAGICKCORE_LAYER_H return MergeImageLayers((Image *)image, FlattenLayer, exception); #else return FlattenImages(image, exception); #endif }
/** * Merge all the images into a single image. * * Ruby usage: * - @verbatim ImageList#flatten_images @endverbatim * * Notes: * - Can't use "flatten" because that's an Array method * * @param self this object * @return the new image */ VALUE ImageList_flatten_images(VALUE self) { Image *images, *new_image; ExceptionInfo *exception; images = images_from_imagelist(self); exception = AcquireExceptionInfo(); #if defined(HAVE_ENUM_FLATTENLAYER) new_image = MergeImageLayers(images, FlattenLayer, exception); #else new_image = FlattenImages(images, exception); #endif rm_split(images); rm_check_exception(exception, new_image, DestroyOnError); (void) DestroyExceptionInfo(exception); rm_ensure_result(new_image); return rm_image_new(new_image); }
bool ScImgDataLoader_GMagick::loadPicture(const QString& fn, int /*page*/, int res, bool thumbnail) { if (!QFile::exists(fn)) return false; bool valid = m_imageInfoRecord.isRequest; QMap<int, ImageLoadRequest> req = m_imageInfoRecord.RequestProps; initialize(); m_imageInfoRecord.RequestProps = req; m_imageInfoRecord.isRequest = valid; m_imageInfoRecord.type = ImageTypeOther; m_imageInfoRecord.exifDataValid = false; m_imageInfoRecord.layerInfo.clear(); m_imageInfoRecord.PDSpathData.clear(); initGraphicsMagick(); ExceptionInfo exception; GetExceptionInfo(&exception); ImageInfo *image_info = CloneImageInfo(0); strcpy(image_info->filename, fn.toUtf8().data()); image_info->units = PixelsPerInchResolution; Image *image = ReadImage(image_info, &exception); if (exception.severity != UndefinedException) CatchException(&exception); if (!image) { qCritical() << "Failed to read image" << fn; return false; } int width = image->columns; int height = image->rows; double xres = image->x_resolution; double yres = image->y_resolution; if (thumbnail) image = FlattenImages(image, &exception); else { struct PSDLayer layer; layerCount = 0; Image *flatten_image = CloneImage(image, 0, 0, true, &exception); Image *next; if ((flatten_image != (Image *) NULL) && (image->next != (Image *) NULL)) { bool visible = true; double opacity = 1.0; QString compositeOp = blendModeToString(flatten_image->compose); QString layerName = QString("layer%1").arg(layerCount+1); if ((m_imageInfoRecord.isRequest) && (m_imageInfoRecord.RequestProps.contains(layerCount))) opacity = m_imageInfoRecord.RequestProps[layerCount].opacity / 255.0; if ((m_imageInfoRecord.isRequest) && (m_imageInfoRecord.RequestProps.contains(layerCount))) visible = m_imageInfoRecord.RequestProps[layerCount].visible; if ((m_imageInfoRecord.isRequest) && (m_imageInfoRecord.RequestProps.contains(layerCount))) compositeOp = m_imageInfoRecord.RequestProps[layerCount].blend; layer.layerName = layerName; layer.channelType.clear(); layer.channelLen.clear(); layer.opacity = qRound(opacity * 255); layer.blend = compositeOp; layer.maskYpos = 0; layer.maskXpos = 0; layer.maskHeight = 0; layer.maskWidth = 0; layer.flags = visible ? 0 : 2; QImage imt; if (image->colorspace == CMYKColorspace) { RawImage r2_image; readCMYK(flatten_image, &r2_image, width, height); imt = r2_image.convertToQImage(true); } else { m_useRawImage = false; imt = QImage(width, height, QImage::Format_ARGB32); readRGB(flatten_image, &imt, width, height); } double sx = imt.width() / 40.0; double sy = imt.height() / 40.0; layer.thumb = sy < sx ? imt.scaled(qRound(imt.width() / sx), qRound(imt.height() / sx), Qt::IgnoreAspectRatio, Qt::SmoothTransformation) : imt.scaled(qRound(imt.width() / sy), qRound(imt.height() / sy), Qt::IgnoreAspectRatio, Qt::SmoothTransformation); m_imageInfoRecord.layerInfo.append(layer); layerCount++; if (!visible) { (void)CompositeImage(flatten_image, ClearCompositeOp, flatten_image, flatten_image->page.x, flatten_image->page.y); } for (next = image->next; next != (Image*)NULL; next = next->next) { visible = true; opacity = 1.0; compositeOp = blendModeToString(next->compose); layerName = QString("layer%1").arg(layerCount+1); if ((m_imageInfoRecord.isRequest) && (m_imageInfoRecord.RequestProps.contains(layerCount))) opacity = m_imageInfoRecord.RequestProps[layerCount].opacity / 255.0; if ((m_imageInfoRecord.isRequest) && (m_imageInfoRecord.RequestProps.contains(layerCount))) visible = m_imageInfoRecord.RequestProps[layerCount].visible; if ((m_imageInfoRecord.isRequest) && (m_imageInfoRecord.RequestProps.contains(layerCount))) compositeOp = m_imageInfoRecord.RequestProps[layerCount].blend; layer.layerName = layerName; layer.channelType.clear(); layer.channelLen.clear(); layer.opacity = qRound(opacity * 255); layer.blend = compositeOp; layer.maskYpos = 0; layer.maskXpos = 0; layer.maskHeight = 0; layer.maskWidth = 0; layer.flags = visible ? 0 : 2; if (image->colorspace == CMYKColorspace) { RawImage r2_image; readCMYK(next, &r2_image, width, height); imt = r2_image.convertToQImage(true); } else { m_useRawImage = false; imt = QImage(width, height, QImage::Format_ARGB32); readRGB(next, &imt, width, height); } double sx = imt.width() / 40.0; double sy = imt.height() / 40.0; layer.thumb = sy < sx ? imt.scaled(qRound(imt.width() / sx), qRound(imt.height() / sx), Qt::IgnoreAspectRatio, Qt::SmoothTransformation) : imt.scaled(qRound(imt.width() / sy), qRound(imt.height() / sy), Qt::IgnoreAspectRatio, Qt::SmoothTransformation); m_imageInfoRecord.layerInfo.append(layer); layerCount++; if (visible) (void)CompositeImage(flatten_image, (CompositeOperator)blendModeToInt(compositeOp), next, next->page.x, next->page.y); } image = CloneImage(flatten_image, 0, 0, true, &exception); } } if (image->colorspace == CMYKColorspace) { m_useRawImage = true; if (!readCMYK(image, &r_image, width, height)) return false; m_imageInfoRecord.colorspace = ColorSpaceCMYK; m_pixelFormat = (r_image.channels() == 5) ? Format_CMYKA_8 : Format_CMYK_8; } else { m_useRawImage = false; m_image = QImage(width, height, QImage::Format_ARGB32); if (!readRGB(image, &m_image, width, height)) return false; m_imageInfoRecord.colorspace = ColorSpaceRGB; m_pixelFormat = Format_BGRA_8; } m_imageInfoRecord.exifDataValid = false; if (thumbnail) { m_imageInfoRecord.exifDataValid = true; m_imageInfoRecord.exifInfo.thumbnail = m_image; m_imageInfoRecord.exifInfo.height = height; m_imageInfoRecord.exifInfo.width = width; } m_imageInfoRecord.type = ImageTypeOther; m_imageInfoRecord.xres = qMax(72, qRound(xres)); m_imageInfoRecord.yres = qMax(72, qRound(yres)); m_imageInfoRecord.BBoxX = 0; m_imageInfoRecord.BBoxH = m_image.height(); m_imageInfoRecord.valid = true; return true; }