@@ -2908,6 +2908,84 @@ MagickExport void SetImageInfoFile(ImageInfo *image_info,FILE *file)
2908
2908
% %
2909
2909
% %
2910
2910
% %
2911
+ % S e t I m a g e A l p h a %
2912
+ % %
2913
+ % %
2914
+ % %
2915
+ %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2916
+ %
2917
+ % SetImageAlpha() sets the alpha levels of the image.
2918
+ %
2919
+ % The format of the SetImageAlpha method is:
2920
+ %
2921
+ % MagickBooleanType SetImageAlpha(Image *image,const Quantum alpha,
2922
+ % ExceptionInfo *exception)
2923
+ %
2924
+ % A description of each parameter follows:
2925
+ %
2926
+ % o image: the image.
2927
+ %
2928
+ % o Alpha: the level of transparency: 0 is fully opaque and QuantumRange is
2929
+ % fully transparent.
2930
+ %
2931
+ */
2932
+ MagickExport MagickBooleanType SetImageAlpha (Image * image ,const Quantum alpha ,
2933
+ ExceptionInfo * exception )
2934
+ {
2935
+ CacheView
2936
+ * image_view ;
2937
+
2938
+ MagickBooleanType
2939
+ status ;
2940
+
2941
+ ssize_t
2942
+ y ;
2943
+
2944
+ assert (image != (Image * ) NULL );
2945
+ if (image -> debug != MagickFalse )
2946
+ (void ) LogMagickEvent (TraceEvent ,GetMagickModule (),"..." );
2947
+ assert (image -> signature == MagickCoreSignature );
2948
+ image -> alpha_trait = BlendPixelTrait ;
2949
+ status = MagickTrue ;
2950
+ image_view = AcquireAuthenticCacheView (image ,exception );
2951
+ #if defined(MAGICKCORE_OPENMP_SUPPORT )
2952
+ #pragma omp parallel for schedule(static,4) shared(status) \
2953
+ magick_threads(image,image,image->rows,1)
2954
+ #endif
2955
+ for (y = 0 ; y < (ssize_t ) image -> rows ; y ++ )
2956
+ {
2957
+ register Quantum
2958
+ * magick_restrict q ;
2959
+
2960
+ register ssize_t
2961
+ x ;
2962
+
2963
+ if (status == MagickFalse )
2964
+ continue ;
2965
+ q = GetCacheViewAuthenticPixels (image_view ,0 ,y ,image -> columns ,1 ,exception );
2966
+ if (q == (Quantum * ) NULL )
2967
+ {
2968
+ status = MagickFalse ;
2969
+ continue ;
2970
+ }
2971
+ for (x = 0 ; x < (ssize_t ) image -> columns ; x ++ )
2972
+ {
2973
+ if (GetPixelReadMask (image ,q ) != 0 )
2974
+ SetPixelAlpha (image ,alpha ,q );
2975
+ q += GetPixelChannels (image );
2976
+ }
2977
+ if (SyncCacheViewAuthenticPixels (image_view ,exception ) == MagickFalse )
2978
+ status = MagickFalse ;
2979
+ }
2980
+ image_view = DestroyCacheView (image_view );
2981
+ return (status );
2982
+ }
2983
+
2984
+ /*
2985
+ %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2986
+ % %
2987
+ % %
2988
+ % %
2911
2989
% S e t I m a g e M a s k %
2912
2990
% %
2913
2991
% %
@@ -3031,29 +3109,33 @@ MagickExport MagickBooleanType SetImageMask(Image *image,const PixelMask type,
3031
3109
% %
3032
3110
% %
3033
3111
% %
3034
- % S e t I m a g e A l p h a %
3112
+ % S e t I m a g e R e g i o n M a s k %
3035
3113
% %
3036
3114
% %
3037
3115
% %
3038
3116
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3039
3117
%
3040
- % SetImageAlpha() sets the alpha levels of the image.
3118
+ % SetImageRegionMask() associates a mask as defined by a region with the
3119
+ % image.
3041
3120
%
3042
- % The format of the SetImageAlpha method is:
3121
+ % The format of the SetImageRegionMask method is:
3043
3122
%
3044
- % MagickBooleanType SetImageAlpha (Image *image,const Quantum alpha ,
3045
- % ExceptionInfo *exception)
3123
+ % MagickBooleanType SetImageRegionMask (Image *image,const PixelMask type ,
3124
+ % const RectangleInfo *region, ExceptionInfo *exception)
3046
3125
%
3047
3126
% A description of each parameter follows:
3048
3127
%
3049
3128
% o image: the image.
3050
3129
%
3051
- % o Alpha: the level of transparency: 0 is fully opaque and QuantumRange is
3052
- % fully transparent.
3130
+ % o type: the mask type, ReadPixelMask or WritePixelMask.
3131
+ %
3132
+ % o geometry: the mask region.
3133
+ %
3134
+ % o exception: return any errors or warnings in this structure.
3053
3135
%
3054
3136
*/
3055
- MagickExport MagickBooleanType SetImageAlpha (Image * image , const Quantum alpha ,
3056
- ExceptionInfo * exception )
3137
+ MagickExport MagickBooleanType SetImageRegionMask (Image * image ,
3138
+ const PixelMask type , const RectangleInfo * region , ExceptionInfo * exception )
3057
3139
{
3058
3140
CacheView
3059
3141
* image_view ;
@@ -3064,16 +3146,34 @@ MagickExport MagickBooleanType SetImageAlpha(Image *image,const Quantum alpha,
3064
3146
ssize_t
3065
3147
y ;
3066
3148
3149
+ /*
3150
+ Set image mask as defined by the region.
3151
+ */
3067
3152
assert (image != (Image * ) NULL );
3068
3153
if (image -> debug != MagickFalse )
3069
3154
(void ) LogMagickEvent (TraceEvent ,GetMagickModule (),"..." );
3070
3155
assert (image -> signature == MagickCoreSignature );
3071
- image -> alpha_trait = BlendPixelTrait ;
3156
+ if (region == (const RectangleInfo * ) NULL )
3157
+ {
3158
+ switch (type )
3159
+ {
3160
+ case WritePixelMask : image -> write_mask = MagickFalse ; break ;
3161
+ default : image -> read_mask = MagickFalse ; break ;
3162
+ }
3163
+ return (SyncImagePixelCache (image ,exception ));
3164
+ }
3165
+ switch (type )
3166
+ {
3167
+ case WritePixelMask : image -> write_mask = MagickTrue ; break ;
3168
+ default : image -> read_mask = MagickTrue ; break ;
3169
+ }
3170
+ if (SyncImagePixelCache (image ,exception ) == MagickFalse )
3171
+ return (MagickFalse );
3072
3172
status = MagickTrue ;
3073
3173
image_view = AcquireAuthenticCacheView (image ,exception );
3074
3174
#if defined(MAGICKCORE_OPENMP_SUPPORT )
3075
3175
#pragma omp parallel for schedule(static,4) shared(status) \
3076
- magick_threads(image,image,image->rows ,1)
3176
+ magick_threads(image,image,1 ,1)
3077
3177
#endif
3078
3178
for (y = 0 ; y < (ssize_t ) image -> rows ; y ++ )
3079
3179
{
@@ -3093,8 +3193,23 @@ MagickExport MagickBooleanType SetImageAlpha(Image *image,const Quantum alpha,
3093
3193
}
3094
3194
for (x = 0 ; x < (ssize_t ) image -> columns ; x ++ )
3095
3195
{
3096
- if (GetPixelReadMask (image ,q ) != 0 )
3097
- SetPixelAlpha (image ,alpha ,q );
3196
+ MagickRealType
3197
+ intensity ;
3198
+
3199
+ intensity = 0 ;
3200
+ switch (type )
3201
+ {
3202
+ case WritePixelMask :
3203
+ {
3204
+ SetPixelWriteMask (image ,ClampToQuantum (QuantumRange - intensity ),q );
3205
+ break ;
3206
+ }
3207
+ default :
3208
+ {
3209
+ SetPixelReadMask (image ,ClampToQuantum (QuantumRange - intensity ),q );
3210
+ break ;
3211
+ }
3212
+ }
3098
3213
q += GetPixelChannels (image );
3099
3214
}
3100
3215
if (SyncCacheViewAuthenticPixels (image_view ,exception ) == MagickFalse )
0 commit comments