From 16ea042bab854bbb1b0d97621ed93af1744488c5 Mon Sep 17 00:00:00 2001 From: jacksonmj Date: Sat, 14 Jan 2012 17:46:38 +0000 Subject: [PATCH] Make transform_save work with new save functions Conflicts: src/powder.c --- includes/powder.h | 2 - includes/save.h | 4 +- src/powder.c | 115 ------------------------------------- src/save.c | 140 +++++++++++++++++++++++++++++++++++++++++++++- 4 files changed, 142 insertions(+), 119 deletions(-) diff --git a/includes/powder.h b/includes/powder.h index 1e727d3f9..62a0c844a 100644 --- a/includes/powder.h +++ b/includes/powder.h @@ -791,8 +791,6 @@ int create_parts(int x, int y, int rx, int ry, int c, int flags); void create_line(int x1, int y1, int x2, int y2, int rx, int ry, int c, int flags); -void *transform_save(void *odata, int *size, matrix2d transform, vector2d translate); - void orbitalparts_get(int block1, int block2, int resblock1[], int resblock2[]); void orbitalparts_set(int *block1, int *block2, int resblock1[], int resblock2[]); diff --git a/includes/save.h b/includes/save.h index a9645a07b..e81b766d2 100644 --- a/includes/save.h +++ b/includes/save.h @@ -1,6 +1,8 @@ #ifndef SAVE_H #define SAVE_H +void *transform_save(void *odata, int *size, matrix2d transform, vector2d translate); + void *build_thumb(int *size, int bzip2); pixel *prerender_save(void *save, int size, int *width, int *height); @@ -22,4 +24,4 @@ void *build_save_PSv(int *size, int orig_x0, int orig_y0, int orig_w, int orig_h int parse_save_PSv(void *save, int size, int replace, int x0, int y0, unsigned char bmap[YRES/CELL][XRES/CELL], float fvx[YRES/CELL][XRES/CELL], float fvy[YRES/CELL][XRES/CELL], sign signs[MAXSIGNS], void* partsptr, unsigned pmap[YRES][XRES]); -#endif \ No newline at end of file +#endif diff --git a/src/powder.c b/src/powder.c index 289c3a7fb..9267397b8 100644 --- a/src/powder.c +++ b/src/powder.c @@ -3211,121 +3211,6 @@ void create_line(int x1, int y1, int x2, int y2, int rx, int ry, int c, int flag } } -void *transform_save(void *odata, int *size, matrix2d transform, vector2d translate) -{ - void *ndata; - unsigned char (*bmapo)[XRES/CELL] = calloc((YRES/CELL)*(XRES/CELL), sizeof(unsigned char)); - unsigned char (*bmapn)[XRES/CELL] = calloc((YRES/CELL)*(XRES/CELL), sizeof(unsigned char)); - particle *partst = calloc(sizeof(particle), NPART); - sign *signst = calloc(MAXSIGNS, sizeof(sign)); - unsigned (*pmapt)[XRES] = calloc(YRES*XRES, sizeof(unsigned)); - float (*fvxo)[XRES/CELL] = calloc((YRES/CELL)*(XRES/CELL), sizeof(float)); - float (*fvyo)[XRES/CELL] = calloc((YRES/CELL)*(XRES/CELL), sizeof(float)); - float (*fvxn)[XRES/CELL] = calloc((YRES/CELL)*(XRES/CELL), sizeof(float)); - float (*fvyn)[XRES/CELL] = calloc((YRES/CELL)*(XRES/CELL), sizeof(float)); - int i, x, y, nx, ny, w, h, nw, nh; - vector2d pos, tmp, ctl, cbr; - vector2d cornerso[4]; - unsigned char *odatac = odata; - if (parse_save(odata, *size, 0, 0, 0, bmapo, fvxo, fvyo, signst, partst, pmapt)) - { - free(bmapo); - free(bmapn); - free(partst); - free(signst); - free(pmapt); - free(fvxo); - free(fvyo); - free(fvxn); - free(fvyn); - return odata; - } - w = odatac[6]*CELL; - h = odatac[7]*CELL; - // undo any translation caused by rotation - cornerso[0] = v2d_new(0,0); - cornerso[1] = v2d_new(w-1,0); - cornerso[2] = v2d_new(0,h-1); - cornerso[3] = v2d_new(w-1,h-1); - for (i=0; i<4; i++) - { - tmp = m2d_multiply_v2d(transform,cornerso[i]); - if (i==0) ctl = cbr = tmp; // top left, bottom right corner - if (tmp.xcbr.x) cbr.x = tmp.x; - if (tmp.y>cbr.y) cbr.y = tmp.y; - } - // casting as int doesn't quite do what we want with negative numbers, so use floor() - tmp = v2d_new(floor(ctl.x+0.5f),floor(ctl.y+0.5f)); - translate = v2d_sub(translate,tmp); - nw = floor(cbr.x+0.5f)-floor(ctl.x+0.5f)+1; - nh = floor(cbr.y+0.5f)-floor(ctl.y+0.5f)+1; - if (nw>XRES) nw = XRES; - if (nh>YRES) nh = YRES; - // rotate and translate signs, parts, walls - for (i=0; i=nw || ny<0 || ny>=nh) - { - signst[i].text[0] = 0; - continue; - } - signst[i].x = nx; - signst[i].y = ny; - } - for (i=0; i=nw || ny<0 || ny>=nh) - { - partst[i].type = PT_NONE; - continue; - } - partst[i].x = nx; - partst[i].y = ny; - } - for (y=0; y=nw || ny<0 || ny>=nh) - continue; - if (bmapo[y][x]) - { - bmapn[ny][nx] = bmapo[y][x]; - if (bmapo[y][x]==WL_FAN) - { - fvxn[ny][nx] = fvxo[y][x]; - fvyn[ny][nx] = fvyo[y][x]; - } - } - } - ndata = build_save(size,0,0,nw,nh,bmapn,fvxn,fvyn,signst,partst); - free(bmapo); - free(bmapn); - free(partst); - free(signst); - free(pmapt); - free(fvxo); - free(fvyo); - free(fvxn); - free(fvyn); - return ndata; -} - #if defined(WIN32) && !defined(__GNUC__) void orbitalparts_get(int block1, int block2, int resblock1[], int resblock2[]) #else diff --git a/src/save.c b/src/save.c index a73440cb7..69036afbf 100644 --- a/src/save.c +++ b/src/save.c @@ -22,6 +22,7 @@ pixel *prerender_save(void *save, int size, int *width, int *height) { return prerender_save_PSv(save, size, width, height); } + return NULL; } void *build_save(int *size, int orig_x0, int orig_y0, int orig_w, int orig_h, unsigned char bmap[YRES/CELL][XRES/CELL], float vx[YRES/CELL][XRES/CELL], float vy[YRES/CELL][XRES/CELL], float pv[YRES/CELL][XRES/CELL], float fvx[YRES/CELL][XRES/CELL], float fvy[YRES/CELL][XRES/CELL], sign signs[MAXSIGNS], void* partsptr) @@ -48,6 +49,7 @@ int parse_save(void *save, int size, int replace, int x0, int y0, unsigned char { return parse_save_PSv(save, size, replace, x0, y0, bmap, fvx, fvy, signs, partsptr, pmap); } + return 1; } pixel *prerender_save_OPS(void *save, int size, int *width, int *height) @@ -756,7 +758,7 @@ int parse_save_OPS(void *save, int size, int replace, int x0, int y0, unsigned c } else { - fprintf(stderr, "Wrong type for \n", bson_iterator_key(&subiter)); + fprintf(stderr, "Wrong type for %s\n", bson_iterator_key(&subiter)); } } } @@ -2170,3 +2172,139 @@ void *build_thumb(int *size, int bzip2) *size = j; return d; } + +void *transform_save(void *odata, int *size, matrix2d transform, vector2d translate) +{ + void *ndata; + unsigned char (*bmapo)[XRES/CELL] = calloc((YRES/CELL)*(XRES/CELL), sizeof(unsigned char)); + unsigned char (*bmapn)[XRES/CELL] = calloc((YRES/CELL)*(XRES/CELL), sizeof(unsigned char)); + particle *partst = calloc(sizeof(particle), NPART); + sign *signst = calloc(MAXSIGNS, sizeof(sign)); + unsigned (*pmapt)[XRES] = calloc(YRES*XRES, sizeof(unsigned)); + float (*fvxo)[XRES/CELL] = calloc((YRES/CELL)*(XRES/CELL), sizeof(float)); + float (*fvyo)[XRES/CELL] = calloc((YRES/CELL)*(XRES/CELL), sizeof(float)); + float (*fvxn)[XRES/CELL] = calloc((YRES/CELL)*(XRES/CELL), sizeof(float)); + float (*fvyn)[XRES/CELL] = calloc((YRES/CELL)*(XRES/CELL), sizeof(float)); + float (*vxo)[XRES/CELL] = calloc((YRES/CELL)*(XRES/CELL), sizeof(float)); + float (*vyo)[XRES/CELL] = calloc((YRES/CELL)*(XRES/CELL), sizeof(float)); + float (*vxn)[XRES/CELL] = calloc((YRES/CELL)*(XRES/CELL), sizeof(float)); + float (*vyn)[XRES/CELL] = calloc((YRES/CELL)*(XRES/CELL), sizeof(float)); + float (*pvo)[XRES/CELL] = calloc((YRES/CELL)*(XRES/CELL), sizeof(float)); + float (*pvn)[XRES/CELL] = calloc((YRES/CELL)*(XRES/CELL), sizeof(float)); + int i, x, y, nx, ny, w, h, nw, nh; + vector2d pos, tmp, ctl, cbr; + vector2d cornerso[4]; + unsigned char *odatac = odata; + if (parse_save(odata, *size, 0, 0, 0, bmapo, vxo, vyo, pvo, fvxo, fvyo, signst, partst, pmapt)) + { + free(bmapo); + free(bmapn); + free(partst); + free(signst); + free(pmapt); + free(fvxo); + free(fvyo); + free(fvxn); + free(fvyn); + free(vxo); + free(vyo); + free(vxn); + free(vyn); + free(pvo); + free(pvn); + return odata; + } + w = odatac[6]*CELL; + h = odatac[7]*CELL; + // undo any translation caused by rotation + cornerso[0] = v2d_new(0,0); + cornerso[1] = v2d_new(w-1,0); + cornerso[2] = v2d_new(0,h-1); + cornerso[3] = v2d_new(w-1,h-1); + for (i=0; i<4; i++) + { + tmp = m2d_multiply_v2d(transform,cornerso[i]); + if (i==0) ctl = cbr = tmp; // top left, bottom right corner + if (tmp.xcbr.x) cbr.x = tmp.x; + if (tmp.y>cbr.y) cbr.y = tmp.y; + } + // casting as int doesn't quite do what we want with negative numbers, so use floor() + tmp = v2d_new(floor(ctl.x+0.5f),floor(ctl.y+0.5f)); + translate = v2d_sub(translate,tmp); + nw = floor(cbr.x+0.5f)-floor(ctl.x+0.5f)+1; + nh = floor(cbr.y+0.5f)-floor(ctl.y+0.5f)+1; + if (nw>XRES) nw = XRES; + if (nh>YRES) nh = YRES; + // rotate and translate signs, parts, walls + for (i=0; i=nw || ny<0 || ny>=nh) + { + signst[i].text[0] = 0; + continue; + } + signst[i].x = nx; + signst[i].y = ny; + } + for (i=0; i=nw || ny<0 || ny>=nh) + { + partst[i].type = PT_NONE; + continue; + } + partst[i].x = nx; + partst[i].y = ny; + } + for (y=0; y=nw || ny<0 || ny>=nh) + continue; + if (bmapo[y][x]) + { + bmapn[ny][nx] = bmapo[y][x]; + if (bmapo[y][x]==WL_FAN) + { + fvxn[ny][nx] = fvxo[y][x]; + fvyn[ny][nx] = fvyo[y][x]; + } + } + vxn[ny][nx] = vxo[y][x]; + vyn[ny][nx] = vyo[y][x]; + pvn[ny][nx] = pvo[y][x]; + } + ndata = build_save(size,0,0,nw,nh,bmapn,vxn,vyn,pvn,fvxn,fvyn,signst,partst); + free(bmapo); + free(bmapn); + free(partst); + free(signst); + free(pmapt); + free(fvxo); + free(fvyo); + free(fvxn); + free(fvyn); + free(vxo); + free(vyo); + free(vxn); + free(vyn); + free(pvo); + free(pvn); + return ndata; +}