예제 #1
0
파일: qrimage.c 프로젝트: wxxweb/w2x
QRimageResultType QRimage_writeImage(
	QRcode *qrcode,
	const char *outfile,
	QRimageType imagetype
	)
{
	if (!qrcode) {
		return QR_IMG_QRCODE_IS_NULL;
	}
	switch(imagetype) {
		case QR_IMG_PNG:
			return writePNG(qrcode, outfile);
		case QR_IMG_EPS:
			return writeEPS(qrcode, outfile);
		case QR_IMG_SVG:
			return writeSVG(qrcode, outfile);
		case QR_IMG_ANSI:
			return writeANSI(qrcode, outfile, 0);
		case QR_IMG_ANSI256:
			return writeANSI(qrcode, outfile, 1);
		case QR_IMG_ASCIIi:
			return writeASCII(qrcode, outfile,  1);
		case QR_IMG_ASCII:
			return writeASCII(qrcode, outfile,  0);
		case QR_IMG_UTF8:
			return writeUTF8(qrcode, outfile, 0);
		case QR_IMG_ANSIUTF8:
			return writeUTF8(qrcode, outfile, 1);
		default:
			return QR_IMG_UNKNOW_IMAGE_TYPE;
	}
	return QR_IMG_SUCCESS;
}
예제 #2
0
int main(void) {
	static const char *const nibbles[16] = {
		"0000", "0001", "0010", "0011",
		"0100", "0101", "0110", "0111",
		"1000", "1001", "1010", "1011",
		"1100", "1101", "1110", "1111"
	};

	unsigned long value;
	char buffer[20], *end, *ch;
	unsigned shift;

	while (scanf("%lu", &value)==1) {
		end = writeUTF8(buffer, value);

		shift = 32;
		do {
			shift -= 4;
			printf("  %s" + !(shift & 4), nibbles[(value >> shift) & 15]);
		} while (shift);
		putchar('\n');

		for (ch = buffer; ch!=end; ++ch) {
			printf("  %s %s", nibbles[(unsigned char)*ch >> 4],
			       nibbles[*ch & 15]);
		}
		putchar('\n');
	}


	return 0;
}
예제 #3
0
파일: qrenc.c 프로젝트: binape/ybb-apitool
static void qrencode(const unsigned char *intext, int length, const char *outfile)
{
	QRcode *qrcode;
	
	qrcode = encode(intext, length);
	if(qrcode == NULL) {
		perror("Failed to encode the input data");
		exit(EXIT_FAILURE);
	}

	if(verbose) {
		fprintf(stderr, "File: %s, Version: %d\n", (outfile!=NULL)?outfile:"(stdout)", qrcode->version);
	}

	switch(image_type) {
		case PNG_TYPE:
			writePNG(qrcode, outfile);
			break;
		case EPS_TYPE:
			writeEPS(qrcode, outfile);
			break;
		case SVG_TYPE:
			writeSVG(qrcode, outfile);
			break;
		case ANSI_TYPE:
		case ANSI256_TYPE:
			writeANSI(qrcode, outfile);
			break;
		case ASCIIi_TYPE:
			writeASCII(qrcode, outfile,  1);
			break;
		case ASCII_TYPE:
			writeASCII(qrcode, outfile,  0);
			break;
		case UTF8_TYPE:
			writeUTF8(qrcode, outfile, 0);
			break;
		case ANSIUTF8_TYPE:
			writeUTF8(qrcode, outfile, 1);
			break;
		default:
			fprintf(stderr, "Unknown image type.\n");
			exit(EXIT_FAILURE);
	}

	QRcode_free(qrcode);
}
예제 #4
0
파일: text.c 프로젝트: DJwa163/swftools
static void addchar(gfxdevice_t*dev, int unicode)
{
    internal_t*i = (internal_t*)dev->internal;
    if(!i->current_page) {
        text_startpage(dev, 0, 0);
    }
    if(i->current_page->textpos + 10 > i->current_page->textsize) {
	i->current_page->textsize += 4096;
	i->current_page->text = realloc(i->current_page->text, i->current_page->textsize);
    }
    writeUTF8(unicode, &i->current_page->text[i->current_page->textpos]);
    i->current_page->textpos += strlen(&i->current_page->text[i->current_page->textpos]);
}
예제 #5
0
파일: qrenc.c 프로젝트: binape/ybb-apitool
static void qrencodeStructured(const unsigned char *intext, int length, const char *outfile)
{
	QRcode_List *qrlist, *p;
	char filename[FILENAME_MAX];
	char *base, *q, *suffix = NULL;
	const char *type_suffix;
	int i = 1;
	size_t suffix_size;

	switch(image_type) {
		case PNG_TYPE:
			type_suffix = ".png";
			break;
		case EPS_TYPE:
			type_suffix = ".eps";
			break;
		case SVG_TYPE:
			type_suffix = ".svg";
			break;
		case ANSI_TYPE:
		case ANSI256_TYPE:
		case ASCII_TYPE:
		case UTF8_TYPE:
		case ANSIUTF8_TYPE:
			type_suffix = ".txt";
			break;
		default:
			fprintf(stderr, "Unknown image type.\n");
			exit(EXIT_FAILURE);
	}

	if(outfile == NULL) {
		fprintf(stderr, "An output filename must be specified to store the structured images.\n");
		exit(EXIT_FAILURE);
	}
	base = strdup(outfile);
	if(base == NULL) {
		fprintf(stderr, "Failed to allocate memory.\n");
		exit(EXIT_FAILURE);
	}
	suffix_size = strlen(type_suffix);
	if(strlen(base) > suffix_size) {
		q = base + strlen(base) - suffix_size;
		if(strcasecmp(type_suffix, q) == 0) {
			suffix = strdup(q);
			*q = '\0';
		}
	}
	
	qrlist = encodeStructured(intext, length);
	if(qrlist == NULL) {
		perror("Failed to encode the input data");
		exit(EXIT_FAILURE);
	}

	for(p = qrlist; p != NULL; p = p->next) {
		if(p->code == NULL) {
			fprintf(stderr, "Failed to encode the input data.\n");
			exit(EXIT_FAILURE);
		}
		if(suffix) {
			snprintf(filename, FILENAME_MAX, "%s-%02d%s", base, i, suffix);
		} else {
			snprintf(filename, FILENAME_MAX, "%s-%02d", base, i);
		}

		if(verbose) {
			fprintf(stderr, "File: %s, Version: %d\n", filename, p->code->version);
		}

		switch(image_type) {
			case PNG_TYPE: 
				writePNG(p->code, filename);
				break;
			case EPS_TYPE: 
				writeEPS(p->code, filename);
				break;
			case SVG_TYPE: 
				writeSVG(p->code, filename);
				break;
			case ANSI_TYPE:
			case ANSI256_TYPE:
				writeANSI(p->code, filename);
				break;
			case ASCIIi_TYPE:
				writeASCII(p->code, filename, 1);
				break;
			case ASCII_TYPE:
				writeASCII(p->code, filename, 0);
				break;
			case UTF8_TYPE:
				writeUTF8(p->code, filename, 0);
				break;
			case ANSIUTF8_TYPE:
				writeUTF8(p->code, filename, 0);
				break;

			default:
				fprintf(stderr, "Unknown image type.\n");
				exit(EXIT_FAILURE);
		}
		i++;
	}

	free(base);
	if(suffix) {
		free(suffix);
	}

	QRcode_List_free(qrlist);
}