MagickCore  6.7.5
prepress.c
Go to the documentation of this file.
00001 /*
00002 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
00003 %                                                                             %
00004 %                                                                             %
00005 %                                                                             %
00006 %           PPPP    RRRR    EEEEE  PPPP   RRRR   EEEEE  SSSSS  SSSSS          %
00007 %           P   P   R   R   E      P   P  R   R  E      SS     SS             %
00008 %           PPPP    RRRR    EEE    PPPP   RRRR   EEE     SSS    SSS           %
00009 %           P       R R     E      P      R R    E         SS     SS          %
00010 %           P       R  R    EEEEE  P      R  R   EEEEE  SSSSS  SSSSS          %
00011 %                                                                             %
00012 %                                                                             %
00013 %                         MagickCore Prepress Methods                         %
00014 %                                                                             %
00015 %                              Software Design                                %
00016 %                                John Cristy                                  %
00017 %                                October 2001                                 %
00018 %                                                                             %
00019 %                                                                             %
00020 %  Copyright 1999-2012 ImageMagick Studio LLC, a non-profit organization      %
00021 %  dedicated to making software imaging solutions freely available.           %
00022 %                                                                             %
00023 %  You may not use this file except in compliance with the License.  You may  %
00024 %  obtain a copy of the License at                                            %
00025 %                                                                             %
00026 %    http://www.imagemagick.org/script/license.php                            %
00027 %                                                                             %
00028 %  Unless required by applicable law or agreed to in writing, software        %
00029 %  distributed under the License is distributed on an "AS IS" BASIS,          %
00030 %  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.   %
00031 %  See the License for the specific language governing permissions and        %
00032 %  limitations under the License.                                             %
00033 %                                                                             %
00034 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
00035 %
00036 %
00037 */
00038 
00039 /*
00040   Include declarations.
00041 */
00042 #include "MagickCore/studio.h"
00043 #include "MagickCore/cache-view.h"
00044 #include "MagickCore/exception.h"
00045 #include "MagickCore/exception-private.h"
00046 #include "MagickCore/hashmap.h"
00047 #include "MagickCore/image.h"
00048 #include "MagickCore/list.h"
00049 #include "MagickCore/memory_.h"
00050 #include "MagickCore/pixel-accessor.h"
00051 #include "MagickCore/prepress.h"
00052 #include "MagickCore/registry.h"
00053 #include "MagickCore/semaphore.h"
00054 #include "MagickCore/splay-tree.h"
00055 #include "MagickCore/string_.h"
00056 
00057 /*
00058 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
00059 %                                                                             %
00060 %                                                                             %
00061 %                                                                             %
00062 %   G e t I m a g e T o t a l I n k D e n s i t y                             %
00063 %                                                                             %
00064 %                                                                             %
00065 %                                                                             %
00066 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
00067 %
00068 %  GetImageTotalInkDensity() returns the total ink density for a CMYK image.
00069 %  Total Ink Density (TID) is determined by adding the CMYK values in the
00070 %  darkest shadow area in an image.
00071 %
00072 %  The format of the GetImageTotalInkDensity method is:
00073 %
00074 %      double GetImageTotalInkDensity(const Image *image,
00075 %        ExceptionInfo *exception)
00076 %
00077 %  A description of each parameter follows:
00078 %
00079 %    o image: the image.
00080 %
00081 %    o exception: return any errors or warnings in this structure.
00082 %
00083 */
00084 MagickExport double GetImageTotalInkDensity(Image *image,
00085   ExceptionInfo *exception)
00086 {
00087   CacheView
00088     *image_view;
00089 
00090   double
00091     total_ink_density;
00092 
00093   MagickBooleanType
00094     status;
00095 
00096   ssize_t
00097     y;
00098 
00099   assert(image != (Image *) NULL);
00100   if (image->debug != MagickFalse)
00101     (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
00102   assert(image->signature == MagickSignature);
00103   if (image->colorspace != CMYKColorspace)
00104     {
00105       (void) ThrowMagickException(exception,GetMagickModule(),ImageError,
00106         "ColorSeparatedImageRequired","`%s'",image->filename);
00107       return(0.0);
00108     }
00109   status=MagickTrue;
00110   total_ink_density=0.0;
00111   image_view=AcquireCacheView(image);
00112 #if defined(MAGICKCORE_OPENMP_SUPPORT)
00113   #pragma omp parallel for schedule(static,4) shared(status)
00114 #endif
00115   for (y=0; y < (ssize_t) image->rows; y++)
00116   {
00117     double
00118       density;
00119 
00120     register const Quantum
00121       *p;
00122 
00123     register ssize_t
00124       x;
00125 
00126     p=GetCacheViewVirtualPixels(image_view,0,y,image->columns,1,exception);
00127     if (p == (const Quantum *) NULL)
00128       {
00129         status=MagickFalse;
00130         continue;
00131       }
00132     for (x=0; x < (ssize_t) image->columns; x++)
00133     {
00134       density=(double) GetPixelRed(image,p)+GetPixelGreen(image,p)+
00135         GetPixelBlue(image,p)+GetPixelBlack(image,p);
00136       if (density > total_ink_density)
00137 #if defined(MAGICKCORE_OPENMP_SUPPORT)
00138   #pragma omp critical (MagickCore_GetImageTotalInkDensity)
00139 #endif
00140         {
00141           if (density > total_ink_density)
00142             total_ink_density=density;
00143         }
00144       p+=GetPixelChannels(image);
00145     }
00146   }
00147   image_view=DestroyCacheView(image_view);
00148   if (status == MagickFalse)
00149     total_ink_density=0.0;
00150   return(total_ink_density);
00151 }