Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add webp support for cards images #1802

Draft
wants to merge 4 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions forge-core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,11 @@
<artifactId>commons-lang3</artifactId>
<version>3.12.0</version>
</dependency>
<dependency>
<groupId>io.github.zumikua</groupId>
<artifactId>webploader-common</artifactId>
<version>0.1.0</version>
</dependency>
</dependencies>

</project>
6 changes: 3 additions & 3 deletions forge-core/src/main/java/forge/ImageKeys.java
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ public static void initializeDirs(String cards, Map<String, String> cardsSub, St

// image file extensions for various formats in order of likelihood
// the last, empty, string is for keys that come in with an extension already in place
private static final String[] FILE_EXTENSIONS = { ".jpg", ".png", "" };
private static final String[] FILE_EXTENSIONS = { ".jpg", ".png", ".webp", "" };

public static String getTokenKey(String tokenName) {
return ImageKeys.TOKEN_PREFIX + tokenName;
Expand Down Expand Up @@ -362,11 +362,11 @@ public static boolean hasImage(PaperCard pc, boolean update) {
HashSet<String> setFolderContent = new HashSet<>();
for (String filename : Arrays.asList(f.list())) {
// TODO: should this use FILE_EXTENSIONS ?
if (!filename.endsWith(".jpg") && !filename.endsWith(".png"))
if (!filename.endsWith(".jpg") && !filename.endsWith(".png") && !filename.endsWith(".webp"))
continue; // not image - not interested
setFolderContent.add(filename.split("\\.")[0]); // get rid of any full or fullborder
//preload cachedCards at startUp
String key = setFolder + "/" + filename.replace(".fullborder", ".full").replace(".jpg", "").replace(".png", "");
String key = setFolder + "/" + filename.replace(".fullborder", ".full").replace(".jpg", "").replace(".png", "").replace(".webp", "");
File value = new File(CACHE_CARD_PICS_DIR + setFolder + "/" + filename);
cachedCards.put(key, value);
}
Expand Down
6 changes: 6 additions & 0 deletions forge-gui-android/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,12 @@
<version>2.2.3-SNAPSHOT</version>
<type>aar</type>
</dependency>
<dependency>
<groupId>io.github.zumikua</groupId>
<artifactId>webploader-android</artifactId>
<version>0.1.0</version>
<type>aar</type>
</dependency>
</dependencies>

<profiles>
Expand Down
7 changes: 6 additions & 1 deletion forge-gui-desktop/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -270,10 +270,15 @@
<artifactId>mp3-wav</artifactId>
<version>1.0.3</version>
</dependency>
<dependency>
<groupId>com.twelvemonkeys.imageio</groupId>
<artifactId>imageio-webp</artifactId>
<version>3.9.3</version>
</dependency>
<dependency>
<groupId>com.twelvemonkeys.imageio</groupId>
<artifactId>imageio-jpeg</artifactId>
<version>3.7.0</version>
<version>3.9.3</version>
</dependency>
</dependencies>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -421,7 +421,8 @@ public String map(String filename) {
if (validFilenames.containsKey(filename)) {
return validFilenames.get(filename);
} else if (StringUtils.endsWithIgnoreCase(filename, ".jpg")
|| StringUtils.endsWithIgnoreCase(filename, ".png")) {
|| StringUtils.endsWithIgnoreCase(filename, ".png")
|| StringUtils.endsWithIgnoreCase(filename, ".webp")) {
return filename;
}
return null;
Expand Down
38 changes: 38 additions & 0 deletions forge-gui-mobile/src/forge/assets/WebpLoader.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package forge.assets;

import com.badlogic.gdx.assets.AssetManager;
import com.badlogic.gdx.graphics.Texture;
import io.github.zumikua.webploader.common.WebPLoaderFactory;
import io.github.zumikua.webploader.common.WebPLoaderNativeInterface;
import io.github.zumikua.webploader.common.WebPTextureFactory;
import io.github.zumikua.webploader.common.WebPTextureLoader;

/**
*
*/
public class WebpLoader {

private final WebPTextureFactory textureFactory;

/**
*
* @param nativeInterface
*/
public WebpLoader(WebPLoaderNativeInterface nativeInterface) {
WebPLoaderFactory mFactory = new WebPLoaderFactory(nativeInterface);
textureFactory = mFactory.getTextureFactory();
}

/**
* Load the webp file into Texture file.
* @param filename Webp image file
* @return Texture file load
*/
public Texture load(String filename) {
AssetManager mAssetManager = new AssetManager();
mAssetManager.setLoader(Texture.class, ".webp", new WebPTextureLoader(mAssetManager.getFileHandleResolver(), textureFactory));
mAssetManager.load(filename, Texture.class);
mAssetManager.finishLoading();
return mAssetManager.get(filename, Texture.class);
}
}
2 changes: 1 addition & 1 deletion forge-gui-mobile/src/forge/card/CardRenderer.java
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ public static FImageComplex getCardArt(CardView card) {

public static FImageComplex getCardArt(String imageKey, boolean isSplitCard, boolean isHorizontalCard, boolean isAftermathCard, boolean isSaga, boolean isClass, boolean isDungeon, boolean isFlipCard, boolean isPlanesWalker, boolean isModernFrame) {
FImageComplex cardArt = Forge.getAssets().cardArtCache().get(imageKey);
boolean isClassicModule = imageKey != null && imageKey.length() > 2 && classicModuleCardtoCrop.contains(imageKey.substring(ImageKeys.CARD_PREFIX.length()).replace(".jpg", "").replace(".png", ""));
boolean isClassicModule = imageKey != null && imageKey.length() > 2 && classicModuleCardtoCrop.contains(imageKey.substring(ImageKeys.CARD_PREFIX.length()).replace(".jpg", "").replace(".png", "").replace(".webp", ""));
if (cardArt == null) {
Texture image = new RendererCachedCardImage(imageKey, true).getImage();
if (image != null) {
Expand Down
1 change: 1 addition & 0 deletions forge-gui/release-files/CONTRIBUTORS.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
add-le
Agetian
Alumi
Aoki-Kujo
Expand Down