forked from DylanVann/react-native-fast-image
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request DylanVann#3 from ArekChr/feat/merge_patches_from_e…
…xpensify feat: migrate patches
- Loading branch information
Showing
8 changed files
with
152 additions
and
14 deletions.
There are no files selected for viewing
44 changes: 44 additions & 0 deletions
44
android/src/main/java/com/dylanvann/fastimage/BitmapSizeDecoder.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
package com.dylanvann.fastimage; | ||
|
||
import android.graphics.BitmapFactory; | ||
|
||
import androidx.annotation.NonNull; | ||
import androidx.annotation.Nullable; | ||
import androidx.exifinterface.media.ExifInterface; | ||
|
||
import com.bumptech.glide.load.Options; | ||
import com.bumptech.glide.load.ResourceDecoder; | ||
import com.bumptech.glide.load.engine.Resource; | ||
import com.bumptech.glide.load.resource.SimpleResource; | ||
|
||
import java.io.IOException; | ||
import java.io.InputStream; | ||
|
||
public class BitmapSizeDecoder implements ResourceDecoder<InputStream, BitmapFactory.Options> { | ||
|
||
@Override | ||
public boolean handles(@NonNull InputStream source, @NonNull Options options) throws IOException { | ||
return true; | ||
} | ||
|
||
@Nullable | ||
@Override | ||
public Resource<BitmapFactory.Options> decode(@NonNull InputStream source, int width, int height, @NonNull Options options) throws IOException { | ||
BitmapFactory.Options bitmapOptions = new BitmapFactory.Options(); | ||
bitmapOptions.inJustDecodeBounds = true; | ||
BitmapFactory.decodeStream(source, null, bitmapOptions); | ||
|
||
// BitmapFactory#decodeStream leaves stream's position where ever it was after reading the encoded data | ||
// https://developer.android.com/reference/android/graphics/BitmapFactory#decodeStream(java.io.InputStream) | ||
// so we need to rewind the stream to be able to read image header with exif values | ||
source.reset(); | ||
|
||
int orientation = new ExifInterface(source).getAttributeInt(ExifInterface.TAG_ORIENTATION, ExifInterface.ORIENTATION_UNDEFINED); | ||
if (orientation == ExifInterface.ORIENTATION_ROTATE_90 || orientation == ExifInterface.ORIENTATION_ROTATE_270) { | ||
int tmpWidth = bitmapOptions.outWidth; | ||
bitmapOptions.outWidth = bitmapOptions.outHeight; | ||
bitmapOptions.outHeight = tmpWidth; | ||
} | ||
return new SimpleResource(bitmapOptions); | ||
} | ||
} |
23 changes: 23 additions & 0 deletions
23
android/src/main/java/com/dylanvann/fastimage/BitmapSizeTranscoder.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package com.dylanvann.fastimage; | ||
|
||
import android.graphics.BitmapFactory; | ||
|
||
import androidx.annotation.NonNull; | ||
import androidx.annotation.Nullable; | ||
|
||
import com.bumptech.glide.load.Options; | ||
import com.bumptech.glide.load.engine.Resource; | ||
import com.bumptech.glide.load.resource.SimpleResource; | ||
import com.bumptech.glide.load.resource.transcode.ResourceTranscoder; | ||
|
||
public class BitmapSizeTranscoder implements ResourceTranscoder<BitmapFactory.Options, Size> { | ||
@Nullable | ||
@Override | ||
public Resource<Size> transcode(@NonNull Resource<BitmapFactory.Options> toTranscode, @NonNull Options options) { | ||
BitmapFactory.Options bitmap = toTranscode.get(); | ||
Size size = new Size(); | ||
size.width = bitmap.outWidth; | ||
size.height = bitmap.outHeight; | ||
return new SimpleResource(size); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
package com.dylanvann.fastimage; | ||
|
||
public class Size { | ||
int width; | ||
int height; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters