Changeset 4111


Ignore:
Timestamp:
03/30/11 08:13:27 (2 years ago)
Author:
anthony
Message:

Addition of a -distort Resize distortion (geomerty argument)

Location:
ImageMagick/trunk
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • ImageMagick/trunk/ChangeLog

    r4106 r4111  
     12011-03-30 6.6.9-2 Anthony Thyssen <A.Thyssen@griffith...> 
     2  * Add a "Resize" distortion method (distort equivalent of -resize). 
     3  * Special CLI handling so -distort Resize takes a "geometry" argument. 
     4 
    152011-03-29  6.6.9-2 Cristy  <quetzlzacatenango@image...> 
    26  * Expand PCL compressed pixel buffer to prevent delta compressed overrun. 
  • ImageMagick/trunk/magick/distort.c

    r3928 r4111  
    6868#include "magick/thread-private.h" 
    6969#include "magick/token.h" 
     70#include "magick/transform.h" 
    7071 
    7172/* 
     
    431432      number_coeff=10; 
    432433      break; 
    433     case UndefinedDistortion: 
    434434    default: 
    435435      assert(! "Unknown Method Given"); /* just fail assertion */ 
     
    13191319%                                                                             % 
    13201320%                                                                             % 
     1321+   D i s t o r t R e s i z e I m a g e                                       % 
     1322%                                                                             % 
     1323%                                                                             % 
     1324%                                                                             % 
     1325%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 
     1326% 
     1327%  DistortResizeImage() resize image using the equivelent but slower image 
     1328%  distortion operator.  The filter is applied using a EWA cylindrical 
     1329%  resampling. But like resize the final image size is limited to whole pixels 
     1330%  with no effects by virtual-pixels on the result. 
     1331% 
     1332%  Note that images containing a transparency channel will be twice as slow to 
     1333%  resize as images one without transparency. 
     1334% 
     1335%  The format of the DistortResizeImage method is: 
     1336% 
     1337%      Image *AdaptiveResizeImage(const Image *image,const size_t columns, 
     1338%        const size_t rows,ExceptionInfo *exception) 
     1339% 
     1340%  A description of each parameter follows: 
     1341% 
     1342%    o image: the image. 
     1343% 
     1344%    o columns: the number of columns in the resized image. 
     1345% 
     1346%    o rows: the number of rows in the resized image. 
     1347% 
     1348%    o exception: return any errors or warnings in this structure. 
     1349% 
     1350*/ 
     1351MagickExport Image *DistortResizeImage(const Image *image, 
     1352  const size_t columns,const size_t rows,ExceptionInfo *exception) 
     1353{ 
     1354#define DistortResizeImageTag  "Distort/Image" 
     1355 
     1356  Image 
     1357    *resize_image, 
     1358    *tmp_image; 
     1359 
     1360  RectangleInfo 
     1361    crop_area; 
     1362 
     1363  double 
     1364    distort_args[12]; 
     1365 
     1366  VirtualPixelMethod 
     1367    vp_save; 
     1368 
     1369  /* 
     1370    Distort resize image. 
     1371  */ 
     1372  assert(image != (const Image *) NULL); 
     1373  assert(image->signature == MagickSignature); 
     1374  if (image->debug != MagickFalse) 
     1375    (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename); 
     1376  assert(exception != (ExceptionInfo *) NULL); 
     1377  assert(exception->signature == MagickSignature); 
     1378  if ((columns == 0) || (rows == 0)) 
     1379    return((Image *) NULL); 
     1380  /* Do not short-circuit this resize if final image size is unchanged */ 
     1381 
     1382  SetImageVirtualPixelMethod(image,TransparentVirtualPixelMethod); 
     1383 
     1384  (void) ResetMagickMemory(distort_args,0,12*sizeof(double)); 
     1385  distort_args[4]=image->columns; 
     1386  distort_args[6]=columns; 
     1387  distort_args[9]=image->rows; 
     1388  distort_args[11]=rows; 
     1389 
     1390  vp_save=GetImageVirtualPixelMethod(image); 
     1391 
     1392  tmp_image=CloneImage(image,0,0,MagickTrue,exception); 
     1393  if ( tmp_image == (Image *) NULL ) 
     1394    return((Image *) NULL); 
     1395  (void) SetImageVirtualPixelMethod(tmp_image,TransparentVirtualPixelMethod); 
     1396 
     1397  if (image->matte == MagickFalse) 
     1398    { 
     1399      /* 
     1400        Image has not transparency channel, so we free to use it 
     1401      */ 
     1402      (void) SetImageAlphaChannel(tmp_image,SetAlphaChannel); 
     1403      resize_image=DistortImage(tmp_image,AffineDistortion,12,distort_args, 
     1404            MagickTrue,exception), 
     1405 
     1406      tmp_image=DestroyImage(tmp_image); 
     1407      if ( resize_image == (Image *) NULL ) 
     1408        return((Image *) NULL); 
     1409 
     1410      (void) SetImageAlphaChannel(resize_image,DeactivateAlphaChannel); 
     1411      InheritException(exception,&image->exception); 
     1412    } 
     1413  else 
     1414    { 
     1415      /* 
     1416        Image has transparency so handle colors and alpha separatly. 
     1417        Basically we need to separate Virtual-Pixel alpha in the resized 
     1418        image, so only the actual original images alpha channel is used. 
     1419      */ 
     1420      Image 
     1421        *resize_alpha; 
     1422 
     1423      /* distort alpha channel separatally */ 
     1424      (void) SeparateImageChannel(tmp_image,TrueAlphaChannel); 
     1425      (void) SetImageAlphaChannel(tmp_image,OpaqueAlphaChannel); 
     1426      resize_alpha=DistortImage(tmp_image,AffineDistortion,12,distort_args, 
     1427            MagickTrue,exception), 
     1428      tmp_image=DestroyImage(tmp_image); 
     1429      if ( resize_alpha == (Image *) NULL ) 
     1430        return((Image *) NULL); 
     1431 
     1432      /* distort the actual image containing alpha + VP alpha */ 
     1433      tmp_image=CloneImage(image,0,0,MagickTrue,exception); 
     1434      if ( tmp_image == (Image *) NULL ) 
     1435        return((Image *) NULL); 
     1436      (void) SetImageVirtualPixelMethod(tmp_image, 
     1437                   TransparentVirtualPixelMethod); 
     1438      resize_image=DistortImage(tmp_image,AffineDistortion,12,distort_args, 
     1439            MagickTrue,exception), 
     1440      tmp_image=DestroyImage(tmp_image); 
     1441      if ( resize_image == (Image *) NULL) 
     1442        { 
     1443          resize_alpha=DestroyImage(resize_alpha); 
     1444          return((Image *) NULL); 
     1445        } 
     1446 
     1447      /* replace resize images alpha with the separally distorted alpha */ 
     1448      (void) SetImageAlphaChannel(resize_image,DeactivateAlphaChannel); 
     1449      (void) SetImageAlphaChannel(resize_alpha,DeactivateAlphaChannel); 
     1450      (void) CompositeImage(resize_image,CopyOpacityCompositeOp,resize_alpha, 
     1451                    0,0); 
     1452      InheritException(exception,&resize_image->exception); 
     1453      resize_alpha=DestroyImage(resize_alpha); 
     1454    } 
     1455  (void) SetImageVirtualPixelMethod(resize_image,vp_save); 
     1456 
     1457  /* 
     1458    Clean up the results of the Distortion 
     1459  */ 
     1460  crop_area.width=columns; 
     1461  crop_area.height=rows; 
     1462  crop_area.x=0; 
     1463  crop_area.y=0; 
     1464 
     1465  tmp_image=resize_image; 
     1466  resize_image=CropImage(tmp_image,&crop_area,exception); 
     1467  tmp_image=DestroyImage(tmp_image); 
     1468 
     1469  if ( resize_image == (Image *) NULL ) 
     1470    return((Image *) NULL); 
     1471 
     1472  return(resize_image); 
     1473} 
     1474 
     1475/* 
     1476%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 
     1477%                                                                             % 
     1478%                                                                             % 
     1479%                                                                             % 
    13211480%   D i s t o r t I m a g e                                                   % 
    13221481%                                                                             % 
     
    14021561% 
    14031562*/ 
     1563 
    14041564MagickExport Image *DistortImage(const Image *image,DistortImageMethod method, 
    14051565  const size_t number_arguments,const double *arguments, 
     
    14271587  assert(exception != (ExceptionInfo *) NULL); 
    14281588  assert(exception->signature == MagickSignature); 
     1589 
     1590 
     1591  /* 
     1592    Handle Special Compound Distortions (in-direct distortions) 
     1593  */ 
     1594  if ( method == ResizeDistortion ) 
     1595    { 
     1596      if ( number_arguments != 2 ) 
     1597        { 
     1598          (void) ThrowMagickException(exception,GetMagickModule(),OptionError, 
     1599                    "InvalidArgument","%s : '%s'","Resize", 
     1600                    "Invalid number of args: 2 only"); 
     1601          return((Image *) NULL); 
     1602        } 
     1603      distort_image=DistortResizeImage(image,(size_t)arguments[0], 
     1604         (size_t)arguments[1], exception); 
     1605      return(distort_image); 
     1606    } 
    14291607 
    14301608  /* 
  • ImageMagick/trunk/magick/distort.h

    r3261 r4111  
    5050  BarrelInverseDistortion, 
    5151  ShepardsDistortion, 
     52  ResizeDistortion, 
    5253  SentinelDistortion 
    5354} DistortImageMethod; 
     
    6970  *DistortImage(const Image *,const DistortImageMethod,const size_t, 
    7071    const double *,MagickBooleanType,ExceptionInfo *exception), 
     72  *DistortResizeImage(const Image *,const size_t,const size_t,ExceptionInfo *), 
    7173  *SparseColorImage(const Image *,const ChannelType,const SparseColorMethod, 
    7274    const size_t,const double *,ExceptionInfo *); 
  • ImageMagick/trunk/magick/option.c

    r4078 r4111  
    888888    { "BarrelInverse", (ssize_t) BarrelInverseDistortion, MagickFalse }, 
    889889    { "Shepards", (ssize_t) ShepardsDistortion, MagickFalse }, 
     890    { "Resize", (ssize_t) ResizeDistortion, MagickFalse }, 
    890891    { (char *) NULL, (ssize_t) UndefinedDistortion, MagickFalse } 
    891892  }, 
  • ImageMagick/trunk/wand/mogrify.c

    r4105 r4111  
    13511351            method=(DistortImageMethod) ParseMagickOption(MagickDistortOptions, 
    13521352              MagickFalse,argv[i+1]); 
     1353            if ( method == ResizeDistortion ) 
     1354              { 
     1355                 /* Special Case - Argument is actually a resize geometry! 
     1356                 ** Convert that to an appropriate distortion argument array. 
     1357                 */ 
     1358                 double 
     1359                   resize_args[2]; 
     1360                 (void) ParseRegionGeometry(*image,argv[i+2],&geometry, 
     1361                      exception); 
     1362                 resize_args[0]=(double)geometry.width; 
     1363                 resize_args[1]=(double)geometry.height; 
     1364                 mogrify_image=DistortImage(*image,method,(size_t)2, 
     1365                      resize_args,MagickTrue,exception); 
     1366                 break; 
     1367              } 
    13531368            args=InterpretImageProperties(mogrify_info,*image,argv[i+2]); 
    13541369            InheritException(exception,&(*image)->exception); 
Note: See TracChangeset for help on using the changeset viewer.