home *** CD-ROM | disk | FTP | other *** search
/ Source Code 1994 March / Source_Code_CD-ROM_Walnut_Creek_March_1994.iso / compsrcs / x / volume20 / imagemgc / part29 < prev    next >
Encoding:
Text File  |  1993-07-13  |  50.3 KB  |  1,562 lines

  1. Newsgroups: comp.sources.x
  2. From: cristy@eplrx7.es.duPont.com (Cristy)
  3. Subject: v20i085:  imagemagic - X11 image processing and display, Part29/38
  4. Message-ID: <1993Jul14.232108.22827@sparky.sterling.com>
  5. X-Md4-Signature: 05605897a8e950d385e8f78efa6111dc
  6. Sender: chris@sparky.sterling.com (Chris Olson)
  7. Organization: Sterling Software
  8. Date: Wed, 14 Jul 1993 23:21:08 GMT
  9. Approved: chris@sterling.com
  10.  
  11. Submitted-by: cristy@eplrx7.es.duPont.com (Cristy)
  12. Posting-number: Volume 20, Issue 85
  13. Archive-name: imagemagic/part29
  14. Environment: X11
  15. Supersedes: imagemagic: Volume 13, Issue 17-37
  16.  
  17. #!/bin/sh
  18. # this is magick.29 (part 29 of ImageMagick)
  19. # do not concatenate these parts, unpack them in order with /bin/sh
  20. # file ImageMagick/image.c continued
  21. #
  22. if test ! -r _shar_seq_.tmp; then
  23.     echo 'Please unpack part 1 first!'
  24.     exit 1
  25. fi
  26. (read Scheck
  27.  if test "$Scheck" != 29; then
  28.     echo Please unpack part "$Scheck" next!
  29.     exit 1
  30.  else
  31.     exit 0
  32.  fi
  33. ) < _shar_seq_.tmp || exit 1
  34. if test ! -f _shar_wnt_.tmp; then
  35.     echo 'x - still skipping ImageMagick/image.c'
  36. else
  37. echo 'x - continuing file ImageMagick/image.c'
  38. sed 's/^X//' << 'SHAR_EOF' >> 'ImageMagick/image.c' &&
  39. X    return;
  40. X  /*
  41. X    Allocate memory for pixel indexes.
  42. X  */
  43. X  pixels=(unsigned short *) malloc(image->colors*sizeof(unsigned short));
  44. X  if (pixels == (unsigned short *) NULL)
  45. X    {
  46. X      Warning("unable to sort colormap","memory allocation failed");
  47. X      return;
  48. X    }
  49. X  /*
  50. X    Assign index values to colormap entries.
  51. X  */
  52. X  for (i=0; i < image->colors; i++)
  53. X    image->colormap[i].index=(unsigned short) i;
  54. X  /*
  55. X    Sort image colormap by decreasing color popularity.
  56. X  */
  57. X  (void) qsort((void *) image->colormap,(int) image->colors,sizeof(ColorPacket),
  58. X    IntensityCompare);
  59. X  /*
  60. X    Update image colormap indexes to sorted colormap order.
  61. X  */
  62. X  for (i=0; i < image->colors; i++)
  63. X    pixels[image->colormap[i].index]=(unsigned short) i;
  64. X  p=image->pixels;
  65. X  for (i=0; i < image->packets; i++)
  66. X  {
  67. X    index=pixels[p->index];
  68. X    p->red=image->colormap[index].red;
  69. X    p->green=image->colormap[index].green;
  70. X    p->blue=image->colormap[index].blue;
  71. X    p->index=index;
  72. X    p++;
  73. X  }
  74. X  (void) free((char *) pixels);
  75. }
  76. X
  77. /*
  78. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  79. %                                                                             %
  80. %                                                                             %
  81. %                                                                             %
  82. %   S t e r e o I m a g e                                                     %
  83. %                                                                             %
  84. %                                                                             %
  85. %                                                                             %
  86. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  87. %
  88. %  Function StereoImage combines two images and produces a single image that
  89. %  is the composite of a left and right image of a stereo pair.  The left
  90. %  image is converted to grayscale and written to the red channel of the
  91. %  stereo image.  The right image is converted to grayscale and written to the
  92. %  blue channel of the stereo image.  View the composite image with red-blue
  93. %  glasses to create a stereo effect.
  94. %
  95. %  The format of the StereoImage routine is:
  96. %
  97. %      stereo_image=StereoImage(left_image,right_image)
  98. %
  99. %  A description of each parameter follows:
  100. %
  101. %    o stereo_image: Function StereoImage returns a pointer to the stereo
  102. %      image.  A null image is returned if there is a memory shortage.
  103. %
  104. %    o left_image: The address of a structure of type Image.
  105. %
  106. %    o right_image: The address of a structure of type Image.
  107. %
  108. %
  109. */
  110. Image *StereoImage(left_image,right_image)
  111. Image
  112. X  *left_image,
  113. X  *right_image;
  114. {
  115. X  Image
  116. X    *stereo_image;
  117. X
  118. X  register int
  119. X    i;
  120. X
  121. X  register RunlengthPacket
  122. X    *p,
  123. X    *q,
  124. X    *r;
  125. X
  126. X  if ((left_image->columns != right_image->columns) ||
  127. X      (left_image->rows != right_image->rows))
  128. X    {
  129. X      Warning("unable to create stereo image",
  130. X        "left and right image sizes differ");
  131. X      return((Image *) NULL);
  132. X    }
  133. X  /*
  134. X    Initialize stereo image attributes.
  135. X  */
  136. X  stereo_image=CopyImage(left_image,left_image->columns,left_image->rows,False);
  137. X  if (stereo_image == (Image *) NULL)
  138. X    {
  139. X      Warning("unable to create stereo image","memory allocation failed");
  140. X      return((Image *) NULL);
  141. X    }
  142. X  stereo_image->class=DirectClass;
  143. X  /*
  144. X    Copy left image to red channel and right image to blue channel.
  145. X  */
  146. X  QuantizeImage(left_image,256,8,False,GRAYColorspace,True);
  147. X  p=left_image->pixels;
  148. X  left_image->runlength=p->length+1;
  149. X  QuantizeImage(right_image,256,8,False,GRAYColorspace,True);
  150. X  q=right_image->pixels;
  151. X  right_image->runlength=q->length+1;
  152. X  r=stereo_image->pixels;
  153. X  for (i=0; i < (stereo_image->columns*stereo_image->rows); i++)
  154. X  {
  155. X    if (left_image->runlength != 0)
  156. X      left_image->runlength--;
  157. X    else
  158. X      {
  159. X        p++;
  160. X        left_image->runlength=p->length;
  161. X      }
  162. X    if (right_image->runlength != 0)
  163. X      right_image->runlength--;
  164. X    else
  165. X      {
  166. X        q++;
  167. X        right_image->runlength=q->length;
  168. X      }
  169. X    r->red=(unsigned int) (p->red*12) >> 4;
  170. X    r->green=0;
  171. X    r->blue=q->blue;
  172. X    r->index=0;
  173. X    r->length=0;
  174. X    r++;
  175. X  }
  176. X  return(stereo_image);
  177. }
  178. X
  179. /*
  180. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  181. %                                                                             %
  182. %                                                                             %
  183. %                                                                             %
  184. %   S y n c I m a g e                                                         %
  185. %                                                                             %
  186. %                                                                             %
  187. %                                                                             %
  188. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  189. %
  190. %  Function SyncImage initializes the red, green, and blue intensities of each
  191. %  pixel as defined by the colormap index.
  192. %
  193. %  The format of the SyncImage routine is:
  194. %
  195. %      SyncImage(image)
  196. %
  197. %  A description of each parameter follows:
  198. %
  199. %    o image: The address of a structure of type Image.
  200. %
  201. %
  202. */
  203. void SyncImage(image)
  204. Image
  205. X  *image;
  206. {
  207. X  register int
  208. X    i;
  209. X
  210. X  register RunlengthPacket
  211. X    *p;
  212. X
  213. X  register unsigned short
  214. X    index;
  215. X
  216. X  p=image->pixels;
  217. X  for (i=0; i < image->packets; i++)
  218. X  {
  219. X    index=p->index;
  220. X    p->red=image->colormap[index].red;
  221. X    p->green=image->colormap[index].green;
  222. X    p->blue=image->colormap[index].blue;
  223. X    p++;
  224. X  }
  225. }
  226. X
  227. /*
  228. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  229. %                                                                             %
  230. %                                                                             %
  231. %                                                                             %
  232. %   T r a n s f o r m I m a g e                                               %
  233. %                                                                             %
  234. %                                                                             %
  235. %                                                                             %
  236. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  237. %
  238. %  Function TransformImage creates a new image that is a transformed size of
  239. %  of existing one as specified by the clip, image and scale geometries.  It
  240. %  allocates the memory necessary for the new Image structure and returns a
  241. %  pointer to the new image.
  242. %
  243. %  If a clip geometry is specified a subregion of the image is obtained.
  244. %  If the specified image size, as defined by the image and scale geometries,
  245. %  is smaller than the actual image size, the image is first reduced to an
  246. %  integral of the specified image size with an antialias digital filter.  The
  247. %  image is then scaled to the exact specified image size with pixel
  248. %  replication.  If the specified image size is greater than the actual image
  249. %  size, the image is first enlarged to an integral of the specified image
  250. %  size with bilinear interpolation.  The image is then scaled to the exact
  251. %  specified image size with pixel replication.
  252. %
  253. %  The format of the TransformImage routine is:
  254. %
  255. %      TransformImage(image,clip_geometry,image_geometry,scale_geometry)
  256. %
  257. %  A description of each parameter follows:
  258. %
  259. %    o image: The address of an address of a structure of type Image.  The
  260. %      transformed image is returned as this parameter.
  261. %
  262. %    o clip_geometry: Specifies a pointer to a clip geometry string.
  263. %      This geometry defines a subregion of the image.
  264. %
  265. %    o image_geometry: Specifies a pointer to a image geometry string.
  266. %      The specified width and height of this geometry string are absolute.
  267. %
  268. %    o scale_geometry: Specifies a pointer to a scale geometry string.
  269. %      The specified width and height of this geometry string are relative.
  270. %
  271. %
  272. */
  273. void TransformImage(image,clip_geometry,image_geometry,scale_geometry)
  274. Image
  275. X  **image;
  276. X
  277. char
  278. X  *clip_geometry,
  279. X  *image_geometry,
  280. X  *scale_geometry;
  281. {
  282. X  Image
  283. X    *transformed_image;
  284. X
  285. X  int
  286. X    flags,
  287. X    x,
  288. X    y;
  289. X
  290. X  unsigned int
  291. X    height,
  292. X    width;
  293. X
  294. X  transformed_image=(*image);
  295. X  if (clip_geometry != (char *) NULL)
  296. X    {
  297. X      Image
  298. X        *clipped_image;
  299. X
  300. X      RectangleInfo
  301. X        clip_info;
  302. X
  303. X      /*
  304. X        Clip transformed_image to a user specified size.
  305. X      */
  306. X      clip_info.x=0;
  307. X      clip_info.y=0;
  308. X      flags=XParseGeometry(clip_geometry,&clip_info.x,&clip_info.y,
  309. X        &clip_info.width,&clip_info.height);
  310. X      if ((flags & WidthValue) == 0)
  311. X        clip_info.width=(unsigned int)
  312. X          ((int) transformed_image->columns-clip_info.x);
  313. X      if ((flags & HeightValue) == 0)
  314. X        clip_info.height=(unsigned int)
  315. X          ((int) transformed_image->rows-clip_info.y);
  316. X      if ((flags & XNegative) != 0)
  317. X        clip_info.x+=transformed_image->columns-clip_info.width;
  318. X      if ((flags & YNegative) != 0)
  319. X        clip_info.y+=transformed_image->rows-clip_info.height;
  320. X      clipped_image=ClipImage(transformed_image,&clip_info);
  321. X      if (clipped_image != (Image *) NULL)
  322. X        {
  323. X          DestroyImage(transformed_image);
  324. X          transformed_image=clipped_image;
  325. X        }
  326. X    }
  327. X  /*
  328. X    Scale image to a user specified size.
  329. X  */
  330. X  width=transformed_image->columns;
  331. X  height=transformed_image->rows;
  332. X  if (scale_geometry != (char *) NULL)
  333. X    {
  334. X      float
  335. X        height_factor,
  336. X        width_factor;
  337. X
  338. X      width_factor=1.0;
  339. X      height_factor=0.0;
  340. X      (void) sscanf(scale_geometry,"%fx%f",&width_factor,&height_factor);
  341. X      if (height_factor == 0.0)
  342. X        height_factor=width_factor;
  343. X      width=(unsigned int) (width*width_factor);
  344. X      height=(unsigned int) (height*height_factor);
  345. X    }
  346. X  if (image_geometry != (char *) NULL)
  347. X    (void) XParseGeometry(image_geometry,&x,&y,&width,&height);
  348. X  while ((transformed_image->columns >= (width << 1)) &&
  349. X         (transformed_image->rows >= (height << 1)))
  350. X  {
  351. X    Image
  352. X      *reduced_image;
  353. X
  354. X    /*
  355. X      Reduce image with a antialias digital filter.
  356. X     */
  357. X    reduced_image=ReduceImage(transformed_image);
  358. X    if (reduced_image == (Image *) NULL)
  359. X      break;
  360. X    DestroyImage(transformed_image);
  361. X    transformed_image=reduced_image;
  362. X  }
  363. X  while ((transformed_image->columns <= (width >> 1)) &&
  364. X         (transformed_image->rows <= (height >> 1)))
  365. X  {
  366. X    Image
  367. X      *zoomed_image;
  368. X
  369. X    /*
  370. X      Zoom transformed_image with bilinear interpolation.
  371. X    */
  372. X    zoomed_image=ZoomImage(transformed_image);
  373. X    if (zoomed_image == (Image *) NULL)
  374. X      break;
  375. X    DestroyImage(transformed_image);
  376. X    transformed_image=zoomed_image;
  377. X  }
  378. X  if ((transformed_image->columns != width) ||
  379. X      (transformed_image->rows != height))
  380. X    {
  381. X      Image
  382. X        *scaled_image;
  383. X
  384. X      /*
  385. X        Scale image with pixel replication.
  386. X      */
  387. X      scaled_image=ScaleImage(transformed_image,width,height);
  388. X      if (scaled_image != (Image *) NULL)
  389. X        {
  390. X          DestroyImage(transformed_image);
  391. X          transformed_image=scaled_image;
  392. X        }
  393. X    }
  394. X  *image=transformed_image;
  395. }
  396. X
  397. /*
  398. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  399. %                                                                             %
  400. %                                                                             %
  401. %     T r a n s f o r m R G B I m a g e                                       %
  402. %                                                                             %
  403. %                                                                             %
  404. %                                                                             %
  405. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  406. %
  407. %  Procedure TransformRGBImage converts the reference image from an alternate
  408. %  colorspace to RGB.
  409. %
  410. %  The format of the TransformRGBImage routine is:
  411. %
  412. %      TransformRGBImage(image,colorspace)
  413. %
  414. %  A description of each parameter follows:
  415. %
  416. %    o image: The address of a structure of type Image;  returned from
  417. %      ReadImage.
  418. %
  419. %    o colorspace: An unsigned integer value that indicates the colorspace
  420. %      the image is currently in.  On return the image is in the RGB
  421. %      color space.
  422. %
  423. %
  424. */
  425. void TransformRGBImage(image,colorspace)
  426. Image
  427. X  *image;
  428. X
  429. unsigned int
  430. X  colorspace;
  431. {
  432. #define R 0
  433. #define G (MaxRGB+1)
  434. #define B (MaxRGB+1)*2
  435. X
  436. X  long
  437. X    *blue,
  438. X    *green,
  439. X    *red;
  440. X
  441. X  register int
  442. X    i,
  443. X    x,
  444. X    y,
  445. X    z;
  446. X
  447. X  register RunlengthPacket
  448. X    *p;
  449. X
  450. X  register unsigned char
  451. X    *range_limit;
  452. X
  453. X  unsigned char
  454. X    *range_table;
  455. X
  456. X  if ((colorspace == RGBColorspace) || (colorspace == GRAYColorspace))
  457. X    return;
  458. X  /*
  459. X    Allocate the tables.
  460. X  */
  461. X  red=(long *) malloc(3*(MaxRGB+1)*sizeof(long));
  462. X  green=(long *) malloc(3*(MaxRGB+1)*sizeof(long));
  463. X  blue=(long *) malloc(3*(MaxRGB+1)*sizeof(long));
  464. X  range_table=(unsigned char *) malloc(3*(MaxRGB+1)*sizeof(unsigned char));
  465. X  if ((red == (long *) NULL) || (green == (long *) NULL) ||
  466. X      (blue == (long *) NULL) || (range_table == (unsigned char *) NULL))
  467. X    {
  468. X      Warning("unable to transform color space","memory allocation failed");
  469. X      return;
  470. X    }
  471. X  /*
  472. X    Initialize tables.
  473. X  */
  474. X  for (i=0; i <= MaxRGB; i++)
  475. X  {
  476. X    range_table[i]=0;
  477. X    range_table[i+(MaxRGB+1)]=(unsigned char) i;
  478. X    range_table[i+(MaxRGB+1)*2]=MaxRGB;
  479. X  }
  480. X  range_limit=range_table+(MaxRGB+1);
  481. X  switch (colorspace)
  482. X  {
  483. X    case XYZColorspace:
  484. X    {
  485. X      /*
  486. X        Initialize XYZ tables:
  487. X
  488. X          R =  2.36444*X-0.89680*Y-0.46770*Z
  489. X          G = -0.51483*X+1.42523*Y+0.08817*Z
  490. X          B =  0.00500*X-0.01439*Y+1.00921*Z
  491. X      */
  492. X      for (i=0; i <= MaxRGB; i++)
  493. X      {
  494. X        red[i+R]=UpShifted(2.36444)*i;
  495. X        green[i+R]=(-UpShifted(0.89680))*i;
  496. X        blue[i+R]=(-UpShifted(0.46770))*i;
  497. X        red[i+G]=(-UpShifted(0.51483))*i;
  498. X        green[i+G]=UpShifted(1.42523)*i;
  499. X        blue[i+G]=UpShifted(0.08817)*i;
  500. X        red[i+B]=UpShifted(0.00500)*i;
  501. X        green[i+B]=(-UpShifted(0.01439))*i;
  502. X        blue[i+B]=UpShifted(1.00921)*i;
  503. X      }
  504. X      break;
  505. X    }
  506. X    case YCbCrColorspace:
  507. X    {
  508. X      /*
  509. X        Initialize YCbCr tables:
  510. X
  511. X          R = Y           +1.40200*Cr
  512. X          G = Y-0.34414*Cb-0.71414*Cr
  513. X          B = Y+1.77200*Cb
  514. X
  515. X        Cb and Cr, normally -0.5 through 0.5, must be normalized to the range 0
  516. X        through MaxRGB.
  517. X      */
  518. X      for (i=0; i <= MaxRGB; i++)
  519. X      {
  520. X        red[i+R]=UpShifted(1.00000)*i;
  521. X        green[i+R]=0;
  522. X        blue[i+R]=UpShifted(1.40200/2)*(2*i-MaxRGB);
  523. X        red[i+G]=UpShifted(1.00000)*i;
  524. X        green[i+G]=(-UpShifted(0.34414/2))*(2*i-MaxRGB);
  525. X        blue[i+G]=(-UpShifted(0.71414/2))*(2*i-MaxRGB);
  526. X        red[i+B]=UpShifted(1.00000)*i;
  527. X        green[i+B]=UpShifted(1.77200/2)*(2*i-MaxRGB);
  528. X        blue[i+B]=0;
  529. X      }
  530. X      break;
  531. X    }
  532. X    case YIQColorspace:
  533. X    {
  534. X      /*
  535. X        Initialize YIQ tables:
  536. X
  537. X          R = Y+0.95620*I+0.62140*Q
  538. X          G = Y-0.27270*I-0.64680*Q
  539. X          B = Y-1.10370*I+1.70060*Q
  540. X      */
  541. X      for (i=0; i <= MaxRGB; i++)
  542. X      {
  543. X        red[i+R]=UpShifted(1.00000)*i;
  544. X        green[i+R]=UpShifted(0.95620)*i;
  545. X        blue[i+R]=UpShifted(0.62140)*i;
  546. X        red[i+G]=UpShifted(1.00000)*i;
  547. X        green[i+G]=(-UpShifted(0.27270))*i;
  548. X        blue[i+G]=(-UpShifted(0.64680))*i;
  549. X        red[i+B]=UpShifted(1.00000)*i;
  550. X        green[i+B]=(-UpShifted(1.10370))*i;
  551. X        blue[i+B]=UpShifted(1.70060)*i;
  552. X      }
  553. X      break;
  554. X    }
  555. X    case YUVColorspace:
  556. X    default:
  557. X    {
  558. X      /*
  559. X        Initialize YUV tables:
  560. X
  561. X          R = Y          +1.13980*V
  562. X          G = Y-0.39380*U-0.58050*V
  563. X          B = Y+2.02790*U
  564. X
  565. X        U and V, normally -0.5 through 0.5, must be normalized to the range 0
  566. X        through MaxRGB.
  567. X      */
  568. X      for (i=0; i <= MaxRGB; i++)
  569. X      {
  570. X        red[i+R]=UpShifted(1.00000)*i;
  571. X        green[i+R]=0;
  572. X        blue[i+R]=UpShifted(1.13980/2)*(2*i-MaxRGB);
  573. X        red[i+G]=UpShifted(1.00000)*i;
  574. X        green[i+G]=(-UpShifted(0.39380/2))*(2*i-MaxRGB);
  575. X        blue[i+G]=(-UpShifted(0.58050/2))*(2*i-MaxRGB);
  576. X        red[i+B]=UpShifted(1.00000)*i;
  577. X        green[i+B]=UpShifted(2.02790/2)*(2*i-MaxRGB);
  578. X        blue[i+B]=0;
  579. X      }
  580. X      break;
  581. X    }
  582. X  }
  583. X  /*
  584. X    Convert to RGB.
  585. X  */
  586. X  switch (image->class)
  587. X  {
  588. X    case DirectClass:
  589. X    {
  590. X      /*
  591. X        Convert DirectClass image.
  592. X      */
  593. X      p=image->pixels;
  594. X      for (i=0; i < image->packets; i++)
  595. X      {
  596. X        x=p->red;
  597. X        y=p->green;
  598. X        z=p->blue;
  599. X        p->red=range_limit[DownShift(red[x+R]+green[y+R]+blue[z+R])];
  600. X        p->green=range_limit[DownShift(red[x+G]+green[y+G]+blue[z+G])];
  601. X        p->blue=range_limit[DownShift(red[x+B]+green[y+B]+blue[z+B])];
  602. X        p++;
  603. X      }
  604. X      break;
  605. X    }
  606. X    case PseudoClass:
  607. X    {
  608. X      /*
  609. X        Convert PseudoClass image.
  610. X      */
  611. X      for (i=0; i < image->colors; i++)
  612. X      {
  613. X        x=image->colormap[i].red;
  614. X        y=image->colormap[i].green;
  615. X        z=image->colormap[i].blue;
  616. X        image->colormap[i].red=
  617. X          range_limit[DownShift(red[x+R]+green[y+R]+blue[z+R])];
  618. X        image->colormap[i].green=
  619. X          range_limit[DownShift(red[x+G]+green[y+G]+blue[z+G])];
  620. X        image->colormap[i].blue=
  621. X          range_limit[DownShift(red[x+B]+green[y+B]+blue[z+B])];
  622. X      }
  623. X      p=image->pixels;
  624. X      for (i=0; i < image->packets; i++)
  625. X      {
  626. X        x=p->red;
  627. X        y=p->green;
  628. X        z=p->blue;
  629. X        p->red=range_limit[DownShift(red[x+R]+green[y+R]+blue[z+R])];
  630. X        p->green=range_limit[DownShift(red[x+G]+green[y+G]+blue[z+G])];
  631. X        p->blue=range_limit[DownShift(red[x+B]+green[y+B]+blue[z+B])];
  632. X        p++;
  633. X      }
  634. X      break;
  635. X    }
  636. X  }
  637. X  /*
  638. X    Free allocated memory.
  639. X  */
  640. X  (void) free((char *) range_table);
  641. X  (void) free((char *) blue);
  642. X  (void) free((char *) green);
  643. X  (void) free((char *) red);
  644. }
  645. X
  646. /*
  647. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  648. %                                                                             %
  649. %                                                                             %
  650. %                                                                             %
  651. %   U n C o m p r e s s I m a g e                                             %
  652. %                                                                             %
  653. %                                                                             %
  654. %                                                                             %
  655. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  656. %
  657. %  Function UncompressImage uncompresses runlength-encoded pixels packets to
  658. %  a rectangular array of pixels.
  659. %
  660. %  The format of the UncompressImage routine is:
  661. %
  662. %      status=UncompressImage(image)
  663. %
  664. %  A description of each parameter follows:
  665. %
  666. %    o status: Function UncompressImage returns True if the image is
  667. %      uncompressed otherwise False.
  668. %
  669. %    o image: The address of a structure of type Image.
  670. %
  671. %
  672. */
  673. unsigned int UncompressImage(image)
  674. Image
  675. X  *image;
  676. {
  677. X  register int
  678. X    i,
  679. X    j,
  680. X    length;
  681. X
  682. X  register RunlengthPacket
  683. X    *p,
  684. X    *q;
  685. X
  686. X  RunlengthPacket
  687. X    *uncompressed_pixels;
  688. X
  689. X  if (image->packets == (image->columns*image->rows))
  690. X    return(True);
  691. X  /*
  692. X    Uncompress runlength-encoded packets.
  693. X  */
  694. X  uncompressed_pixels=(RunlengthPacket *) realloc((char *) image->pixels,
  695. X    image->columns*image->rows*sizeof(RunlengthPacket));
  696. X  if (uncompressed_pixels == (RunlengthPacket *) NULL)
  697. X    return(False);
  698. X  image->pixels=uncompressed_pixels;
  699. X  p=image->pixels+image->packets-1;
  700. X  q=uncompressed_pixels+image->columns*image->rows-1;
  701. X  for (i=0; i < image->packets; i++)
  702. X  {
  703. X    length=p->length;
  704. X    for (j=0; j <= length; j++)
  705. X    {
  706. X      *q=(*p);
  707. X      q->length=0;
  708. X      q--;
  709. X    }
  710. X    p--;
  711. X  }
  712. X  image->packets=image->columns*image->rows;
  713. X  return(True);
  714. }
  715. X
  716. /*
  717. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  718. %                                                                             %
  719. %                                                                             %
  720. %                                                                             %
  721. %   Z o o m I m a g e                                                         %
  722. %                                                                             %
  723. %                                                                             %
  724. %                                                                             %
  725. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  726. %
  727. %  Function ZoomImage creates a new image that is a integral size greater
  728. %  than an existing one.  It allocates the memory necessary for the new Image
  729. %  structure and returns a pointer to the new image.
  730. %
  731. %  ZoomImage scans the reference image to create a zoomed image by bilinear
  732. %  interpolation.  The zoomed image columns and rows become:
  733. %
  734. %    number_columns << 1
  735. %    number_rows << 1
  736. %
  737. %  The format of the ZoomImage routine is:
  738. %
  739. %      zoomed_image=ZoomImage(image)
  740. %
  741. %  A description of each parameter follows:
  742. %
  743. %    o zoomed_image: Function ZoomImage returns a pointer to the image after
  744. %      zooming.  A null image is returned if there is a a memory shortage.
  745. %
  746. %    o image: The address of a structure of type Image.
  747. %
  748. %
  749. */
  750. static Image *ZoomImage(image)
  751. Image
  752. X  *image;
  753. {
  754. X  Image
  755. X    *zoomed_image;
  756. X
  757. X  register RunlengthPacket
  758. X    *cs,
  759. X    *ns,
  760. X    *p,
  761. X    *q,
  762. X    *s;
  763. X
  764. X  register unsigned int
  765. X    x;
  766. X
  767. X  RunlengthPacket
  768. X    *scanline;
  769. X
  770. X  unsigned int
  771. X    y;
  772. X
  773. X  if (((image->columns*image->rows) << 1) > MaxImageSize)
  774. X    {
  775. X      Warning("unable to zoom image","image size too large");
  776. X      return((Image *) NULL);
  777. X    }
  778. X  /*
  779. X    Initialize scaled image attributes.
  780. X  */
  781. X  zoomed_image=CopyImage(image,image->columns << 1,image->rows << 1,False);
  782. X  if (zoomed_image == (Image *) NULL)
  783. X    {
  784. X      Warning("unable to zoom image","memory allocation failed");
  785. X      return((Image *) NULL);
  786. X    }
  787. X  zoomed_image->class=DirectClass;
  788. X  /*
  789. X    Allocate scan line buffer.
  790. X  */
  791. X  scanline=(RunlengthPacket *) malloc(4*image->columns*sizeof(RunlengthPacket));
  792. X  if (scanline == (RunlengthPacket *) NULL)
  793. X    {
  794. X      Warning("unable to zoom image","memory allocation failed");
  795. X      DestroyImage(zoomed_image);
  796. X      return((Image *) NULL);
  797. X    }
  798. X  /*
  799. X    Preload a scan line and interpolate.
  800. X  */
  801. X  p=image->pixels;
  802. X  image->runlength=p->length+1;
  803. X  s=scanline;
  804. X  for (x=0; x < image->columns; x++)
  805. X  {
  806. X    *s=(*p);
  807. X    s++;
  808. X    if (image->runlength != 0)
  809. X      {
  810. X        image->runlength--;
  811. X        *s=(*p);
  812. X      }
  813. X    else
  814. X      {
  815. X        p++;
  816. X        image->runlength=p->length;
  817. X        s->red=(unsigned char) ((int) (p->red+(s-1)->red) >> 1);
  818. X        s->green=(unsigned char) ((int) (p->green+(s-1)->green) >> 1);
  819. X        s->blue=(unsigned char) ((int) (p->blue+(s-1)->blue) >> 1);
  820. X        s->index=(unsigned short) ((int) (p->index+(s-1)->index) >> 1);
  821. X      }
  822. X    s++;
  823. X  }
  824. X  /*
  825. X    Zoom each row.
  826. X  */
  827. X  p=image->pixels;
  828. X  image->runlength=p->length+1;
  829. X  q=zoomed_image->pixels;
  830. X  for (y=0; y < image->rows; y++)
  831. X  {
  832. X    cs=scanline+image->columns*((y+0) % 2)*2;
  833. X    ns=scanline+image->columns*((y+1) % 2)*2;
  834. X    /*
  835. X      Read a scan line and interpolate.
  836. X    */
  837. X    s=ns;
  838. X    for (x=0; x < image->columns; x++)
  839. X    {
  840. X      *s=(*p);
  841. X      s++;
  842. X      if (image->runlength != 0)
  843. X        {
  844. X          image->runlength--;
  845. X          *s=(*p);
  846. X        }
  847. X      else
  848. X        {
  849. X          p++;
  850. X          image->runlength=p->length;
  851. X          s->red=(unsigned char) ((int) (p->red+(s-1)->red) >> 1);
  852. X          s->green=(unsigned char) ((int) (p->green+(s-1)->green) >> 1);
  853. X          s->blue=(unsigned char) ((int) (p->blue+(s-1)->blue) >> 1);
  854. X          s->index=(unsigned short) ((int) (p->index+(s-1)->index) >> 1);
  855. X        }
  856. X      s++;
  857. X    }
  858. X    /*
  859. X      Dump column interpolation values.
  860. X    */
  861. X    s=cs;
  862. X    for (x=0; x < zoomed_image->columns; x++)
  863. X    {
  864. X      *q=(*s);
  865. X      q->length=0;
  866. X      q++;
  867. X      s++;
  868. X    }
  869. X    /*
  870. X      Dump row interpolation values.
  871. X    */
  872. X    for (x=0; x < zoomed_image->columns; x++)
  873. X    {
  874. X      q->red=(unsigned char) ((int) (cs->red+ns->red) >> 1);
  875. X      q->green=(unsigned char) ((int) (cs->green+ns->green) >> 1);
  876. X      q->blue=(unsigned char) ((int) (cs->blue+ns->blue) >> 1);
  877. X      q->index=(unsigned short) ((int) (cs->index+ns->index) >> 1);
  878. X      q->length=0;
  879. X      q++;
  880. X      cs++;
  881. X      ns++;
  882. X    }
  883. X  }
  884. X  (void) free((char *) scanline);
  885. X  return(zoomed_image);
  886. }
  887. SHAR_EOF
  888. echo 'File ImageMagick/image.c is complete' &&
  889. chmod 0644 ImageMagick/image.c ||
  890. echo 'restore of ImageMagick/image.c failed'
  891. Wc_c="`wc -c < 'ImageMagick/image.c'`"
  892. test 119137 -eq "$Wc_c" ||
  893.     echo 'ImageMagick/image.c: original size 119137, current size' "$Wc_c"
  894. rm -f _shar_wnt_.tmp
  895. fi
  896. # ============= ImageMagick/image.h ==============
  897. if test -f 'ImageMagick/image.h' -a X"$1" != X"-c"; then
  898.     echo 'x - skipping ImageMagick/image.h (File already exists)'
  899.     rm -f _shar_wnt_.tmp
  900. else
  901. > _shar_wnt_.tmp
  902. echo 'x - extracting ImageMagick/image.h (Text)'
  903. sed 's/^X//' << 'SHAR_EOF' > 'ImageMagick/image.h' &&
  904. /*
  905. X  Image define declarations.
  906. */
  907. #define AbsoluteValue(x)  ((x) < 0 ? -(x) : (x))
  908. #define DegreesToRadians(x) ((x)*3.14159265358979323846/180.0)
  909. #define Intensity(color)  (unsigned int)  \
  910. X  ((unsigned int) ((color).red*77+(color).green*150+(color).blue*29) >> 8)
  911. #define MaxColormapSize  65535
  912. #define MaxImageSize  (4096*4096)
  913. #define MaxRGB  255
  914. #define MaxRunlength  255
  915. X
  916. /*
  917. X  Image Id's
  918. */
  919. #define UndefinedId  0
  920. #define ImageMagickId  1
  921. /*
  922. X  Image classes:
  923. */
  924. #define UndefinedClass  0
  925. #define DirectClass  1
  926. #define PseudoClass  2
  927. /*
  928. X  Image colorspaces:
  929. */
  930. #define UndefinedColorspace  0
  931. #define RGBColorspace  1
  932. #define GRAYColorspace 2
  933. #define XYZColorspace  3
  934. #define YCbCrColorspace  4
  935. #define YIQColorspace  5
  936. #define YUVColorspace  6
  937. /*
  938. X  Image compression algorithms:
  939. */
  940. #define UndefinedCompression  0
  941. #define NoCompression  1
  942. #define RunlengthEncodedCompression  2
  943. #define QEncodedCompression  3
  944. /*
  945. X  Image interlace:
  946. */
  947. #define UndefinedInterlace  0
  948. #define NoneInterlace  1
  949. #define LineInterlace  2
  950. #define PlaneInterlace  3
  951. /*
  952. X  Image compositing operations:
  953. */
  954. #define UndefinedCompositeOp  0
  955. #define OverCompositeOp  1
  956. #define InCompositeOp  2
  957. #define OutCompositeOp  3
  958. #define AtopCompositeOp  4
  959. #define XorCompositeOp  5
  960. #define PlusCompositeOp  6
  961. #define MinusCompositeOp  7
  962. #define AddCompositeOp  8
  963. #define SubtractCompositeOp  9
  964. #define DifferenceCompositeOp  10
  965. #define ReplaceCompositeOp  11
  966. X
  967. /*
  968. X  Typedef declarations for the Display program.
  969. */
  970. typedef struct _ColorPacket
  971. {
  972. X  unsigned char
  973. X    red,
  974. X    green,
  975. X    blue,
  976. X    flags;
  977. X
  978. X  unsigned short
  979. X    index;
  980. } ColorPacket;
  981. X
  982. typedef struct _ImageInfo
  983. {
  984. X  char
  985. X    filename[2048];
  986. X
  987. X  char
  988. X    *server_name,
  989. X    *font,
  990. X    *geometry,
  991. X    *density,
  992. X    *page,
  993. X    *border_color;
  994. X
  995. X  unsigned int
  996. X    interlace,
  997. X    monochrome,
  998. X    quality,
  999. X    verbose;
  1000. X
  1001. X  char
  1002. X    *undercolor;
  1003. } ImageInfo;
  1004. X
  1005. typedef struct _RectangleInfo
  1006. {
  1007. X  unsigned int
  1008. X    width,
  1009. X    height;
  1010. X
  1011. X  int
  1012. X    x,
  1013. X    y;
  1014. } RectangleInfo;
  1015. X
  1016. typedef struct _RunlengthPacket
  1017. {
  1018. X  unsigned char
  1019. X    red,
  1020. X    green,
  1021. X    blue,
  1022. X    length;
  1023. X
  1024. X  unsigned short
  1025. X    index;
  1026. } RunlengthPacket;
  1027. X
  1028. typedef struct _Image
  1029. {
  1030. X  FILE
  1031. X    *file;
  1032. X
  1033. X  int
  1034. X    status;
  1035. X
  1036. X  char
  1037. X    filename[2048],
  1038. X    magick[12],
  1039. X    *comments,
  1040. X    *label;
  1041. X
  1042. X  unsigned int
  1043. X    id,
  1044. X    class,
  1045. X    colorspace,
  1046. X    alpha,
  1047. X    compression,
  1048. X    columns,
  1049. X    rows,
  1050. X    colors,
  1051. X    scene;
  1052. X
  1053. X  char
  1054. X    *montage,
  1055. X    *directory;
  1056. X
  1057. X  ColorPacket
  1058. X    *colormap;
  1059. X
  1060. X  char
  1061. X    *signature;
  1062. X
  1063. X  RunlengthPacket
  1064. X    *pixels,
  1065. X    *packet;
  1066. X
  1067. X  unsigned long
  1068. X    packets;
  1069. X
  1070. X  unsigned int
  1071. X    runlength,
  1072. X    packet_size;
  1073. X
  1074. X  unsigned char
  1075. X    *packed_pixels;
  1076. X
  1077. X  unsigned int
  1078. X    orphan;
  1079. X
  1080. X  struct _Image
  1081. X    *previous,
  1082. X    *next;
  1083. } Image;
  1084. X
  1085. /*
  1086. X  Image utilities routines.
  1087. */
  1088. extern Image
  1089. X  *AllocateImage _Declare((char *)),
  1090. X  *BorderImage _Declare((Image *,RectangleInfo *,ColorPacket *,ColorPacket *)),
  1091. X  *ClipImage _Declare((Image *,RectangleInfo *)),
  1092. X  *CopyImage _Declare((Image *,unsigned int,unsigned int,unsigned int)),
  1093. X  *EnhanceImage _Declare((Image *)),
  1094. X  *FrameImage _Declare((Image *,RectangleInfo *,unsigned int,ColorPacket *,
  1095. X    ColorPacket *)),
  1096. X  *NoisyImage _Declare((Image *)),
  1097. X  *ReadImage _Declare((ImageInfo *)),
  1098. X  *ReflectImage _Declare((Image *)),
  1099. X  *RollImage _Declare((Image *,int,int)),
  1100. X  *RotateImage _Declare((Image *,double,unsigned int)),
  1101. X  *ScaleImage _Declare((Image *,unsigned int,unsigned int)),
  1102. X  *ShearImage _Declare((Image *,double,double,unsigned int)),
  1103. X  *StereoImage _Declare((Image *,Image *));
  1104. X
  1105. extern int
  1106. X  ReadDataBlock _Declare((char *,FILE *));
  1107. X
  1108. extern unsigned int
  1109. X  NumberColors _Declare((Image *,FILE *)),
  1110. X  ReadData _Declare((char *,int,int,FILE *)),
  1111. X  UncompressImage _Declare((Image *)),
  1112. X  WriteImage _Declare((ImageInfo *,Image *));
  1113. X
  1114. extern void
  1115. X  CloseImage _Declare((Image *)),
  1116. X  ColormapSignature _Declare((Image *)),
  1117. X  CompositeImage _Declare((Image *,unsigned int,Image *,int,int)),
  1118. X  CompressColormap _Declare((Image *)),
  1119. X  CompressImage _Declare((Image *)),
  1120. X  DestroyImage _Declare((Image *)),
  1121. X  DestroyImages _Declare((Image *)),
  1122. X  GammaImage _Declare((Image *,double)),
  1123. X  InverseImage _Declare((Image *)),
  1124. X  GetImageInfo _Declare((ImageInfo *)),
  1125. X  NormalizeImage _Declare((Image *)),
  1126. X  OpenImage _Declare((Image *,char *)),
  1127. X  QuantizationError _Declare((Image *,unsigned int *,double *,double *)),
  1128. X  QuantizeImage _Declare((Image *,unsigned int,unsigned int,unsigned int,
  1129. X    unsigned int,unsigned int)),
  1130. X  QuantizeImages _Declare((Image **,unsigned int,Image *,unsigned int,
  1131. X    unsigned int,unsigned int,unsigned int,unsigned int)),
  1132. X  RGBTransformImage _Declare((Image *,unsigned int)),
  1133. X  SortColormapByIntensity _Declare((Image *)),
  1134. X  SyncImage _Declare((Image *)),
  1135. X  TransformImage _Declare((Image **,char *,char *,char *)),
  1136. X  TransformRGBImage _Declare((Image *,unsigned int));
  1137. SHAR_EOF
  1138. chmod 0644 ImageMagick/image.h ||
  1139. echo 'restore of ImageMagick/image.h failed'
  1140. Wc_c="`wc -c < 'ImageMagick/image.h'`"
  1141. test 4822 -eq "$Wc_c" ||
  1142.     echo 'ImageMagick/image.h: original size 4822, current size' "$Wc_c"
  1143. rm -f _shar_wnt_.tmp
  1144. fi
  1145. # ============= ImageMagick/import.man ==============
  1146. if test -f 'ImageMagick/import.man' -a X"$1" != X"-c"; then
  1147.     echo 'x - skipping ImageMagick/import.man (File already exists)'
  1148.     rm -f _shar_wnt_.tmp
  1149. else
  1150. > _shar_wnt_.tmp
  1151. echo 'x - extracting ImageMagick/import.man (Text)'
  1152. sed 's/^X//' << 'SHAR_EOF' > 'ImageMagick/import.man' &&
  1153. .ad l
  1154. .nh
  1155. .TH import 1 "10 October 1992" "ImageMagick"
  1156. .SH NAME
  1157. import - capture some or all of an X server screen and save the image to
  1158. a file.
  1159. .SH SYNOPSIS
  1160. .B "import"
  1161. [ \fIoptions\fP ... ] \fIfile\fP
  1162. .SH DESCRIPTION
  1163. \fBimport\fP reads an image from any visible window on an X server and
  1164. outputs it as an image file.  You can capture a single window, the
  1165. entire screen, or any rectangular portion of the screen.  Use
  1166. \fBdisplay\fP (see \fBdisplay(1)\fP) for redisplay, printing, editing,
  1167. formatting, archiving, image processing, etc. of the captured image.
  1168. .PP
  1169. The target window can be specified by id, name, or may be selected by
  1170. clicking the mouse in the desired window.  If you press a button and
  1171. then drag, a rectangle will form which expands and contracts as
  1172. the mouse moves.  To save the portion of the screen  defined by the
  1173. rectangle, just release the button.  The keyboard bell is rung once at
  1174. the beginning of the screen capture and twice when it completes.
  1175. .PP
  1176. .SH EXAMPLES
  1177. .PP
  1178. To select an X window with the mouse and save it in the MIFF image
  1179. format to a file titled window.miff, use:
  1180. .PP
  1181. .B
  1182. X     import window.miff
  1183. .PP
  1184. To select an X window and save it in the Encapsulated Postscript format
  1185. to include in another document, use:
  1186. .PP
  1187. .B
  1188. X     import figure.eps
  1189. .PP
  1190. To capture the entire X server screen in the JPEG image format in a file
  1191. titled root.jpeg, use:
  1192. .PP
  1193. .B
  1194. X     import -window root root.jpeg
  1195. .SH OPTIONS
  1196. \fBimport\fP options can appear on the command line or in your X resources
  1197. file (see \fBX(1)\fP).  Options on the command line supersede values specified
  1198. in your X resources file.
  1199. .TP 5
  1200. .B "-border"
  1201. include image borders in the output image.
  1202. .TP 5
  1203. .B "-compress \fItype\fP"
  1204. the type of image compression: \fIQEncoded\fP or \fIRunlengthEncoded\fP.
  1205. See \fBmiff(5)\fP for details.
  1206. X
  1207. Specify \fB\+compress\fP to store the binary image in an uncompressed format.
  1208. The default is the compression type of the specified image file.
  1209. .TP 5
  1210. .B "-delay \fIseconds\fP"
  1211. pause before selecting target window.
  1212. X
  1213. This option is useful when you need time to ready the target window before
  1214. it is captured to a file.
  1215. .TP 5
  1216. .B "-density \fI<width>x<height>
  1217. vertical and horizonal density of the image.
  1218. X
  1219. This option specifies an image density whose interpretation changes
  1220. with the type of image.  The default is 72 dots per inch in the
  1221. horizonal and vertical direction for Postscript.  Text files default to
  1222. 80 characters in width and 60 lines in height.  Use this option to
  1223. alter the default density.
  1224. .TP 5
  1225. .B "-descend"
  1226. obtain image by descending window hierarchy.
  1227. X
  1228. Normally the colormap of the chosen window is used to obtain the red,
  1229. green, and blue values.  This option reads each subwindow and its
  1230. colormap of the chosen window.  The final image is guarenteed to have the
  1231. correct colors but obtaining the image is significantly slower.
  1232. .TP 5
  1233. .B "-display \fIhost:display[.screen]\fP"
  1234. specifies the X server to contact; see \fBX(1)\fP.
  1235. .TP 5
  1236. .B "-frame"
  1237. include window manager frame.
  1238. .TP 5
  1239. .B "-geometry \fI<width>x<height>{\+-}<x offset>{\+-}<y offset>\fP"
  1240. the width and height of the image.
  1241. X
  1242. Use this option to specified the width and height of raw images whose
  1243. dimensions are unknown such as \fBGRAY\fP, \fBRGB\fP, and \fBCMYK\fP.
  1244. This option can also change the default 8.5 by 11 width and height of
  1245. the Postscript canvas.   When printing an image, \fI<x offset>\fP and
  1246. \fI<y offset>\fP is relative to a Postscript page.
  1247. .TP 5
  1248. .B "-interlace \fItype\fP"
  1249. the type of interlacing scheme: \fBNONE\fP, \fBLINE\fP, or \fBPLANE\fP.
  1250. X
  1251. This option is used to specify the type of interlacing scheme for raw
  1252. image formats such as \fBRGB\fP or \fBYUV\fP.  \fBNONE\fP means do not
  1253. interlace (RGBRGBRGBRGBRGBRGB...), \fBLINE\fP uses scanline
  1254. interlacing (RRR...GGG...BBB...RRR...GGG...BBB...), and \fBPLANE\fP uses
  1255. plane interlacing (RRRRRR...GGGGGG...BBBBBB...).
  1256. .TP 5
  1257. .B "-monochrome"
  1258. transform image to black and white.
  1259. .TP 5
  1260. .B "-page \fI<width>x<height>{\+-}<x offset>{\+-}<y offset>\fP"
  1261. preferred size and location of the Postscript page.
  1262. X
  1263. Use this option to specify the dimensions of the Postscript page in picas.  The
  1264. default is to center the image on a letter page, 612 by 792 picas.
  1265. Other common sizes are:
  1266. X
  1267. X    540x720   Note
  1268. X    612x1008  Legal
  1269. X    842x1190  A3
  1270. X    595x842   A4
  1271. X    421x595   A5
  1272. X    297x421   A6
  1273. X    709x1002  B4
  1274. X    612x936   U.S. Foolscap
  1275. X    612x936   European Foolscap
  1276. X    396x612   Half Letter
  1277. X    792x1224  11x17
  1278. X    1224x792  Ledger
  1279. X
  1280. The page geometry is relative to the vertical and horizonal density of the
  1281. Postscript page.  See \fB-density\fP for details.
  1282. .TP 5
  1283. .B "-quality \fIvalue\fP"
  1284. JPEG quality setting.
  1285. X
  1286. Quality is 0 (worst) to 100 (best). The default is 75.
  1287. .TP 5
  1288. .B "-rotate \fIdegrees\fP"
  1289. apply Paeth image rotation to the image.
  1290. X
  1291. Empty triangles left over from rotating the image are filled with the
  1292. color defined by the pixel at location (0,0).
  1293. .TP 5
  1294. .B "-scene \fIvalue\fP"
  1295. image scene number.
  1296. .TP 5
  1297. .B "-screen"
  1298. This option indicates that the GetImage request used to obtain the image
  1299. should be done on the root window, rather than directly on the specified
  1300. window.  In this way, you can obtain pieces of other windows that overlap
  1301. the specified window, and more importantly, you can capture menus or other
  1302. popups that are independent windows but appear over the specified window.
  1303. .TP 5
  1304. .B -verbose
  1305. print detailed information about the image.
  1306. X
  1307. This information is printed: image scene number;  image name;  image size;
  1308. the image class (\fIDirectClass\fP or \fIPseudoClass\fP);  the total
  1309. number of unique colors;  and the number of seconds to read and write the
  1310. image.
  1311. .TP 5
  1312. .B "-window \fIid\fP"
  1313. select window with this id or name.
  1314. X
  1315. With this option you can specify the target window by id or name rather
  1316. than using the mouse.  Specify 'root' to select X's root window as the
  1317. target window.
  1318. .PP
  1319. Change \fI-\fP to \fI+\fP in any option above to reverse its effect.  For
  1320. example \fB+frame\fP means do include window manager frame.
  1321. .PP
  1322. \fIfile\fP specifies the image filename.  By default, the image is
  1323. written in the Postscript image format.  To specify a particular image
  1324. format, precede the filename with an image format name and a colon
  1325. (i.e.  ps:image) or specify the image type as the filename suffix (i.e.
  1326. image.ps).  See \fBconvert(1)\fP for a list of valid image formats.
  1327. .PP
  1328. If \fIfile\fP has the extension \fB.Z\fP or \fB.gz\fP, the file size is
  1329. compressed using with \fBcompress\fP or \fBgzip\fP respectively.  If
  1330. \fIfile\fP already exists, you will be prompted as to whether it
  1331. should be overwritten.
  1332. .SH ENVIRONMENT
  1333. .PP
  1334. .TP 5
  1335. .B display
  1336. To get the default host, display number, and screen.
  1337. .SH SEE ALSO
  1338. .B
  1339. display(1), animate(1), mogrify(1), convert(1), quantize(9), X(1), miff(5)
  1340. .SH COPYRIGHT
  1341. Copyright 1993 E. I. du Pont de Nemours & Company
  1342. .PP
  1343. Permission to use, copy, modify, distribute, and sell this software and
  1344. its documentation for any purpose is hereby granted without fee,
  1345. provided that the above copyright notice appear in all copies and that
  1346. both that copyright notice and this permission notice appear in
  1347. supporting documentation, and that the name of E. I. du Pont de Nemours
  1348. & Company not be used in advertising or publicity pertaining to
  1349. distribution of the software without specific, written prior
  1350. permission.  E. I. du Pont de Nemours & Company makes no representations
  1351. about the suitability of this software for any purpose.  It is provided
  1352. "as is" without express or implied warranty.
  1353. .PP
  1354. E. I. du Pont de Nemours & Company disclaims all warranties with regard
  1355. to this software, including all implied warranties of merchantability
  1356. and fitness, in no event shall E. I. du Pont de Nemours & Company be
  1357. liable for any special, indirect or consequential damages or any
  1358. damages whatsoever resulting from loss of use, data or profits, whether
  1359. in an action of contract, negligence or other tortious action, arising
  1360. out of or in connection with the use or performance of this software.
  1361. .SH AUTHORS
  1362. John Cristy, E.I. du Pont De Nemours & Company Incorporated
  1363. SHAR_EOF
  1364. chmod 0644 ImageMagick/import.man ||
  1365. echo 'restore of ImageMagick/import.man failed'
  1366. Wc_c="`wc -c < 'ImageMagick/import.man'`"
  1367. test 8036 -eq "$Wc_c" ||
  1368.     echo 'ImageMagick/import.man: original size 8036, current size' "$Wc_c"
  1369. rm -f _shar_wnt_.tmp
  1370. fi
  1371. # ============= ImageMagick/quantize.c ==============
  1372. if test -f 'ImageMagick/quantize.c' -a X"$1" != X"-c"; then
  1373.     echo 'x - skipping ImageMagick/quantize.c (File already exists)'
  1374.     rm -f _shar_wnt_.tmp
  1375. else
  1376. > _shar_wnt_.tmp
  1377. echo 'x - extracting ImageMagick/quantize.c (Text)'
  1378. sed 's/^X//' << 'SHAR_EOF' > 'ImageMagick/quantize.c' &&
  1379. /*
  1380. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  1381. %                                                                             %
  1382. %                                                                             %
  1383. %                                                                             %
  1384. %           QQQ   U   U   AAA   N   N  TTTTT  IIIII   ZZZZZ  EEEEE            %
  1385. %          Q   Q  U   U  A   A  NN  N    T      I        ZZ  E                %
  1386. %          Q   Q  U   U  AAAAA  N N N    T      I      ZZZ   EEEEE            %
  1387. %          Q  QQ  U   U  A   A  N  NN    T      I     ZZ     E                %
  1388. %           QQQQ   UUU   A   A  N   N    T    IIIII   ZZZZZ  EEEEE            %
  1389. %                                                                             %
  1390. %                                                                             %
  1391. %              Reduce the Number of Unique Colors in an Image                 %
  1392. %                                                                             %
  1393. %                                                                             %
  1394. %                                                                             %
  1395. %                           Software Design                                   %
  1396. %                             John Cristy                                     %
  1397. %                              July 1992                                      %
  1398. %                                                                             %
  1399. %  Copyright 1993 E. I. du Pont de Nemours & Company                          %
  1400. %                                                                             %
  1401. %  Permission to use, copy, modify, distribute, and sell this software and    %
  1402. %  its documentation for any purpose is hereby granted without fee,           %
  1403. %  provided that the above Copyright notice appear in all copies and that     %
  1404. %  both that Copyright notice and this permission notice appear in            %
  1405. %  supporting documentation, and that the name of E. I. du Pont de Nemours    %
  1406. %  & Company not be used in advertising or publicity pertaining to            %
  1407. %  distribution of the software without specific, written prior               %
  1408. %  permission.  E. I. du Pont de Nemours & Company makes no representations   %
  1409. %  about the suitability of this software for any purpose.  It is provided    %
  1410. %  "as is" without express or implied warranty.                               %
  1411. %                                                                             %
  1412. %  E. I. du Pont de Nemours & Company disclaims all warranties with regard    %
  1413. %  to this software, including all implied warranties of merchantability      %
  1414. %  and fitness, in no event shall E. I. du Pont de Nemours & Company be       %
  1415. %  liable for any special, indirect or consequential damages or any           %
  1416. %  damages whatsoever resulting from loss of use, data or profits, whether    %
  1417. %  in an action of contract, negligence or other tortious action, arising     %
  1418. %  out of or in connection with the use or performance of this software.      %
  1419. %                                                                             %
  1420. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  1421. %
  1422. %  Realism in computer graphics typically requires using 24 bits/pixel to
  1423. %  generate an image.  Yet many graphic display devices do not contain
  1424. %  the amount of memory necessary to match the spatial and color
  1425. %  resolution of the human eye.  The QUANTIZE program takes a 24 bit
  1426. %  image and reduces the number of colors so it can be displayed on
  1427. %  raster device with less bits per pixel.  In most instances, the
  1428. %  quantized image closely resembles the original reference image.
  1429. %
  1430. %  A reduction of colors in an image is also desirable for image
  1431. %  transmission and real-time animation.
  1432. %
  1433. %  Function Quantize takes a standard RGB or monochrome images and quantizes
  1434. %  them down to some fixed number of colors.
  1435. %
  1436. %  For purposes of color allocation, an image is a set of n pixels, where
  1437. %  each pixel is a point in RGB space.  RGB space is a 3-dimensional
  1438. %  vector space, and each pixel, pi,  is defined by an ordered triple of
  1439. %  red, green, and blue coordinates, (ri, gi, bi).
  1440. %
  1441. %  Each primary color component (red, green, or blue) represents an
  1442. %  intensity which varies linearly from 0 to a maximum value, cmax, which
  1443. %  corresponds to full saturation of that color.  Color allocation is
  1444. %  defined over a domain consisting of the cube in RGB space with
  1445. %  opposite vertices at (0,0,0) and (cmax,cmax,cmax).  QUANTIZE requires
  1446. %  cmax = 255.
  1447. %
  1448. %  The algorithm maps this domain onto a tree in which each node
  1449. %  represents a cube within that domain.  In the following discussion
  1450. %  these cubes are defined by the coordinate of two opposite vertices:
  1451. %  The vertex nearest the origin in RGB space and the vertex farthest
  1452. %  from the origin.
  1453. %
  1454. %  The tree's root node represents the the entire domain, (0,0,0) through
  1455. %  (cmax,cmax,cmax).  Each lower level in the tree is generated by
  1456. %  subdividing one node's cube into eight smaller cubes of equal size.
  1457. %  This corresponds to bisecting the parent cube with planes passing
  1458. %  through the midpoints of each edge.
  1459. %
  1460. %  The basic algorithm operates in three phases: Classification,
  1461. %  Reduction, and Assignment.  Classification builds a color
  1462. %  description tree for the image.  Reduction collapses the tree until
  1463. %  the number it represents, at most, the number of colors desired in the
  1464. %  output image.  Assignment defines the output image's color map and
  1465. %  sets each pixel's color by reclassification in the reduced tree.
  1466. %
  1467. %  Classification begins by initializing a color description tree of
  1468. %  sufficient depth to represent each possible input color in a leaf.
  1469. %  However, it is impractical to generate a fully-formed color
  1470. %  description tree in the classification phase for realistic values of
  1471. %  cmax.  If colors components in the input image are quantized to k-bit
  1472. %  precision, so that cmax= 2k-1, the tree would need k levels below the
  1473. %  root node to allow representing each possible input color in a leaf.
  1474. %  This becomes prohibitive because the tree's total number of nodes is
  1475. %  1 + sum(i=1,k,8k).
  1476. %
  1477. %  A complete tree would require 19,173,961 nodes for k = 8, cmax = 255.
  1478. %  Therefore, to avoid building a fully populated tree, QUANTIZE: (1)
  1479. %  Initializes data structures for nodes only as they are needed;  (2)
  1480. %  Chooses a maximum depth for the tree as a function of the desired
  1481. %  number of colors in the output image (currently log2(colormap size)).
  1482. %
  1483. %  For each pixel in the input image, classification scans downward from
  1484. %  the root of the color description tree.  At each level of the tree it
  1485. %  identifies the single node which represents a cube in RGB space
  1486. %  containing the pixel's color.  It updates the following data for each
  1487. %  such node:
  1488. %
  1489. %    n1 : Number of pixels whose color is contained in the RGB cube
  1490. %    which this node represents;
  1491. %
  1492. %    n2 : Number of pixels whose color is not represented in a node at
  1493. %    lower depth in the tree;  initially,  n2 = 0 for all nodes except
  1494. %    leaves of the tree.
  1495. %
  1496. %    Sr, Sg, Sb : Sums of the red, green, and blue component values for
  1497. %    all pixels not classified at a lower depth. The combination of
  1498. %    these sums and n2  will ultimately characterize the mean color of a
  1499. %    set of pixels represented by this node.
  1500. %
  1501. %  Reduction repeatedly prunes the tree until the number of nodes with
  1502. %  n2 > 0 is less than or equal to the maximum number of colors allowed
  1503. %  in the output image.  On any given iteration over the tree, it selects
  1504. %  those nodes whose n1  count is minimal for pruning and merges their
  1505. %  color statistics upward. It uses a pruning threshold, ns, to govern
  1506. %  node selection as follows:
  1507. %
  1508. %    ns = 0
  1509. %    while number of nodes with (n2 > 0) > required maximum number of colors
  1510. %      prune all nodes such that n1 <= ns
  1511. %      Set ns to minimum n1 in remaining nodes
  1512. %
  1513. %  When a node to be pruned has offspring, the pruning procedure invokes
  1514. %  itself recursively in order to prune the tree from the leaves upward.
  1515. %  n2,  Sr, Sg,  and  Sb in a node being pruned are always added to the
  1516. %  corresponding data in that node's parent.  This retains the pruned
  1517. %  node's color characteristics for later averaging.
  1518. %
  1519. %  For each node, n2 pixels exist for which that node represents the
  1520. %  smallest volume in RGB space containing those pixel's colors.  When n2
  1521. %  > 0 the node will uniquely define a color in the output image. At the
  1522. %  beginning of reduction,  n2 = 0  for all nodes except a the leaves of
  1523. %  the tree which represent colors present in the input image.
  1524. %
  1525. %  The other pixel count, n1, indicates the total number of colors
  1526. %  within the cubic volume which the node represents.  This includes n1 -
  1527. %  n2  pixels whose colors should be defined by nodes at a lower level in
  1528. %  the tree.
  1529. %
  1530. %  Assignment generates the output image from the pruned tree.  The
  1531. %  output image consists of two parts: (1)  A color map, which is an
  1532. %  array of color descriptions (RGB triples) for each color present in
  1533. %  the output image;  (2)  A pixel array, which represents each pixel as
  1534. %  an index into the color map array.
  1535. %
  1536. %  First, the assignment phase makes one pass over the pruned color
  1537. %  description tree to establish the image's color map.  For each node
  1538. %  with n2  > 0, it divides Sr, Sg, and Sb by n2 .  This produces the
  1539. %  mean color of all pixels that classify no lower than this node.  Each
  1540. %  of these colors becomes an entry in the color map.
  1541. %
  1542. %  Finally,  the assignment phase reclassifies each pixel in the pruned
  1543. %  tree to identify the deepest node containing the pixel's color.  The
  1544. %  pixel's value in the pixel array becomes the index of this node's mean
  1545. %  color in the color map.
  1546. %
  1547. %  For efficiency, QUANTIZE requires that the reference image be in a
  1548. SHAR_EOF
  1549. true || echo 'restore of ImageMagick/quantize.c failed'
  1550. fi
  1551. echo 'End of ImageMagick part 29'
  1552. echo 'File ImageMagick/quantize.c is continued in part 30'
  1553. echo 30 > _shar_seq_.tmp
  1554. exit 0
  1555.  
  1556. exit 0 # Just in case...
  1557. -- 
  1558.   // chris@Sterling.COM           | Send comp.sources.x submissions to:
  1559. \X/  Amiga - The only way to fly! |    sources-x@sterling.com
  1560.  "It's intuitively obvious to the |
  1561.   most casual observer..."        | GCS d+/-- p+ c++ l+ m+ s++/+ g+ w+ t+ r+ x+
  1562.