Skip to content

Commit

Permalink
Merge pull request #21 from SumiMakito/develop
Browse files Browse the repository at this point in the history
Fixed the "divide by zero" error mentioned in #20.
  • Loading branch information
sumimakito authored Aug 25, 2017
2 parents 4ed2531 + 58bbcd9 commit 82a3811
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 22 deletions.
15 changes: 1 addition & 14 deletions .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 4 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ Then, add below lines in build.gradle of your app module:

```
dependencies {
compile 'com.github.SumiMakito:AwesomeQRCode:1.0.5'
compile 'com.github.SumiMakito:AwesomeQRCode:latest'
}
```

Expand Down Expand Up @@ -112,8 +112,10 @@ logoScale | float | Value used to scale the logo image. Larger value may result

## Changelog

### Version 1.0.5
#### Version 1.0.6
- Fixed a "divide by zero" error mentioned in [#20](https://github.com/SumiMakito/AwesomeQRCode/issues/20).

#### Version 1.0.5
- The way to use AwesomeQRCode is more elegant.

### Version 1.0.4
Expand Down
4 changes: 2 additions & 2 deletions library/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ android {
defaultConfig {
minSdkVersion 9
targetSdkVersion 25
versionCode 6
versionName "1.0.5"
versionCode 7
versionName "1.0.6"

testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -374,10 +374,16 @@ private static int getDominantColor(Bitmap bitmap) {
}
}
newBitmap.recycle();
red = Math.max(0, Math.min(0xFF, red / c));
green = Math.max(0, Math.min(0xFF, green / c));
blue = Math.max(0, Math.min(0xFF, blue / c));
return (0xFF << 24) | (red << 16) | (green << 8) | blue;
if(c==0){
// got a bitmap with no pixels in it
// avoid the "divide by zero" error
return 0xFF000000;
}else {
red = Math.max(0, Math.min(0xFF, red / c));
green = Math.max(0, Math.min(0xFF, green / c));
blue = Math.max(0, Math.min(0xFF, blue / c));
return (0xFF << 24) | (red << 16) | (green << 8) | blue;
}
}

private static void binarize(Bitmap bitmap, int threshold) {
Expand Down

0 comments on commit 82a3811

Please sign in to comment.