Skip to content

Commit

Permalink
5.1
Browse files Browse the repository at this point in the history
  • Loading branch information
Dituon committed Dec 5, 2022
1 parent 87563ca commit 9b4beb9
Show file tree
Hide file tree
Showing 13 changed files with 30 additions and 29 deletions.
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
# petpet special
/example-data/output
!/data/xmmt.dituon.petpet
!/config/xmmt.dituon.petpet

# User-specific stuff
.idea/
Expand Down
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -176,11 +176,11 @@
> (当Gif中包含`40`帧, 尺寸为`300*500`时)
> - 输出的Gif长度不变, 尺寸为`120*200`
- **gifQuality**: `100`
- **gifQuality**: `10`

> Gif编码质量(1-100), 默认为100
> Gif编码质量(`1`-`99`), 默认为`10`
>
> 数字越大, 速度越慢, 质量越好 (小于70时, 速度不会有明显提升)
> 数字越小, 速度越慢, 质量越好 (大于`20`, 速度不会有明显提升)
>
> 仅适用于`ANIMATED_LIB`编码器
Expand Down
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ apply plugin: "java"


group = 'xmmt.dituon'
version = '5.0'
version = '5.1'

repositories {
maven { url 'https://maven.aliyun.com/repository/public' }
Expand Down
4 changes: 2 additions & 2 deletions config/xmmt.dituon.petpet/PetPet.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ gifMaxSize:
- 200
- 200
- 32
# GIF质量, 仅适用于ANIMATED_LIB编码器
gifQuality: 100
# GIF质量, 仅适用于ANIMATED_LIB编码器, 1为质量最佳, 超过20不会有明显性能提升
gifQuality: 10
# 是否使用headless模式
headless: true
# 图片合成线程池容量, 填入0为CPU线程数+1 (默认值)
Expand Down
2 changes: 1 addition & 1 deletion index.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"version": 5.0,
"version": 5.1,
"dataList": [
"reverse",
"fantasy_time",
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/moe/dituon/petpet/plugin/PluginConfig.kt
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@ object Config : AutoSavePluginConfig("PetPet") {
val gifEncoder: Encoder by value(Encoder.ANIMATED_LIB)
@ValueDescription("GIF缩放阈值/尺寸")
val gifMaxSize: List<Int> by value(listOf(200, 200, 32))
@ValueDescription("GIF质量, 仅适用于ANIMATED_LIB编码器")
val gifQuality: Int by value(100)
@ValueDescription("GIF质量, 仅适用于ANIMATED_LIB编码器, 1为质量最佳, 超过20不会有明显性能提升")
val gifQuality: Int by value(10)
@ValueDescription("是否使用headless模式")
val headless: Boolean by value(true)
@ValueDescription("图片合成线程池容量, 填入0为CPU线程数+1 (默认值)")
Expand Down
15 changes: 11 additions & 4 deletions src/main/java/moe/dituon/petpet/plugin/PluginPetService.java
Original file line number Diff line number Diff line change
@@ -1,18 +1,19 @@
package moe.dituon.petpet.plugin;

import kotlin.Pair;
import moe.dituon.petpet.share.BaseConfigFactory;
import moe.dituon.petpet.share.BasePetService;
import moe.dituon.petpet.share.GifAvatarExtraDataProvider;
import moe.dituon.petpet.share.TextExtraData;
import net.mamoe.mirai.contact.Group;
import net.mamoe.mirai.contact.Member;
import net.mamoe.mirai.contact.NormalMember;
import net.mamoe.mirai.message.data.Image;
import net.mamoe.mirai.utils.ExternalResource;
import moe.dituon.petpet.share.BaseConfigFactory;
import moe.dituon.petpet.share.BasePetService;
import moe.dituon.petpet.share.GifAvatarExtraDataProvider;
import moe.dituon.petpet.share.TextExtraData;

import java.io.File;
import java.io.InputStream;
import java.text.MessageFormat;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
Expand Down Expand Up @@ -83,6 +84,12 @@ private void readPluginConfig(Config config) {
super.setGifMaxSize(config.getGifMaxSize());
super.encoder = config.getGifEncoder();
super.quality = (byte) config.getGifQuality();
if (super.quality < 1 || super.quality >= 100) {
System.out.println(
MessageFormat.format("Petpet Plugin 的GIF质量参数范围为 1-99 (1为最佳), 你提供的质量参数为{0}, 已自动更改为默认值10", quality)
);
super.quality = 10;
}

super.setGifMakerThreadPoolSize(config.getThreadPoolSize());
System.out.println("Petpet GifMakerThreadPoolSize: " + super.getGifMakerThreadPoolSize());
Expand Down
6 changes: 2 additions & 4 deletions src/main/java/moe/dituon/petpet/share/BaseGifMaker.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,7 @@

import java.awt.*;
import java.awt.image.BufferedImage;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.*;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
Expand Down Expand Up @@ -108,6 +105,7 @@ public InputStream makeGIF(List<AvatarModel> avatarList, List<TextModel> textLis
BufferedImage.TYPE_3BYTE_BGR);
Graphics2D g = temp.createGraphics();
g.drawImage(image, 0, 0, null);
g.dispose();
FrameData frameData = new FrameData(temp, params.getQuality());
frameMap.put(fi, frameData);
if (fi == 0) {
Expand Down
8 changes: 3 additions & 5 deletions src/main/java/moe/dituon/petpet/share/BaseImageMaker.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,7 @@

import javax.imageio.ImageIO;
import java.awt.image.BufferedImage;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.*;
import java.util.ArrayList;

public class BaseImageMaker {
Expand Down Expand Up @@ -42,7 +39,8 @@ public InputStream makeImage(
BufferedImage sticker, GifRenderParams params) {
for (AvatarModel avatar : avatarList) {
if (avatar.isGif()) return gifMaker.makeGIF(
avatarList, textList, sticker, params);
avatarList, textList, sticker, params
);
}
try {
return bufferedImageToInputStream(ImageSynthesis.synthesisImage(
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/moe/dituon/petpet/share/BasePetService.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@


public class BasePetService {
public static final float VERSION = 5.0F;
public static final float VERSION = 5.1F;
public static final String FONTS_FOLDER = "fonts";
protected boolean antialias = true;
protected byte quality = 100;
protected byte quality = 10;
private List<Integer> gifMaxSize = null;
public Encoder encoder = Encoder.ANIMATED_LIB;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
import java.io.BufferedInputStream;
import java.net.URL;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;

Expand Down Expand Up @@ -63,11 +62,11 @@ protected static void g2dDrawZoomAvatar(
);
int resultWidth = (int) (w * ratio);
int resultHeight = (int) (h * ratio);
if (resultWidth <= 0 || resultHeight <= 0) return;

int[] cropPos = new int[]{
0, 0, resultWidth, resultHeight
};
System.out.println(Arrays.toString(cropPos));

newAvatarImage = cropImage(newAvatarImage, cropPos);
break;
Expand Down
2 changes: 1 addition & 1 deletion src/main/resources/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"dataPath": "data/xmmt.dituon.petpet",
"gifMaxSize": [200, 200, 32],
"gifEncoder": "ANIMATED_LIB",
"gifQuality": 100,
"gifQuality": 10,
"gifMakerThreadPoolSize": 0,
"headless": true
}
2 changes: 1 addition & 1 deletion src/test/java/moe/dituon/petpet/example/HelloPetpet.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
import java.util.List;

public class HelloPetpet {
//(。・∀・)ノ゙嗨 欢迎来到第一人称互动式实例, 本实例可以让你快速了解到Petpet基础API的使用
//(。・∀・)ノ゙嗨 欢迎来到互动式实例, 本实例可以让你快速了解到Petpet基础API的使用
static BasePetService service = new BasePetService(); //在开始之前, 需要先实例化PetService
//Service是什么呢?
//在Petpet中, Service是程序的核心, 可以把Service理解成工厂
Expand Down

0 comments on commit 9b4beb9

Please sign in to comment.