Coverage Report

Created: 2025-12-31 07:53

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/graphicsmagick/coders/matte.c
Line
Count
Source
1
/*
2
% Copyright (C) 2003-2025 GraphicsMagick Group
3
% Copyright (C) 2002 ImageMagick Studio
4
% Copyright 1991-1999 E. I. du Pont de Nemours and Company
5
%
6
% This program is covered by multiple licenses, which are described in
7
% Copyright.txt. You should have received a copy of Copyright.txt with this
8
% package; otherwise see http://www.graphicsmagick.org/www/Copyright.html.
9
%
10
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
11
%                                                                             %
12
%                                                                             %
13
%                                                                             %
14
%                     M   M   AAA   TTTTT  TTTTT  EEEEE                       %
15
%                     MM MM  A   A    T      T    E                           %
16
%                     M M M  AAAAA    T      T    EEE                         %
17
%                     M   M  A   A    T      T    E                           %
18
%                     M   M  A   A    T      T    EEEEE                       %
19
%                                                                             %
20
%                                                                             %
21
%                     Write Matte Channel To MIFF File.                       %
22
%                                                                             %
23
%                                                                             %
24
%                              Software Design                                %
25
%                                John Cristy                                  %
26
%                                 July 1992                                   %
27
%                                                                             %
28
%                                                                             %
29
%                                                                             %
30
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
31
%
32
%
33
*/
34

35
/*
36
  Include declarations.
37
*/
38
#include "magick/studio.h"
39
#include "magick/blob.h"
40
#include "magick/pixel_cache.h"
41
#include "magick/constitute.h"
42
#include "magick/magick.h"
43
#include "magick/monitor.h"
44
#include "magick/utility.h"
45
#include "magick/static.h"
46

47
/*
48
  Forward declarations.
49
*/
50
static unsigned int
51
  WriteMATTEImage(const ImageInfo *,Image *);
52

53
/*
54
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
55
%                                                                             %
56
%                                                                             %
57
%                                                                             %
58
%   R e g i s t e r M A T T E I m a g e                                       %
59
%                                                                             %
60
%                                                                             %
61
%                                                                             %
62
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
63
%
64
%  Method RegisterMATTEImage adds attributes for the MATTE image format to
65
%  the list of supported formats.  The attributes include the image format
66
%  tag, a method to read and/or write the format, whether the format
67
%  supports the saving of more than one frame to the same file or blob,
68
%  whether the format supports native in-memory I/O, and a brief
69
%  description of the format.
70
%
71
%  The format of the RegisterMATTEImage method is:
72
%
73
%      RegisterMATTEImage(void)
74
%
75
*/
76
ModuleExport void RegisterMATTEImage(void)
77
0
{
78
0
  MagickInfo
79
0
    *entry;
80
81
0
  entry=SetMagickInfo("MATTE");
82
0
  entry->encoder=(EncoderHandler) WriteMATTEImage;
83
0
  entry->raw=True;
84
0
  entry->description="MATTE raw opacity format";
85
0
  entry->module="MATTE";
86
0
  entry->extension_treatment=ObeyExtensionTreatment;
87
0
  (void) RegisterMagickInfo(entry);
88
0
}
89

90
/*
91
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
92
%                                                                             %
93
%                                                                             %
94
%                                                                             %
95
%   U n r e g i s t e r M A T T E I m a g e                                   %
96
%                                                                             %
97
%                                                                             %
98
%                                                                             %
99
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
100
%
101
%  Method UnregisterMATTEImage removes format registrations made by the
102
%  MATTE module from the list of supported formats.
103
%
104
%  The format of the UnregisterMATTEImage method is:
105
%
106
%      UnregisterMATTEImage(void)
107
%
108
*/
109
ModuleExport void UnregisterMATTEImage(void)
110
0
{
111
0
  (void) UnregisterMagickInfo("MATTE");
112
0
}
113

114
/*
115
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
116
%                                                                             %
117
%                                                                             %
118
%                                                                             %
119
%   W r i t e M A T T E I m a g e                                             %
120
%                                                                             %
121
%                                                                             %
122
%                                                                             %
123
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
124
%
125
%  Function WriteMATTEImage writes an image of matte bytes to a file.  It
126
%  consists of data from the matte component of the image [0..255].
127
%
128
%  The format of the WriteMATTEImage method is:
129
%
130
%      unsigned int WriteMATTEImage(const ImageInfo *image_info,Image *image)
131
%
132
%  A description of each parameter follows.
133
%
134
%    o status: Function WriteMATTEImage return True if the image is written.
135
%      False is returned is there is a memory shortage or if the image file
136
%      fails to write.
137
%
138
%    o image_info: Specifies a pointer to a ImageInfo structure.
139
%
140
%    o image:  A pointer to an Image structure.
141
%
142
%
143
*/
144
static unsigned int WriteMATTEImage(const ImageInfo *image_info,Image *image)
145
0
{
146
0
  Image
147
0
    *matte_image;
148
149
0
  long
150
0
    y;
151
152
0
  register const PixelPacket
153
0
    *p;
154
155
0
  register long
156
0
    x;
157
158
0
  register PixelPacket
159
0
    *q;
160
161
0
  unsigned int
162
0
    status;
163
164
0
  if (!image->matte)
165
0
    ThrowWriterException(CoderError,ImageDoesNotHaveAMatteChannel,image);
166
0
  matte_image=
167
0
    CloneImage(image,image->columns,image->rows,True,&image->exception);
168
0
  if (matte_image == (Image *) NULL)
169
0
    return(False);
170
0
  (void) (void) SetImageType(matte_image,TrueColorType);
171
  /*
172
    Convert image to matte pixels.
173
  */
174
0
  for (y=0; y < (long) image->rows; y++)
175
0
  {
176
0
    p=AcquireImagePixels(image,0,y,image->columns,1,&image->exception);
177
0
    q=SetImagePixels(matte_image,0,y,matte_image->columns,1);
178
0
    if ((p == (const PixelPacket *) NULL) || (q == (PixelPacket *) NULL))
179
0
      break;
180
0
    for (x=0; x < (long) image->columns; x++)
181
0
    {
182
0
      q->red=p->opacity;
183
0
      q->green=p->opacity;
184
0
      q->blue=p->opacity;
185
0
      q->opacity=OpaqueOpacity;
186
0
      p++;
187
0
      q++;
188
0
    }
189
0
    if (!SyncImagePixels(matte_image))
190
0
      break;
191
0
    if (image->previous == (Image *) NULL)
192
0
      if (QuantumTick(y,image->rows))
193
0
        if (!MagickMonitorFormatted(y,image->rows,&image->exception,
194
0
                                    SaveImageText,image->filename,
195
0
                                    image->columns,image->rows))
196
0
          break;
197
0
  }
198
0
  (void) FormatString(matte_image->filename,"MIFF:%.1024s",image->filename);
199
0
  status=WriteImage(image_info,matte_image);
200
0
  DestroyImage(matte_image);
201
0
  return(status);
202
0
}