|
|
1.1 ! root 1: #include <stdio.h> ! 2: #include <sys/types.h> ! 3: #include <sys/stat.h> ! 4: #include "defines.h" ! 5: #include "piclib.h" ! 6: ! 7: #define Min(a,b) ((a)>(b)?(b):(a)) ! 8: #define Max(a,b) ((a)<(b)?(b):(a)) ! 9: ! 10: int Wmax, Hmax, Xmin, Ymin; ! 11: int Dither=0, Times=1, Bright=2, Film=8, Filter=GREEN, Reso=4; ! 12: int xoffset=0, yoffset=0, fad=1, h, w, H, W; ! 13: struct pfile image; ! 14: unsigned char nq[9]; ! 15: ! 16: give_status() ! 17: { int i; ! 18: getbright(nq); ! 19: Reso = resolution(); ! 20: printf("qbright ref 36 58 81 103 126 148 171 193 220\n"); ! 21: printf(" actual "); ! 22: for(i = 0; i < 9; i++) ! 23: printf("%d ", nq[i]); ! 24: printf("\n"); ! 25: moduleno(); ! 26: printf("shutter: %s\n", (fad)?"automatic":"manual"); ! 27: printf("dither : %d\n", Dither); ! 28: printf("offset : %d,%d\n", xoffset, yoffset); ! 29: printf("enlarge: %d\n", Times); ! 30: if (W || H) printf("image : %d,%d\n", W, H); ! 31: printf("filmtype: "); ! 32: switch (Film) { ! 33: case NONE: printf("polaroid type 52\n"); break; ! 34: case LINEAR: printf("linear lookup tables\n"); break; ! 35: case EKTA100: printf("ektachrome 100 - for 2k mode\n"); break; ! 36: case EKTA100_4k: printf("ektachrome 100 - for 4k mode\n"); break; ! 37: case POLA559: printf("polaroid type 559 - for 2k mode\n"); break; ! 38: case POLA559_4k: printf("polaroid type 559 - for 4k mode\n"); break; ! 39: case POLA809_4k: printf("polaroid type 809 - for 4k mode\n"); break; ! 40: case TMAX_100: printf("tmax_100 film\n"); break; ! 41: default: printf("filmtype unknown\n"); break; ! 42: } ! 43: printf("filter : "); ! 44: switch (Filter) { ! 45: case RED: printf("red\n"); break; ! 46: case GREEN: printf("green\n"); break; ! 47: case BLUE: printf("blue\n"); break; ! 48: case NEUTRAL: printf("neutral\n"); break; ! 49: default: printf("none\n"); break; ! 50: } ! 51: } ! 52: ! 53: reminder() ! 54: { printf("PM: reset, bright, enlarge, filmtype, load, expose\n"); ! 55: } ! 56: ! 57: help() ! 58: { printf("reset - a full reset\n"); ! 59: printf("status - report all current settings\n"); ! 60: printf("error - expanded error status\n"); ! 61: printf("exit - return to Unix\n"); ! 62: printf("load imagefile - read in the file to be printed\n"); ! 63: printf("dither on/off/N - dithering off, on, on mod(N)\n"); ! 64: printf("shutter open/closed/auto - auto is default\n"); ! 65: printf("filter red/green/blue/neutral - is used for b&w imaging\n"); ! 66: printf("expose - a black&white image\n"); ! 67: printf("expose3 - a color image\n"); ! 68: printf("expose1 red/green/blue - imaging of 1 specific channel\n"); ! 69: printf("offset X Y - offset from lower left hand corner\n"); ! 70: printf("bright N - set brightness level N [0-8]\n"); ! 71: printf("enlarge N - enlargement factor\n"); ! 72: printf("reso N - set resolution N [2,4]\n"); ! 73: printf("filmtype tmax_100 - select tmax_100 correction tables\n"); ! 74: printf(" other available filmtypes: \n"); ! 75: printf(" linear \t(no correction)\n"); ! 76: printf(" tmax_100\t(Kodak 35mm Tmax 100 ASA b&w negative)\n"); ! 77: printf(" ekta_100\t(Kodak 35mm Ektachrome 100 ASA color neg)\n"); ! 78: printf(" pola_52 \t(Polaroid Type 52 b&w 4x5 inch sheet)\n"); ! 79: printf(" pola_559\t(Polaroid Type 559 b&w pack film)\n"); ! 80: printf(" pola_809\t(Polaroid Type 809 color 8x10 inch)\n"); ! 81: } ! 82: ! 83: set_luts(n) ! 84: { ! 85: switch (n) { ! 86: case NONE: ! 87: case LINEAR: ! 88: case POLA559: ! 89: case EKTA100: ! 90: case EKTA100_4k: ! 91: case POLA559_4k: ! 92: case POLA809_4k: ! 93: case TMAX_100: ! 94: Film = n; ! 95: filmtype(n); ! 96: break; ! 97: default: ! 98: printf("bad filmtype %d\n", n); ! 99: break; ! 100: } ! 101: } ! 102: ! 103: main() ! 104: { reminder(); ! 105: while (1) ! 106: { printf("qt: "); ! 107: fflush(stdout); ! 108: yyparse(); ! 109: fflush(stdout); ! 110: } ! 111: } ! 112: ! 113: setbright(n) ! 114: { extern int Errors; ! 115: Bright = Min((Max(0,n)), 8); ! 116: brightness(Bright, Bright, Bright, Bright); ! 117: if (!Errors) ! 118: printf("brightness %d = %d\n", n, nq[n]); ! 119: } ! 120: ! 121: full_reset() ! 122: { ! 123: qreset(); ! 124: getbright(nq); ! 125: Reso = resolution(); ! 126: nocalibs(); ! 127: handshake(1); ! 128: filmtype(Film); ! 129: advance(fad); ! 130: setbright(Bright); ! 131: } ! 132: ! 133: load_image(fname) ! 134: char *fname; ! 135: { ! 136: int fd; ! 137: ! 138: if((fd = openf(fname, &image)) == -1 || !readf(fd, &image)) ! 139: { printf("bad image %s\n", fname); ! 140: closef(&image); ! 141: } ! 142: close(fd); ! 143: W = image.r.corner.x - image.r.origin.x; ! 144: H = image.r.corner.y - image.r.origin.y; ! 145: if (Reso == 2) ! 146: { xoffset = (2048-W)/2; ! 147: yoffset = (1536-H)/2; ! 148: } else ! 149: { xoffset = (4096-W)/2; ! 150: yoffset = (2732-H)/2; ! 151: } ! 152: printf("%s loaded, size %dx%d, offset %d,%d\n", ! 153: fname, W, H, xoffset, yoffset); ! 154: fflush(stdout); ! 155: } ! 156: ! 157: crop() ! 158: { if (!image.pixred) ! 159: { printf("error: no image loaded\n"); ! 160: return 0; ! 161: } ! 162: if (Reso == 2) ! 163: { Wmax = 2048; Hmax = 1366; ! 164: Xmin = -1024; Ymin = 683; ! 165: } else ! 166: { Wmax = 4096; Hmax = 2732; ! 167: Xmin = -2048; Ymin = 1366; ! 168: } ! 169: w = Min((Wmax/Times - xoffset), W); ! 170: h = Min((Hmax/Times - yoffset), H); ! 171: printf("image: %d x %d -> %d x %d\n", W, H, w, h); ! 172: printf("offset %d %d, enlarge %d\n", xoffset, yoffset, Times); ! 173: window(Xmin+xoffset, Ymin-yoffset, w*Times, h*Times); ! 174: fflush(stdout); ! 175: return 1; ! 176: } ! 177: ! 178: one_pass(which) ! 179: { ! 180: if (!crop()) return; ! 181: singlepass(Filter); ! 182: switch (which) { ! 183: default: ! 184: case RED: onechannel(image.pixred, h, w); break; ! 185: case GREEN: onechannel(image.pixgrn, h, w); break; ! 186: case BLUE: onechannel(image.pixblu, h, w); break; ! 187: } ! 188: } ! 189: ! 190: new_offset(a, b) ! 191: { xoffset = a; ! 192: yoffset = b; ! 193: } ! 194: ! 195: three_pass(height, width) ! 196: { extern int Errors; ! 197: if (!crop() || Errors) return; ! 198: if (image.nchan != 3) ! 199: { printf("error: no color image loaded\n"); ! 200: return; ! 201: } ! 202: threepass(); ! 203: printf("red.."); onechannel(image.pixred, h, w); ! 204: printf("grn.."); onechannel(image.pixgrn, h, w); ! 205: printf("blu.."); onechannel(image.pixblu, h, w); ! 206: } ! 207: ! 208: onechannel(from, h, w) ! 209: unsigned char *from; ! 210: { ! 211: register i, j, k; ! 212: register unsigned char *p, *q; ! 213: unsigned char obuf[8192]; ! 214: int chunk = w*Times; ! 215: extern int Errors; ! 216: ! 217: fflush(stdout); ! 218: if (Errors) ! 219: return; ! 220: if (Dither) ! 221: onedither(from, h, w); ! 222: else ! 223: for (i = 0; i < h; i++) ! 224: { p = &from[W*i]; ! 225: q = obuf; ! 226: for (j = 0; j < w; j++, p++) ! 227: for (k = 0; k < Times; k++) ! 228: *q++ = *p; ! 229: for (k = 0; k < Times; k++) ! 230: { qwrite(obuf, chunk); ! 231: if (chunk > 2048) qwait(200); ! 232: } } ! 233: } ! 234: ! 235: short Nrand[5000]; ! 236: ! 237: prerand() ! 238: { register int i, D1=Dither, D2=Dither/2; ! 239: ! 240: for (i = 0; i < 5000; i++) ! 241: Nrand[i] = (short) (nrand(D1) - D2); ! 242: } ! 243: ! 244: onedither(from, h, w) ! 245: unsigned char *from; ! 246: { ! 247: register int c, m, kk=0; ! 248: register unsigned char *p, *q; ! 249: unsigned char obuf[8192]; ! 250: int i, j, k; ! 251: int chunk = w*Times; ! 252: ! 253: prerand(); ! 254: for (i = 0; i < h; i++) ! 255: for (k = 0; k < Times; k++) ! 256: { q = obuf; ! 257: p = &from[W*i]; ! 258: j = w; ! 259: do { m = Times; ! 260: do { c = *p + Nrand[kk]; ! 261: if (++kk >= 5000) kk = 0; ! 262: if (c<0) ! 263: c=0; ! 264: else if (c>255) ! 265: c=255; ! 266: *q++ = c; ! 267: } while(--m > 0); ! 268: p++; ! 269: } while(--j > 0); ! 270: qwrite(obuf, chunk); ! 271: } ! 272: } ! 273: ! 274: qwait(n) ! 275: { int i; ! 276: for (i = 0; i < n; i++) ; ! 277: } ! 278: ! 279: dimension(fd) ! 280: { struct stat bam; ! 281: int N; ! 282: extern float fsqrt(); ! 283: ! 284: if (fstat(fd, &bam)==0) ! 285: { N = bam.st_size; ! 286: N = (int) fsqrt((double)N+1.0); ! 287: return N; ! 288: } ! 289: return 0; ! 290: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.