void main(int argc, char *argv[]) { char header[512]; unsigned char img[640*480*3], newimg[640*480*3]; int bufflen, hdrlen; unsigned row=0, col=0, chan=0, pix; int i, j, k; double alpha=1.25; unsigned char beta=25; if(argc < 2) { printf("Use: brighten inputfile\n"); exit(-1); } // TEST CASE #0 // // Basic PPM file read, scaling and bias test, and write-back // header[0]='\0'; readppm(img, &bufflen, header, &hdrlen, &row, &col, &chan, argv[1]); alpha=1.25, beta =25; scaleImage(img, newimg, row, col, chan, alpha, beta); writeppm(newimg, bufflen, header, hdrlen, "brighter-1.25-25.ppm"); alpha=1.5, beta =50; scaleImage(img, newimg, row, col, chan, alpha, beta); writeppm(newimg, bufflen, header, hdrlen, "brighter-1.5-50.ppm"); // // END TEST CASE #0 }
int writeimage(char * name, int xres, int yres, unsigned char *imgdata, int format) { if (imgdata == NULL) return IMAGENULLDATA; switch (format) { case RT_FORMAT_PPM: return writeppm(name, xres, yres, imgdata); case RT_FORMAT_SGIRGB: return writergb(name, xres, yres, imgdata); case RT_FORMAT_JPEG: return writejpeg(name, xres, yres, imgdata); case RT_FORMAT_PNG: return writepng(name, xres, yres, imgdata); case RT_FORMAT_WINBMP: return writebmp(name, xres, yres, imgdata); case RT_FORMAT_TARGA: default: return writetga(name, xres, yres, imgdata); } }
int main() { const size_t ppmsize = WIDTH * HEIGHT; FILE *ppm = fopen("white2black.ppm", "w"); if (ppm) { writeppm(ppm, ppmsize); } return 0; }
int generate_test_image_set(char *filename, char *groupname, const int size) { int n, m; int x, y, half, px, opx, step; unsigned char *image, *imImage; char file[30]; /* Read image to memory */ image = readppm(filename, &n, &m); if (n != size || m != size) { printf("Image size not correct.\n"); getchar(); return 0; } if (!image) { printf("Some other error."); getchar(); return 0; } step = 1; half = size; while ((half /= 2) > 2) { step *= 2; imImage = (unsigned char *)malloc(sizeof(unsigned char) * half * half * 3); for (y = 0; y < half; ++y) { for (x = 0; x < half; ++x) { px = (y * half + x) * 3; opx = ((y * step * half) + x) * 3 * step; imImage[px] = image[opx]; imImage[px + 1] = image[opx + 1]; imImage[px + 2] = image[opx + 2]; } } sprintf_s(file, 30, "%s%u.ppm", groupname, half); writeppm(file, half, half, imImage); free(imImage); } return 0; }
int main(int argn, char *argv[]) { char *inam, *onam; pix bild; int ox, oy, dx, dy, x, y, i, vvv = 0; #ifdef HAVE_PAM_H pnm_init(&argn, argv); #endif // skip options for (i = 1; i < argn; i++) { if (argv[i][0] != '-') break; if (!strcmp(argv[i], "-?")) help(); else if (!strcmp(argv[i], "-help")) help(); else if (!strcmp(argv[i], "-shrink")) vvv |= 2; else if (!strcmp(argv[i], "-pbm")) vvv |= 4; else printf("unknown option: %s\n", argv[i]); } if (argn - i != 6) help(); inam = argv[i++]; onam = argv[i++]; ox = atoi(argv[i++]); oy = atoi(argv[i++]); dx = atoi(argv[i++]); dy = atoi(argv[i++]); printf("# in=%s out=%s offs=%d,%d len=%d,%d vvv=%d\n", inam, onam, ox, oy, dx, dy, vvv); // ----- read picture if (strstr(inam, ".pbm") || strstr(inam, ".pgm") || strstr(inam, ".ppm") || strstr(inam, ".pnm") || strstr(inam, ".pam")) readpgm(inam, &bild, 1); else if (strstr(inam, ".pcx")) readpcx(inam, &bild, 1); else if (strstr(inam, ".tga")) readtga(inam, &bild, ((vvv > 1) ? 0 : 1)); else { printf("Error: unknown suffix\n"); exit(1); } if (ox < 0 || ox >= bild.x) ox = 0; if (oy < 0 || ox >= bild.y) oy = 0; if (dx <= 0 || ox + dx > bild.x) dx = bild.x - ox; if (dy <= 0 || oy + dy > bild.y) dy = bild.y - oy; if ((vvv & 2) == 2 && bild.bpp == 1) { // -shrink int x, y; printf("# shrinking PGM: offs=%d,%d len=%d,%d\n", ox, oy, dx, dy); for (y = 0; y < dy; y++) { // shrink upper border for (x = 0; x < dx; x++) if (bild.p[x + ox + (y + oy) * bild.x] < 127) break; if (x < dx) { if (y > 0) y--; oy += y; dy -= y; break; } } for (y = 0; y < dy; y++) { // shrink lower border for (x = 0; x < dx; x++) if (bild.p[ox + x + (oy + dy - y - 1) * bild.x] < 127) break; if (x < dx) { if (y > 0) y--; dy -= y; break; } } for (x = 0; x < dx; x++) { // shrink left border for (y = 0; y < dy; y++) if (bild.p[x + ox + (y + oy) * bild.x] < 127) break; if (y < dy) { if (x > 0) x--; ox += x; dx -= x; break; } } for (x = 0; x < dx; x++) { // shrink right border for (y = 0; y < dy; y++) if (bild.p[ox + dx - x - 1 + (oy + y) * bild.x] < 127) break; if (y < dy) { if (x > 0) x--; dx -= x; break; } } } printf("# final dimension: offs=%d,%d len=%d,%d bpp=%d\n", ox, oy, dx, dy, bild.bpp); /* bbg: could be changed to memmoves */ // ---- new size for (y = 0; y < dy; y++) for (x = 0; x < dx; x++) for (i = 0; i < 3; i++) bild.p[i + bild.bpp * (x + dx * y)] = bild.p[i + bild.bpp * (x + ox + (y + oy) * bild.x)]; bild.x = dx; bild.y = dy; // ---- write internal picture of textsite printf("# write %s\n", onam); if (strstr(onam, ".pbm")) writepbm(onam, &bild); else if (strstr(onam, ".pgm")) writepgm(onam, &bild); else if (strstr(onam, ".ppm")) writeppm(onam, &bild); else if (strstr(onam, ".pnm")) writepgm(onam, &bild); else printf("Error: unknown suffix"); free( bild.p ); }
int main() { unsigned char img[2500*2500], newimg[2500*2500]; int bufflen, hdrlen, caseNumber = 0, radius = 0, transformNumber = 0; unsigned row = 0, col = 0, chan = 0; char programCommand = 'a', topMenu[sizeof(TOPMENU)] = TOPMENU, header[512], fileName[250], pipeString[10], newFileName[50]; char singleMenu[sizeof(SINGLEMENU)] = SINGLEMENU, pipeMenu[sizeof(PIPEMENU)] = PIPEMENU; printf("\nWelcome to EagleEye v1.0\n"); while (1) { printf("\nPlease enter the name of the image file you would like to use (must be in same directory as application: "); scanf(" %s", fileName); readppm(img, &bufflen, header, &hdrlen, &row, &col, &chan, fileName, 0); printf("\n%s", topMenu); scanf(" %c", &programCommand); //Single Transform Operation if(programCommand == '1') { printf("\n%s", singleMenu); scanf(" %c",&programCommand); if (programCommand == '1') luminGray(img, newimg, row, col, chan); else if (programCommand == '2') { printf("\nPlease enter radius for blur: "); scanf(" %d", &radius); blur(img, newimg, row, col, chan, radius); printf("Blur Transform completed.\n"); } else if (programCommand = '3') printf("\nGoing back to previous menu\n"); else { printf("Incorrect input, please try again."); printf("\n%s", singleMenu); scanf(" %c",&programCommand); } programCommand = 'a'; transformNumber++; sprintf(newFileName,"newImage%d.ppm",transformNumber); writeppm(newimg, bufflen, header, hdrlen, newFileName, 0); printf("\nNew image created, file name = %s", newFileName); printf("\nWould you like to perform another operation [y/n]: "); scanf(" %c", &programCommand); if(programCommand == 'y' || programCommand == 'Y') { //resetting all allocated memory back to zero states memset(header, 0, sizeof(header)); memset(img, 0, sizeof(img)); memset(newimg,0,sizeof(newimg)); bufflen = 0; hdrlen = 0; row = 0; col = 0; header[0]='\0'; } else { printf("\nProgram Exited.\n"); break; } } //Pipeline Transform Operation else if(programCommand == '2') { printf("\n%s", pipeMenu); scanf(" %s",&pipeString); pipeline(img, newimg, row, col, chan, pipeString); transformNumber++; sprintf(newFileName,"newImage%d.ppm",transformNumber); writeppm(newimg, bufflen, header, hdrlen, newFileName, 0); printf("\nNew image created, file name = %s",newFileName); printf("\nWould you like to perform another operation [y/n]: "); scanf(" %c", &programCommand); if(programCommand == 'y' || programCommand == 'Y') { //resetting all allocated memory back to zero states memset(header, 0, sizeof(header)); memset(img, 0, sizeof(img)); memset(newimg,0,sizeof(newimg)); bufflen = 0; hdrlen = 0; row = 0; col = 0; header[0]='\0'; } else { printf("\nProgram Exited.\n"); break; } } //Quit option else if (programCommand == '3' ) { printf("\nProgram Exited.\n"); break; } else { printf("\nIncorrect Input"); printf("\n\n%s", topMenu); scanf(" %c", &programCommand); } } return 0; }