#include "common.h"
#include <ctype.h>
static void usage (void)
{
fprintf(stderr, "usage: setpbm [ -D debuglvl ] <path>\n");
exit(1);
}
static void skip_whitespaces (FILE *f) {
int c;
while (!feof (f)) {
c = fgetc (f);
if (!isspace (c)) {
if (c == '#') {
while (!feof (f) && (c = fgetc (f)) != '\n')
;
}
else {
ungetc (c, f);
break;
}
}
}
}
static int verify_pbm (FILE *f, int x, int y) {
u_int16_t magic;
unsigned int width, height;
int c;
if (fread (&magic, 1, 2, f) < 2) {
return -1;
}
if (magic != 0x3450) {
return -1;
}
skip_whitespaces(f);
width = 0;
fscanf (f, "%u", &width);
if (width != x) {
return -1;
}
skip_whitespaces (f);
fscanf (f, "%u", &height);
if (height != y) {
return -1;
}
c = fgetc (f);
if (!isspace (c)) {
return -1;
}
return 0;
}
int main(int argc, char **argv)
{
int n, opt, debug;
extern int optind;
extern char *optarg;
char *path;
int x, y, bytes;
debug = 0;
while ( (opt = getopt(argc, argv, "D:")) != -1 ) {
switch (opt) {
case 'D':
debug= atoi(optarg);
break;
default:
usage();
}
}
argc -= optind;
argv += optind;
if ( argc != 1 ) usage();
path= argv[0];
printf("Uploading image:\n");
printf("Filename: %s\n", path);
fprintf(stderr, "could not locate any jukeboxes\n");
return 1;
}
if ( n == 0 ) {
fprintf(stderr, "no NJB devices found\n");
return 0;
}
njb = njbs;
return 1;
}
printf("This device does not support setting the bitmap.");
} else {
FILE *f;
unsigned char data[1088];
if ( (f = fopen(path, "rb")) == NULL) {
printf("Could not open bitmap file.\n");
exit(-1);
}
if (verify_pbm(f, x, y) == -1) {
printf("Bad bitmap dimensions or bad file.\n");
fclose (f);
exit(-1);
}
if ( fread (data, 1, 1088, f) < 1088 ) {
printf("Could not read in bitmap file.\n");
fclose (f);
exit(-1);
}
fclose (f);
}
}
return 0;
}
int NJB_Capture(njb_t *njb)
Definition: procedure.c:223
int NJB_Get_Bitmap_Dimensions(njb_t *njb, int *x, int *y, int *bytes)
Definition: procedure.c:3043
void NJB_Close(njb_t *njb)
Definition: procedure.c:184
int NJB_Discover(njb_t *njbs, int limit, int *n)
Definition: procedure.c:108
int NJB_Release(njb_t *njb)
Definition: procedure.c:266
int NJB_Open(njb_t *njb)
Definition: procedure.c:130
int NJB_Set_Bitmap(njb_t *njb, const unsigned char *bitmap)
Definition: procedure.c:3099
void NJB_Set_Debug(int debug_flags)
Definition: procedure.c:2819
void NJB_Error_Dump(njb_t *njb, FILE *fp)
Definition: njb_error.c:418
#define NJB_MAX_DEVICES
Definition: libnjb.h:60