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; }
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); }
bool TwoDAFile::writeASCII(const Common::UString &fileName) const { Common::WriteFile file; if (!file.open(fileName)) return false; writeASCII(file); file.close(); return true; }
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); }
int main(int argc, char** argv) { if (argc < 2) { printf("Usage: bin2ascii fname\n fname: input ply in binary big endian format\n"); return 1; } std::string inputFile = argv[1]; if (inputFile.substr(inputFile.find_last_of('.')+1) != "ply") { printf("Error: expected ply file\n"); return 2; } std::ifstream ifs(inputFile.c_str(), std::ios::binary); if (ifs.is_open()) { std::string outputFile = inputFile.substr(0, inputFile.find_last_of('.')) + "_ascii.ply"; std::ofstream ofs(outputFile.c_str()); if (DEBUG) { printf("Converting %s to %s...\n", inputFile.c_str(), outputFile.c_str()); } std::string line; for(int i=0; i<2; i++) { std::getline(ifs, line); } ofs << "ply" << std::endl << "format " << ASCII_FORMAT << std::endl; std::vector<std::string> vertexProperties, faceProperties, edgeProperties; unsigned int vertices = 0, faces = 0, edges = 0, state = 0; // read header lines do { std::getline(ifs, line); ofs << line << std::endl; std::vector<std::string> tokens; split(line, tokens); if (tokens[0] == "element") { if (tokens[1] == "vertex") { vertices = atoi(tokens[2].c_str()); state = 1; } else if (tokens[1] == "face") { faces = atoi(tokens[2].c_str()); state = 2; } else if (tokens[1] == "edge") { edges = atoi(tokens[2].c_str()); state = 3; } } else if (tokens[0] == "property") { if (state == 1) { vertexProperties.push_back(tokens[1]); } else if (state == 2) { faceProperties.push_back(tokens[1]); faceProperties.push_back(tokens[2]); faceProperties.push_back(tokens[3]); } else if (state == 3) { edgeProperties.push_back(tokens[1]); } } } while(line != END_HEADER); // convert binary data and write to output file for(unsigned int i=0; i<vertices; i++) { writeASCII(ifs, ofs, vertexProperties); } for(unsigned int i=0; i<faces; i++) { writeASCII(ifs, ofs, faceProperties); } for(unsigned int i=0; i<edges; i++) { writeASCII(ifs, ofs, edgeProperties); } ofs.close(); } else { printf("Error opening file\n"); return 3; } ifs.close(); printf("Finished!\n"); return 0; }