From 35e7483ed5a2f9c5b33db9ee6066ec89ddb2bc04 Mon Sep 17 00:00:00 2001 From: David Capello Date: Wed, 29 Jul 2020 11:13:44 -0300 Subject: [PATCH] Minor change BmpFormat::onSave() Use "w" and "h" instead of "image->width()/height()" --- src/app/file/bmp_format.cpp | 28 ++++++++++++++++------------ 1 file changed, 16 insertions(+), 12 deletions(-) diff --git a/src/app/file/bmp_format.cpp b/src/app/file/bmp_format.cpp index 7b4d65773..0af7cff4f 100644 --- a/src/app/file/bmp_format.cpp +++ b/src/app/file/bmp_format.cpp @@ -752,6 +752,8 @@ bool BmpFormat::onLoad(FileOp *fop) bool BmpFormat::onSave(FileOp *fop) { const Image* image = fop->sequenceImage(); + const int w = image->width(); + const int h = image->height(); int bfSize; int biSizeImage; int indexBits = fop->sequenceGetNColors(); @@ -764,22 +766,22 @@ bool BmpFormat::onSave(FileOp *fop) int bpp = (image->pixelFormat() == IMAGE_RGB ? 24 : indexBits); int filler; if (bpp == 24) - filler = 3 - ((image->width() * (bpp / 8) - 1) & 3); + filler = 3 - ((w * (bpp / 8) - 1) & 3); else if(bpp == 8) - filler = (3 - ((image->width() - 1) & 3)); + filler = (3 - ((w - 1) & 3)); else - filler = (3 - (((image->width()+1)/2 - 1) & 3)); + filler = (3 - (((w+1)/2 - 1) & 3)); int c, i, j, r, g, b; if (bpp <= 8) { - biSizeImage = (image->width() + filler)*bpp/8 * image->height(); + biSizeImage = (w + filler)*bpp/8 * h; bfSize = (54 /* header */ + (indexColorCount)*4 /* palette */ + biSizeImage); /* image data */ } else { - biSizeImage = (image->width()*3 + filler) * image->height(); + biSizeImage = (w*3 + filler) * h; bfSize = 54 + biSizeImage; /* header + image data */ } @@ -799,8 +801,8 @@ bool BmpFormat::onSave(FileOp *fop) /* info_header */ fputl(40, f); /* biSize */ - fputl(image->width(), f); /* biWidth */ - fputl(image->height(), f); /* biHeight */ + fputl(w, f); /* biWidth */ + fputl(h, f); /* biHeight */ fputw(1, f); /* biPlanes */ fputw(bpp, f); /* biBitCount */ fputl(0, f); /* biCompression */ @@ -835,15 +837,17 @@ bool BmpFormat::onSave(FileOp *fop) int colorsInByte = 8/bpp; /* image data */ - for (i=image->height()-1; i>=0; i--) { - for (j=0; jwidth(); j++) { + for (i=h-1; i>=0; i--) { + for (j=0; jpixelFormat() == IMAGE_INDEXED) { char value = 0; for (int k = colorsInByte-1; k >= 0; --k) { int shiftValue = bpp*k; - if (j+(colorsInByte-1-k) < image->width()) - value |= (get_pixel_fast(image, j+(colorsInByte-1-k), i)<<((shiftValue)))&(colorMask<<((shiftValue))); + int u = (j+(colorsInByte-1-k)); + if (u >= w) + break; + value |= (get_pixel_fast(image, u, i)<<((shiftValue)))&(colorMask<<((shiftValue))); } fputc(value, f); @@ -870,7 +874,7 @@ bool BmpFormat::onSave(FileOp *fop) for (j=0; jsetProgress((float)(image->height()-i) / (float)image->height()); + fop->setProgress((float)(h-i) / (float)h); } if (ferror(f)) {