Subversion Repositories shark

Compare Revisions

Ignore whitespace Rev 692 → Rev 693

/shark/trunk/ports/snapshot/snapshot.c
39,37 → 39,46
 
struct SNAP_SLOT{
char used;
int x;
int y;
int** buff;
} sslot[16];
int wx;
int wy;
int bytesperpixel;
void *buff;
} sslot[16] = {{0, 0, 0, 0, NULL},
{0, 0, 0, 0, NULL},
{0, 0, 0, 0, NULL},
{0, 0, 0, 0, NULL},
{0, 0, 0, 0, NULL},
{0, 0, 0, 0, NULL},
{0, 0, 0, 0, NULL},
{0, 0, 0, 0, NULL},
{0, 0, 0, 0, NULL},
{0, 0, 0, 0, NULL},
{0, 0, 0, 0, NULL},
{0, 0, 0, 0, NULL},
{0, 0, 0, 0, NULL},
{0, 0, 0, 0, NULL},
{0, 0, 0, 0, NULL},
{0, 0, 0, 0, NULL}};
 
int** snapshot_getslot(int nbuff, int sx, int sy)
void *snapshot_getslot(int nbuff, int wx, int wy, int bytesperpixel)
{
int i;
int** tmp;
void* tmp;
 
if ((sx<=0) || (sy<=0) || (nbuff<=0) || (nbuff>15)){
if ((wx<=0) || (wy<=0) || (nbuff<=0) || (nbuff>15)){
return NULL;
}
if (sslot[nbuff].used)
return NULL;
 
/* Allocate pointers to rows. */
tmp = (int **) kern_alloc((unsigned) (sy)*sizeof(int*));
if (!tmp)
if (sslot[nbuff].used)
return NULL;
 
/* Allocate rows and set pointers to them. */
for (i = 0; i < sy; i++){
tmp[i] = (int *) kern_alloc((unsigned) (sx)*sizeof(int));
if (!tmp[i])
return NULL;
}
/* Allocate memory. */
tmp = (void *)kern_alloc(wx * wy * bytesperpixel);
if (!tmp) return NULL;
 
sslot[nbuff].used = 1;
sslot[nbuff].x = sx;
sslot[nbuff].y = sy;
sslot[nbuff].wx = wx;
sslot[nbuff].wy = wy;
sslot[nbuff].bytesperpixel = bytesperpixel;
sslot[nbuff].buff = tmp;
return tmp;
}
76,42 → 85,40
 
void snapshot_freeslot(int nbuff)
{
int i;
 
if (sslot[nbuff].used){
for (i = 0; i < sslot[nbuff].y; i++)
kern_free(sslot[nbuff].buff[i], (unsigned) (sslot[nbuff].x)*sizeof(int));
kern_free(sslot[nbuff].buff, (unsigned) (sslot[nbuff].y)*sizeof(int*));
sslot[nbuff].used = 0;
}
if (sslot[nbuff].used == 0) return;
kern_free(sslot[nbuff].buff, sslot[nbuff].wx * sslot[nbuff].wy * sslot[nbuff].bytesperpixel);
sslot[nbuff].used = 0;
}
 
void snapshot_grab(int nbuff)
{
int i, j;
int i;
SYS_FLAGS f;
 
for (i = 0; i < sslot[nbuff].x; i++)
for (j = 0; j < sslot[nbuff].x; j++)
sslot[nbuff].buff[i][j] = grx_getpixel(i,j);
f = kern_fsave();
for (i = 0; i < sslot[nbuff].wx * sslot[nbuff].wy; i++)
*(int *)(sslot[nbuff].buff + i*2)= (int)grx_getpixel(i % sslot[nbuff].wx,i / sslot[nbuff].wx);
kern_frestore(f);
 
}
 
int snapshot_save_pgm(int nbuff, char *fname)
{
char out_st[40];
register int i, j;
register int i;
unsigned char tmp;
DOS_FILE *outf;
 
if ((outf = DOS_fopen(fname, "w")) == NULL) {
return -1;
} else {
sprintf(out_st, "P5\n%d %d\n%d\n", sslot[nbuff].x, sslot[nbuff].y, 255);
sprintf(out_st, "P5\n%d %d\n%d\n", sslot[nbuff].wx, sslot[nbuff].wy, 255);
DOS_fwrite(out_st, strlen(out_st), 1, outf);
cprintf(out_st);
 
for (j = 0; j < sslot[nbuff].y; j++) {
for (i = 0; i < sslot[nbuff].x; i++) {
DOS_fwrite(&(sslot[nbuff].buff[i][j]), 1, 1, outf);
}
for (i = 0; i < sslot[nbuff].wy * sslot[nbuff].wx; i++) {
tmp = (unsigned char)(*(int *)(sslot[nbuff].buff + i * 2));
DOS_fwrite(&tmp, 1, 1, outf);
}
DOS_fclose(outf);
}
121,7 → 128,7
int snapshot_save_ppm(int nbuff, char *fname)
{
char out_st[40];
register int i, j;
register int i;
int col_r, col_g, col_b;
DOS_FILE *outf;
 
128,18 → 135,16
if ((outf = DOS_fopen(fname, "w")) == NULL) {
return -1;
} else {
sprintf(out_st, "P3\n%d %d\n%d\n", sslot[nbuff].x, sslot[nbuff].y, 255);
sprintf(out_st, "P3\n%d %d\n%d\n", sslot[nbuff].wx, sslot[nbuff].wy, 255);
DOS_fwrite(out_st, strlen(out_st), 1, outf);
cprintf(out_st);
 
for (j = 0; j < sslot[nbuff].y; j++) {
for (i = 0; i < sslot[nbuff].x; i++) {
col_r = ((sslot[nbuff].buff[i][j] & 0xF800) >> 11) * 4;
col_g = ((sslot[nbuff].buff[i][j] & 0x07E0) >> 5) * 2;
col_b = (sslot[nbuff].buff[i][j] & 0x001F) * 4;
sprintf(out_st, "%d %d %d ", col_r, col_g, col_b);
DOS_fwrite(out_st, strlen(out_st), 1, outf);
}
for (i = 0; i < sslot[nbuff].wx * sslot[nbuff].wy; i++) {
col_r = ((*(int *)(sslot[nbuff].buff + i*2) & 0xF800) >> 11) * 4;
col_g = ((*(int *)(sslot[nbuff].buff + i*2) & 0x07E0) >> 5) * 2;
col_b = (*(int *)(sslot[nbuff].buff + i*2) & 0x001F) * 4;
sprintf(out_st, "%d %d %d ", col_r, col_g, col_b);
DOS_fwrite(out_st, strlen(out_st), 1, outf);
}
DOS_fclose(outf);
}
/shark/trunk/ports/snapshot/include/snapshot.h
1,11 → 1,11
#ifndef __SNAPSHOT_H__
#define __SNAPSHOT_H__
 
int** snapshot_getslot(int nbuff, int sx, int sy);
void snapshot_freeslot(int nbuff);
void snapshot_grab(int nbuff);
int snapshot_save_pgm(int nbuff, char *fname);
int snapshot_save_ppm(int nbuff, char *fname);
void* snapshot_getslot(int nbuff, int wx, int wy, int bytesperpixel);
void snapshot_freeslot(int nbuff);
void snapshot_grab(int nbuff);
int snapshot_save_pgm(int nbuff, char *fname);
int snapshot_save_ppm(int nbuff, char *fname);
 
#endif