@amazon-devices/expo-image 2.0.1758683737
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.eslintrc.js +2 -0
- package/CHANGELOG.md +285 -0
- package/CMakeLists.txt +91 -0
- package/LICENSE +7 -0
- package/README.kepler.md +123 -0
- package/README.md +54 -0
- package/THIRD_PARTY_NOTICES.txt +24 -0
- package/android/build.gradle +124 -0
- package/android/proguard-rules.pro +28 -0
- package/android/src/main/AndroidManifest.xml +15 -0
- package/android/src/main/java/expo/modules/image/Exceptions.kt +9 -0
- package/android/src/main/java/expo/modules/image/ExpoImageAppGlideModule.kt +19 -0
- package/android/src/main/java/expo/modules/image/ExpoImageModule.kt +192 -0
- package/android/src/main/java/expo/modules/image/ExpoImageView.kt +220 -0
- package/android/src/main/java/expo/modules/image/ExpoImageViewWrapper.kt +652 -0
- package/android/src/main/java/expo/modules/image/GlideModel.kt +73 -0
- package/android/src/main/java/expo/modules/image/ImageUtils.kt +50 -0
- package/android/src/main/java/expo/modules/image/ImageViewWrapperTarget.kt +313 -0
- package/android/src/main/java/expo/modules/image/ResourceIdHelper.kt +47 -0
- package/android/src/main/java/expo/modules/image/ThumbnailRequestCoordinatorExtension.kt +21 -0
- package/android/src/main/java/expo/modules/image/YogaUtils.kt +20 -0
- package/android/src/main/java/expo/modules/image/blurhash/BlurHashFetcher.kt +32 -0
- package/android/src/main/java/expo/modules/image/blurhash/BlurhashDecoder.kt +189 -0
- package/android/src/main/java/expo/modules/image/blurhash/BlurhashModelLoader.kt +30 -0
- package/android/src/main/java/expo/modules/image/blurhash/BlurhashModelLoaderFactory.kt +14 -0
- package/android/src/main/java/expo/modules/image/blurhash/BlurhashModule.kt +17 -0
- package/android/src/main/java/expo/modules/image/dataurls/Base64DataFetcher.kt +27 -0
- package/android/src/main/java/expo/modules/image/dataurls/Base64ModelLoader.kt +24 -0
- package/android/src/main/java/expo/modules/image/dataurls/Base64ModelLoaderFactory.kt +12 -0
- package/android/src/main/java/expo/modules/image/dataurls/Base64Module.kt +16 -0
- package/android/src/main/java/expo/modules/image/drawing/OutlineProvider.kt +201 -0
- package/android/src/main/java/expo/modules/image/enums/ContentFit.kt +89 -0
- package/android/src/main/java/expo/modules/image/enums/ImageCacheType.kt +14 -0
- package/android/src/main/java/expo/modules/image/enums/Priority.kt +15 -0
- package/android/src/main/java/expo/modules/image/events/GlideRequestListener.kt +64 -0
- package/android/src/main/java/expo/modules/image/events/OkHttpProgressListener.kt +26 -0
- package/android/src/main/java/expo/modules/image/okhttp/ExpoImageOkHttpClientGlideModule.kt +80 -0
- package/android/src/main/java/expo/modules/image/okhttp/GlideUrlWrapperLoader.kt +55 -0
- package/android/src/main/java/expo/modules/image/records/CachePolicy.kt +10 -0
- package/android/src/main/java/expo/modules/image/records/ContentPosition.kt +89 -0
- package/android/src/main/java/expo/modules/image/records/ImageTransition.kt +8 -0
- package/android/src/main/java/expo/modules/image/records/SourceMap.kt +160 -0
- package/android/src/main/java/expo/modules/image/records/events.kt +25 -0
- package/android/src/main/java/expo/modules/image/svg/SVGDecoder.kt +33 -0
- package/android/src/main/java/expo/modules/image/svg/SVGDrawableTranscoder.kt +37 -0
- package/android/src/main/java/expo/modules/image/svg/SVGModule.kt +26 -0
- package/android/src/main/java/expo/modules/image/thumbhash/ThumbhashDecoder.kt +365 -0
- package/android/src/main/java/expo/modules/image/thumbhash/ThumbhashFetcher.kt +31 -0
- package/android/src/main/java/expo/modules/image/thumbhash/ThumbhashModelLoader.kt +26 -0
- package/android/src/main/java/expo/modules/image/thumbhash/ThumbhashModelLoaderFactory.kt +14 -0
- package/android/src/main/java/expo/modules/image/thumbhash/ThumbhashModule.kt +17 -0
- package/build/ExpoImage.d.ts +15 -0
- package/build/ExpoImage.d.ts.map +1 -0
- package/build/ExpoImage.js +75 -0
- package/build/ExpoImage.js.map +1 -0
- package/build/ExpoImage.kepler.d.ts +23 -0
- package/build/ExpoImage.kepler.d.ts.map +1 -0
- package/build/ExpoImage.kepler.js +71 -0
- package/build/ExpoImage.kepler.js.map +1 -0
- package/build/ExpoImage.web.d.ts +9 -0
- package/build/ExpoImage.web.d.ts.map +1 -0
- package/build/ExpoImage.web.js +90 -0
- package/build/ExpoImage.web.js.map +1 -0
- package/build/ExpoImageModules.d.ts +3 -0
- package/build/ExpoImageModules.d.ts.map +1 -0
- package/build/ExpoImageModules.js +4 -0
- package/build/ExpoImageModules.js.map +1 -0
- package/build/ExpoImageModules.kepler.d.ts +6 -0
- package/build/ExpoImageModules.kepler.d.ts.map +1 -0
- package/build/ExpoImageModules.kepler.js +5 -0
- package/build/ExpoImageModules.kepler.js.map +1 -0
- package/build/Image.d.ts +30 -0
- package/build/Image.d.ts.map +1 -0
- package/build/Image.js +49 -0
- package/build/Image.js.map +1 -0
- package/build/Image.types.d.ts +374 -0
- package/build/Image.types.d.ts.map +1 -0
- package/build/Image.types.js +2 -0
- package/build/Image.types.js.map +1 -0
- package/build/ImageBackground.d.ts +6 -0
- package/build/ImageBackground.d.ts.map +1 -0
- package/build/ImageBackground.js +13 -0
- package/build/ImageBackground.js.map +1 -0
- package/build/ImageViewNativeComponent.d.ts +20 -0
- package/build/ImageViewNativeComponent.d.ts.map +1 -0
- package/build/ImageViewNativeComponent.js +42 -0
- package/build/ImageViewNativeComponent.js.map +1 -0
- package/build/NativeImageLoaderKepler.d.ts +18 -0
- package/build/NativeImageLoaderKepler.d.ts.map +1 -0
- package/build/NativeImageLoaderKepler.js +3 -0
- package/build/NativeImageLoaderKepler.js.map +1 -0
- package/build/fabric/registerNativeComponent.d.ts +15 -0
- package/build/fabric/registerNativeComponent.d.ts.map +1 -0
- package/build/fabric/registerNativeComponent.js +47 -0
- package/build/fabric/registerNativeComponent.js.map +1 -0
- package/build/index.d.ts +4 -0
- package/build/index.d.ts.map +1 -0
- package/build/index.js +4 -0
- package/build/index.js.map +1 -0
- package/build/utils/AssetSourceResolver.web.d.ts +24 -0
- package/build/utils/AssetSourceResolver.web.d.ts.map +1 -0
- package/build/utils/AssetSourceResolver.web.js +67 -0
- package/build/utils/AssetSourceResolver.web.js.map +1 -0
- package/build/utils/blurhash/base83.d.ts +3 -0
- package/build/utils/blurhash/base83.d.ts.map +1 -0
- package/build/utils/blurhash/base83.js +103 -0
- package/build/utils/blurhash/base83.js.map +1 -0
- package/build/utils/blurhash/decode.d.ts +7 -0
- package/build/utils/blurhash/decode.d.ts.map +1 -0
- package/build/utils/blurhash/decode.js +92 -0
- package/build/utils/blurhash/decode.js.map +1 -0
- package/build/utils/blurhash/error.d.ts +4 -0
- package/build/utils/blurhash/error.d.ts.map +1 -0
- package/build/utils/blurhash/error.js +8 -0
- package/build/utils/blurhash/error.js.map +1 -0
- package/build/utils/blurhash/useBlurhash.d.ts +8 -0
- package/build/utils/blurhash/useBlurhash.d.ts.map +1 -0
- package/build/utils/blurhash/useBlurhash.js +64 -0
- package/build/utils/blurhash/useBlurhash.js.map +1 -0
- package/build/utils/blurhash/utils.d.ts +5 -0
- package/build/utils/blurhash/utils.d.ts.map +1 -0
- package/build/utils/blurhash/utils.js +21 -0
- package/build/utils/blurhash/utils.js.map +1 -0
- package/build/utils/resolveAssetSource.d.ts +3 -0
- package/build/utils/resolveAssetSource.d.ts.map +1 -0
- package/build/utils/resolveAssetSource.js +3 -0
- package/build/utils/resolveAssetSource.js.map +1 -0
- package/build/utils/resolveAssetSource.web.d.ts +9 -0
- package/build/utils/resolveAssetSource.web.d.ts.map +1 -0
- package/build/utils/resolveAssetSource.web.js +31 -0
- package/build/utils/resolveAssetSource.web.js.map +1 -0
- package/build/utils/resolveHashString.d.ts +14 -0
- package/build/utils/resolveHashString.d.ts.map +1 -0
- package/build/utils/resolveHashString.js +31 -0
- package/build/utils/resolveHashString.js.map +1 -0
- package/build/utils/resolveHashString.web.d.ts +20 -0
- package/build/utils/resolveHashString.web.d.ts.map +1 -0
- package/build/utils/resolveHashString.web.js +31 -0
- package/build/utils/resolveHashString.web.js.map +1 -0
- package/build/utils/resolveSources.d.ts +8 -0
- package/build/utils/resolveSources.d.ts.map +1 -0
- package/build/utils/resolveSources.js +45 -0
- package/build/utils/resolveSources.js.map +1 -0
- package/build/utils/thumbhash/thumbhash.d.ts +66 -0
- package/build/utils/thumbhash/thumbhash.d.ts.map +1 -0
- package/build/utils/thumbhash/thumbhash.js +338 -0
- package/build/utils/thumbhash/thumbhash.js.map +1 -0
- package/build/utils.d.ts +17 -0
- package/build/utils.d.ts.map +1 -0
- package/build/utils.js +85 -0
- package/build/utils.js.map +1 -0
- package/build/web/AnimationManager.d.ts +37 -0
- package/build/web/AnimationManager.d.ts.map +1 -0
- package/build/web/AnimationManager.js +155 -0
- package/build/web/AnimationManager.js.map +1 -0
- package/build/web/ColorTintFilter.d.ts +12 -0
- package/build/web/ColorTintFilter.d.ts.map +1 -0
- package/build/web/ColorTintFilter.js +30 -0
- package/build/web/ColorTintFilter.js.map +1 -0
- package/build/web/ImageWrapper.d.ts +5 -0
- package/build/web/ImageWrapper.d.ts.map +1 -0
- package/build/web/ImageWrapper.js +44 -0
- package/build/web/ImageWrapper.js.map +1 -0
- package/build/web/ImageWrapper.types.d.ts +29 -0
- package/build/web/ImageWrapper.types.d.ts.map +1 -0
- package/build/web/ImageWrapper.types.js +2 -0
- package/build/web/ImageWrapper.types.js.map +1 -0
- package/build/web/getImageWrapperEventHandler.d.ts +8 -0
- package/build/web/getImageWrapperEventHandler.d.ts.map +1 -0
- package/build/web/getImageWrapperEventHandler.js +25 -0
- package/build/web/getImageWrapperEventHandler.js.map +1 -0
- package/build/web/hooks.d.ts +13 -0
- package/build/web/hooks.d.ts.map +1 -0
- package/build/web/hooks.js +58 -0
- package/build/web/hooks.js.map +1 -0
- package/build/web/imageStyles.d.ts +2 -0
- package/build/web/imageStyles.d.ts.map +1 -0
- package/build/web/imageStyles.js +137 -0
- package/build/web/imageStyles.js.map +1 -0
- package/build/web/positioning.d.ts +11 -0
- package/build/web/positioning.d.ts.map +1 -0
- package/build/web/positioning.js +35 -0
- package/build/web/positioning.js.map +1 -0
- package/build/web/useSourceSelection.d.ts +14 -0
- package/build/web/useSourceSelection.d.ts.map +1 -0
- package/build/web/useSourceSelection.js +98 -0
- package/build/web/useSourceSelection.js.map +1 -0
- package/expo-module.config.json +9 -0
- package/ios/Blurhash.swift +326 -0
- package/ios/BlurhashLoader.swift +52 -0
- package/ios/ContentFit.swift +55 -0
- package/ios/ContentPosition.swift +108 -0
- package/ios/ExpoImage.podspec +30 -0
- package/ios/ImageCachePolicy.swift +24 -0
- package/ios/ImageCacheType.swift +21 -0
- package/ios/ImageModule.swift +127 -0
- package/ios/ImagePriority.swift +22 -0
- package/ios/ImageSource.swift +44 -0
- package/ios/ImageTransition.swift +67 -0
- package/ios/ImageUtils.swift +227 -0
- package/ios/ImageView.swift +469 -0
- package/ios/Loaders/PhotoLibraryAssetLoader.swift +146 -0
- package/ios/Thumbhash.swift +550 -0
- package/ios/ThumbhashLoader.swift +53 -0
- package/jest.config.js +3 -0
- package/kepler/ExpoImage.cpp +63 -0
- package/kepler/ExpoImage.h +29 -0
- package/kepler/ExpoImageCacheHandler.cpp +15 -0
- package/kepler/ExpoImageCacheHandler.h +28 -0
- package/kepler/ExpoImageComponent.cpp +579 -0
- package/kepler/ExpoImageComponent.h +199 -0
- package/kepler/ImageWrapper/BlurhashImageWrapper.cpp +37 -0
- package/kepler/ImageWrapper/BlurhashImageWrapper.h +23 -0
- package/kepler/ImageWrapper/CacheImageWrapper.cpp +80 -0
- package/kepler/ImageWrapper/CacheImageWrapper.h +41 -0
- package/kepler/ImageWrapper/HashImageWrapper.cpp +21 -0
- package/kepler/ImageWrapper/HashImageWrapper.h +22 -0
- package/kepler/ImageWrapper/ImageWrapper.cpp +24 -0
- package/kepler/ImageWrapper/ImageWrapper.h +33 -0
- package/kepler/ImageWrapper/LocalImageWrapper.cpp +61 -0
- package/kepler/ImageWrapper/LocalImageWrapper.h +30 -0
- package/kepler/ImageWrapper/ThumbhashImageWrapper.cpp +33 -0
- package/kepler/ImageWrapper/ThumbhashImageWrapper.h +20 -0
- package/kepler/KeplerImageViewComponent.h +64 -0
- package/kepler/KeplerInit.cpp +35 -0
- package/kepler/blurhash/common.h +32 -0
- package/kepler/blurhash/decode.cpp +187 -0
- package/kepler/blurhash/decode.h +58 -0
- package/kepler/contentposition/ImageContentPosition.cpp +86 -0
- package/kepler/contentposition/ImageContentPosition.h +48 -0
- package/kepler/enums/ImageContentFit.h +17 -0
- package/kepler/enums/ImagePriority.h +17 -0
- package/kepler/managers/ExpoImageManager.cpp +38 -0
- package/kepler/managers/ExpoImageManager.h +23 -0
- package/kepler/test/ExpoImage.cpp +73 -0
- package/kepler/test/ExpoImageComponent.cpp +290 -0
- package/kepler/test/blurhash/decode.cpp +39 -0
- package/kepler/test/contentposition/ImageContentPosition.cpp +100 -0
- package/kepler/test/managers/ExpoImageManager.cpp +39 -0
- package/kepler/test/thumbhash/decode.cpp +18 -0
- package/kepler/test/utils/LoaderDelegate.cpp +130 -0
- package/kepler/thumbhash/decode.cpp +166 -0
- package/kepler/thumbhash/decode.h +22 -0
- package/kepler/utils/PlaceholderImageLoaderDelegate.cpp +26 -0
- package/kepler/utils/PlaceholderImageLoaderDelegate.h +26 -0
- package/kepler/utils/PrefetchImageLoaderDelegate.cpp +55 -0
- package/kepler/utils/PrefetchImageLoaderDelegate.h +35 -0
- package/kepler/utils/SourceImageLoaderDelegate.cpp +47 -0
- package/kepler/utils/SourceImageLoaderDelegate.h +42 -0
- package/kepler/utils/SourceImageLoaderDelegateEmitter.cpp +15 -0
- package/kepler/utils/SourceImageLoaderDelegateEmitter.h +28 -0
- package/kepler-compatibility.json +8 -0
- package/package.json +1 -0
- package/react-native.config.js +22 -0
- package/src/ExpoImage.kepler.tsx +119 -0
- package/src/ExpoImage.tsx +119 -0
- package/src/ExpoImage.web.tsx +155 -0
- package/src/ExpoImageModules.kepler.ts +7 -0
- package/src/ExpoImageModules.ts +4 -0
- package/src/Image.tsx +82 -0
- package/src/Image.types.ts +450 -0
- package/src/ImageBackground.tsx +18 -0
- package/src/ImageViewNativeComponent.ts +59 -0
- package/src/NativeImageLoaderKepler.ts +22 -0
- package/src/fabric/registerNativeComponent.ts +70 -0
- package/src/index.ts +3 -0
- package/src/utils/AssetSourceResolver.web.ts +88 -0
- package/src/utils/blurhash/base83.ts +104 -0
- package/src/utils/blurhash/decode.ts +114 -0
- package/src/utils/blurhash/error.ts +7 -0
- package/src/utils/blurhash/useBlurhash.tsx +81 -0
- package/src/utils/blurhash/utils.ts +21 -0
- package/src/utils/resolveAssetSource.tsx +3 -0
- package/src/utils/resolveAssetSource.web.ts +40 -0
- package/src/utils/resolveHashString.tsx +36 -0
- package/src/utils/resolveHashString.web.tsx +33 -0
- package/src/utils/resolveSources.tsx +48 -0
- package/src/utils/thumbhash/thumbhash.ts +387 -0
- package/src/utils.ts +109 -0
- package/src/web/AnimationManager.tsx +224 -0
- package/src/web/ColorTintFilter.tsx +36 -0
- package/src/web/ImageWrapper.tsx +85 -0
- package/src/web/ImageWrapper.types.ts +36 -0
- package/src/web/getImageWrapperEventHandler.ts +29 -0
- package/src/web/hooks.ts +72 -0
- package/src/web/imageStyles.tsx +136 -0
- package/src/web/positioning.ts +48 -0
- package/src/web/useSourceSelection.ts +151 -0
- package/tsconfig.json +9 -0
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright (c) 2024 Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
3
|
+
*
|
|
4
|
+
* PROPRIETARY/CONFIDENTIAL
|
|
5
|
+
*
|
|
6
|
+
* Use is subject to license terms.
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
/*
|
|
10
|
+
* This header is added as a workaround until we figure out whether
|
|
11
|
+
* we need to have KeplerImageViewComponent included here and how to achieve that
|
|
12
|
+
*/
|
|
13
|
+
|
|
14
|
+
#pragma once
|
|
15
|
+
|
|
16
|
+
#include <Volta/graphics/DrawableLayer.h>
|
|
17
|
+
#include <Volta/graphics/OpacityLayer.h>
|
|
18
|
+
#include <Volta/utils/Image.h>
|
|
19
|
+
#include <graphics/ImageFilterLayer.h>
|
|
20
|
+
|
|
21
|
+
#include "KeplerScript/components/KeplerViewComponent.h"
|
|
22
|
+
|
|
23
|
+
namespace volta::react {
|
|
24
|
+
class ImageDrawableLayer : public volta::graphics::DrawableLayer {
|
|
25
|
+
public:
|
|
26
|
+
friend class KeplerImageViewComponent;
|
|
27
|
+
enum class Fit { Cover, Contain, Stretch, Repeat, Center };
|
|
28
|
+
ImageDrawableLayer();
|
|
29
|
+
void onDraw(volta::graphics::Canvas& canvas);
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
class KeplerImageViewComponent {
|
|
33
|
+
public:
|
|
34
|
+
KeplerImageViewComponent();
|
|
35
|
+
~KeplerImageViewComponent() noexcept;
|
|
36
|
+
|
|
37
|
+
mutable ImageDrawableLayer imageDrawableLayer_;
|
|
38
|
+
mutable volta::graphics::OpacityLayer opacityLayer_;
|
|
39
|
+
|
|
40
|
+
void didReceiveImage(const facebook::react::ImageResponse& imageResponse) const;
|
|
41
|
+
void didReceiveProgress(float progress) const;
|
|
42
|
+
void didReceiveFailure() const;
|
|
43
|
+
|
|
44
|
+
void setOverlayColor(const int& newValue);
|
|
45
|
+
|
|
46
|
+
void setTintColor(const int& newValue);
|
|
47
|
+
|
|
48
|
+
void setBlurRadius(const double& newValue);
|
|
49
|
+
|
|
50
|
+
void setResizeMode(const std::string& newValue);
|
|
51
|
+
|
|
52
|
+
void setDefaultSource(const utils::json::JsonContainer& newValue);
|
|
53
|
+
|
|
54
|
+
// void buildAccessibilityInfo(AccessibilityContext& accessibilityContext) override;
|
|
55
|
+
|
|
56
|
+
void updateLayoutMetrics(
|
|
57
|
+
const std::shared_ptr<KeplerViewComponentLayoutMetrics>& oldLayoutMetrics,
|
|
58
|
+
const std::shared_ptr<KeplerViewComponentLayoutMetrics>& newLayoutMetrics);
|
|
59
|
+
|
|
60
|
+
void updateState(const std::shared_ptr<const void>& oldState, const std::shared_ptr<const void>& newState);
|
|
61
|
+
|
|
62
|
+
void changeImageLayer(ImageDrawableLayer newImageLayer);
|
|
63
|
+
};
|
|
64
|
+
} // namespace volta::react
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright (c) 2024 Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
3
|
+
*
|
|
4
|
+
* PROPRIETARY/CONFIDENTIAL
|
|
5
|
+
*
|
|
6
|
+
* Use is subject to license terms.
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
#include <KeplerScript/logger/KPLog.h>
|
|
10
|
+
#include <KeplerScript/utils/autolink/KeplerAutoLinkInfo.h>
|
|
11
|
+
#include <keplerui-072/keplerscript-export.h>
|
|
12
|
+
|
|
13
|
+
#include "ExpoImage.h"
|
|
14
|
+
#include "RegisterModule.h"
|
|
15
|
+
#include "managers/ExpoImageManager.h"
|
|
16
|
+
|
|
17
|
+
extern "C" {
|
|
18
|
+
KEPLERSCRIPT_EXPORT void keplerAutoLinkInitV1(const kepler::autolink::v1::KeplerAutoLinkInfo* autoLinkInfo) noexcept {
|
|
19
|
+
volta::react::KPLog.debug("keplerAutoLinkInitV1 for ExpoImage");
|
|
20
|
+
|
|
21
|
+
REGISTER_MODULE(autoLinkInfo, ExpoImage, "ExpoImage");
|
|
22
|
+
|
|
23
|
+
auto* customViewDelegate = autoLinkInfo->customViewManagerDelegate;
|
|
24
|
+
customViewDelegate->registerComponentViewManager("ExpoImageComponent", []() {
|
|
25
|
+
volta::react::KPLog.debug("Creating ExpoImageComponent");
|
|
26
|
+
return std::make_unique<ExpoImageManager>();
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
volta::react::KPLog.debug("ExpoImage after registering module");
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
int main() {
|
|
34
|
+
return 0;
|
|
35
|
+
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright (c) 2024 Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
3
|
+
*
|
|
4
|
+
* PROPRIETARY/CONFIDENTIAL
|
|
5
|
+
*
|
|
6
|
+
* Use is subject to license terms.
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
// Source: https://github.com/woltapp/blurhash/blob/master/C/common.h
|
|
10
|
+
#pragma once
|
|
11
|
+
|
|
12
|
+
#include <cmath>
|
|
13
|
+
|
|
14
|
+
int linearTosRGB(float value) {
|
|
15
|
+
float v = fmaxf(0, fminf(1, value));
|
|
16
|
+
if (v <= 0.0031308)
|
|
17
|
+
return v * 12.92 * 255 + 0.5;
|
|
18
|
+
else
|
|
19
|
+
return (1.055 * powf(v, 1 / 2.4) - 0.055) * 255 + 0.5;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
float sRGBToLinear(int value) {
|
|
23
|
+
float v = (float) value / 255;
|
|
24
|
+
if (v <= 0.04045)
|
|
25
|
+
return v / 12.92;
|
|
26
|
+
else
|
|
27
|
+
return powf((v + 0.055) / 1.055, 2.4);
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
float signPow(float value, float exp) {
|
|
31
|
+
return copysignf(powf(fabsf(value), exp), value);
|
|
32
|
+
}
|
|
@@ -0,0 +1,187 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright (c) 2024 Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
3
|
+
*
|
|
4
|
+
* PROPRIETARY/CONFIDENTIAL
|
|
5
|
+
*
|
|
6
|
+
* Use is subject to license terms.
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
// Source: https://github.com/woltapp/blurhash/blob/master/C/decode.c
|
|
10
|
+
#include "decode.h"
|
|
11
|
+
|
|
12
|
+
#include <unordered_map>
|
|
13
|
+
|
|
14
|
+
#include "common.h"
|
|
15
|
+
|
|
16
|
+
namespace {
|
|
17
|
+
struct Size {
|
|
18
|
+
int y;
|
|
19
|
+
int x;
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
using Color = std::tuple<float, float, float>;
|
|
23
|
+
|
|
24
|
+
const std::string CHARS = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz#$%*+,-.:;=?@[]^_{|}~";
|
|
25
|
+
|
|
26
|
+
std::unordered_map<char, size_t> createCharToIndexMap() {
|
|
27
|
+
std::unordered_map<char, size_t> map;
|
|
28
|
+
for (size_t i = 0; i < CHARS.size(); ++i) {
|
|
29
|
+
map[CHARS[i]] = static_cast<size_t>(i);
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
return map;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
uint8_t clampToUByte(int src) {
|
|
36
|
+
return std::min(std::max(0, src), 255);
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
std::unique_ptr<uint8_t[]> createByteArray(int size) {
|
|
40
|
+
return std::make_unique<uint8_t[]>(size);
|
|
41
|
+
}
|
|
42
|
+
} // namespace
|
|
43
|
+
|
|
44
|
+
int decodeToInt(const std::string& string, int pos) {
|
|
45
|
+
static const auto charsMap = createCharToIndexMap(); // Initialized only once in app's lifetime
|
|
46
|
+
|
|
47
|
+
auto it = charsMap.find(string[pos]);
|
|
48
|
+
if (it == charsMap.end()) {
|
|
49
|
+
return -1;
|
|
50
|
+
}
|
|
51
|
+
return it->second;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
int decodeToInt(const std::string& string, int start, int end) {
|
|
55
|
+
int value = 0;
|
|
56
|
+
for (int i = start; i < end; ++i) {
|
|
57
|
+
auto byteValue = decodeToInt(string, i);
|
|
58
|
+
if (byteValue == -1) {
|
|
59
|
+
return -1;
|
|
60
|
+
}
|
|
61
|
+
value = value * CHARS.size() + byteValue;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
return value;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
Size getImageSize(const std::string& blurhash) {
|
|
68
|
+
int sizeFlag = decodeToInt(blurhash, 0); // Get size from first character
|
|
69
|
+
int numY = (int) floorf(sizeFlag / 9) + 1;
|
|
70
|
+
int numX = (sizeFlag % 9) + 1;
|
|
71
|
+
|
|
72
|
+
return Size{numY, numX};
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
const int MINIMAL_HASH_LENGTH = 6;
|
|
76
|
+
|
|
77
|
+
bool isValidBlurhash(const std::string& blurhash) {
|
|
78
|
+
auto hashLength = blurhash.size();
|
|
79
|
+
if (hashLength < MINIMAL_HASH_LENGTH) return false;
|
|
80
|
+
auto size = getImageSize(blurhash);
|
|
81
|
+
|
|
82
|
+
if (hashLength != 4 + 2 * size.x * size.y) return false;
|
|
83
|
+
return true;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
Color decodeDC(int value) {
|
|
87
|
+
return std::make_tuple(
|
|
88
|
+
sRGBToLinear((value >> 16) & 255), // R-component
|
|
89
|
+
sRGBToLinear((value >> 8) & 255), // G-Component
|
|
90
|
+
sRGBToLinear(value & 255) // B-Component
|
|
91
|
+
);
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
Color decodeAC(int value, float maximumValue) {
|
|
95
|
+
int quantR = (int) floorf(value / (19 * 19));
|
|
96
|
+
int quantG = (int) floorf(value / 19) % 19;
|
|
97
|
+
int quantB = (int) value % 19;
|
|
98
|
+
|
|
99
|
+
return std::make_tuple(
|
|
100
|
+
signPow(((float) quantR - 9) / 9, 2.0) * maximumValue,
|
|
101
|
+
signPow(((float) quantG - 9) / 9, 2.0) * maximumValue,
|
|
102
|
+
signPow(((float) quantB - 9) / 9, 2.0) * maximumValue);
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
int decodeToArray(
|
|
106
|
+
const std::string& blurhash,
|
|
107
|
+
int width,
|
|
108
|
+
int height,
|
|
109
|
+
int punch,
|
|
110
|
+
int nChannels,
|
|
111
|
+
const std::unique_ptr<uint8_t[]>& pixelArray) {
|
|
112
|
+
if (!isValidBlurhash(blurhash)) return -1;
|
|
113
|
+
if (punch < 1) punch = 1;
|
|
114
|
+
|
|
115
|
+
auto size = getImageSize(blurhash);
|
|
116
|
+
|
|
117
|
+
int quantizedMaxValue = decodeToInt(blurhash, 1);
|
|
118
|
+
if (quantizedMaxValue == -1) return -1;
|
|
119
|
+
|
|
120
|
+
float maxValue = ((float) (quantizedMaxValue + 1)) / 166;
|
|
121
|
+
|
|
122
|
+
int colors_size = size.x * size.y;
|
|
123
|
+
float colors[colors_size][3];
|
|
124
|
+
|
|
125
|
+
for (int iter = 0; iter < colors_size; ++iter) {
|
|
126
|
+
float r = 0, g = 0, b = 0;
|
|
127
|
+
if (iter == 0) {
|
|
128
|
+
int value = decodeToInt(blurhash, 2, 6);
|
|
129
|
+
if (value == -1) return -1;
|
|
130
|
+
std::tie(r, g, b) = decodeDC(value);
|
|
131
|
+
|
|
132
|
+
} else {
|
|
133
|
+
int value = decodeToInt(blurhash, 4 + iter * 2, 6 + iter * 2);
|
|
134
|
+
if (value == -1) return -1;
|
|
135
|
+
std::tie(r, g, b) = decodeAC(value, maxValue * punch);
|
|
136
|
+
}
|
|
137
|
+
colors[iter][0] = r;
|
|
138
|
+
colors[iter][1] = g;
|
|
139
|
+
colors[iter][2] = b;
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
int bytesPerRow = width * nChannels;
|
|
143
|
+
int intR = 0, intG = 0, intB = 0;
|
|
144
|
+
|
|
145
|
+
for (int y = 0; y < height; ++y) {
|
|
146
|
+
for (int x = 0; x < width; ++x) {
|
|
147
|
+
float r = 0, g = 0, b = 0;
|
|
148
|
+
|
|
149
|
+
for (int j = 0; j < size.y; ++j) {
|
|
150
|
+
for (int i = 0; i < size.x; ++i) {
|
|
151
|
+
float basics = cos((M_PI * x * i) / width) * cos((M_PI * y * j) / height);
|
|
152
|
+
int idx = i + j * size.x;
|
|
153
|
+
r += colors[idx][0] * basics;
|
|
154
|
+
g += colors[idx][1] * basics;
|
|
155
|
+
b += colors[idx][2] * basics;
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
intR = linearTosRGB(r);
|
|
160
|
+
intG = linearTosRGB(g);
|
|
161
|
+
intB = linearTosRGB(b);
|
|
162
|
+
|
|
163
|
+
pixelArray[nChannels * x + 0 + y * bytesPerRow] = clampToUByte(intR);
|
|
164
|
+
pixelArray[nChannels * x + 1 + y * bytesPerRow] = clampToUByte(intG);
|
|
165
|
+
pixelArray[nChannels * x + 2 + y * bytesPerRow] = clampToUByte(intB);
|
|
166
|
+
|
|
167
|
+
if (nChannels == 4)
|
|
168
|
+
pixelArray[nChannels * x + 3 + y * bytesPerRow] =
|
|
169
|
+
255; // If nChannels=4, treat each pixel as RGBA instead of RGB
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
return 0;
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
std::unique_ptr<uint8_t[]> decodeBlurhash(
|
|
177
|
+
const std::string& blurhash,
|
|
178
|
+
int width,
|
|
179
|
+
int height,
|
|
180
|
+
int punch,
|
|
181
|
+
int nChannels) {
|
|
182
|
+
int bytesPerRow = width * nChannels;
|
|
183
|
+
auto pixelArray = createByteArray(bytesPerRow * height);
|
|
184
|
+
|
|
185
|
+
if (decodeToArray(blurhash, width, height, punch, nChannels, pixelArray) == -1) return nullptr;
|
|
186
|
+
return pixelArray;
|
|
187
|
+
}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright (c) 2024 Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
3
|
+
*
|
|
4
|
+
* PROPRIETARY/CONFIDENTIAL
|
|
5
|
+
*
|
|
6
|
+
* Use is subject to license terms.
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
// Source: https://github.com/woltapp/blurhash/blob/master/C/decode.h
|
|
10
|
+
|
|
11
|
+
#pragma once
|
|
12
|
+
|
|
13
|
+
#include <cstdint>
|
|
14
|
+
#include <memory>
|
|
15
|
+
#include <string>
|
|
16
|
+
|
|
17
|
+
// Blurhash implementation from https://github.com/woltapp/blurhash
|
|
18
|
+
|
|
19
|
+
/*
|
|
20
|
+
decode : Returns the pixel array of the result image given the blurhash string,
|
|
21
|
+
Parameters :
|
|
22
|
+
blurhash : A string representing the blurhash to be decoded.
|
|
23
|
+
width : Width of the resulting image
|
|
24
|
+
height : Height of the resulting image
|
|
25
|
+
punch : The factor to improve the contrast, default = 1
|
|
26
|
+
nChannels : Number of channels in the resulting image array, 3 = RGB, 4 = RGBA
|
|
27
|
+
Returns : A pointer to memory region where pixels are stored in (H, W, C) format
|
|
28
|
+
*/
|
|
29
|
+
std::unique_ptr<uint8_t[]> decodeBlurhash(const std::string& blurhash, int width, int height, int punch, int nChannels);
|
|
30
|
+
|
|
31
|
+
/*
|
|
32
|
+
decodeToArray : Decodes the blurhash and copies the pixels to pixelArray,
|
|
33
|
+
This method is suggested if you use an external memory allocator for pixelArray.
|
|
34
|
+
pixelArray should be of size : width * height * nChannels
|
|
35
|
+
Parameters :
|
|
36
|
+
blurhash : A string representing the blurhash to be decoded.
|
|
37
|
+
width : Width of the resulting image
|
|
38
|
+
height : Height of the resulting image
|
|
39
|
+
punch : The factor to improve the contrast, default = 1
|
|
40
|
+
nChannels : Number of channels in the resulting image array, 3 = RGB, 4 = RGBA
|
|
41
|
+
pixelArray : Pointer to memory region where pixels needs to be copied.
|
|
42
|
+
Returns : int, -1 if error 0 if successful
|
|
43
|
+
*/
|
|
44
|
+
int decodeToArray(
|
|
45
|
+
const std::string& blurhash,
|
|
46
|
+
int width,
|
|
47
|
+
int height,
|
|
48
|
+
int punch,
|
|
49
|
+
int nChannels,
|
|
50
|
+
const std::unique_ptr<uint8_t[]>& pixelArray);
|
|
51
|
+
|
|
52
|
+
/*
|
|
53
|
+
isValidBlurhash : Checks if the Blurhash is valid or not.
|
|
54
|
+
Parameters :
|
|
55
|
+
blurhash : A string representing the blurhash
|
|
56
|
+
Returns : bool (true if it is a valid blurhash, else false)
|
|
57
|
+
*/
|
|
58
|
+
bool isValidBlurhash(const std::string& blurhash);
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright (c) 2024 Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
3
|
+
*
|
|
4
|
+
* PROPRIETARY/CONFIDENTIAL
|
|
5
|
+
*
|
|
6
|
+
* Use is subject to license terms.
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
#include "ImageContentPosition.h"
|
|
10
|
+
|
|
11
|
+
#include <JsonContainer/JsonContainer.h>
|
|
12
|
+
|
|
13
|
+
float calcTranslation(
|
|
14
|
+
float value,
|
|
15
|
+
float imageRefValue,
|
|
16
|
+
float viewRefValue,
|
|
17
|
+
bool isPercentage = false,
|
|
18
|
+
bool isReverse = false) {
|
|
19
|
+
if (isPercentage) {
|
|
20
|
+
float finalPercentage = isReverse ? 100.0f - value : value;
|
|
21
|
+
return (finalPercentage / 100.0f) * (viewRefValue - imageRefValue);
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
return isReverse ? viewRefValue - imageRefValue - value : value;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
float calcXTranslation(
|
|
28
|
+
float value,
|
|
29
|
+
const volta::graphics::Size& imageRect,
|
|
30
|
+
const volta::graphics::Size& viewRect,
|
|
31
|
+
bool isPercentage = false,
|
|
32
|
+
bool isReverse = false) {
|
|
33
|
+
return calcTranslation(value, imageRect.width(), viewRect.width(), isPercentage, isReverse);
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
float calcYTranslation(
|
|
37
|
+
float value,
|
|
38
|
+
const volta::graphics::Size& imageRect,
|
|
39
|
+
const volta::graphics::Size& viewRect,
|
|
40
|
+
bool isPercentage = false,
|
|
41
|
+
bool isReverse = false) {
|
|
42
|
+
return calcTranslation(value, imageRect.height(), viewRect.height(), isPercentage, isReverse);
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
ImageContentPositionValue::ImageContentPositionValue() : value_(std::nullopt), isPercentage_(true) {}
|
|
46
|
+
|
|
47
|
+
ImageContentPositionValue::ImageContentPositionValue(float value, bool isPercentage) :
|
|
48
|
+
value_(value),
|
|
49
|
+
isPercentage_(isPercentage) {}
|
|
50
|
+
|
|
51
|
+
std::optional<float> ImageContentPositionValue::calcOffset(
|
|
52
|
+
bool isReverse,
|
|
53
|
+
const volta::graphics::Size& imageRect,
|
|
54
|
+
const volta::graphics::Size& viewRect,
|
|
55
|
+
std::function<float(float, const volta::graphics::Size&, const volta::graphics::Size&, bool, bool)>
|
|
56
|
+
calcAxisOffset) {
|
|
57
|
+
return value_ ? calcAxisOffset(value_.value(), imageRect, viewRect, isPercentage_, isReverse) : value_;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
ImageContentPosition::ImageContentPosition() :
|
|
61
|
+
top_(ImageContentPositionValue()),
|
|
62
|
+
bottom_(ImageContentPositionValue()),
|
|
63
|
+
right_(ImageContentPositionValue()),
|
|
64
|
+
left_(ImageContentPositionValue()) {}
|
|
65
|
+
|
|
66
|
+
ImageContentPosition::ImageContentPosition(
|
|
67
|
+
ImageContentPositionValue top,
|
|
68
|
+
ImageContentPositionValue bottom,
|
|
69
|
+
ImageContentPositionValue right,
|
|
70
|
+
ImageContentPositionValue left) :
|
|
71
|
+
top_(top),
|
|
72
|
+
bottom_(bottom),
|
|
73
|
+
right_(right),
|
|
74
|
+
left_(left) {}
|
|
75
|
+
|
|
76
|
+
float ImageContentPosition::offsetX(const volta::graphics::Size& imageRect, const volta::graphics::Size& viewRect) {
|
|
77
|
+
return left_.calcOffset(false, imageRect, viewRect, &calcXTranslation)
|
|
78
|
+
.value_or(right_.calcOffset(true, imageRect, viewRect, &calcXTranslation)
|
|
79
|
+
.value_or(calcXTranslation(50.0f, imageRect, viewRect, true)));
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
float ImageContentPosition::offsetY(const volta::graphics::Size& imageRect, const volta::graphics::Size& viewRect) {
|
|
83
|
+
return top_.calcOffset(false, imageRect, viewRect, &calcYTranslation)
|
|
84
|
+
.value_or(bottom_.calcOffset(true, imageRect, viewRect, &calcYTranslation)
|
|
85
|
+
.value_or(calcYTranslation(50.0f, imageRect, viewRect, true)));
|
|
86
|
+
}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright (c) 2024 Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
3
|
+
*
|
|
4
|
+
* PROPRIETARY/CONFIDENTIAL
|
|
5
|
+
*
|
|
6
|
+
* Use is subject to license terms.
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
#pragma once
|
|
10
|
+
#include <Volta/graphics/Size.h>
|
|
11
|
+
|
|
12
|
+
#include <functional>
|
|
13
|
+
#include <optional>
|
|
14
|
+
#include <string>
|
|
15
|
+
|
|
16
|
+
class ImageContentPositionValue {
|
|
17
|
+
public:
|
|
18
|
+
std::optional<float> value_;
|
|
19
|
+
bool isPercentage_;
|
|
20
|
+
ImageContentPositionValue();
|
|
21
|
+
ImageContentPositionValue(float value, bool isPercentage);
|
|
22
|
+
std::optional<float> calcOffset(
|
|
23
|
+
bool isReverse,
|
|
24
|
+
const volta::graphics::Size& imageRect,
|
|
25
|
+
const volta::graphics::Size& viewRect,
|
|
26
|
+
std::function<float(float, const volta::graphics::Size&, const volta::graphics::Size&, bool, bool)>
|
|
27
|
+
calcAxisOffset);
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
class ImageContentPosition {
|
|
31
|
+
public:
|
|
32
|
+
ImageContentPosition();
|
|
33
|
+
ImageContentPosition(
|
|
34
|
+
ImageContentPositionValue top,
|
|
35
|
+
ImageContentPositionValue bottom,
|
|
36
|
+
ImageContentPositionValue right,
|
|
37
|
+
ImageContentPositionValue left);
|
|
38
|
+
float offsetX(const volta::graphics::Size& imageRect, const volta::graphics::Size& viewRect);
|
|
39
|
+
float offsetY(const volta::graphics::Size& imageRect, const volta::graphics::Size& viewRect);
|
|
40
|
+
|
|
41
|
+
#ifndef UNIT_TEST
|
|
42
|
+
private:
|
|
43
|
+
#endif
|
|
44
|
+
ImageContentPositionValue top_;
|
|
45
|
+
ImageContentPositionValue bottom_;
|
|
46
|
+
ImageContentPositionValue right_;
|
|
47
|
+
ImageContentPositionValue left_;
|
|
48
|
+
};
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright (c) 2024 Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
3
|
+
*
|
|
4
|
+
* PROPRIETARY/CONFIDENTIAL
|
|
5
|
+
*
|
|
6
|
+
* Use is subject to license terms.
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
#pragma once
|
|
10
|
+
|
|
11
|
+
enum ImageContentFit {
|
|
12
|
+
Cover,
|
|
13
|
+
Contain,
|
|
14
|
+
Fill,
|
|
15
|
+
None,
|
|
16
|
+
ScaleDown,
|
|
17
|
+
};
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright (c) 2024 Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
3
|
+
*
|
|
4
|
+
* PROPRIETARY/CONFIDENTIAL
|
|
5
|
+
*
|
|
6
|
+
* Use is subject to license terms.
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
#pragma once
|
|
10
|
+
|
|
11
|
+
#include <cstdint>
|
|
12
|
+
|
|
13
|
+
enum class ImagePriority : uint8_t {
|
|
14
|
+
Low,
|
|
15
|
+
Normal,
|
|
16
|
+
High
|
|
17
|
+
};
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright (c) 2024 Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
3
|
+
*
|
|
4
|
+
* PROPRIETARY/CONFIDENTIAL
|
|
5
|
+
*
|
|
6
|
+
* Use is subject to license terms.
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
#include "ExpoImageManager.h"
|
|
10
|
+
|
|
11
|
+
#include <KeplerScript/components/KeplerViewComponent.h>
|
|
12
|
+
#include <KeplerScript/utils/image/KeplerScriptImageCacheHandler.h>
|
|
13
|
+
|
|
14
|
+
#include "ExpoImageComponent.h"
|
|
15
|
+
|
|
16
|
+
ExpoImageManager::ExpoImageManager() :
|
|
17
|
+
imageCacheHandler_(std::make_shared<volta::react::KeplerScriptImageCacheHandler>()) {}
|
|
18
|
+
|
|
19
|
+
std::shared_ptr<volta::react::KeplerViewComponent> ExpoImageManager::createComponentView() {
|
|
20
|
+
VOLTA_TRACE_SECTION(ExpoImageManager::createComponentView);
|
|
21
|
+
return volta::RenderObject::create<ExpoImageComponent>(imageCacheHandler_);
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
void ExpoImageManager::aggregatePropSetters(volta::react::PropSetterAggregator& aggregator) {
|
|
25
|
+
ViewComponentViewManager::aggregatePropSetters(aggregator);
|
|
26
|
+
aggregator.addPropSetter("contentFit", &ExpoImageComponent::setContentFit, std::string{""});
|
|
27
|
+
aggregator.addPropSetter("placeholderContentFit", &ExpoImageComponent::setPlaceholderContentFit, std::string{""});
|
|
28
|
+
aggregator.addPropSetter("allowDownscaling", &ExpoImageComponent::setAllowDownscaling, true);
|
|
29
|
+
aggregator.addPropSetter("contentPosition", &ExpoImageComponent::setContentPosition, utils::json::JsonContainer());
|
|
30
|
+
aggregator.addPropSetter("overlayColor", &ExpoImageComponent::setOverlayColor, std::numeric_limits<int>::max());
|
|
31
|
+
aggregator.addPropSetter("tintColor", &ExpoImageComponent::setTintColor, std::numeric_limits<int>::max());
|
|
32
|
+
aggregator.addPropSetter("blurRadius", &ExpoImageComponent::setBlurRadius, 0.0);
|
|
33
|
+
aggregator.addPropSetter("placeholder", &ExpoImageComponent::setPlaceholder, utils::json::JsonContainer());
|
|
34
|
+
aggregator.addPropSetter("source", &ExpoImageComponent::setSource, utils::json::JsonContainer());
|
|
35
|
+
aggregator.addPropSetter("priority", &ExpoImageComponent::setPriority, std::string{""});
|
|
36
|
+
aggregator.addPropSetter("transition", &ExpoImageComponent::setTransition, utils::json::JsonContainer());
|
|
37
|
+
aggregator.addPropSetter("recyclingKey", &ExpoImageComponent::setRecyclingKey, std::string{""});
|
|
38
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright (c) 2024 Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
3
|
+
*
|
|
4
|
+
* PROPRIETARY/CONFIDENTIAL
|
|
5
|
+
*
|
|
6
|
+
* Use is subject to license terms.
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
#pragma once
|
|
10
|
+
|
|
11
|
+
#include <KeplerScript/components/ViewComponentViewManager.h>
|
|
12
|
+
#include <KeplerScript/utils/image/KeplerScriptImageCacheHandler.h>
|
|
13
|
+
|
|
14
|
+
class ExpoImageManager : public volta::react::ViewComponentViewManager {
|
|
15
|
+
public:
|
|
16
|
+
ExpoImageManager();
|
|
17
|
+
void aggregatePropSetters(volta::react::PropSetterAggregator& aggregator) override;
|
|
18
|
+
std::shared_ptr<volta::react::KeplerViewComponent> createComponentView() override;
|
|
19
|
+
|
|
20
|
+
private:
|
|
21
|
+
std::shared_ptr<volta::react::KeplerScriptImageCacheHandler> imageCacheHandler_;
|
|
22
|
+
};
|
|
23
|
+
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
#include "../ExpoImage.h"
|
|
2
|
+
|
|
3
|
+
#include <KeplerScript/components/ImageSourceBuilder.h>
|
|
4
|
+
#include <KeplerScript/logger/KPLog.h>
|
|
5
|
+
#include <KeplerScript/utils/image/KeplerScriptImageLoaderDelegate.h>
|
|
6
|
+
#include <gmock/gmock-actions.h>
|
|
7
|
+
#include <gmock/gmock.h>
|
|
8
|
+
#include <gtest/gtest.h>
|
|
9
|
+
|
|
10
|
+
#include "../ExpoImageCacheHandler.h"
|
|
11
|
+
#include "catch.hpp"
|
|
12
|
+
|
|
13
|
+
namespace volta::react {
|
|
14
|
+
|
|
15
|
+
std::unique_ptr<volta::graphics::Image> mockImage() {
|
|
16
|
+
auto data = std::make_unique<uint8_t[]>(4);
|
|
17
|
+
return volta::graphics::Image::makeRasterImage(volta::graphics::Size{1, 1}, std::move(data), 4);
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
void fullfillPromise(volta::react::Promise& promise) {
|
|
21
|
+
promise.promiseOperation_(std::make_shared<Promise>(Callback(), Callback()));
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
class MockExpoImageCacheHandler : public IExpoImageCacheHandler {
|
|
25
|
+
public:
|
|
26
|
+
MockExpoImageCacheHandler() = default;
|
|
27
|
+
|
|
28
|
+
MOCK_METHOD(void, clearMemoryCache, (), (override));
|
|
29
|
+
MOCK_METHOD(void, clearDiskCache, (), (override));
|
|
30
|
+
|
|
31
|
+
MOCK_METHOD(
|
|
32
|
+
void,
|
|
33
|
+
load,
|
|
34
|
+
(volta::ImageDetails & details, const volta::react::KeplerScriptImageLoaderDelegate::Shared& delegate),
|
|
35
|
+
(override));
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
TEST_CASE("ExpoImage") {
|
|
39
|
+
auto handler = std::make_shared<MockExpoImageCacheHandler>();
|
|
40
|
+
|
|
41
|
+
ExpoImage module(handler);
|
|
42
|
+
|
|
43
|
+
SECTION("load") {
|
|
44
|
+
std::vector<std::string> urls = {
|
|
45
|
+
"https://example.com/image1.png",
|
|
46
|
+
"https://example.com/image2.png",
|
|
47
|
+
"https://example.com/image3.png"};
|
|
48
|
+
|
|
49
|
+
EXPECT_CALL(*handler, load(testing::_, testing::_))
|
|
50
|
+
.Times(3)
|
|
51
|
+
.WillRepeatedly(
|
|
52
|
+
testing::Invoke([](volta::ImageDetails& details,
|
|
53
|
+
const volta::react::KeplerScriptImageLoaderDelegate::Shared& delegate) {
|
|
54
|
+
auto mockImg = mockImage();
|
|
55
|
+
|
|
56
|
+
delegate->notifyImageLoadSuccess(*mockImg);
|
|
57
|
+
}));
|
|
58
|
+
|
|
59
|
+
auto promise = module.prefetch(urls);
|
|
60
|
+
fullfillPromise(promise);
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
SECTION("clearMemoryCache") {
|
|
64
|
+
EXPECT_CALL(*handler, clearMemoryCache()).Times(1);
|
|
65
|
+
module.clearMemoryCache();
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
SECTION("clearDiskCache") {
|
|
69
|
+
EXPECT_CALL(*handler, clearDiskCache()).Times(1);
|
|
70
|
+
module.clearDiskCache();
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
} // namespace volta::react
|