| 1 | /*************************************************************************** |
|---|
| 2 | * graphicsTransform.cc |
|---|
| 3 | * |
|---|
| 4 | * Thu Nov 23 2007 |
|---|
| 5 | * Copyright 2007 Dmytro Milinevskyy |
|---|
| 6 | * milinevskyy@gmail.com |
|---|
| 7 | ****************************************************************************/ |
|---|
| 8 | |
|---|
| 9 | /* |
|---|
| 10 | * This program is free software; you can redistribute it and/or modify |
|---|
| 11 | * it under the terms of the GNU Lesser General Public License version 2.1 as published by |
|---|
| 12 | * the Free Software Foundation; |
|---|
| 13 | * |
|---|
| 14 | * This program is distributed in the hope that it will be useful, |
|---|
| 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
|---|
| 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|---|
| 17 | * GNU Library General Public License for more details. |
|---|
| 18 | * |
|---|
| 19 | * You should have received a copy of the GNU Lesser General Public License |
|---|
| 20 | * along with this program; if not, write to the Free Software |
|---|
| 21 | * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
|---|
| 22 | */ |
|---|
| 23 | |
|---|
| 24 | /** |
|---|
| 25 | * vim indentation settings |
|---|
| 26 | * set tabstop=4 |
|---|
| 27 | * set shiftwidth=4 |
|---|
| 28 | */ |
|---|
| 29 | |
|---|
| 30 | #include <libdodo/directives.h> |
|---|
| 31 | |
|---|
| 32 | #ifdef IMAGEMAGICK_EXT |
|---|
| 33 | #ifndef IMAGEMAGICK_PRE_63 |
|---|
| 34 | #include <magick/MagickCore.h> |
|---|
| 35 | #else |
|---|
| 36 | #include <magick/ImageMagick.h> |
|---|
| 37 | #endif |
|---|
| 38 | #include <math.h> |
|---|
| 39 | |
|---|
| 40 | #include "graphicsImage.inline" |
|---|
| 41 | |
|---|
| 42 | #include <libdodo/graphicsTransform.h> |
|---|
| 43 | #include <libdodo/graphicsImage.h> |
|---|
| 44 | #include <libdodo/graphicsTransformEx.h> |
|---|
| 45 | |
|---|
| 46 | using namespace dodo::graphics; |
|---|
| 47 | |
|---|
| 48 | //------------------------------------------------------------------- |
|---|
| 49 | |
|---|
| 50 | void |
|---|
| 51 | transform::scale(image &image, |
|---|
| 52 | unsigned long width, |
|---|
| 53 | unsigned long height) |
|---|
| 54 | { |
|---|
| 55 | if (image.collectedData.handle->im == NULL) |
|---|
| 56 | dodo_throw exception::basic(exception::MODULE_GRAPHICSTRANSFORM, TRANSFORMEX_SCALE, exception::ERRNO_IMAGEMAGICK, TRANSFORMEX_EMPTYIMAGE, GRAPHICSTRANSFORMEX_EMPTYIMAGE_STR, __LINE__, __FILE__); |
|---|
| 57 | |
|---|
| 58 | GetExceptionInfo((ExceptionInfo *)image.exInfo); |
|---|
| 59 | |
|---|
| 60 | Image *im = ScaleImage(image.collectedData.handle->im, width, height, (ExceptionInfo *)image.exInfo); |
|---|
| 61 | if (im == NULL) |
|---|
| 62 | dodo_throw exception::basic(exception::MODULE_GRAPHICSTRANSFORM, TRANSFORMEX_SCALE, exception::ERRNO_IMAGEMAGICK, ((ExceptionInfo *)image.exInfo)->error_number, ((ExceptionInfo *)image.exInfo)->reason, __LINE__, __FILE__, ((ExceptionInfo *)image.exInfo)->description ? ((ExceptionInfo *)image.exInfo)->description : __dodostring__); |
|---|
| 63 | |
|---|
| 64 | DestroyImage(image.collectedData.handle->im); |
|---|
| 65 | |
|---|
| 66 | image.collectedData.handle->im = im; |
|---|
| 67 | } |
|---|
| 68 | |
|---|
| 69 | //------------------------------------------------------------------- |
|---|
| 70 | |
|---|
| 71 | void |
|---|
| 72 | transform::scale(image &image, |
|---|
| 73 | unsigned long size) |
|---|
| 74 | { |
|---|
| 75 | if (image.collectedData.handle->im == NULL) |
|---|
| 76 | dodo_throw exception::basic(exception::MODULE_GRAPHICSTRANSFORM, TRANSFORMEX_SCALE, exception::ERRNO_IMAGEMAGICK, TRANSFORMEX_EMPTYIMAGE, GRAPHICSTRANSFORMEX_EMPTYIMAGE_STR, __LINE__, __FILE__); |
|---|
| 77 | |
|---|
| 78 | float mult = (float)size / (float)((image.collectedData.handle->im->columns > image.collectedData.handle->im->rows) ? image.collectedData.handle->im->columns : image.collectedData.handle->im->rows); |
|---|
| 79 | |
|---|
| 80 | GetExceptionInfo((ExceptionInfo *)image.exInfo); |
|---|
| 81 | |
|---|
| 82 | Image *im = ScaleImage(image.collectedData.handle->im, (unsigned long)floor(image.collectedData.handle->im->columns * mult), (unsigned long)floor(image.collectedData.handle->im->rows * mult), (ExceptionInfo *)image.exInfo); |
|---|
| 83 | if (im == NULL) |
|---|
| 84 | dodo_throw exception::basic(exception::MODULE_GRAPHICSTRANSFORM, TRANSFORMEX_SCALE, exception::ERRNO_IMAGEMAGICK, ((ExceptionInfo *)image.exInfo)->error_number, ((ExceptionInfo *)image.exInfo)->reason, __LINE__, __FILE__, ((ExceptionInfo *)image.exInfo)->description ? ((ExceptionInfo *)image.exInfo)->description : __dodostring__); |
|---|
| 85 | |
|---|
| 86 | DestroyImage(image.collectedData.handle->im); |
|---|
| 87 | |
|---|
| 88 | image.collectedData.handle->im = im; |
|---|
| 89 | } |
|---|
| 90 | |
|---|
| 91 | //------------------------------------------------------------------- |
|---|
| 92 | |
|---|
| 93 | void |
|---|
| 94 | transform::rotate(image &image, |
|---|
| 95 | double angle) |
|---|
| 96 | { |
|---|
| 97 | if (image.collectedData.handle->im == NULL) |
|---|
| 98 | dodo_throw exception::basic(exception::MODULE_GRAPHICSTRANSFORM, TRANSFORMEX_ROTATE, exception::ERRNO_IMAGEMAGICK, TRANSFORMEX_EMPTYIMAGE, GRAPHICSTRANSFORMEX_EMPTYIMAGE_STR, __LINE__, __FILE__); |
|---|
| 99 | |
|---|
| 100 | GetExceptionInfo((ExceptionInfo *)image.exInfo); |
|---|
| 101 | |
|---|
| 102 | Image *im = RotateImage(image.collectedData.handle->im, angle, (ExceptionInfo *)image.exInfo); |
|---|
| 103 | if (im == NULL) |
|---|
| 104 | dodo_throw exception::basic(exception::MODULE_GRAPHICSTRANSFORM, TRANSFORMEX_ROTATE, exception::ERRNO_IMAGEMAGICK, ((ExceptionInfo *)image.exInfo)->error_number, ((ExceptionInfo *)image.exInfo)->reason, __LINE__, __FILE__, ((ExceptionInfo *)image.exInfo)->description ? ((ExceptionInfo *)image.exInfo)->description : __dodostring__); |
|---|
| 105 | |
|---|
| 106 | DestroyImage(image.collectedData.handle->im); |
|---|
| 107 | |
|---|
| 108 | image.collectedData.handle->im = im; |
|---|
| 109 | } |
|---|
| 110 | #endif |
|---|
| 111 | |
|---|
| 112 | //------------------------------------------------------------------- |
|---|
| 113 | |
|---|