Skip to content

Commit

Permalink
PMD.TooManyStaticImports: qualify ImageType
Browse files Browse the repository at this point in the history
It's actually harder to read with static imports, hard to know if one is enum or int constant.
Also there was mixed usage of static and non-static access to ImageType.
  • Loading branch information
TWiStErRob committed Jan 1, 2018
1 parent 0d90947 commit 4809049
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 14 deletions.
2 changes: 0 additions & 2 deletions library/pmd-ruleset.xml
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,6 @@
<exclude name="AvoidFinalLocalVariable" />
<!-- These are often useful for clarity and explicitly suggested by Google's code style. -->
<exclude name="UselessParentheses" />
<!-- Theoretically this might be reasonable but the number of imports probably varies from class to class and this doesn't seem worth the overhead to maintain. -->
<exclude name="TooManyStaticImports" />
<!-- Lots of existing violations, not clear that the overhead is worthwhile though there are some cases where we definitely need to call super. FIXME. -->
<exclude name="CallSuperInConstructor" />
<!-- This is a reasonable idea, but in practice often the != null case is the expected case and it makes sense for it to come first. -->
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,5 @@
package com.bumptech.glide.load.resource.bitmap;

import static com.bumptech.glide.load.ImageHeaderParser.ImageType.GIF;
import static com.bumptech.glide.load.ImageHeaderParser.ImageType.JPEG;
import static com.bumptech.glide.load.ImageHeaderParser.ImageType.PNG;
import static com.bumptech.glide.load.ImageHeaderParser.ImageType.PNG_A;
import static com.bumptech.glide.load.ImageHeaderParser.ImageType.UNKNOWN;

import android.util.Log;
import com.bumptech.glide.load.ImageHeaderParser;
import com.bumptech.glide.load.engine.bitmap_recycle.ArrayPool;
Expand Down Expand Up @@ -83,7 +77,7 @@ private ImageType getType(Reader reader) throws IOException {

// JPEG.
if (firstTwoBytes == EXIF_MAGIC_NUMBER) {
return JPEG;
return ImageType.JPEG;
}

final int firstFourBytes = (firstTwoBytes << 16 & 0xFFFF0000) | (reader.getUInt16() & 0xFFFF);
Expand All @@ -94,30 +88,30 @@ private ImageType getType(Reader reader) throws IOException {
reader.skip(25 - 4);
int alpha = reader.getByte();
// A RGB indexed PNG can also have transparency. Better safe than sorry!
return alpha >= 3 ? PNG_A : PNG;
return alpha >= 3 ? ImageType.PNG_A : ImageType.PNG;
}

// GIF from first 3 bytes.
if (firstFourBytes >> 8 == GIF_HEADER) {
return GIF;
return ImageType.GIF;
}

// WebP (reads up to 21 bytes). See https://developers.google.com/speed/webp/docs/riff_container
// for details.
if (firstFourBytes != RIFF_HEADER) {
return UNKNOWN;
return ImageType.UNKNOWN;
}
// Bytes 4 - 7 contain length information. Skip these.
reader.skip(4);
final int thirdFourBytes =
(reader.getUInt16() << 16 & 0xFFFF0000) | (reader.getUInt16() & 0xFFFF);
if (thirdFourBytes != WEBP_HEADER) {
return UNKNOWN;
return ImageType.UNKNOWN;
}
final int fourthFourBytes =
(reader.getUInt16() << 16 & 0xFFFF0000) | (reader.getUInt16() & 0xFFFF);
if ((fourthFourBytes & VP8_HEADER_MASK) != VP8_HEADER) {
return UNKNOWN;
return ImageType.UNKNOWN;
}
if ((fourthFourBytes & VP8_HEADER_TYPE_MASK) == VP8_HEADER_TYPE_EXTENDED) {
// Skip some more length bytes and check for transparency/alpha flag.
Expand Down

0 comments on commit 4809049

Please sign in to comment.