Alexei Podtelezhnikov pushed to branch master at FreeType / FreeType Demo Programs
Commits:
-
dee1c4cd
by Alexei Podtelezhnikov at 2021-10-17T22:32:41-04:00
2 changed files:
Changes:
... | ... | @@ -162,7 +162,8 @@ |
162 | 162 |
* grNewBitmap
|
163 | 163 |
*
|
164 | 164 |
* <Description>
|
165 |
- * creates a new bitmap or resizes an existing one
|
|
165 |
+ * Creates a new bitmap or resizes an existing one. The allocated
|
|
166 |
+ * pixel buffer is not initialized.
|
|
166 | 167 |
*
|
167 | 168 |
* <Input>
|
168 | 169 |
* pixel_mode :: the target surface's pixel_mode
|
... | ... | @@ -177,8 +178,8 @@ |
177 | 178 |
* Error code. 0 means success.
|
178 | 179 |
*
|
179 | 180 |
* <Note>
|
180 |
- * This function really allocates a pixel buffer, zero it, then
|
|
181 |
- * returns a descriptor for it.
|
|
181 |
+ * This function really allocates a pixel buffer, then returns
|
|
182 |
+ * a descriptor for it.
|
|
182 | 183 |
*
|
183 | 184 |
* An existing bitmap will be resized.
|
184 | 185 |
*
|
... | ... | @@ -140,7 +140,8 @@ |
140 | 140 |
* grNewBitmap
|
141 | 141 |
*
|
142 | 142 |
* <Description>
|
143 |
- * creates a new bitmap or resizes an existing one
|
|
143 |
+ * Creates a new bitmap or resizes an existing one. The allocated
|
|
144 |
+ * pixel buffer is not initialized.
|
|
144 | 145 |
*
|
145 | 146 |
* <Input>
|
146 | 147 |
* pixel_mode :: the target surface's pixel_mode
|
... | ... | @@ -162,7 +163,9 @@ |
162 | 163 |
int height,
|
163 | 164 |
grBitmap *bit )
|
164 | 165 |
{
|
165 |
- int pitch;
|
|
166 |
+ int pitch;
|
|
167 |
+ unsigned char* buffer;
|
|
168 |
+ |
|
166 | 169 |
|
167 | 170 |
/* check mode */
|
168 | 171 |
if (check_mode(pixel_mode,num_grays))
|
... | ... | @@ -197,29 +200,20 @@ |
197 | 200 |
return 0;
|
198 | 201 |
}
|
199 | 202 |
|
200 |
- if ( !bit->buffer )
|
|
201 |
- {
|
|
202 |
- bit->buffer = grAlloc( (size_t)pitch * (size_t)height );
|
|
203 |
- if (!bit->buffer) goto Fail;
|
|
204 |
- }
|
|
205 |
- else /* resize */
|
|
203 |
+ buffer = (unsigned char*)realloc( bit->buffer,
|
|
204 |
+ (size_t)pitch * (size_t)height );
|
|
205 |
+ if ( !buffer && pitch && height )
|
|
206 | 206 |
{
|
207 |
- unsigned char* buffer;
|
|
208 |
- |
|
209 |
- |
|
210 |
- buffer = (unsigned char*)realloc( bit->buffer,
|
|
211 |
- (size_t)pitch * (size_t)height );
|
|
212 |
- if ( buffer || !pitch || !height )
|
|
213 |
- bit->buffer = buffer;
|
|
214 |
- else
|
|
215 |
- goto Fail;
|
|
207 |
+ grError = gr_err_memory;
|
|
208 |
+ goto Fail;
|
|
216 | 209 |
}
|
217 | 210 |
|
218 |
- bit->width = width;
|
|
219 |
- bit->rows = height;
|
|
220 |
- bit->pitch = pitch;
|
|
221 |
- bit->mode = pixel_mode;
|
|
222 |
- bit->grays = num_grays;
|
|
211 |
+ bit->buffer = buffer;
|
|
212 |
+ bit->width = width;
|
|
213 |
+ bit->rows = height;
|
|
214 |
+ bit->pitch = pitch;
|
|
215 |
+ bit->mode = pixel_mode;
|
|
216 |
+ bit->grays = num_grays;
|
|
223 | 217 |
|
224 | 218 |
return 0;
|
225 | 219 |
|