colormap.c
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044 #include "magick/studio.h"
00045 #include "magick/blob.h"
00046 #include "magick/cache-view.h"
00047 #include "magick/cache.h"
00048 #include "magick/color.h"
00049 #include "magick/color-private.h"
00050 #include "magick/colormap.h"
00051 #include "magick/client.h"
00052 #include "magick/configure.h"
00053 #include "magick/exception.h"
00054 #include "magick/exception-private.h"
00055 #include "magick/gem.h"
00056 #include "magick/geometry.h"
00057 #include "magick/image-private.h"
00058 #include "magick/memory_.h"
00059 #include "magick/monitor.h"
00060 #include "magick/monitor-private.h"
00061 #include "magick/option.h"
00062 #include "magick/pixel-private.h"
00063 #include "magick/quantize.h"
00064 #include "magick/quantum.h"
00065 #include "magick/semaphore.h"
00066 #include "magick/string_.h"
00067 #include "magick/token.h"
00068 #include "magick/utility.h"
00069 #include "magick/xml-tree.h"
00070
00071
00072
00073
00074
00075
00076
00077
00078
00079
00080
00081
00082
00083
00084
00085
00086
00087
00088
00089
00090
00091
00092
00093
00094
00095
00096
00097 MagickExport MagickBooleanType CycleColormapImage(Image *image,
00098 const long displace)
00099 {
00100 CacheView
00101 *image_view;
00102
00103 ExceptionInfo
00104 *exception;
00105
00106 long
00107 y;
00108
00109 MagickBooleanType
00110 status;
00111
00112 assert(image != (Image *) NULL);
00113 assert(image->signature == MagickSignature);
00114 if (image->debug != MagickFalse)
00115 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
00116 if (image->storage_class == DirectClass)
00117 (void) SetImageType(image,PaletteType);
00118 status=MagickTrue;
00119 exception=(&image->exception);
00120 image_view=AcquireCacheView(image);
00121 #if defined(MAGICKCORE_OPENMP_SUPPORT)
00122 #pragma omp parallel for schedule(dynamic,4) shared(status)
00123 #endif
00124 for (y=0; y < (long) image->rows; y++)
00125 {
00126 long
00127 index;
00128
00129 register IndexPacket
00130 *__restrict indexes;
00131
00132 register long
00133 x;
00134
00135 register PixelPacket
00136 *__restrict q;
00137
00138 if (status == MagickFalse)
00139 continue;
00140 q=GetCacheViewAuthenticPixels(image_view,0,y,image->columns,1,exception);
00141 if (q == (PixelPacket *) NULL)
00142 {
00143 status=MagickFalse;
00144 continue;
00145 }
00146 indexes=GetCacheViewAuthenticIndexQueue(image_view);
00147 for (x=0; x < (long) image->columns; x++)
00148 {
00149 index=(long) (indexes[x]+displace) % image->colors;
00150 if (index < 0)
00151 index+=image->colors;
00152 indexes[x]=(IndexPacket) index;
00153 q->red=image->colormap[index].red;
00154 q->green=image->colormap[index].green;
00155 q->blue=image->colormap[index].blue;
00156 q++;
00157 }
00158 if (SyncCacheViewAuthenticPixels(image_view,exception) == MagickFalse)
00159 status=MagickFalse;
00160 }
00161 image_view=DestroyCacheView(image_view);
00162 return(status);
00163 }
00164
00165
00166
00167
00168
00169
00170
00171
00172
00173
00174
00175
00176
00177
00178
00179
00180
00181
00182
00183
00184
00185
00186
00187
00188
00189 #if defined(__cplusplus) || defined(c_plusplus)
00190 extern "C" {
00191 #endif
00192
00193 static int IntensityCompare(const void *x,const void *y)
00194 {
00195 const PixelPacket
00196 *color_1,
00197 *color_2;
00198
00199 int
00200 intensity;
00201
00202 color_1=(const PixelPacket *) x;
00203 color_2=(const PixelPacket *) y;
00204 intensity=(int) PixelIntensityToQuantum(color_2)-
00205 (int) PixelIntensityToQuantum(color_1);
00206 return(intensity);
00207 }
00208
00209 #if defined(__cplusplus) || defined(c_plusplus)
00210 }
00211 #endif
00212
00213 MagickExport MagickBooleanType SortColormapByIntensity(Image *image)
00214 {
00215 CacheView
00216 *image_view;
00217
00218 ExceptionInfo
00219 *exception;
00220
00221 long
00222 y;
00223
00224 MagickBooleanType
00225 status;
00226
00227 register long
00228 i;
00229
00230 unsigned short
00231 *pixels;
00232
00233 assert(image != (Image *) NULL);
00234 if (image->debug != MagickFalse)
00235 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
00236 assert(image->signature == MagickSignature);
00237 if (image->storage_class != PseudoClass)
00238 return(MagickTrue);
00239
00240
00241
00242 pixels=(unsigned short *) AcquireQuantumMemory((size_t) image->colors,
00243 sizeof(*pixels));
00244 if (pixels == (unsigned short *) NULL)
00245 ThrowBinaryException(ResourceLimitError,"MemoryAllocationFailed",
00246 image->filename);
00247
00248
00249
00250 #if defined(MAGICKCORE_OPENMP_SUPPORT)
00251 #pragma omp parallel for schedule(dynamic,4) shared(status)
00252 #endif
00253 for (i=0; i < (long) image->colors; i++)
00254 image->colormap[i].opacity=(IndexPacket) i;
00255
00256
00257
00258 qsort((void *) image->colormap,(size_t) image->colors,
00259 sizeof(*image->colormap),IntensityCompare);
00260
00261
00262
00263 #if defined(MAGICKCORE_OPENMP_SUPPORT)
00264 #pragma omp parallel for schedule(dynamic,4) shared(status)
00265 #endif
00266 for (i=0; i < (long) image->colors; i++)
00267 pixels[(long) image->colormap[i].opacity]=(unsigned short) i;
00268 status=MagickTrue;
00269 exception=(&image->exception);
00270 image_view=AcquireCacheView(image);
00271 for (y=0; y < (long) image->rows; y++)
00272 {
00273 IndexPacket
00274 index;
00275
00276 register long
00277 x;
00278
00279 register IndexPacket
00280 *__restrict indexes;
00281
00282 register PixelPacket
00283 *__restrict q;
00284
00285 q=GetCacheViewAuthenticPixels(image_view,0,y,image->columns,1,exception);
00286 if (q == (PixelPacket *) NULL)
00287 {
00288 status=MagickFalse;
00289 continue;
00290 }
00291 indexes=GetCacheViewAuthenticIndexQueue(image_view);
00292 for (x=0; x < (long) image->columns; x++)
00293 {
00294 index=(IndexPacket) pixels[(long) indexes[x]];
00295 indexes[x]=index;
00296 *q++=image->colormap[(long) index];
00297 }
00298 if (SyncCacheViewAuthenticPixels(image_view,exception) == MagickFalse)
00299 status=MagickFalse;
00300 if (status == MagickFalse)
00301 break;
00302 }
00303 image_view=DestroyCacheView(image_view);
00304 pixels=(unsigned short *) RelinquishMagickMemory(pixels);
00305 return(status);
00306 }