adding gzip into bmf
This commit is contained in:
parent
691f4aab06
commit
73d9c4da1e
3
.gitmodules
vendored
Normal file
3
.gitmodules
vendored
Normal file
@ -0,0 +1,3 @@
|
||||
[submodule "tools/sillyimage"]
|
||||
path = tools/sillyimage
|
||||
url = https://git.sillysagiri.moe/sillysagiri/sillyimage.git
|
5
.vscode/settings.json
vendored
5
.vscode/settings.json
vendored
@ -1,6 +1,9 @@
|
||||
{
|
||||
"java.project.referencedLibraries": [
|
||||
"vendor/**/*.jar",
|
||||
"/home/sillysagiri/Documents/wtk/lib/midpapi20.jar",
|
||||
"/home/sillysagiri/Documents/wtk/lib/cldcapi11.jar",
|
||||
"/home/sillysagiri/Documents/wtk/lib/midpapi20.jar",
|
||||
"/home/sillysagiri/Documents/wtk/lib/mmapi.jar",
|
||||
"library/tinygzip/tinylinegzip.jar"
|
||||
],
|
||||
"java.project.sourcePaths": [
|
||||
|
Binary file not shown.
Before Width: | Height: | Size: 1.1 KiB |
Binary file not shown.
Binary file not shown.
Binary file not shown.
Before Width: | Height: | Size: 2.1 KiB |
BIN
assets/silly/bmf/onds12_0.silly.gz
Normal file
BIN
assets/silly/bmf/onds12_0.silly.gz
Normal file
Binary file not shown.
Binary file not shown.
Before Width: | Height: | Size: 11 KiB After Width: | Height: | Size: 1.9 KiB |
@ -7,6 +7,8 @@ import javax.microedition.lcdui.Graphics;
|
||||
import javax.microedition.lcdui.Image;
|
||||
import javax.microedition.lcdui.game.Sprite;
|
||||
|
||||
import com.tinyline.util.GZIPInputStream;
|
||||
|
||||
import sillysagiri.scene.DeathError;
|
||||
|
||||
public class BMF {
|
||||
@ -29,21 +31,33 @@ public class BMF {
|
||||
{
|
||||
}
|
||||
|
||||
public static final BMF Create(String path_img, String path_fnt) throws Exception
|
||||
public static final BMF Create(String path_sillyimg, String path_fnt, int tint) throws Exception
|
||||
{
|
||||
BMF bmf = new BMF();
|
||||
bmf.img = Image.createImage(path_img);
|
||||
// InputStream in = bmf.getClass().getResourceAsStream(path_sillyimg);
|
||||
GZIPInputStream in = new GZIPInputStream(bmf.getClass().getResourceAsStream(path_sillyimg));
|
||||
|
||||
// read header
|
||||
byte[] temp = new byte[4];
|
||||
in.read(temp, 0, 4);
|
||||
|
||||
int w = ((temp[1] << 8 | temp[0])) & 0xFF;
|
||||
int h = ((temp[3] << 8 | temp[2])) & 0xFF;
|
||||
int[] buffer = new int[w*h];
|
||||
|
||||
for (int i=0; true; i++)
|
||||
{
|
||||
int read = in.read(temp, 0, 2);
|
||||
if (read == -1) break;
|
||||
|
||||
int rgb = Utils.ARGB15to255((char)((temp[1] << 8) | (temp[0] & 0xff)));
|
||||
if (rgb == 0xFFFFFFFF) buffer[i] = tint;
|
||||
else buffer[i] = rgb;
|
||||
}
|
||||
|
||||
bmf.img = Image.createRGBImage(buffer, w, h, true);
|
||||
bmf.Parse_fnt(path_fnt);
|
||||
|
||||
return bmf;
|
||||
}
|
||||
|
||||
public static final BMF Create(Image img, String path_fnt) throws Exception
|
||||
{
|
||||
BMF bmf = new BMF();
|
||||
bmf.img = img;
|
||||
bmf.Parse_fnt(path_fnt);
|
||||
|
||||
in.close();
|
||||
return bmf;
|
||||
}
|
||||
|
||||
@ -148,76 +162,6 @@ public class BMF {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* this is cpu intensive process
|
||||
* consider creating new BMF for each color instead
|
||||
*
|
||||
* limitation:
|
||||
* currently can only be used once
|
||||
* since its replacing white pixel with tinted color
|
||||
*/
|
||||
public void SetColor(int rgb)
|
||||
{
|
||||
// int[] buffer = new int[img.getWidth()*img.getHeight()];
|
||||
// img.getRGB(buffer, 0, img.getWidth(), 0, 0, img.getWidth(), img.getHeight());
|
||||
|
||||
// for (int i=0; i<buffer.length; i++)
|
||||
// {
|
||||
// if (buffer[i] == 0xFF000000) buffer[i] = rgb;
|
||||
// else buffer[i] = 0x00000000;
|
||||
// }
|
||||
|
||||
try
|
||||
{
|
||||
// ByteArrayOutputStream out = new ByteArrayOutputStream(128*64);
|
||||
// Gzip.gunzip(this.getClass().getResourceAsStream("/silly/bmf/nds12_0.silly.gz"), out);
|
||||
|
||||
// GZIPInputStream in = new GZIPInputStream(this.getClass().getResourceAsStream("/silly/bmf/nds12_0.silly.gz"));
|
||||
|
||||
InputStream in = this.getClass().getResourceAsStream("/silly/bmf/nds12_0.silly");
|
||||
int[] buffer = new int[128*64];
|
||||
|
||||
// read header
|
||||
byte[] size = new byte[4];
|
||||
in.read(size, 0, 4);
|
||||
int pointer = 0;
|
||||
while(true)
|
||||
{
|
||||
byte[] temp = new byte[2];
|
||||
int res = in.read(temp, 0, 2);
|
||||
if (res == -1) break;
|
||||
|
||||
char i = (char)((temp[1] << 8) | temp[0]);
|
||||
|
||||
// Extract 5-bit ABGR;
|
||||
char alpha = (char)((i >> 15) & 0x01);
|
||||
char blue = (char)((i >> 10) & 0x1F);
|
||||
char green = (char)((i >> 5) & 0x1F);
|
||||
char red = (char)(i & 0x1F);
|
||||
|
||||
// Scale the 5-bit values to 8-bit
|
||||
if (alpha == 1) alpha = 255;
|
||||
else alpha = 0;
|
||||
|
||||
red = (char)((red << 3) | 0x07);
|
||||
blue = (char)((green << 3) | 0x07);
|
||||
green = (char)((blue << 3) | 0x07);
|
||||
|
||||
// Combine into 24-bit value AARRGGBB
|
||||
buffer[pointer] = (alpha << 24) | (red << 16) | (green << 8) | blue;
|
||||
pointer++;
|
||||
}
|
||||
|
||||
// img = Image.createRGBImage(buffer, img.getWidth(), img.getHeight(), true);
|
||||
img = Image.createRGBImage(buffer, 128, 64, true);
|
||||
}
|
||||
catch(Exception e)
|
||||
{
|
||||
e.printStackTrace();
|
||||
Sagiri._instance.Set_Scene(new DeathError(e));
|
||||
}
|
||||
}
|
||||
|
||||
// TODO: handle multiline
|
||||
public short[] Measure(String str)
|
||||
|
@ -39,7 +39,7 @@ public class Sagiri
|
||||
|
||||
public Input input;
|
||||
|
||||
public int fps = 20;
|
||||
public int fps = 60;
|
||||
|
||||
private Scene _scene_current = null;
|
||||
public long time_begin = 0;
|
||||
|
@ -6,6 +6,25 @@ import javax.microedition.lcdui.Image;
|
||||
import dothack.Global;
|
||||
|
||||
public final class Utils {
|
||||
public static int ARGB15to255(char argb15)
|
||||
{
|
||||
// Extract 5-bit ABGR;
|
||||
int a5 = ((argb15 >> 15) & 0x01);
|
||||
int b5 = ((argb15 >> 10) & 0x1F);
|
||||
int g5 = ((argb15 >> 5) & 0x1F);
|
||||
int r5 = (argb15 & 0x1F);
|
||||
|
||||
// Scale the 5-bit values to 8-bit
|
||||
if (a5 == 1) a5 = 255;
|
||||
else a5 = 0;
|
||||
|
||||
int r8 = (r5 * 255) / 31;
|
||||
int g8 = (g5 * 255) / 31;
|
||||
int b8 = (b5 * 255) / 31;
|
||||
|
||||
return (a5 << 24) | (r8 << 16) | (g8 << 8) | b8;
|
||||
}
|
||||
|
||||
public static void Clear_Screen(Graphics gg, int r, int g, int b)
|
||||
{
|
||||
gg.setColor(r,g,b);
|
||||
|
@ -10,6 +10,7 @@ public class DeathError extends Scene {
|
||||
public DeathError(Exception e)
|
||||
{
|
||||
super();
|
||||
e.printStackTrace();
|
||||
this.e = e;
|
||||
}
|
||||
|
||||
|
@ -14,7 +14,7 @@ public class Intro extends Scene {
|
||||
private long counter = 0;
|
||||
private int state = 0;
|
||||
|
||||
private BMF bmf_normal;
|
||||
private BMF bmf_white;
|
||||
private BMF bmf_black;
|
||||
private BMF bmf_outline;
|
||||
private Image img_logo = null;
|
||||
@ -23,10 +23,9 @@ public class Intro extends Scene {
|
||||
public void Preload() {
|
||||
try
|
||||
{
|
||||
bmf_normal = BMF.Create("/silly/bmf/nds12_0.png", "/silly/bmf/nds12.fnt");
|
||||
bmf_outline = BMF.Create("/silly/bmf/onds12_0.png", "/silly/bmf/onds12.fnt");
|
||||
bmf_black = BMF.Create("/silly/bmf/nds12_0.png", "/silly/bmf/nds12.fnt");
|
||||
bmf_black.SetColor(0xFFFF0000);
|
||||
bmf_white = BMF.Create("/silly/bmf/nds12_0.silly.gz", "/silly/bmf/nds12.fnt", 0xffffffff);
|
||||
bmf_outline = BMF.Create("/silly/bmf/onds12_0.silly.gz", "/silly/bmf/onds12.fnt", 0xffffffff);
|
||||
bmf_black = BMF.Create("/silly/bmf/nds12_0.silly.gz", "/silly/bmf/nds12.fnt", 0xff000000);
|
||||
img_logo = Image.createImage("/t_1.png");
|
||||
}
|
||||
catch(Exception e)
|
||||
@ -39,7 +38,7 @@ public class Intro extends Scene {
|
||||
{
|
||||
img_logo = null;
|
||||
img_theworld = null;
|
||||
bmf_normal = null;
|
||||
bmf_white = null;
|
||||
bmf_black = null;
|
||||
bmf_outline = null;
|
||||
}
|
||||
@ -68,7 +67,7 @@ public class Intro extends Scene {
|
||||
g.drawRegion(
|
||||
img_logo,
|
||||
0, 0, img_logo.getWidth(), halfH, Sprite.TRANS_NONE,
|
||||
pos, Utils.GetScreenHeight()/2-1,
|
||||
pos, Utils.GetScreenHeight()/2,
|
||||
Graphics.BOTTOM | Graphics.HCENTER);
|
||||
|
||||
g.drawRegion(
|
||||
@ -117,7 +116,7 @@ public class Intro extends Scene {
|
||||
5, Utils.GetScreenHeight()-5,
|
||||
Graphics.LEFT | Graphics.BOTTOM);
|
||||
|
||||
bmf_normal.Draw(g,
|
||||
bmf_white.Draw(g,
|
||||
"VOL 1 - v0.1-silly",
|
||||
5, 5);
|
||||
|
||||
@ -128,8 +127,6 @@ public class Intro extends Scene {
|
||||
Utils.GetScreenWidth()/2, (int)(Utils.GetScreenHeight()*0.7),
|
||||
Graphics.VCENTER | Graphics.HCENTER);
|
||||
|
||||
g.drawImage(bmf_black.img, 0, 0, 20);
|
||||
|
||||
if (sagiri.input.IsKeyDownAny())
|
||||
sagiri.Set_Scene(new MainMenu());
|
||||
}
|
||||
|
@ -1,9 +1,8 @@
|
||||
package sillysagiri.scene;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import javax.microedition.lcdui.Graphics;
|
||||
import javax.microedition.lcdui.Image;
|
||||
import javax.microedition.lcdui.game.Sprite;
|
||||
|
||||
import sillysagiri.BMF;
|
||||
import sillysagiri.Scene;
|
||||
@ -14,12 +13,23 @@ public class MainMenu extends Scene {
|
||||
private int state = 0;
|
||||
|
||||
private Image img_bg;
|
||||
private Image img_box;
|
||||
private Image img_bandai;
|
||||
private BMF bmf;
|
||||
private BMF bmf_white;
|
||||
private BMF bmf_blue;
|
||||
|
||||
private Image img_head1;
|
||||
private Image img_head2;
|
||||
private Image img_head3;
|
||||
private Image img_head4;
|
||||
|
||||
private Image img_arrow;
|
||||
|
||||
public void Preload() {
|
||||
try {
|
||||
bmf = BMF.Create("/silly/bmf/onds12_0.png", "/silly/bmf/onds12.fnt");
|
||||
bmf_white = BMF.Create("/silly/bmf/onds12_0.silly.gz", "/silly/bmf/onds12.fnt", 0xffffffff);
|
||||
bmf_blue = BMF.Create("/silly/bmf/onds12_0.silly.gz", "/silly/bmf/onds12.fnt", 0xff00dbff);
|
||||
bmf_blue.lineHeight = (short)(bmf_blue.lineHeight*1.5);
|
||||
Image img_loop = Image.createImage("/m_2.png");
|
||||
img_bandai = Image.createImage("/c_0.png");
|
||||
|
||||
@ -31,6 +41,19 @@ public class MainMenu extends Scene {
|
||||
|
||||
for (int i = 0; i<loopCount; i++)
|
||||
g_bg.drawImage(img_loop, 0, i*img_loop.getHeight(), Graphics.LEFT | Graphics.TOP);
|
||||
|
||||
int boxw = (int)(bmf_blue.Measure("INSTRUCTION")[0]+bmf_blue.lineHeight*1.4);
|
||||
int boxh = bmf_blue.lineHeight*8;
|
||||
int[] temp = new int[boxw*boxh];
|
||||
for (int i=0; i<temp.length; i++) temp[i] = 0x93800000;
|
||||
img_box = Image.createRGBImage(temp, boxw, boxh, true);
|
||||
temp = null;
|
||||
|
||||
img_head1 = Image.createImage("/bF_0.png");
|
||||
img_head2 = Image.createImage("/bF_1.png");
|
||||
img_head3 = Image.createImage("/bF_4.png");
|
||||
img_head4 = Image.createImage("/bF_2.png");
|
||||
img_arrow = Image.createImage("/i_0.png");
|
||||
}
|
||||
catch(Exception e)
|
||||
{
|
||||
@ -58,7 +81,7 @@ public class MainMenu extends Scene {
|
||||
|
||||
if (counter >= 600) counter = 0;
|
||||
if (counter < 400)
|
||||
bmf.DrawEx(g,
|
||||
bmf_white.DrawEx(g,
|
||||
"PRESS ANY KEY",
|
||||
Utils.GetScreenWidth()/2, (int)(Utils.GetScreenHeight()*0.7),
|
||||
Graphics.VCENTER | Graphics.HCENTER);
|
||||
@ -70,6 +93,51 @@ public class MainMenu extends Scene {
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case 1:
|
||||
{
|
||||
Utils.Clear_Screen(g, 255, 108, 0);
|
||||
g.drawImage(img_bg, 0, 0, Graphics.TOP | Graphics.LEFT);
|
||||
|
||||
int padding = 3;
|
||||
g.drawImage(img_head1, padding, padding, Graphics.LEFT | Graphics.TOP);
|
||||
g.drawImage(img_head2, Utils.GetScreenWidth()-padding, padding, Graphics.RIGHT | Graphics.TOP);
|
||||
g.drawImage(img_head3, padding, Utils.GetScreenHeight()-padding, Graphics.LEFT | Graphics.BOTTOM);
|
||||
g.drawImage(img_head4, Utils.GetScreenWidth()-padding, Utils.GetScreenHeight()-5, Graphics.RIGHT | Graphics.BOTTOM);
|
||||
|
||||
int cursor = (int)(Utils.GetScreenHeight()*0.35);
|
||||
g.drawImage(img_box, Utils.GetScreenWidth()/2, cursor-(bmf_blue.lineHeight/2), Graphics.HCENTER | Graphics.TOP);
|
||||
|
||||
bmf_blue.DrawEx(g, "NEW GAME", Utils.GetScreenWidth()/2, cursor, Graphics.HCENTER | Graphics.TOP);
|
||||
bmf_blue.DrawEx(g, "LOAD GAME", Utils.GetScreenWidth()/2, cursor+=bmf_blue.lineHeight, Graphics.HCENTER | Graphics.TOP);
|
||||
bmf_blue.DrawEx(g, "INSTRUCTION", Utils.GetScreenWidth()/2, cursor+=bmf_blue.lineHeight, Graphics.HCENTER | Graphics.TOP);
|
||||
bmf_blue.DrawEx(g, "OPTIONS", Utils.GetScreenWidth()/2, cursor+=bmf_blue.lineHeight, Graphics.HCENTER | Graphics.TOP);
|
||||
bmf_blue.DrawEx(g, "LEADERBOARD", Utils.GetScreenWidth()/2, cursor+=bmf_blue.lineHeight, Graphics.HCENTER | Graphics.TOP);
|
||||
bmf_blue.DrawEx(g, "CREDITS", Utils.GetScreenWidth()/2, cursor+=bmf_blue.lineHeight, Graphics.HCENTER | Graphics.TOP);
|
||||
bmf_blue.DrawEx(g, "EXIT GAME", Utils.GetScreenWidth()/2, cursor+=bmf_blue.lineHeight, Graphics.HCENTER | Graphics.TOP);
|
||||
|
||||
// if (counter > 360) counter = 0;
|
||||
|
||||
padding = (int)(Math.sin((float)counter/200) * 3) + 3;
|
||||
cursor = (int)(Utils.GetScreenHeight()*0.35);
|
||||
|
||||
g.drawRegion(
|
||||
img_arrow,
|
||||
0, 0,
|
||||
img_arrow.getWidth()/2, img_arrow.getHeight(),
|
||||
Sprite.TRANS_NONE,
|
||||
(Utils.GetScreenWidth()/2) + (img_box.getWidth()/2)+padding, cursor,
|
||||
Graphics.LEFT | Graphics.TOP);
|
||||
|
||||
g.drawRegion(
|
||||
img_arrow,
|
||||
img_arrow.getWidth()/2, 0,
|
||||
img_arrow.getWidth()/2, img_arrow.getHeight(),
|
||||
Sprite.TRANS_NONE,
|
||||
(Utils.GetScreenWidth()/2) - (img_box.getWidth()/2)-padding, cursor,
|
||||
Graphics.RIGHT | Graphics.TOP);
|
||||
}
|
||||
break;
|
||||
|
||||
default: break;
|
||||
}
|
||||
|
1
tools/sillyimage
Submodule
1
tools/sillyimage
Submodule
@ -0,0 +1 @@
|
||||
Subproject commit cfadc0314b3d9c41bc693b63bef3d162ca45c8fb
|
Loading…
x
Reference in New Issue
Block a user