Changeset 11610

Show
Ignore:
Timestamp:
07/10/08 11:45:52 (7 weeks ago)
Author:
cristy
Message:
 
Files:
1 modified

Legend:

Unmodified
Added
Removed
  • ImageMagick/trunk/magick/distort.c

    r11606 r11610  
    5555#include "magick/matrix.h" 
    5656#include "magick/memory_.h" 
     57#include "magick/monitor-private.h" 
    5758#include "magick/pixel.h" 
    5859#include "magick/pixel-private.h" 
     
    114115*/ 
    115116 
     117static ResampleFilter **DestroyResampleFilterThreadSet(ResampleFilter **filter) 
     118{ 
     119  register long 
     120    i; 
     121 
     122  assert(filter != (ResampleFilter **) NULL); 
     123  for (i=0; i < (long) GetCacheViewMaximumThreads(); i++) 
     124    if (filter[i] != (ResampleFilter *) NULL) 
     125      filter[i]=DestroyResampleFilter(filter[i]); 
     126  return((ResampleFilter **) RelinquishMagickMemory(filter)); 
     127} 
     128 
     129static ResampleFilter **AcquireResampleFilterThreadSet(const Image *image, 
     130  ExceptionInfo *exception) 
     131{ 
     132  register long 
     133    i; 
     134 
     135  ResampleFilter 
     136    **filter; 
     137 
     138  filter=(ResampleFilter **) AcquireQuantumMemory(GetCacheViewMaximumThreads(), 
     139    sizeof(*filter)); 
     140  if (filter == (ResampleFilter **) NULL) 
     141    return((ResampleFilter **) NULL); 
     142  (void) ResetMagickMemory(filter,0,GetCacheViewMaximumThreads()* 
     143    sizeof(*filter)); 
     144  for (i=0; i < (long) GetCacheViewMaximumThreads(); i++) 
     145  { 
     146    filter[i]=AcquireResampleFilter(image,exception); 
     147    if (filter[i] == (ResampleFilter *) NULL) 
     148      return(DestroyResampleFilterThreadSet(filter)); 
     149  } 
     150  return(filter); 
     151} 
     152 
    116153static void InvertAffineCoefficients(const double *coefficients,double *inverse) 
    117154{ 
     
    171208    *distort_image; 
    172209 
     210  long 
     211    j, 
     212    y; 
     213 
     214  MagickBooleanType 
     215    status; 
     216 
     217  PointInfo 
     218    point;          /* point to sample (center of filtered resample of area) */ 
     219 
     220  RectangleInfo 
     221    geometry; 
     222 
    173223  register long 
    174224    i, 
    175225    x; 
    176226 
    177   long 
    178     j, 
    179     y; 
    180  
    181   PointInfo 
    182     point;          /* point to sample (center of filtered resample of area) */ 
    183  
    184   MagickPixelPacket 
    185     pixel,          /* pixel to assign to distorted image */ 
    186     invalid;  /* the color to assign when distort result is invalid */ 
    187  
    188   register IndexPacket 
    189     *indexes; 
    190  
    191   register PixelPacket 
    192     *q; 
    193  
    194227  ResampleFilter 
    195     *resample_filter; 
     228    **resample_filter; 
    196229 
    197230  ViewInfo 
    198     *distort_view; 
    199  
    200   MagickBooleanType 
    201     status; 
    202  
    203   RectangleInfo 
    204     geometry; 
     231    **distort_view; 
    205232 
    206233  assert(image != (Image *) NULL); 
     
    802829    distort_image->matte=MagickTrue; 
    803830 
    804   /* Open Image views as needed. */ 
    805   resample_filter=AcquireResampleFilter(image,exception); 
    806   GetMagickPixelPacket(distort_image,&pixel); 
    807   distort_view=AcquireCacheView(distort_image); 
    808  
    809   /* Define constant scaling vectors for Affine Distortions */ 
    810   switch (method) 
    811   { 
    812     case AffineDistortion: 
    813     case AffineProjectionDistortion: 
    814     case ScaleRotateTranslateDistortion: 
    815       ScaleResampleFilter( resample_filter, 
    816         coefficients[0], coefficients[2], 
    817         coefficients[1], coefficients[3] ); 
    818       break; 
    819     default: 
    820       break; 
    821   } 
    822  
    823   /* Initialize default pixel validity 
    824    *    negative:         pixel is invalid  output 'matte_color' 
    825    *    0.0 to 1.0:       antialiased, mix with resample output 
    826    *    1.0 or greater:   use resampled output. 
    827    */ 
    828   validity = 1.0; 
    829   GetMagickPixelPacket(distort_image,&invalid); 
    830   SetMagickPixelPacket(distort_image, &distort_image->matte_color, 
    831              (IndexPacket *) NULL, &invalid); 
    832   if (distort_image->colorspace == CMYKColorspace) 
    833         ConvertRGBToCMYK(&invalid);   /* what about other color spaces? */ 
    834  
    835831  /* Sample the source image to each pixel in the distort image.  */ 
     832  status=MagickTrue; 
     833  resample_filter=AcquireResampleFilterThreadSet(image,exception); 
     834  distort_view=AcquireCacheViewThreadSet(distort_image); 
     835  #pragma omp parallel for 
    836836  for (j=0; j < (long) distort_image->rows; j++) 
    837837  { 
    838     q=SetCacheViewPixels(distort_view,0,j,distort_image->columns,1); 
     838    long 
     839      y; 
     840 
     841    MagickPixelPacket 
     842      pixel,    /* pixel to assign to distorted image */ 
     843      invalid;  /* the color to assign when distort result is invalid */ 
     844 
     845    PointInfo 
     846      point;    /* point to sample (center of filtered resample of area) */ 
     847 
     848    register IndexPacket 
     849      *indexes; 
     850 
     851    register long 
     852      i, 
     853      id, 
     854      x; 
     855 
     856    register PixelPacket 
     857      *q; 
     858 
     859    id=GetCacheViewThreadId(); 
     860    q=SetCacheViewPixels(distort_view[id],0,j,distort_image->columns,1); 
    839861    if (q == (PixelPacket *) NULL) 
    840       break; 
    841     indexes=GetCacheViewIndexes(distort_view); 
     862      { 
     863        status=MagickFalse; 
     864        continue; 
     865      } 
     866    indexes=GetCacheViewIndexes(distort_view[id]); 
     867 
     868    GetMagickPixelPacket(distort_image,&pixel); 
     869 
     870    /* Define constant scaling vectors for Affine Distortions */ 
     871    switch (method) 
     872    { 
     873      case AffineDistortion: 
     874      case AffineProjectionDistortion: 
     875      case ScaleRotateTranslateDistortion: 
     876        ScaleResampleFilter( resample_filter[id], 
     877          coefficients[0], coefficients[2], 
     878          coefficients[1], coefficients[3] ); 
     879        break; 
     880      default: 
     881        break; 
     882    } 
     883 
     884    /* Initialize default pixel validity 
     885     *    negative:         pixel is invalid  output 'matte_color' 
     886     *    0.0 to 1.0:       antialiased, mix with resample output 
     887     *    1.0 or greater:   use resampled output. 
     888     */ 
     889    validity = 1.0; 
     890    GetMagickPixelPacket(distort_image,&invalid); 
     891    SetMagickPixelPacket(distort_image,&distort_image->matte_color, 
     892      (IndexPacket *) NULL, &invalid); 
     893    if (distort_image->colorspace == CMYKColorspace) 
     894      ConvertRGBToCMYK(&invalid);   /* what about other color spaces? */ 
     895    point.x=0; 
     896    point.y=0; 
    842897    y = j+geometry.y; 
    843898    for (i=0; i < (long) distort_image->columns; i++) 
     
    862917            coefficients[7]; 
    863918          /* Bilinear partial derivitives of scaling vectors */ 
    864           ScaleResampleFilter( resample_filter, 
     919          ScaleResampleFilter( resample_filter[id], 
    865920              coefficients[0] + coefficients[2]*y, 
    866921              coefficients[1] + coefficients[2]*x, 
     
    897952            /* Perspective Partial Derivatives or Scaling Vectors */ 
    898953            scale *= scale; 
    899             ScaleResampleFilter( resample_filter, 
     954            ScaleResampleFilter( resample_filter[id], 
    900955              (r*coefficients[0] - p*coefficients[6])*scale, 
    901956              (r*coefficients[1] - p*coefficients[7])*scale, 
     
    918973          */ 
    919974          if ( radius > MagickEpsilon ) 
    920             ScaleResampleFilter( resample_filter, 
     975            ScaleResampleFilter( resample_filter[id], 
    921976                coefficients[1]/(2*MagickPI) / radius, 0, 0, coefficients[3] ); 
    922977          else 
    923             ScaleResampleFilter( resample_filter, 
     978            ScaleResampleFilter( resample_filter[id], 
    924979                 MagickHuge, 0, 0, coefficients[3] ); 
    925980          break; 
     
    9461001      else { 
    9471002        /* resample the source image to find its correct color */ 
    948         pixel=ResamplePixelColor(resample_filter,point.x,point.y); 
     1003        pixel=ResamplePixelColor(resample_filter[id],point.x,point.y); 
    9491004        /* if validity between 0.0 and 1.0 mix result with invalid pixel */ 
    9501005        if ( validity < 1.0 ) { 
     
    9591014      indexes++; 
    9601015    } 
    961     if (SyncCacheView(distort_view) == MagickFalse) 
    962       break; 
    963     if ((image->progress_monitor != (MagickProgressMonitor) NULL) && 
    964         (QuantumTick(y,image->rows) != MagickFalse)) 
    965       { 
    966         status=image->progress_monitor(DistortImageTag,y,image->rows, 
    967           image->client_data); 
    968         if (status == MagickFalse) 
    969           break; 
    970       } 
     1016    if (SyncCacheView(distort_view[id]) == MagickFalse) 
     1017      status=MagickFalse; 
     1018    if (SetImageProgress(image,DistortImageTag,y,image->rows) == MagickFalse) 
     1019      status=MagickFalse; 
    9711020  } 
    972   distort_view=DestroyCacheView(distort_view); 
    973   resample_filter=DestroyResampleFilter(resample_filter); 
     1021  distort_view=DestroyCacheViewThreadSet(distort_view); 
     1022  resample_filter=DestroyResampleFilterThreadSet(resample_filter); 
    9741023 
    9751024  /* Arc does not return an offset unless 'bestfit' is in effect */ 
     
    9781027    distort_image->page.y = 0; 
    9791028  } 
     1029  if (status == MagickFalse) 
     1030    distort_image=DestroyImage(distort_image); 
    9801031  return(distort_image); 
    9811032}