Beispiel #1
0
int main(int argc, char** argv) {
	if(argc != 5 && argc != 4) syntax();
	int startarg = 1;
	int x=INT_MAX,y=INT_MAX,xmax=INT_MIN,ymax=INT_MIN,w=-1,h=-1;
	if(strncmp(argv[1], "-dim=", 5) == 0) {
		sscanf(argv[1]+5, "%d,%d,%d,%d", &x, &y, &w, &h);
		startarg++;
	}
	const char* pic1 = argv[startarg++];
	const char* pic2 = argv[startarg++];
	const char* out = argv[startarg++];
	struct Pix* p1 = pixRead(pic1);
	struct Pix* p2 = pixRead(pic2);
	if(p1->h != p2->h || p1->w != p2->w) {
		dprintf(2, "error: both pics need same dimensions!");
		exit(1);
	}
	struct Pix* p1b = pixConvertTo32(p1);
	struct Pix* p2b = pixConvertTo32(p2);
	int X, Y, W = p1->w, H = p1->h;
	if(x == INT_MAX) {
		for(Y = 0; Y < H; Y++) {
			for(X = 0; X < W; X++) {
				if(((uint32_t*)p1b->data)[Y * W + X] != ((uint32_t*)p2b->data)[Y * W + X]) {
					if(X < x) x = X;
					if(X > xmax) xmax = X;
					if(Y < y) y = Y;
					if(Y > ymax) ymax = Y;
				}
			}
		}
		++xmax; ++ymax;
		w = xmax - x;
		h = ymax - y;
	}
	struct Pix* po = pixCreate(w,h,32);
	int ox, oy;
	for(oy = 0, Y = y; Y < y + h; oy++, Y++) for(ox = 0, X = x; X < x + w; ox++, X++) {
		if(((uint32_t*)p1b->data)[Y * W + X] != ((uint32_t*)p2b->data)[Y * W + X])
			((uint32_t*)po->data)[oy * w + ox] = ((uint32_t*)p2b->data)[Y * W + X];
		else 
			((uint32_t*)po->data)[oy * w + ox] = 0;
	}
	pixWritePng(out, po, 0);
	dprintf(1, "wrote pixels x,y,w,h: %d,%d,%d,%d to %s\n", x,y,w,h,out);
	return 0;
	
}
Beispiel #2
0
int main() {
	const struct palpic* f = & sprite .header;
	PIX* o = pixCreate(f->width*scramble_factor, palpic_getspritecount(f) * palpic_getspriteheight(f)/scramble_factor, 32);
	prgb* palette = palpic_getpalette(f);
	prgb* bufptr = (prgb*) o->data;
	size_t i;
	for(i = 0; i < f->spritecount; i++) {
		int x, y;
		const uint8_t *source = palpic_getspritedata(f, i);
		for(y = 0; y < palpic_getspriteheight(f); y++) {
			for(x = 0; x < palpic_getspritewidth(f); x++) {
				*bufptr++ = palette[*source++];
			}
		}
	}
	pixWritePng("test.png", o, 0.0);
	return 0;
}
Beispiel #3
0
/*!
 *  pixWriteRGBAPng()
 *
 *      Input:  filename
 *              pix (rgba)
 *      Return: 0 if OK, 1 on error
 *
 *  Notes:
 *      (1) Wrapper to write the alpha sample of a 32 bpp pix to
 *          a png file in rgba format.
 *      (2) The default behavior of pix write to png is to ignore
 *          the alpha sample.
 *      (3) This always leaves alpha writing in the same mode as
 *          when this function begins.  So if alpha writing is in
 *          default mode, this enables it, writes out a rgba png file
 *          that includes the alpha channel, and resets to default.
 *          Otherwise, it leaves alpha writing enabled.
 */
l_int32
pixWriteRGBAPng(const char *filename,
                PIX        *pix)
{
l_int32  ret;

    PROCNAME("pixWriteRGBAPng");

    if (!pix)
        return ERROR_INT("pix not defined", procName, 1);
    if (!filename)
        return ERROR_INT("filename not defined", procName, 1);

        /* If alpha channel writing is enabled, just write it */
    if (var_PNG_WRITE_ALPHA == TRUE)
        return pixWrite(filename, pix, IFF_PNG);

    l_pngSetWriteAlpha(1);
    ret = pixWritePng(filename, pix, 0.0);
    l_pngSetWriteAlpha(0);  /* reset to default */
    return ret;
}
Beispiel #4
0
int main(int argc, char**argv) {
	if(argc != 3) {
		dprintf(2, "%s in.png out.png\n", argv[0]);
		return 1;
	}
	const char *in = argv[1];
	const char *out = argv[2];
	struct Pix* pin = pixRead(in);
	struct Pix* pin32 = pixConvertTo32(pin);
	struct Pix* pout = pixCreate(59, 16*30, 32);
	
	int xo = 0, yo = 0, i;
	uint32_t *od = (void*) pout->data;
	for(i = 0; i < 30; i++) {
		int xi = 3 + (i % 5) * 64;
		int yi = 5 + (i / 5) * 23;
		copy_rect(xi, yi, 59, 16, (void*) pin32->data, pin32->w, od);
		od += 16*59;
	}
	pixWritePng(out, pout, 0);
	return 0;
}