Added braces

This commit is contained in:
Andrew Murray 2020-05-11 07:46:12 +10:00
parent 9f2773b3f7
commit 3a75e843f4
14 changed files with 78 additions and 50 deletions

View File

@ -490,8 +490,9 @@ getpixel(Imaging im, ImagingAccess access, int x, int y)
case IMAGING_TYPE_FLOAT32: case IMAGING_TYPE_FLOAT32:
return PyFloat_FromDouble(pixel.f); return PyFloat_FromDouble(pixel.f);
case IMAGING_TYPE_SPECIAL: case IMAGING_TYPE_SPECIAL:
if (strncmp(im->mode, "I;16", 4) == 0) if (strncmp(im->mode, "I;16", 4) == 0) {
return PyLong_FromLong(pixel.h); return PyLong_FromLong(pixel.h);
}
break; break;
} }
@ -1456,8 +1457,9 @@ _point(ImagingObject* self, PyObject* args)
lut[i*4] = CLIP8(data[i]); lut[i*4] = CLIP8(data[i]);
lut[i*4+1] = CLIP8(data[i+256]); lut[i*4+1] = CLIP8(data[i+256]);
lut[i*4+2] = CLIP8(data[i+512]); lut[i*4+2] = CLIP8(data[i+512]);
if (n > 768) if (n > 768) {
lut[i*4+3] = CLIP8(data[i+768]); lut[i*4+3] = CLIP8(data[i+768]);
}
} }
im = ImagingPoint(self->image, mode, (void*) lut); im = ImagingPoint(self->image, mode, (void*) lut);
} else { } else {
@ -1523,16 +1525,18 @@ _putdata(ImagingObject* self, PyObject* args)
/* Plain string data */ /* Plain string data */
for (i = y = 0; i < n; i += image->xsize, y++) { for (i = y = 0; i < n; i += image->xsize, y++) {
x = n - i; x = n - i;
if (x > (int) image->xsize) if (x > (int) image->xsize) {
x = image->xsize; x = image->xsize;
}
memcpy(image->image8[y], p+i, x); memcpy(image->image8[y], p+i, x);
} }
} else { } else {
/* Scaled and clipped string data */ /* Scaled and clipped string data */
for (i = x = y = 0; i < n; i++) { for (i = x = y = 0; i < n; i++) {
image->image8[y][x] = CLIP8((int) (p[i] * scale + offset)); image->image8[y][x] = CLIP8((int) (p[i] * scale + offset));
if (++x >= (int) image->xsize) if (++x >= (int) image->xsize) {
x = 0, y++; x = 0, y++;
}
} }
} }
} else { } else {
@ -1932,12 +1936,14 @@ im_setmode(ImagingObject* self, PyObject* args)
/* color to color */ /* color to color */
strcpy(im->mode, mode); strcpy(im->mode, mode);
im->bands = modelen; im->bands = modelen;
if (!strcmp(mode, "RGBA")) if (!strcmp(mode, "RGBA")) {
(void) ImagingFillBand(im, 3, 255); (void) ImagingFillBand(im, 3, 255);
}
} else { } else {
/* trying doing an in-place conversion */ /* trying doing an in-place conversion */
if (!ImagingConvertInPlace(im, mode)) if (!ImagingConvertInPlace(im, mode)) {
return NULL; return NULL;
}
} }
if (self->access) { if (self->access) {

View File

@ -406,11 +406,11 @@ text_layout_raqm(PyObject* string, FontObject* self, const char* dir, PyObject *
direction = RAQM_DIRECTION_DEFAULT; direction = RAQM_DIRECTION_DEFAULT;
if (dir) { if (dir) {
if (strcmp(dir, "rtl") == 0) if (strcmp(dir, "rtl") == 0) {
direction = RAQM_DIRECTION_RTL; direction = RAQM_DIRECTION_RTL;
else if (strcmp(dir, "ltr") == 0) } else if (strcmp(dir, "ltr") == 0) {
direction = RAQM_DIRECTION_LTR; direction = RAQM_DIRECTION_LTR;
else if (strcmp(dir, "ttb") == 0) { } else if (strcmp(dir, "ttb") == 0) {
direction = RAQM_DIRECTION_TTB; direction = RAQM_DIRECTION_TTB;
if (p_raqm.version_atleast == NULL || !(*p_raqm.version_atleast)(0, 7, 0)) { if (p_raqm.version_atleast == NULL || !(*p_raqm.version_atleast)(0, 7, 0)) {
PyErr_SetString(PyExc_ValueError, "libraqm 0.7 or greater required for 'ttb' direction"); PyErr_SetString(PyExc_ValueError, "libraqm 0.7 or greater required for 'ttb' direction");
@ -694,8 +694,9 @@ font_getsize(FontObject* self, PyObject* args)
offset = -glyph_info[i].y_advance - offset = -glyph_info[i].y_advance -
face->glyph->metrics.height - face->glyph->metrics.height -
face->glyph->metrics.vertBearingY; face->glyph->metrics.vertBearingY;
if (offset < 0) if (offset < 0) {
y_max -= offset; y_max -= offset;
}
} }
if (bbox.xMax > x_max) { if (bbox.xMax > x_max) {

View File

@ -1085,8 +1085,9 @@ PyImaging_JpegEncoderNew(PyObject* self, PyObject* args)
if (extra && extra_size > 0) { if (extra && extra_size > 0) {
/* malloc check ok, length is from python parsearg */ /* malloc check ok, length is from python parsearg */
char* p = malloc(extra_size); // Freed in JpegEncode, Case 5 char* p = malloc(extra_size); // Freed in JpegEncode, Case 5
if (!p) if (!p) {
return PyErr_NoMemory(); return PyErr_NoMemory();
}
memcpy(p, extra, extra_size); memcpy(p, extra, extra_size);
extra = p; extra = p;
} else { } else {
@ -1097,7 +1098,9 @@ PyImaging_JpegEncoderNew(PyObject* self, PyObject* args)
/* malloc check ok, length is from python parsearg */ /* malloc check ok, length is from python parsearg */
char* pp = malloc(rawExifLen); // Freed in JpegEncode, Case 5 char* pp = malloc(rawExifLen); // Freed in JpegEncode, Case 5
if (!pp) { if (!pp) {
if (extra) free(extra); if (extra) {
free(extra);
}
return PyErr_NoMemory(); return PyErr_NoMemory();
} }
memcpy(pp, rawExif, rawExifLen); memcpy(pp, rawExif, rawExifLen);

View File

@ -1660,17 +1660,16 @@ convert(Imaging imOut, Imaging imIn, const char *mode,
} }
} }
if (!convert) if (!convert) {
#ifdef notdef #ifdef notdef
return (Imaging) ImagingError_ValueError("conversion not supported"); return (Imaging) ImagingError_ValueError("conversion not supported");
#else #else
{ static char buf[256];
static char buf[256]; /* FIXME: may overflow if mode is too large */
/* FIXME: may overflow if mode is too large */ sprintf(buf, "conversion from %s to %s not supported", imIn->mode, mode);
sprintf(buf, "conversion from %s to %s not supported", imIn->mode, mode); return (Imaging) ImagingError_ValueError(buf);
return (Imaging) ImagingError_ValueError(buf);
}
#endif #endif
}
imOut = ImagingNew2Dirty(mode, imOut, imIn); imOut = ImagingNew2Dirty(mode, imOut, imIn);
if (!imOut) { if (!imOut) {

View File

@ -32,11 +32,13 @@ ImagingCrop(Imaging imIn, int sx0, int sy0, int sx1, int sy1)
} }
xsize = sx1 - sx0; xsize = sx1 - sx0;
if (xsize < 0) if (xsize < 0) {
xsize = 0; xsize = 0;
}
ysize = sy1 - sy0; ysize = sy1 - sy0;
if (ysize < 0) if (ysize < 0) {
ysize = 0; ysize = 0;
}
imOut = ImagingNewDirty(imIn->mode, xsize, ysize); imOut = ImagingNewDirty(imIn->mode, xsize, ysize);
if (!imOut) { if (!imOut) {

View File

@ -941,8 +941,9 @@ ellipse(Imaging im, int x0, int y0, int x1, int y1,
} }
lx = x, ly = y; lx = x, ly = y;
} }
if (n == 0) if (n == 0) {
return 0; return 0;
}
if (inner) { if (inner) {
// Inner circle // Inner circle

View File

@ -39,15 +39,18 @@ ImagingGetBBox(Imaging im, int bbox[4])
for (x = 0; x < im->xsize; x++) {\ for (x = 0; x < im->xsize; x++) {\
if (im->image[y][x] & mask) {\ if (im->image[y][x] & mask) {\
has_data = 1;\ has_data = 1;\
if (x < bbox[0])\ if (x < bbox[0]) {\
bbox[0] = x;\ bbox[0] = x;\
if (x >= bbox[2])\ }\
if (x >= bbox[2]) {\
bbox[2] = x+1;\ bbox[2] = x+1;\
}\
}\ }\
}\ }\
if (has_data) {\ if (has_data) {\
if (bbox[1] < 0)\ if (bbox[1] < 0) {\
bbox[1] = y;\ bbox[1] = y;\
}\
bbox[3] = y+1;\ bbox[3] = y+1;\
}\ }\
} }

View File

@ -52,8 +52,9 @@
default:\ default:\
return -1;\ return -1;\
}\ }\
if (state->y < state->ysize)\ if (state->y < state->ysize) {\
out = im->image8[state->y + state->yoff] + state->xoff;\ out = im->image8[state->y + state->yoff] + state->xoff;\
}\
} }
@ -70,24 +71,25 @@ ImagingGifDecode(Imaging im, ImagingCodecState state, UINT8* buffer, Py_ssize_t
if (!state->state) { if (!state->state) {
/* Initialise state */ /* Initialise state */
if (context->bits < 0 || context->bits > 12) { if (context->bits < 0 || context->bits > 12) {
state->errcode = IMAGING_CODEC_CONFIG; state->errcode = IMAGING_CODEC_CONFIG;
return -1; return -1;
} }
/* Clear code */ /* Clear code */
context->clear = 1 << context->bits; context->clear = 1 << context->bits;
/* End code */ /* End code */
context->end = context->clear + 1; context->end = context->clear + 1;
/* Interlace */ /* Interlace */
if (context->interlace) { if (context->interlace) {
context->interlace = 1; context->interlace = 1;
context->step = context->repeat = 8; context->step = context->repeat = 8;
} else } else {
context->step = 1; context->step = 1;
}
state->state = 1; state->state = 1;
} }

View File

@ -179,8 +179,9 @@ ImagingGetHistogram(Imaging im, Imaging imMask, void* minmax)
FLOAT32* in = (FLOAT32*) im->image32[y]; FLOAT32* in = (FLOAT32*) im->image32[y];
for (x = 0; x < im->xsize; x++) { for (x = 0; x < im->xsize; x++) {
i = (int) (((*in++)-fmin)*scale); i = (int) (((*in++)-fmin)*scale);
if (i >= 0 && i < 256) if (i >= 0 && i < 256) {
h->histogram[i]++; h->histogram[i]++;
}
} }
} }
ImagingSectionLeave(&cookie); ImagingSectionLeave(&cookie);

View File

@ -219,8 +219,9 @@ ImagingPointTransform(Imaging imIn, double scale, double offset)
if (!imIn || (strcmp(imIn->mode, "I") != 0 && if (!imIn || (strcmp(imIn->mode, "I") != 0 &&
strcmp(imIn->mode, "I;16") != 0 && strcmp(imIn->mode, "I;16") != 0 &&
strcmp(imIn->mode, "F") != 0)) strcmp(imIn->mode, "F") != 0)) {
return (Imaging) ImagingError_ModeError(); return (Imaging) ImagingError_ModeError();
}
imOut = ImagingNew(imIn->mode, imIn->xsize, imIn->ysize); imOut = ImagingNew(imIn->mode, imIn->xsize, imIn->ysize);
if (!imOut) { if (!imOut) {

View File

@ -689,8 +689,12 @@ static void
free_box_tree(BoxNode *n) free_box_tree(BoxNode *n)
{ {
PixelList *p,*pp; PixelList *p,*pp;
if (n->l) free_box_tree(n->l); if (n->l) {
if (n->r) free_box_tree(n->r); free_box_tree(n->l);
}
if (n->r) {
free_box_tree(n->r);
}
for (p=n->head[0];p;p=pp) { for (p=n->head[0];p;p=pp) {
pp=p->next[0]; pp=p->next[0];
free(p); free(p);
@ -1008,7 +1012,9 @@ compute_palette_from_median_cut(
/* malloc check ok, using calloc */ /* malloc check ok, using calloc */
if (!(avg[i]=calloc(nPaletteEntries, sizeof(uint32_t)))) { if (!(avg[i]=calloc(nPaletteEntries, sizeof(uint32_t)))) {
for(i=0;i<3;i++) { for(i=0;i<3;i++) {
if (avg[i]) free (avg[i]); if (avg[i]) {
free (avg[i]);
}
} }
free(count); free(count);
return 0; return 0;

View File

@ -41,8 +41,9 @@ ImagingRawEncode(Imaging im, ImagingCodecState state, UINT8* buf, int bytes)
} }
state->count = state->bytes; state->count = state->bytes;
state->bytes = bytes; state->bytes = bytes;
} else } else {
state->count = state->bytes; state->count = state->bytes;
}
/* The "ystep" field specifies the orientation */ /* The "ystep" field specifies the orientation */

View File

@ -90,8 +90,9 @@ ImagingXbmEncode(Imaging im, ImagingCodecState state, UINT8* buf, int bytes)
bytes--; bytes--;
state->count = 0; state->count = 0;
} }
} else } else {
*ptr++ = '\n'; *ptr++ = '\n';
}
bytes -= 5; bytes -= 5;

View File

@ -307,8 +307,9 @@ ImagingZipEncode(Imaging im, ImagingCodecState state, UINT8* buf, int bytes)
} }
if (context->z_stream.avail_out == 0) if (context->z_stream.avail_out == 0) {
break; /* Buffer full */ break; /* Buffer full */
}
case 2: case 2: