summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEamon Walsh <ewalsh@tycho.nsa.gov>2011-05-23 16:48:32 -0400
committerEamon Walsh <ewalsh@tycho.nsa.gov>2011-05-23 16:48:32 -0400
commit545076f952b8488d010a56d40d459abacf29414c (patch)
tree98cf1c0837b39462df9afc663a86f113986ac0d1
parentd0d31acd2a44195ae634dbdb2fd50c0cea1fbda0 (diff)
Update background image processing to match data/README.
-rw-r--r--data/desktopbg.rgbbin909434 -> 909434 bytes
-rw-r--r--data/genimage.c5
-rw-r--r--data/serverbg.rgbbin909434 -> 909434 bytes
-rw-r--r--src/dclient.c1
-rw-r--r--src/sclient.c27
-rw-r--r--src/sclient.h2
6 files changed, 24 insertions, 11 deletions
diff --git a/data/desktopbg.rgb b/data/desktopbg.rgb
index e137fe9..7ea25a7 100644
--- a/data/desktopbg.rgb
+++ b/data/desktopbg.rgb
Binary files differ
diff --git a/data/genimage.c b/data/genimage.c
index 08aa8bc..78696e7 100644
--- a/data/genimage.c
+++ b/data/genimage.c
@@ -4,6 +4,7 @@
#include <stdint.h>
#include <fcntl.h>
#include <unistd.h>
+#include <arpa/inet.h>
/*
* This C file contains the image data.
@@ -15,8 +16,8 @@
int main(int argc, char **argv)
{
- uint32_t width = gimp_image.width;
- uint32_t height = gimp_image.height;
+ uint32_t width = htonl(gimp_image.width);
+ uint32_t height = htonl(gimp_image.height);
unsigned i, r, g, b;
unsigned char pixel;
diff --git a/data/serverbg.rgb b/data/serverbg.rgb
index 56ca21f..0964306 100644
--- a/data/serverbg.rgb
+++ b/data/serverbg.rgb
Binary files differ
diff --git a/src/dclient.c b/src/dclient.c
index 3bef50d..09c4cbf 100644
--- a/src/dclient.c
+++ b/src/dclient.c
@@ -117,7 +117,6 @@ dclient_setup(void)
background = malloc(width * height);
if (!background)
return -1;
- memset(background, 0x9b, width * height);
sclient_read_background_image(IMG_FILE, background, width, height);
diff --git a/src/sclient.c b/src/sclient.c
index 3c9192d..4c2f635 100644
--- a/src/sclient.c
+++ b/src/sclient.c
@@ -5,6 +5,7 @@
#include <fcntl.h>
#include <unistd.h>
#include <signal.h>
+#include <arpa/inet.h>
#include "sys-queue.h"
#include "client.h"
@@ -32,20 +33,28 @@ sclient_mouse(struct display *d, struct mouse_event *m)
void
sclient_read_background_image(const char *filename, unsigned char *buf,
- int dw, int dh)
+ const int dw, const int dh)
{
uint32_t iw, ih, w, h, o;
unsigned i;
- unsigned char *ptr = buf;
+ unsigned char bg, *ptr = buf;
int fd = open(filename, O_RDONLY);
if (fd < 0)
- return;
+ goto err;
if (read(fd, &iw, sizeof(iw)) != sizeof(iw))
- goto out;
+ goto err2;
if (read(fd, &ih, sizeof(ih)) != sizeof(ih))
- goto out;
+ goto err2;
+ if (read(fd, &bg, 1) != 1)
+ goto err2;
+
+ lseek(fd, -1, SEEK_CUR);
+ memset(buf, bg, dw * dh);
+
+ iw = ntohl(iw);
+ ih = ntohl(ih);
w = (iw > dw) ? dw : iw;
h = (ih > dh) ? dh : ih;
@@ -57,8 +66,13 @@ sclient_read_background_image(const char *filename, unsigned char *buf,
lseek(fd, iw - w, SEEK_CUR);
}
-out:
close(fd);
+ return;
+
+err2:
+ close(fd);
+err:
+ memset(buf, 0, dw * dh);
}
int
@@ -72,7 +86,6 @@ sclient_setup(void)
background = malloc(width * height);
if (!background)
return -1;
- memset(background, 0, width * height);
sclient_read_background_image(IMG_FILE, background, width, height);
diff --git a/src/sclient.h b/src/sclient.h
index d18a208..8f96084 100644
--- a/src/sclient.h
+++ b/src/sclient.h
@@ -12,7 +12,7 @@ sclient_setup(void);
extern void
sclient_read_background_image(const char *filename, unsigned char *buf,
- int buf_width, int buf_height);
+ const int buf_width, const int buf_height);
extern struct display *
dclient_new(void);