int main(int argc, char * argv[]) { FILE* ifp; bit** bits; int rows, cols; const char * inputFilename; pbm_init(&argc, argv); if (argc-1 > 0) pm_error("Too many arguments (%d). The only valid argument is an " "input file name.", argc-1); else if (argc-1 == 1) inputFilename = argv[1]; else inputFilename = "-"; ifp = pm_openr(inputFilename); bits = pbm_readpbm(ifp, &cols, &rows); if (rows > 255) pm_error("Image is too high: %d rows. Max height: 255 rows", rows); if (cols > 255) pm_error("Image is too wide: %d cols. Max width: 255 cols", cols); generateMo(stdout, bits, cols, rows); pm_close(ifp); pbm_freearray(bits, rows); exit(0); }
Feature::Feature(const char* _filename) { filename = strcpy(new char[std::strlen(_filename)+1], _filename); FILE* infile = fopen(filename, "rb"); bit** bits = pbm_readpbm(infile, &cols, &rows); fclose(infile); cols32 = (cols + 31) / 32; right_mask = static_cast<unsigned int>(-1) << (32 - (cols % 32)); // fprintf(stderr, "width %d height %d mask %x\n", cols, rows, right_mask); integers = new unsigned int[cols32 * rows]; for (int y = 0; y < rows; y++) { int index = 0; for (int x = 0; x < cols32; x++) { int i = 0; for (int b = 0; b < 32; b++) { i = i << 1; if (index < cols && bits[y][index]) i++; index++; } integers[x + y * cols32] = i; } } pbm_freearray(bits, rows); /* fprintf(stderr, "%dx%d %s\n%x %x\n%x %x\n%x %x\n", cols, rows, filename, integers[(rows - 3) * cols32], integers[(rows - 3) * cols32 + 1], integers[(rows - 2) * cols32], integers[(rows - 2) * cols32 + 1], integers[(rows - 1) * cols32], integers[(rows - 1) * cols32 + 1]); */ if (getBottomLeft() == 0) { fprintf(stderr, "WARNING: bottom left in %s is zero\n", filename); } }
/** return data */ const void *GeoImage::data() { if (data_) return (void *) data_; qDebug("GeoImage::data() - load data"); QString fname = filename(); qDebug("GeoImage::data() %s", fname.toLatin1().constData()); FILE *fp; fp = fopen(fname.toLatin1().constData(), "r"); if (!fp) { qDebug("# (ERROR)GeoImage::load(%s) Can't open file for reading!", fname.toLatin1().constData()); return 0; } int cols, rows; //float minval, maxval; switch (type_) { case PFM_FLOAT: case PFM_UINT: case PFM_SINT: case PFM_SINT16: case PFM_UINT16: case PFM_BYTE: case PFM_3BYTE: data_ = pfm_readpfm_type(fp, &cols, &rows, &minval_, &maxval_, type_, 0); testSize(cols, rows, type_); break; case PBM: data_ = (void *) pbm_readpbm(fp, &cols, &rows); minval_ = 0.0, maxval_ = 1.0; testSize(cols, rows, type_); break; case PGM:{ gray maxval, **data_g; data_g = pgm_readpgm(fp, &cols, &rows, &maxval); data_ = (void *) data_g; minval_ = 0.0, maxval_ = (float) maxval; testSize(cols, rows, type_); } break; case PPM: pixval maxval; pixel **dat_p; dat_p = ppm_readppm(fp, &cols, &rows, &maxval); data_ = (void *) dat_p; minval_ = 0.0, maxval_ = (float) maxval; testSize(cols, rows, type_); break; default: qDebug("Unknown type %d",type_); fclose(fp); return 0; } fclose(fp); if (data_) dataSize_=rows_*cols_*sizeOfData(type_); cache_.useImage(this); return data_; }
int main(int argc, const char * argv[]) { struct cmdlineInfo cmdline; FILE * ifP; bit ** bits; int rows, cols; unsigned int top, bottom, left, right; /* boundaries of principal part of image -- i.e. excluding white borders */ pm_proginit(&argc, argv); parseCommandLine(argc, argv, &cmdline); ifP = pm_openr(cmdline.inputFileName); bits = pbm_readpbm(ifP, &cols, &rows); pm_close(ifP); findPrincipalImage(bits, rows, cols, &top, &bottom, &left, &right); printf("%%!PS-Adobe-2.0 EPSF-1.2\n"); outputBoundingBox(top, bottom, left, right, rows, cmdline.dpiX, cmdline.dpiY); if (!cmdline.bbonly) { int row; printf("%%%%BeginPreview: %d %d 1 %d\n", right - left + 1, bottom - top + 1, bottom - top + 1); for (row = top; row <= bottom; row++) { unsigned int col; unsigned int outChars; printf("%% "); outChars = 2; /* initial value */ for (col = left; col <= right; col += 8) { if (outChars == 72) { printf("\n%% "); outChars = 2; } printf("%02x", eightPixels(bits, row, col, cols)); outChars += 2; } if (outChars > 0) printf("\n"); } printf("%%%%EndImage\n"); printf("%%%%EndPreview\n"); } return 0; }
/** * Função que lê uma imagem pgm e retorna uma matriz de ints * * @param arq Caminho para o arquivo pbm * @param tabuleiro Ponteiro para a matriz de ints * @param nlin Ponteiro para o número de linhas * @param ncol Ponteiro para o número de colunas */ void pbm(char *arq, int ***tabuleiro, int *nlin, int *ncol) { FILE *img; bit **tab; img = fopen(arq, "r"); if(img) { //void bit** pbm_readpbm(FILE * fp, int *colsP, int *rowsP); tab = pbm_readpbm(img, ncol, nlin); bit2int(tab, nlin, ncol, tabuleiro); pbm_freearray(tab, *nlin); fclose(img); return; } else { // Erro na leitura printf("Arquivo não encontrado\n"); exit(0); } }
int main(int argc, char *argv[]) { gray *outrow, maxval; int right, left, down, up; bit **inbits; int rows, cols; FILE *ifd; int row; int width, height; const char * const usage = "<w> <h> [pbmfile]"; pgm_init( &argc, argv ); if (argc > 4 || argc < 3) pm_usage(usage); width = atoi(argv[1]); height = atoi(argv[2]); if (width < 1 || height < 1) pm_error("width and height must be > 0"); left=width/2; right=width-left; up=width/2; down=height-up; if (argc == 4) ifd = pm_openr(argv[3]); else ifd = stdin ; inbits = pbm_readpbm(ifd, &cols, &rows) ; if (width > cols) pm_error("You specified a sample width (%u columns) which is greater " "than the image width (%u columns)", height, rows); if (height > rows) pm_error("You specified a sample height (%u rows) which is greater " "than the image height (%u rows)", height, rows); outrow = pgm_allocrow(cols) ; maxval = MIN(PGM_OVERALLMAXVAL, width*height); pgm_writepgminit(stdout, cols, rows, maxval, 0) ; for (row = 0; row < rows; row++) { int const t = (row > up) ? (row-up) : 0; int const b = (row+down < rows) ? (row+down) : rows; int const onv = height - (t-row+up) - (row+down-b); unsigned int col; for (col = 0; col < cols; col++) { int const l = (col > left) ? (col-left) : 0; int const r = (col+right < cols) ? (col+right) : cols; int const onh = width - (l-col+left) - (col+right-r); int value; int x; value = 0; /* initial value */ for (x = l; x < r; ++x) { int y; for (y = t; y < b; ++y) if (inbits[y][x] == PBM_WHITE) ++value; } outrow[col] = maxval*value/(onh*onv); } pgm_writepgmrow(stdout, outrow, cols, maxval, 0) ; } pm_close(ifd); return 0; }