You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@commons.apache.org by GitBox <gi...@apache.org> on 2021/07/02 12:50:10 UTC

[GitHub] [commons-imaging] kinow commented on a change in pull request #154: Simplify conditions and avoid extra checks.

kinow commented on a change in pull request #154:
URL: https://github.com/apache/commons-imaging/pull/154#discussion_r662987475



##########
File path: src/main/java/org/apache/commons/imaging/formats/png/PngWriter.java
##########
@@ -447,7 +447,7 @@ public void writeImage(final BufferedImage src, final OutputStream os, Map<Strin
             final PaletteFactory paletteFactory = new PaletteFactory();
 
             if (hasAlpha) {
-                palette = paletteFactory.makeQuantizedRgbaPalette(src, hasAlpha, maxColors);
+                palette = paletteFactory.makeQuantizedRgbaPalette(src, true, maxColors);

Review comment:
       I think it's fine to pass `hasAlpha` here. Easier to see (or guess) that that's a flag for transparency, especially in case we add more booleans to that method later.

##########
File path: src/main/java/org/apache/commons/imaging/palette/LongestAxisMedianCut.java
##########
@@ -43,7 +43,7 @@ public boolean performNextMedianCut(final List<ColorGroup> colorGroups, final bo
                 && colorGroup.alphaDiff > colorGroup.redDiff
                 && colorGroup.alphaDiff > colorGroup.greenDiff
                 && colorGroup.alphaDiff > colorGroup.blueDiff) {
-            doCut(colorGroup, ColorComponent.ALPHA, colorGroups, ignoreAlpha);
+            doCut(colorGroup, ColorComponent.ALPHA, colorGroups, false);

Review comment:
       I think it was harmless to keep using `ignoreAlpha` here. There are other conditions in this if statement, and they are all using `ignoreAlpha`. Having that variable in all the conditions might make it easier to remove/update it later if necessary.




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@commons.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org