Skip to content

Commit

Permalink
Merge pull request #754 from stweil/fix_warnings
Browse files Browse the repository at this point in the history
Fix warnings for builds with clang compiler
  • Loading branch information
DanBloomberg authored Oct 14, 2024
2 parents 0e8ac0c + b322384 commit 681f4a3
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 87 deletions.
18 changes: 9 additions & 9 deletions prog/partition_reg.c
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,9 @@

#include "allheaders.h"

void TestPartition(L_REGPARAMS *rp, const char *fname, l_int32 sorttype,
l_int32 maxboxes, l_int32 ovlap, const char *fileout,
PIXA *pixad);
static void TestPartition(L_REGPARAMS *rp, const char *fname, l_int32 sorttype,
l_int32 maxboxes, l_float32 ovlap,
const char *fileout, PIXA *pixad);

int main(int argc,
char **argv)
Expand All @@ -68,13 +68,13 @@ L_REGPARAMS *rp;
lept_mkdir("lept/part");

pixad = pixaCreate(4); /* only for display */
TestPartition(rp, "test8.jpg", L_SORT_BY_HEIGHT, 20, 0.0, "test0.pdf",
TestPartition(rp, "test8.jpg", L_SORT_BY_HEIGHT, 20, 0.0f, "test0.pdf",
pixad);
TestPartition(rp, "test8.jpg", L_SORT_BY_AREA, 20, 0.0, "test1.pdf",
TestPartition(rp, "test8.jpg", L_SORT_BY_AREA, 20, 0.0f, "test1.pdf",
pixad);
TestPartition(rp, "test8.jpg", L_SORT_BY_AREA, 20, 0.4, "test2.pdf",
TestPartition(rp, "test8.jpg", L_SORT_BY_AREA, 20, 0.4f, "test2.pdf",
pixad);
TestPartition(rp, "feyn-fract.tif", L_SORT_BY_AREA, 20, 0.0, "test3.pdf",
TestPartition(rp, "feyn-fract.tif", L_SORT_BY_AREA, 20, 0.0f, "test3.pdf",
pixad);

/* If display requested, make a tiled image of all the results */
Expand All @@ -90,9 +90,9 @@ L_REGPARAMS *rp;
}


void
static void
TestPartition(L_REGPARAMS *rp, const char *fname, l_int32 sorttype,
l_int32 maxboxes, l_int32 ovlap, const char *fileout,
l_int32 maxboxes, l_float32 ovlap, const char *fileout,
PIXA *pixad)
{
char pathout[256];
Expand Down
14 changes: 0 additions & 14 deletions src/bmp.h
Original file line number Diff line number Diff line change
Expand Up @@ -107,18 +107,4 @@ typedef struct BMP_InfoHeader BMP_IH;
/*! Number of bytes in a BMP info header */
#define BMP_IHBYTES sizeof(BMP_IH)


/*-------------------------------------------------------------*
* Align BMP headers on 4 byte boundaries *
*-------------------------------------------------------------*/

/*! BMP_IH is misaligned, causing crashes on some big-endians.
* A packed struct forces alignment. */
#if defined(__GNUC__)
typedef struct __attribute__((__packed__)) {
BMP_FH bmpfh;
BMP_IH bmpih;
} BMP_HEADER;
#endif

#endif /* LEPTONICA_BMP_H */
63 changes: 23 additions & 40 deletions src/bmpio.c
Original file line number Diff line number Diff line change
Expand Up @@ -142,12 +142,7 @@ l_uint32 ihbytes;
l_uint32 *line, *pixdata, *pword;
l_int64 npixels;
BMP_FH *bmpfh;
#if defined(__GNUC__)
BMP_HEADER *bmph;
#define bmpih (&bmph->bmpih)
#else
BMP_IH *bmpih;
#endif
BMP_IH bmpih;
PIX *pix, *pix1;
PIXCMAP *cmap;

Expand All @@ -161,12 +156,8 @@ PIXCMAP *cmap;
bftype = bmpfh->bfType[0] + ((l_int32)bmpfh->bfType[1] << 8);
if (bftype != BMP_ID)
return (PIX *)ERROR_PTR("not bmf format", __func__, NULL);
#if defined(__GNUC__)
bmph = (BMP_HEADER *)bmpfh;
#else
bmpih = (BMP_IH *)(cdata + BMP_FHBYTES);
#endif
compression = convertOnBigEnd32(bmpih->biCompression);
memcpy(&bmpih, cdata + BMP_FHBYTES, BMP_IHBYTES);
compression = convertOnBigEnd32(bmpih.biCompression);
if (compression != 0)
return (PIX *)ERROR_PTR("cannot read compressed BMP files",
__func__, NULL);
Expand All @@ -180,15 +171,15 @@ PIXCMAP *cmap;
/* Read the remaining useful data in the infoheader.
* Note that the first 4 bytes give the infoheader size.
* The infoheader pointer on sparc64 is not 32-bit aligned. */
bmpih_b = (l_uint8 *)bmpih;
bmpih_b = (l_uint8 *)&bmpih;
ihbytes = bmpih_b[0] | ((l_int32)bmpih_b[1] << 8) |
((l_int32)bmpih_b[2] << 16) | ((l_uint32)bmpih_b[3] << 24);
width = convertOnBigEnd32(bmpih->biWidth);
height = convertOnBigEnd32(bmpih->biHeight);
depth = convertOnBigEnd16(bmpih->biBitCount);
imagebytes = convertOnBigEnd32(bmpih->biSizeImage);
xres = convertOnBigEnd32(bmpih->biXPelsPerMeter);
yres = convertOnBigEnd32(bmpih->biYPelsPerMeter);
width = convertOnBigEnd32(bmpih.biWidth);
height = convertOnBigEnd32(bmpih.biHeight);
depth = convertOnBigEnd16(bmpih.biBitCount);
imagebytes = convertOnBigEnd32(bmpih.biSizeImage);
xres = convertOnBigEnd32(bmpih.biXPelsPerMeter);
yres = convertOnBigEnd32(bmpih.biYPelsPerMeter);

/* Some sanity checking. We impose limits on the image
* dimensions, resolution and number of pixels. We make sure the
Expand Down Expand Up @@ -476,12 +467,7 @@ l_uint32 offbytes, fimagebytes;
l_uint32 *line, *pword;
size_t fsize;
BMP_FH *bmpfh;
#if defined(__GNUC__)
BMP_HEADER *bmph;
#define bmpih (&bmph->bmpih)
#else
BMP_IH *bmpih;
#endif
BMP_IH bmpih;
PIX *pix;
PIXCMAP *cmap;
RGBA_QUAD *pquad;
Expand Down Expand Up @@ -602,21 +588,18 @@ RGBA_QUAD *pquad;
bmpfh->bfOffBits[3] = (l_uint8)(offbytes >> 24);

/* Convert to little-endian and write the info header data */
#if defined(__GNUC__)
bmph = (BMP_HEADER *)bmpfh;
#else
bmpih = (BMP_IH *)(fdata + BMP_FHBYTES);
#endif
bmpih->biSize = convertOnBigEnd32(BMP_IHBYTES);
bmpih->biWidth = convertOnBigEnd32(w);
bmpih->biHeight = convertOnBigEnd32(h);
bmpih->biPlanes = convertOnBigEnd16(1);
bmpih->biBitCount = convertOnBigEnd16(fdepth);
bmpih->biSizeImage = convertOnBigEnd32(fimagebytes);
bmpih->biXPelsPerMeter = convertOnBigEnd32(xres);
bmpih->biYPelsPerMeter = convertOnBigEnd32(yres);
bmpih->biClrUsed = convertOnBigEnd32(ncolors);
bmpih->biClrImportant = convertOnBigEnd32(ncolors);
bmpih.biSize = convertOnBigEnd32(BMP_IHBYTES);
bmpih.biWidth = convertOnBigEnd32(w);
bmpih.biHeight = convertOnBigEnd32(h);
bmpih.biPlanes = convertOnBigEnd16(1);
bmpih.biBitCount = convertOnBigEnd16(fdepth);
bmpih.biCompression = 0;
bmpih.biSizeImage = convertOnBigEnd32(fimagebytes);
bmpih.biXPelsPerMeter = convertOnBigEnd32(xres);
bmpih.biYPelsPerMeter = convertOnBigEnd32(yres);
bmpih.biClrUsed = convertOnBigEnd32(ncolors);
bmpih.biClrImportant = convertOnBigEnd32(ncolors);
memcpy(fdata + BMP_FHBYTES, &bmpih, BMP_IHBYTES);

/* Copy the colormap data and free the cta if necessary */
if (ncolors > 0) {
Expand Down
48 changes: 24 additions & 24 deletions src/scale2.c
Original file line number Diff line number Diff line change
Expand Up @@ -216,68 +216,68 @@ PIX *pixt, *pixd;
return (PIX *)ERROR_PTR("pixs not defined", __func__, NULL);
if (pixGetDepth(pixs) != 1)
return (PIX *)ERROR_PTR("pixs not 1 bpp", __func__, NULL);
if (scalefactor <= 0.0)
if (scalefactor <= 0.0f)
return (PIX *)ERROR_PTR("scalefactor <= 0.0", __func__, NULL);
if (scalefactor >= 1.0)
if (scalefactor >= 1.0f)
return (PIX *)ERROR_PTR("scalefactor >= 1.0", __func__, NULL);
pixGetDimensions(pixs, &w, &h, NULL);
minsrc = L_MIN(w, h);
mindest = (l_int32)((l_float32)minsrc * scalefactor);
if (mindest < 2)
return (PIX *)ERROR_PTR("scalefactor too small", __func__, NULL);

if (scalefactor > 0.5) { /* see note (5) */
if (scalefactor > 0.5f) { /* see note (5) */
mag = 2.0f * scalefactor; /* will be < 2.0 */
/* lept_stderr("2x with mag %7.3f\n", mag); */
if ((pixt = pixScaleBinary(pixs, mag, mag)) == NULL)
return (PIX *)ERROR_PTR("pixt not made", __func__, NULL);
pixd = pixScaleToGray2(pixt);
} else if (scalefactor == 0.5) {
} else if (scalefactor == 0.5f) {
return pixd = pixScaleToGray2(pixs);
} else if (scalefactor > 0.33333) { /* see note (5) */
} else if (scalefactor > 0.33333f) { /* see note (5) */
mag = 3.0f * scalefactor; /* will be < 1.5 */
/* lept_stderr("3x with mag %7.3f\n", mag); */
if ((pixt = pixScaleBinary(pixs, mag, mag)) == NULL)
return (PIX *)ERROR_PTR("pixt not made", __func__, NULL);
pixd = pixScaleToGray3(pixt);
} else if (scalefactor > 0.25) { /* see note (5) */
} else if (scalefactor > 0.25f) { /* see note (5) */
mag = 4.0f * scalefactor; /* will be < 1.3333 */
/* lept_stderr("4x with mag %7.3f\n", mag); */
if ((pixt = pixScaleBinary(pixs, mag, mag)) == NULL)
return (PIX *)ERROR_PTR("pixt not made", __func__, NULL);
pixd = pixScaleToGray4(pixt);
} else if (scalefactor == 0.25) {
} else if (scalefactor == 0.25f) {
return pixd = pixScaleToGray4(pixs);
} else if (scalefactor > 0.16667) { /* see note (5) */
} else if (scalefactor > 0.16667f) { /* see note (5) */
mag = 6.0f * scalefactor; /* will be < 1.5 */
/* lept_stderr("6x with mag %7.3f\n", mag); */
if ((pixt = pixScaleBinary(pixs, mag, mag)) == NULL)
return (PIX *)ERROR_PTR("pixt not made", __func__, NULL);
pixd = pixScaleToGray6(pixt);
} else if (scalefactor == 0.16667) {
} else if (scalefactor == 0.16667f) {
return pixd = pixScaleToGray6(pixs);
} else if (scalefactor > 0.125) { /* see note (5) */
} else if (scalefactor > 0.125f) { /* see note (5) */
mag = 8.0f * scalefactor; /* will be < 1.3333 */
/* lept_stderr("8x with mag %7.3f\n", mag); */
if ((pixt = pixScaleBinary(pixs, mag, mag)) == NULL)
return (PIX *)ERROR_PTR("pixt not made", __func__, NULL);
pixd = pixScaleToGray8(pixt);
} else if (scalefactor == 0.125) {
} else if (scalefactor == 0.125f) {
return pixd = pixScaleToGray8(pixs);
} else if (scalefactor > 0.0625) { /* see note (6) */
} else if (scalefactor > 0.0625f) { /* see note (6) */
red = 8.0f * scalefactor; /* will be > 0.5 */
/* lept_stderr("8x with red %7.3f\n", red); */
if ((pixt = pixScaleBinary(pixs, red, red)) == NULL)
return (PIX *)ERROR_PTR("pixt not made", __func__, NULL);
pixd = pixScaleToGray8(pixt);
} else if (scalefactor == 0.0625) {
} else if (scalefactor == 0.0625f) {
return pixd = pixScaleToGray16(pixs);
} else { /* see note (7) */
red = 16.0f * scalefactor; /* will be <= 1.0 */
/* lept_stderr("16x with red %7.3f\n", red); */
if ((pixt = pixScaleToGray16(pixs)) == NULL)
return (PIX *)ERROR_PTR("pixt not made", __func__, NULL);
if (red < 0.7)
if (red < 0.7f)
pixd = pixScaleSmooth(pixt, red, red); /* see note (3) */
else
pixd = pixScaleGrayLI(pixt, red, red); /* see note (2) */
Expand Down Expand Up @@ -325,9 +325,9 @@ PIX *pixt, *pixd;
return (PIX *)ERROR_PTR("pixs not defined", __func__, NULL);
if (pixGetDepth(pixs) != 1)
return (PIX *)ERROR_PTR("pixs not 1 bpp", __func__, NULL);
if (scalefactor <= 0.0)
if (scalefactor <= 0.0f)
return (PIX *)ERROR_PTR("scalefactor <= 0.0", __func__, NULL);
if (scalefactor >= 1.0)
if (scalefactor >= 1.0f)
return (PIX *)ERROR_PTR("scalefactor >= 1.0", __func__, NULL);
pixGetDimensions(pixs, &w, &h, NULL);
minsrc = L_MIN(w, h);
Expand All @@ -337,20 +337,20 @@ PIX *pixt, *pixd;
eps = 0.0001f;

/* Handle the special cases */
if (scalefactor > 0.5 - eps && scalefactor < 0.5 + eps)
if (scalefactor > 0.5f - eps && scalefactor < 0.5f + eps)
return pixScaleToGray2(pixs);
else if (scalefactor > 0.33333 - eps && scalefactor < 0.33333 + eps)
else if (scalefactor > 0.33333f - eps && scalefactor < 0.33333f + eps)
return pixScaleToGray3(pixs);
else if (scalefactor > 0.25 - eps && scalefactor < 0.25 + eps)
else if (scalefactor > 0.25f - eps && scalefactor < 0.25f + eps)
return pixScaleToGray4(pixs);
else if (scalefactor > 0.16666 - eps && scalefactor < 0.16666 + eps)
else if (scalefactor > 0.16666f - eps && scalefactor < 0.16666f + eps)
return pixScaleToGray6(pixs);
else if (scalefactor > 0.125 - eps && scalefactor < 0.125 + eps)
else if (scalefactor > 0.125f - eps && scalefactor < 0.125f + eps)
return pixScaleToGray8(pixs);
else if (scalefactor > 0.0625 - eps && scalefactor < 0.0625 + eps)
else if (scalefactor > 0.0625f - eps && scalefactor < 0.0625f + eps)
return pixScaleToGray16(pixs);

if (scalefactor > 0.0625) { /* scale binary first */
if (scalefactor > 0.0625f) { /* scale binary first */
factor = 2.0f * scalefactor;
if ((pixt = pixScaleBinary(pixs, factor, factor)) == NULL)
return (PIX *)ERROR_PTR("pixt not made", __func__, NULL);
Expand All @@ -359,7 +359,7 @@ PIX *pixt, *pixd;
factor = 16.0f * scalefactor; /* will be < 1.0 */
if ((pixt = pixScaleToGray16(pixs)) == NULL)
return (PIX *)ERROR_PTR("pixt not made", __func__, NULL);
if (factor < 0.7)
if (factor < 0.7f)
pixd = pixScaleSmooth(pixt, factor, factor);
else
pixd = pixScaleGrayLI(pixt, factor, factor);
Expand Down

0 comments on commit 681f4a3

Please sign in to comment.