@@ -95,132 +95,165 @@ typedef struct
9595} CUTPalHeader ;
9696
9797
98- static void InsertRow (Image * image ,ssize_t depth ,unsigned char * p , ssize_t y ,
99- ExceptionInfo * exception )
98+ static MagickBooleanType InsertRow (Image * image ,ssize_t bpp ,unsigned char * p ,
99+ ssize_t y , ExceptionInfo * exception )
100100{
101- size_t bit ; ssize_t x ;
102- register Quantum * q ;
103- Quantum index ;
101+ int
102+ bit ;
104103
105- index = 0 ;
106- switch (depth )
107- {
104+ Quantum
105+ index ;
106+
107+ register Quantum
108+ * q ;
109+
110+ ssize_t
111+ x ;
112+
113+ q = QueueAuthenticPixels (image ,0 ,y ,image -> columns ,1 ,exception );
114+ if (q == (Quantum * ) NULL )
115+ return (MagickFalse );
116+ switch (bpp )
117+ {
108118 case 1 : /* Convert bitmap scanline. */
109119 {
110- q = QueueAuthenticPixels (image ,0 ,y ,image -> columns ,1 ,exception );
111- if (q == (Quantum * ) NULL )
112- break ;
113120 for (x = 0 ; x < ((ssize_t ) image -> columns - 7 ); x += 8 )
114121 {
115122 for (bit = 0 ; bit < 8 ; bit ++ )
116123 {
117- index = (Quantum ) (((( * p ) & (0x80 >> bit )) != 0 ) ? 0x01 : 0x00 );
124+ index = (( * p ) & (0x80 >> bit ) ? 0x01 : 0x00 );
118125 SetPixelIndex (image ,index ,q );
126+ if (index < image -> colors )
127+ SetPixelViaPixelInfo (image ,image -> colormap + (ssize_t ) index ,q );
119128 q += GetPixelChannels (image );
120129 }
121130 p ++ ;
122131 }
123132 if ((image -> columns % 8 ) != 0 )
124133 {
125- for (bit = 0 ; bit < (image -> columns % 8 ); bit ++ )
126- {
127- index = (Quantum ) ((((* p ) & (0x80 >> bit )) != 0 ) ? 0x01 : 0x00 );
128- SetPixelIndex (image ,index ,q );
129- q += GetPixelChannels (image );
130- }
134+ for (bit = 0 ; bit < (ssize_t ) (image -> columns % 8 ); bit ++ )
135+ {
136+ index = ((* p ) & (0x80 >> bit ) ? 0x01 : 0x00 );
137+ SetPixelIndex (image ,index ,q );
138+ if (index < image -> colors )
139+ SetPixelViaPixelInfo (image ,image -> colormap + (ssize_t ) index ,q );
140+ SetPixelViaPixelInfo (image ,image -> colormap + (ssize_t ) index ,q );
141+ q += GetPixelChannels (image );
142+ }
131143 p ++ ;
132144 }
133- (void ) SyncAuthenticPixels (image ,exception );
134145 break ;
135146 }
136147 case 2 : /* Convert PseudoColor scanline. */
137148 {
138- q = QueueAuthenticPixels (image ,0 ,y ,image -> columns ,1 ,exception );
139- if (q == (Quantum * ) NULL )
140- break ;
141- for (x = 0 ; x < ((ssize_t ) image -> columns - 1 ); x += 2 )
149+ for (x = 0 ; x < ((ssize_t ) image -> columns - 3 ); x += 4 )
142150 {
143- index = ConstrainColormapIndex (image ,(* p >> 6 ) & 0x3 ,exception );
144- SetPixelIndex (image ,index ,q );
145- q += GetPixelChannels (image );
146- index = ConstrainColormapIndex (image ,(* p >> 4 ) & 0x3 ,exception );
147- SetPixelIndex (image ,index ,q );
148- q += GetPixelChannels (image );
149- index = ConstrainColormapIndex (image ,(* p >> 2 ) & 0x3 ,exception );
150- SetPixelIndex (image ,index ,q );
151- q += GetPixelChannels (image );
152- index = ConstrainColormapIndex (image ,(* p ) & 0x3 ,exception );
153- SetPixelIndex (image ,index ,q );
154- q += GetPixelChannels (image );
155- p ++ ;
151+ index = ConstrainColormapIndex (image ,(* p >> 6 ) & 0x3 ,exception );
152+ SetPixelIndex (image ,index ,q );
153+ if (index < image -> colors )
154+ SetPixelViaPixelInfo (image ,image -> colormap + (ssize_t ) index ,q );
155+ q += GetPixelChannels (image );
156+ index = ConstrainColormapIndex (image ,(* p >> 4 ) & 0x3 ,exception );
157+ SetPixelIndex (image ,index ,q );
158+ if (index < image -> colors )
159+ SetPixelViaPixelInfo (image ,image -> colormap + (ssize_t ) index ,q );
160+ q += GetPixelChannels (image );
161+ index = ConstrainColormapIndex (image ,(* p >> 2 ) & 0x3 ,exception );
162+ SetPixelIndex (image ,index ,q );
163+ if (index < image -> colors )
164+ SetPixelViaPixelInfo (image ,image -> colormap + (ssize_t ) index ,q );
165+ q += GetPixelChannels (image );
166+ index = ConstrainColormapIndex (image ,(* p ) & 0x3 ,exception );
167+ SetPixelIndex (image ,index ,q );
168+ if (index < image -> colors )
169+ SetPixelViaPixelInfo (image ,image -> colormap + (ssize_t ) index ,q );
170+ q += GetPixelChannels (image );
171+ p ++ ;
156172 }
157- if ((image -> columns % 4 ) != 0 )
173+ if ((image -> columns % 4 ) != 0 )
158174 {
159175 index = ConstrainColormapIndex (image ,(* p >> 6 ) & 0x3 ,exception );
160176 SetPixelIndex (image ,index ,q );
177+ if (index < image -> colors )
178+ SetPixelViaPixelInfo (image ,image -> colormap + (ssize_t ) index ,q );
161179 q += GetPixelChannels (image );
162- if ((image -> columns % 4 ) >= 1 )
163-
180+ if ((image -> columns % 4 ) > 1 )
164181 {
165182 index = ConstrainColormapIndex (image ,(* p >> 4 ) & 0x3 ,exception );
166183 SetPixelIndex (image ,index ,q );
184+ if (index < image -> colors )
185+ SetPixelViaPixelInfo (image ,image -> colormap + (ssize_t ) index ,q );
167186 q += GetPixelChannels (image );
168- if ((image -> columns % 4 ) >= 2 )
169-
187+ if ((image -> columns % 4 ) > 2 )
170188 {
171189 index = ConstrainColormapIndex (image ,(* p >> 2 ) & 0x3 ,
172190 exception );
173191 SetPixelIndex (image ,index ,q );
192+ if (index < image -> colors )
193+ SetPixelViaPixelInfo (image ,image -> colormap + (ssize_t )
194+ index ,q );
174195 q += GetPixelChannels (image );
175196 }
176197 }
177198 p ++ ;
178199 }
179- (void ) SyncAuthenticPixels (image ,exception );
180200 break ;
181201 }
182202
183203 case 4 : /* Convert PseudoColor scanline. */
184204 {
185- q = QueueAuthenticPixels (image ,0 ,y ,image -> columns ,1 ,exception );
186- if (q == (Quantum * ) NULL )
187- break ;
188205 for (x = 0 ; x < ((ssize_t ) image -> columns - 1 ); x += 2 )
189- {
190- index = ConstrainColormapIndex (image ,(* p >> 4 ) & 0xf ,exception );
206+ {
207+ index = ConstrainColormapIndex (image ,(* p >> 4 ) & 0x0f ,exception );
191208 SetPixelIndex (image ,index ,q );
209+ if (index < image -> colors )
210+ SetPixelViaPixelInfo (image ,image -> colormap + (ssize_t ) index ,q );
192211 q += GetPixelChannels (image );
193- index = ConstrainColormapIndex (image ,(* p ) & 0xf ,exception );
212+ index = ConstrainColormapIndex (image ,(* p ) & 0x0f ,exception );
194213 SetPixelIndex (image ,index ,q );
195- q += GetPixelChannels (image );
214+ if (index < image -> colors )
215+ SetPixelViaPixelInfo (image ,image -> colormap + (ssize_t ) index ,q );
196216 p ++ ;
217+ q += GetPixelChannels (image );
197218 }
198219 if ((image -> columns % 2 ) != 0 )
199220 {
200- index = ConstrainColormapIndex (image ,(* p >> 4 ) & 0xf ,exception );
221+ index = ConstrainColormapIndex (image ,(* p >> 4 ) & 0x0f ,exception );
201222 SetPixelIndex (image ,index ,q );
202- q += GetPixelChannels (image );
223+ if (index < image -> colors )
224+ SetPixelViaPixelInfo (image ,image -> colormap + (ssize_t ) index ,q );
203225 p ++ ;
226+ q += GetPixelChannels (image );
204227 }
205- (void ) SyncAuthenticPixels (image ,exception );
206228 break ;
207229 }
208230 case 8 : /* Convert PseudoColor scanline. */
209231 {
210- q = QueueAuthenticPixels (image ,0 ,y ,image -> columns ,1 ,exception );
211- if (q == (Quantum * ) NULL )
212- break ;
213232 for (x = 0 ; x < (ssize_t ) image -> columns ; x ++ )
233+ {
234+ index = ConstrainColormapIndex (image ,* p ,exception );
235+ SetPixelIndex (image ,index ,q );
236+ if (index < image -> colors )
237+ SetPixelViaPixelInfo (image ,image -> colormap + (ssize_t ) index ,q );
238+ p ++ ;
239+ q += GetPixelChannels (image );
240+ }
241+ }
242+ break ;
243+
244+ case 24 : /* Convert DirectColor scanline. */
245+ for (x = 0 ; x < (ssize_t ) image -> columns ; x ++ )
214246 {
215- index = ConstrainColormapIndex (image ,* p , exception );
216- SetPixelIndex (image ,index ,q );
217- p ++ ;
247+ SetPixelRed (image ,ScaleCharToQuantum ( * p ++ ), q );
248+ SetPixelGreen (image ,ScaleCharToQuantum ( * p ++ ) ,q );
249+ SetPixelBlue ( image , ScaleCharToQuantum ( * p ++ ), q ) ;
218250 q += GetPixelChannels (image );
219251 }
220- (void ) SyncAuthenticPixels (image ,exception );
221- break ;
222- }
252+ break ;
223253 }
254+ if (!SyncAuthenticPixels (image ,exception ))
255+ return (MagickFalse );
256+ return (MagickTrue );
224257}
225258
226259/*
0 commit comments