Skip to content

Commit d46c8a6

Browse files
authored
Merge pull request #109 from algrid/fix-grayscale
M13ProgressViewImage - fix createImageForCurrentProgress (types and g…
2 parents cee320a + 5c64775 commit d46c8a6

File tree

1 file changed

+9
-9
lines changed

1 file changed

+9
-9
lines changed

Classes/ProgressViews/M13ProgressViewImage.m

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -187,10 +187,10 @@ - (void)drawRect:(CGRect)rect
187187
- (UIImage *)createImageForCurrentProgress
188188
{
189189
const int ALPHA = 0;
190-
const int RED = 1;
190+
const int RED = 3;
191191
const int GREEN = 2;
192-
const int BLUE = 3;
193-
192+
const int BLUE = 1;
193+
194194
//Create image rectangle with current image width/height
195195
CGRect imageRect = CGRectMake(0, 0, _progressImage.size.width * _progressImage.scale, _progressImage.size.height * _progressImage.scale);
196196

@@ -218,23 +218,23 @@ - (UIImage *)createImageForCurrentProgress
218218
int yTo = height;
219219

220220
if (_progressDirection == M13ProgressViewImageProgressDirectionBottomToTop) {
221-
yTo = height * (int)(1 - self.progress);
221+
yTo = (int)(height * (1 - self.progress));
222222
} else if (_progressDirection == M13ProgressViewImageProgressDirectionTopToBottom) {
223-
yFrom = height * (int)self.progress;
223+
yFrom = (int)(height * self.progress);
224224
} else if (_progressDirection == M13ProgressViewImageProgressDirectionLeftToRight) {
225-
xFrom = width * (int)self.progress;
225+
xFrom = (int)(width * self.progress);
226226
} else if (_progressDirection == M13ProgressViewImageProgressDirectionRightToLeft) {
227-
xTo = width * (int)(1 - self.progress);
227+
xTo = (int)(width * (1 - self.progress));
228228
}
229229

230230
for (int x = xFrom; x < xTo; x++) {
231231
for (int y = yFrom; y < yTo; y++) {
232232
//Get the pixel
233-
uint32_t *rgbaPixel = (uint32_t *) &pixels[y * width + x];
233+
uint8_t *rgbaPixel = (uint8_t *) &pixels[y * width + x];
234234
//Convert
235235
if (_drawGreyscaleBackground) {
236236
//Convert to grayscale using luma coding: http://en.wikipedia.org/wiki/Grayscale#Converting_color_to_grayscale
237-
uint32_t gray = (uint32_t)(0.3 * rgbaPixel[RED] + 0.59 * rgbaPixel[GREEN] + 0.11 * rgbaPixel[BLUE]);
237+
uint8_t gray = (uint8_t)(0.3 * rgbaPixel[RED] + 0.59 * rgbaPixel[GREEN] + 0.11 * rgbaPixel[BLUE]);
238238
// set the pixels to gray
239239
rgbaPixel[RED] = gray;
240240
rgbaPixel[GREEN] = gray;

0 commit comments

Comments
 (0)