Sign Up
Log In
Log In
or
Sign Up
Places
All Projects
Status Monitor
Collapse sidebar
home:derselbst:n64
ppm2c
ppm2c.c
Overview
Repositories
Revisions
Requests
Users
Attributes
Meta
File ppm2c.c of Package ppm2c
#include <stdio.h> #include <stdlib.h> #include <string.h> #include <libgen.h> #define R( c ) ( ( ((unsigned short)c>>3) & 0x1F) << 11 ) #define G( c ) ( ( ((unsigned short)c>>3) & 0x1F) << 6 ) #define B( c ) ( ( ((unsigned short)c>>3) & 0x1F) ) #define packRGB(r,g,b) (unsigned short)( R(r) | G(g) | B(b) ) typedef struct RGB { unsigned char r; unsigned char g; unsigned char b; } RGB; main(argc,argv,envp) int argc; char *argv[]; char *envp; { FILE *image,*outc; RGB *rgb; int x,y,xres,yres,num; char line[256],name[256],*dot; unsigned short outshort; if ( argc < 3 ) { fprintf(stderr,"%s: input.pbm out.c\n",argv[0]); exit(1); } if( (image=fopen(argv[1],"r")) == NULL ) { fprintf(stderr,"can't open input file %s\n",argv[1]); exit(1); } if( (outc=fopen(argv[2],"w")) == NULL ) { fprintf(stderr,"can't open input file %s\n",argv[1]); exit(1); } fscanf(image,"P%d\n",&num); fgets(line,80,image); while (line[0] == '#') fgets(line,80,image); sscanf(line,"%d %d\n",&xres,&yres); fscanf(image,"%d",&num); fprintf(stdout,"num %d\n",num); fprintf(stdout,"c %x\n", fgetc(image)); rgb = (RGB *)malloc( xres*yres*sizeof(RGB) ); for (y=0; y<yres; y++) { for (x=0; x<xres; x++) { rgb[ y * xres + x].r = (unsigned char)fgetc(image); rgb[ y * xres + x].g = (unsigned char)fgetc(image); rgb[ y * xres + x].b = (unsigned char)fgetc(image); } } fprintf(stderr,"Map res %d %d\n",xres,yres); dot = basename(argv[2]); strcpy(name,dot); dot = (char *)strchr(name,'.'); *dot = '\0'; fprintf(outc,"#include <ultra64.h>\n"); fprintf(outc,"static u64 _pad_%s;\n",name); fprintf(outc,"unsigned short %s[]={\n",name); for (y=0; y<yres; y++) { for (x=0; x<xres; x++) { outshort = (unsigned short)packRGB( rgb[y*xres+x].r, rgb[y*xres+x].g,rgb[y*xres+x].b) | 1; fprintf(outc,"0x%04hx,",outshort); } fprintf(outc,"\n"); } fprintf(outc,"};\n"); close(image); close(outc); exit(0); }
Locations
Projects
Search
Status Monitor
Help
OpenBuildService.org
Documentation
API Documentation
Code of Conduct
Contact
Support
@OBShq
Terms
openSUSE Build Service is sponsored by
The Open Build Service is an
openSUSE project
.
Sign Up
Log In
Places
Places
All Projects
Status Monitor