ref: 006f3116af711aeea7331515f92384c9fe518368
parent: 71a278603d4fd68c33ec60e65730611c437b9888
author: qwx <qwx@sciops.net>
date: Sat Apr 24 06:32:10 EDT 2021
fs: plain pics in plan9 format
--- a/dat.h
+++ b/dat.h
@@ -1,1 +1,27 @@
+typedef struct Pic Pic;
+
extern char *prefix;
+
+enum{
+ PCfont,
+ PCarrow,
+ PCspace,
+ PCgrid,
+ PCplanets,
+ PCship,
+ PChud,
+ PCface,
+ PCammo,
+ PChit,
+ PCdir,
+ PCcur,
+ PCscroll,
+ PCgibs,
+ PCend,
+};
+struct Pic{
+ u32int *p;
+ int w;
+ int h;
+};
+extern Pic pics[PCend];
--- a/dporg.c
+++ b/dporg.c
@@ -45,6 +45,8 @@
case 'd': prefix = EARGF(usage()); break;
default: usage();
}ARGEND
+ if(initdraw(nil, nil, "dporg") < 0)
+ sysfatal("initdraw: %r");
initfs();
threadexits(nil);
}
--- a/fs.c
+++ b/fs.c
@@ -1,6 +1,7 @@
#include <u.h>
#include <libc.h>
#include <bio.h>
+#include <draw.h>
#include "dat.h"
#include "fns.h"
@@ -7,6 +8,7 @@
s32int sintab[256];
int npal;
u32int *pal;
+Pic pics[PCend];
static Biobuf *
eopen(char *s, int mode)
@@ -64,8 +66,61 @@
}
static void
-readpal(void)
+loadpic(char *name, Pic *pic)
{
+ int fd, n, m, dx, dy;
+ uchar *b, *s;
+ u32int *p;
+ Image *i;
+
+ if((fd = open(name, OREAD)) < 0)
+ sysfatal("loadpic: %r");
+ if((i = readimage(display, fd, 0)) == nil)
+ sysfatal("readimage: %r");
+ close(fd);
+ if(i->chan != RGBA32)
+ sysfatal("loadpic %s: inappropriate image format", name);
+ dx = Dx(i->r);
+ dy = Dy(i->r);
+ n = dx * dy;
+ p = emalloc(n * sizeof *p);
+ pic->p = p;
+ pic->w = dx;
+ pic->h = dy;
+ m = i->depth / 8;
+ b = emalloc(n * m);
+ unloadimage(i, i->r, b, n * m);
+ freeimage(i);
+ s = b;
+ while(n-- > 0){
+ *p++ = s[0] << 24 | s[3] << 16 | s[2] << 8 | s[1];
+ s += m;
+ }
+ free(b);
+}
+
+static void
+loadpics(void)
+{
+ loadpic("a.bit", pics + PCfont);
+ loadpic("b.bit", pics + PCarrow);
+ loadpic("c.bit", pics + PCspace);
+ loadpic("d.bit", pics + PCgrid);
+ loadpic("e.bit", pics + PCplanets);
+ loadpic("f.bit", pics + PCship);
+ loadpic("k.bit", pics + PChud);
+ loadpic("l.bit", pics + PCface);
+ loadpic("m.bit", pics + PCammo);
+ loadpic("n.bit", pics + PChit);
+ loadpic("o.bit", pics + PCdir);
+ loadpic("p.bit", pics + PCcur);
+ loadpic("q.bit", pics + PCscroll);
+ loadpic("r.bit", pics + PCgibs);
+}
+
+static void
+loadpal(void)
+{
int n;
u8int r, g, b;
u32int *p;
@@ -82,13 +137,13 @@
g = g << 2 | g >> 4;
b = n >> 11 & 0x1f;
b = b << 3 | b >> 2;
- *p = r << 16 | g << 8 | b;
+ *p = 0xff << 24 | r << 16 | g << 8 | b;
}
Bterm(bf);
}
static void
-readsintab(void)
+loadsintab(void)
{
Biobuf *bf;
s32int *s;
@@ -105,8 +160,9 @@
rfork(RFNAMEG);
if(bind(".", prefix, MBEFORE|MCREATE) == -1 || chdir(prefix) < 0)
fprint(2, "initfs: %r\n");
- readsintab();
- readpal();
+ loadsintab();
+ loadpal();
+ loadpics();
}
// grids: 32/256/2048
@@ -119,5 +175,4 @@
// map bsp + str (on demand, with shim load gauge)
// a.map
// base.str
-// .bit (r8g8b8a8)
// + old project code