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

  1. Newsgroups: comp.sources.x
  2. From: cristy@eplrx7.es.duPont.com (Cristy)
  3. Subject: v20i074:  imagemagic - X11 image processing and display, Part18/38
  4. Message-ID: <1993Jul14.175727.1805@sparky.sterling.com>
  5. X-Md4-Signature: 46ead8a54308e026cc7f23507f2a19e7
  6. Sender: chris@sparky.sterling.com (Chris Olson)
  7. Organization: Sterling Software
  8. Date: Wed, 14 Jul 1993 17:57:27 GMT
  9. Approved: chris@sterling.com
  10.  
  11. Submitted-by: cristy@eplrx7.es.duPont.com (Cristy)
  12. Posting-number: Volume 20, Issue 74
  13. Archive-name: imagemagic/part18
  14. Environment: X11
  15. Supersedes: imagemagic: Volume 13, Issue 17-37
  16.  
  17. #!/bin/sh
  18. # this is magick.18 (part 18 of ImageMagick)
  19. # do not concatenate these parts, unpack them in order with /bin/sh
  20. # file ImageMagick/decode.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" != 18; 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/decode.c'
  36. else
  37. echo 'x - continuing file ImageMagick/decode.c'
  38. sed 's/^X//' << 'SHAR_EOF' >> 'ImageMagick/decode.c' &&
  39. X            q->length=0;
  40. X            q++;
  41. X          }
  42. X        }
  43. X      else
  44. X        for (y=0; y < image->rows; y++)
  45. X          for (x=0; x < image->columns; x++)
  46. X          {
  47. X            pixel=XGetPixel(ximage,x,y);
  48. X            color=(pixel >> red_shift) & red_mask;
  49. X            q->red=(unsigned char)
  50. X              ((((unsigned long) color*65535)/red_mask) >> 8);
  51. X            color=(pixel >> green_shift) & green_mask;
  52. X            q->green=(unsigned char)
  53. X              ((((unsigned long) color*65535)/green_mask) >> 8);
  54. X            color=(pixel >> blue_shift) & blue_mask;
  55. X            q->blue=(unsigned char)
  56. X              ((((unsigned long) color*65535)/blue_mask) >> 8);
  57. X            q->index=0;
  58. X            q->length=0;
  59. X            q++;
  60. X          }
  61. X      break;
  62. X    }
  63. X    case PseudoClass:
  64. X    {
  65. X      /*
  66. X        Convert X image to PseudoClass packets.
  67. X      */
  68. X      image->colormap=(ColorPacket *) malloc(image->colors*sizeof(ColorPacket));
  69. X      if (image->colormap == (ColorPacket *) NULL)
  70. X        {
  71. X          Warning("unable to allocate memory",(char *) NULL);
  72. X          DestroyImage(image);
  73. X          return((Image *) NULL);
  74. X        }
  75. X      for (i=0; i < image->colors; i++)
  76. X      {
  77. X        image->colormap[i].red=colors[i].red >> 8;
  78. X        image->colormap[i].green=colors[i].green >> 8;
  79. X        image->colormap[i].blue=colors[i].blue >> 8;
  80. X      }
  81. X      for (y=0; y < image->rows; y++)
  82. X        for (x=0; x < image->columns; x++)
  83. X        {
  84. X          pixel=XGetPixel(ximage,x,y);
  85. X          q->red=(unsigned char) (colors[pixel].red >> 8);
  86. X          q->green=(unsigned char) (colors[pixel].green >> 8);
  87. X          q->blue=(unsigned char) (colors[pixel].blue >> 8);
  88. X          q->index=(unsigned short) pixel;
  89. X          q->length=0;
  90. X          q++;
  91. X        }
  92. X      CompressColormap(image);
  93. X      break;
  94. X    }
  95. X  }
  96. X  /*
  97. X    Free image and colormap.
  98. X  */
  99. X  (void) free((char *) window_name);
  100. X  if (header.ncolors != 0)
  101. X    (void) free((char *) colors);
  102. X  XDestroyImage(ximage);
  103. X  CloseImage(image);
  104. X  return(image);
  105. }
  106. X
  107. /*
  108. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  109. %                                                                             %
  110. %                                                                             %
  111. %                                                                             %
  112. %  R e a d Y U V I m a g e                                                    %
  113. %                                                                             %
  114. %                                                                             %
  115. %                                                                             %
  116. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  117. %
  118. %  Function ReadYUVImage reads an image with raw Y, U, and V bytes and returns
  119. %  it.  It allocates the memory necessary for the new Image structure and
  120. %  returns a pointer to the new image.  U and V, normally -0.5 through 0.5,
  121. %  are expected to be normalized to the range 0 through 255 fit withing a byte.
  122. %
  123. %  The format of the ReadYUVImage routine is:
  124. %
  125. %      image=ReadYUVImage(image_info)
  126. %
  127. %  A description of each parameter follows:
  128. %
  129. %    o image:  Function ReadYUVImage returns a pointer to the image after
  130. %      reading.  A null image is returned if there is a a memory shortage or
  131. %      if the image cannot be read.
  132. %
  133. %    o image_info: Specifies a pointer to an ImageInfo structure.
  134. %
  135. %
  136. */
  137. static Image *ReadYUVImage(image_info)
  138. ImageInfo
  139. X  *image_info;
  140. {
  141. X  Image
  142. X    *image;
  143. X
  144. X  int
  145. X    x,
  146. X    y;
  147. X
  148. X  register int
  149. X    i;
  150. X
  151. X  register RunlengthPacket
  152. X    *q;
  153. X
  154. X  register unsigned char
  155. X    *p;
  156. X
  157. X  unsigned char
  158. X    *yuv_pixels;
  159. X
  160. X  unsigned int
  161. X    height,
  162. X    width;
  163. X
  164. X  /*
  165. X    Allocate image structure.
  166. X  */
  167. X  image=AllocateImage("YUV");
  168. X  if (image == (Image *) NULL)
  169. X    return((Image *) NULL);
  170. X  /*
  171. X    Open image file.
  172. X  */
  173. X  (void) strcpy(image->filename,image_info->filename);
  174. X  OpenImage(image,"r");
  175. X  if (image->file == (FILE *) NULL)
  176. X    {
  177. X      Warning("unable to open file",image->filename);
  178. X      DestroyImage(image);
  179. X      return((Image *) NULL);
  180. X    }
  181. X  /*
  182. X    Create image.
  183. X  */
  184. X  width=512;
  185. X  height=512;
  186. X  if (image_info->geometry != (char *) NULL)
  187. X    (void) XParseGeometry(image_info->geometry,&x,&y,&width,&height);
  188. X  image->columns=width;
  189. X  image->rows=height;
  190. X  image->packets=image->columns*image->rows;
  191. X  yuv_pixels=(unsigned char *)
  192. X    malloc((unsigned int) image->packets*3*sizeof(unsigned char));
  193. X  image->pixels=(RunlengthPacket *)
  194. X    malloc((unsigned int) image->packets*sizeof(RunlengthPacket));
  195. X  if ((yuv_pixels == (unsigned char *) NULL) ||
  196. X      (image->pixels == (RunlengthPacket *) NULL))
  197. X    {
  198. X      Warning("memory allocation error",(char *) NULL);
  199. X      DestroyImage(image);
  200. X      return((Image *) NULL);
  201. X    }
  202. X  /*
  203. X    Convert raster image to runlength-encoded packets.
  204. X  */
  205. X  (void) ReadData((char *) yuv_pixels,3,(int) (image->columns*image->rows),
  206. X    image->file);
  207. X  p=yuv_pixels;
  208. X  switch (image_info->interlace)
  209. X  {
  210. X    case NoneInterlace:
  211. X    default:
  212. X    {
  213. X      /*
  214. X        No interlacing:  YUVYUVYUVYUVYUVYUV...
  215. X      */
  216. X      q=image->pixels;
  217. X      for (i=0; i < (image->columns*image->rows); i++)
  218. X      {
  219. X        q->red=(*p++);
  220. X        q->green=(*p++);
  221. X        q->blue=(*p++);
  222. X        q->index=0;
  223. X        q->length=0;
  224. X        q++;
  225. X      }
  226. X      break;
  227. X    }
  228. X    case LineInterlace:
  229. X    {
  230. X      /*
  231. X        Line interlacing:  YYY...UUU...VVV...YYY...UUU...VVV...
  232. X      */
  233. X      for (y=0; y < image->rows; y++)
  234. X      {
  235. X        q=image->pixels+y*image->columns;
  236. X        for (x=0; x < image->columns; x++)
  237. X        {
  238. X          q->red=(*p++);
  239. X          q->index=0;
  240. X          q->length=0;
  241. X          q++;
  242. X        }
  243. X        q=image->pixels+y*image->columns;
  244. X        for (x=0; x < image->columns; x++)
  245. X        {
  246. X          q->green=(*p++);
  247. X          q++;
  248. X        }
  249. X        q=image->pixels+y*image->columns;
  250. X        for (x=0; x < image->columns; x++)
  251. X        {
  252. X          q->blue=(*p++);
  253. X          q++;
  254. X        }
  255. X      }
  256. X      break;
  257. X    }
  258. X    case PlaneInterlace:
  259. X    {
  260. X      /*
  261. X        Plane interlacing:  YYYYYY...UUUUUU...VVVVVV...
  262. X      */
  263. X      q=image->pixels;
  264. X      for (i=0; i < (image->columns*image->rows); i++)
  265. X      {
  266. X        q->red=(*p++);
  267. X        q->index=0;
  268. X        q->length=0;
  269. X        q++;
  270. X      }
  271. X      q=image->pixels;
  272. X      for (i=0; i < (image->columns*image->rows); i++)
  273. X      {
  274. X        q->green=(*p++);
  275. X        q++;
  276. X      }
  277. X      q=image->pixels;
  278. X      for (i=0; i < (image->columns*image->rows); i++)
  279. X      {
  280. X        q->blue=(*p++);
  281. X        q++;
  282. X      }
  283. X      break;
  284. X    }
  285. X  }
  286. X  (void) free((char *) yuv_pixels);
  287. X  TransformRGBImage(image,YUVColorspace);
  288. X  CloseImage(image);
  289. X  return(image);
  290. }
  291. X
  292. /*
  293. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  294. %                                                                             %
  295. %                                                                             %
  296. %                                                                             %
  297. %   R e a d I m a g e                                                         %
  298. %                                                                             %
  299. %                                                                             %
  300. %                                                                             %
  301. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  302. %
  303. %  Function ReadImage reads an image and returns it.  It allocates
  304. %  the memory necessary for the new Image structure and returns a pointer to
  305. %  the new image.  By default, the image format is determined by its magic
  306. %  number. To specify a particular image format, precede the filename with an
  307. %  explicit image format name and a colon (i.e.  ps:image) or as the filename
  308. %  suffix  (i.e. image.ps).
  309. %
  310. %  The format of the ReadImage routine is:
  311. %
  312. %      image=ReadImage(image_info)
  313. %
  314. %  A description of each parameter follows:
  315. %
  316. %    o image: Function ReadImage returns a pointer to the image after
  317. %      reading.  A null image is returned if there is a a memory shortage or
  318. %      if the image cannot be read.
  319. %
  320. %    o image_info: Specifies a pointer to an ImageInfo structure.
  321. %
  322. %
  323. */
  324. Image *ReadImage(image_info)
  325. ImageInfo
  326. X  *image_info;
  327. {
  328. X  static char
  329. X    *ImageTypes[]=
  330. X    {
  331. X      "ALPHA",
  332. X      "AVS",
  333. X      "BMP",
  334. X      "CMYK",
  335. X      "EPS",
  336. X      "FAX",
  337. X      "GIF",
  338. X      "GRAY",
  339. X      "HISTOGRAM",
  340. X      "IRIS",
  341. X      "JPEG",
  342. X      "JPG",
  343. X      "MIFF",
  344. X      "MTV",
  345. X      "PBM",
  346. X      "PCX",
  347. X      "PGM",
  348. X      "PICT",
  349. X      "PPM",
  350. X      "PNM",
  351. X      "PS",
  352. X      "PS2",
  353. X      "RAS",
  354. X      "RGB",
  355. X      "RLE",
  356. X      "SUN",
  357. X      "TGA",
  358. X      "TEXT",
  359. X      "TIFF",
  360. X      "VICAR",
  361. X      "VIFF",
  362. X      "X",
  363. X      "XBM",
  364. X      "XC",
  365. X      "XV",
  366. X      "XWD",
  367. X      "YUV",
  368. X      (char *) NULL,
  369. X    };
  370. X
  371. X  char
  372. X    magick[12],
  373. X    magic_number[12],
  374. X    *p;
  375. X
  376. X  Image
  377. X    decode_image,
  378. X    *image;
  379. X
  380. X  register char
  381. X    c,
  382. X    *q;
  383. X
  384. X  register int
  385. X    i;
  386. X
  387. X  unsigned int
  388. X    temporary_file;
  389. X
  390. X  /*
  391. X    Look for explicit 'format:image' in filename.
  392. X  */
  393. X  *magick='\0';
  394. X  (void) strcpy(decode_image.filename,image_info->filename);
  395. X  p=decode_image.filename;
  396. X  while ((*p != ':') && (*p != '\0'))
  397. X    p++;
  398. X  if ((*p == ':') && ((p-decode_image.filename) < sizeof(magic_number)))
  399. X    {
  400. X      /*
  401. X        User specified image format.
  402. X      */
  403. X      (void) strncpy(magic_number,decode_image.filename,
  404. X        p-decode_image.filename);
  405. X      magic_number[p-decode_image.filename]='\0';
  406. X      for (q=magic_number; *q != '\0'; q++)
  407. X      {
  408. X        c=(*q);
  409. X        if (isascii(c) && islower(c))
  410. X          *q=toupper(c);
  411. X      }
  412. X      for (i=0; ImageTypes[i] != (char *) NULL; i++)
  413. X        if (strcmp(magic_number,ImageTypes[i]) == 0)
  414. X          {
  415. X            /*
  416. X              Strip off image format prefix.
  417. X            */
  418. X            p++;
  419. X            (void) strcpy(decode_image.filename,p);
  420. X            (void) strcpy(magick,magic_number);
  421. X            break;
  422. X          }
  423. X    }
  424. X  temporary_file=False;
  425. X  if (*magick == '\0')
  426. X    {
  427. X      /*
  428. X        Look for 'image.format' in filename.
  429. X      */
  430. X      (void) strcpy(magick,"MIFF");
  431. X      p=decode_image.filename+strlen(decode_image.filename)-1;
  432. X      while ((*p != '.') && (p > decode_image.filename))
  433. X        p--;
  434. X      if ((*p == '.') && (strlen(p) < sizeof(magic_number)))
  435. X        {
  436. X          /*
  437. X            File specified image format?
  438. X          */
  439. X          (void) strcpy(magic_number,p+1);
  440. X          for (q=magic_number; *q != '\0'; q++)
  441. X          {
  442. X            c=(*q);
  443. X            if (isascii(c) && islower(c))
  444. X              *q=toupper(c);
  445. X          }
  446. X          for (i=0; ImageTypes[i] != (char *) NULL; i++)
  447. X            if (strcmp(magic_number,ImageTypes[i]) == 0)
  448. X              {
  449. X                (void) strcpy(magick,magic_number);
  450. X                break;
  451. X              }
  452. X        }
  453. X      /*
  454. X        Determine type from image magic number.
  455. X      */
  456. X      temporary_file=(*decode_image.filename == '-');
  457. X      if (temporary_file)
  458. X        {
  459. X          char
  460. X            *directory;
  461. X
  462. X          int
  463. X            c;
  464. X
  465. X          /*
  466. X            Copy standard input to temporary file.
  467. X          */
  468. X          directory=(char *) getenv("TMPDIR");
  469. X          if (directory == (char *) NULL)
  470. X            directory="/tmp";
  471. X          (void) sprintf(decode_image.filename,"%s/magickXXXXXX",directory);
  472. X          (void) mktemp(decode_image.filename);
  473. X          decode_image.file=fopen(decode_image.filename,"w");
  474. X          if (decode_image.file == (FILE *) NULL)
  475. X            return((Image *) NULL);
  476. X          c=getchar();
  477. X          while (c != EOF)
  478. X          {
  479. X            (void) putc(c,decode_image.file);
  480. X            c=getchar();
  481. X          }
  482. X          (void) fclose(decode_image.file);
  483. X        }
  484. X      /*
  485. X        Open image file.
  486. X      */
  487. X      *magic_number='\0';
  488. X      OpenImage(&decode_image,"r");
  489. X      if (decode_image.file != (FILE *) NULL)
  490. X        {
  491. X          /*
  492. X            Read magic number.
  493. X          */
  494. X          (void) ReadData(magic_number,sizeof(char),sizeof(magic_number),
  495. X            decode_image.file);
  496. X          CloseImage(&decode_image);
  497. X        }
  498. X      /*
  499. X        Determine the image format.
  500. X      */
  501. X      if (strncmp(magic_number,"BM",2) == 0)
  502. X        (void) strcpy(magick,"BMP");
  503. X      if (strncmp(magic_number,"GIF8",4) == 0)
  504. X        (void) strcpy(magick,"GIF");
  505. X      if (strncmp(magic_number,"\001\332",2) == 0)
  506. X        (void) strcpy(magick,"IRIS");
  507. X      if (strncmp(magic_number,"\377\330\377",3) == 0)
  508. X        (void) strcpy(magick,"JPEG");
  509. X      else
  510. X        if ((strcmp(magick,"JPEG") == 0) || (strcmp(magick,"JPG") == 0))
  511. X          (void) strcpy(magick,"MIFF");
  512. X      if ((unsigned char) *magic_number == 0x0a)
  513. X        (void) strcpy(magick,"PCX");
  514. X      if ((*magic_number == 'P') && isdigit(magic_number[1]))
  515. X        (void) strcpy(magick,"PNM");
  516. X      if (strncmp(magic_number,"%!",2) == 0)
  517. X        (void) strcpy(magick,"PS");
  518. X      if (strncmp(magic_number,"\131\246\152\225",4) == 0)
  519. X        (void) strcpy(magick,"SUN");
  520. X      if ((strncmp(magic_number,"\115\115",2) == 0) ||
  521. X          (strncmp(magic_number,"\111\111",2) == 0))
  522. X        (void) strcpy(magick,"TIFF");
  523. X      if (strncmp(magic_number,"\122\314",2) == 0)
  524. X        (void) strcpy(magick,"RLE");
  525. X      if ((strncmp(magic_number,"LBLSIZE",7) == 0) ||
  526. X         (strncmp(magic_number,"NJPL1I",6) == 0))
  527. X        (void) strcpy(magick,"VICAR");
  528. X      if ((unsigned char) *magic_number == 0xab)
  529. X        (void) strcpy(magick,"VIFF");
  530. X      if (strncmp(magic_number,"#define",7) == 0)
  531. X        (void) strcpy(magick,"XBM");
  532. X      if ((magic_number[1] == 0x00) && (magic_number[2] == 0x00))
  533. X        if ((magic_number[5] == 0x00) && (magic_number[6] == 0x00))
  534. X          if ((magic_number[4] == 0x07) || (magic_number[7] == 0x07))
  535. X            (void) strcpy(magick,"XWD");
  536. X    }
  537. X  /*
  538. X    Call appropriate image reader based on image type.
  539. X  */
  540. X  (void) strcpy(image_info->filename,decode_image.filename);
  541. X  switch (*magick)
  542. X  {
  543. X    case 'A':
  544. X    {
  545. X      if (strcmp(magick,"ALPHA") == 0)
  546. X        image=ReadALPHAImage(image_info);
  547. X      else
  548. X        image=ReadAVSImage(image_info);
  549. X      break;
  550. X    }
  551. X    case 'B':
  552. X    {
  553. X      image=ReadBMPImage(image_info);
  554. X      break;
  555. X    }
  556. X    case 'C':
  557. X    {
  558. X      image=ReadCMYKImage(image_info);
  559. X      break;
  560. X    }
  561. X    case 'E':
  562. X    {
  563. X      image=ReadPSImage(image_info);
  564. X      break;
  565. X    }
  566. X    case 'F':
  567. X    {
  568. X      image=ReadFAXImage(image_info);
  569. X      break;
  570. X    }
  571. X    case 'G':
  572. X    {
  573. X      if (strcmp(magick,"GIF") == 0)
  574. X        image=ReadGIFImage(image_info);
  575. X      else
  576. X        image=
  577. X          ReadGRAYImage(image_info);
  578. X      break;
  579. X    }
  580. X    case 'H':
  581. X    {
  582. X      image=ReadHISTOGRAMImage(image_info);
  583. X      break;
  584. X    }
  585. X    case 'I':
  586. X    {
  587. X      image=ReadIRISImage(image_info);
  588. X      break;
  589. X    }
  590. X    case 'J':
  591. X    {
  592. X      image=ReadJPEGImage(image_info);
  593. X      break;
  594. X    }
  595. X    case 'M':
  596. X    {
  597. X      if (strcmp(magick,"MIFF") == 0)
  598. X        image=ReadMIFFImage(image_info);
  599. X      else
  600. X        image=ReadMTVImage(image_info);
  601. X      break;
  602. X    }
  603. X    case 'P':
  604. X    {
  605. X      if (strcmp(magick,"PCX") == 0)
  606. X        image=ReadPCXImage(image_info);
  607. X      else
  608. X        if (strcmp(magick,"PICT") == 0)
  609. X          image=ReadPICTImage(image_info);
  610. X        else
  611. X          if ((strcmp(magick,"PS") == 0) || (strcmp(magick,"PS2") == 0))
  612. X            image=ReadPSImage(image_info);
  613. X          else
  614. X            image=ReadPNMImage(image_info);
  615. X      break;
  616. X    }
  617. X    case 'R':
  618. X    {
  619. X      if (strcmp(magick,"RAS") == 0)
  620. X        image=ReadSUNImage(image_info);
  621. X      else
  622. X        if (strcmp(magick,"RGB") == 0)
  623. X          image=ReadRGBImage(image_info);
  624. X        else
  625. X          image=ReadRLEImage(image_info);
  626. X      break;
  627. X    }
  628. X    case 'S':
  629. X    {
  630. X      image=ReadSUNImage(image_info);
  631. X      break;
  632. X    }
  633. X    case 'T':
  634. X    {
  635. X      if (strcmp(magick,"TGA") == 0)
  636. X        image=ReadTARGAImage(image_info);
  637. X      else
  638. X        if (strcmp(magick,"TIFF") == 0)
  639. X          image=ReadTIFFImage(image_info);
  640. X        else
  641. X          image=ReadTEXTImage(image_info);
  642. X      break;
  643. X    }
  644. X    case 'V':
  645. X    {
  646. X      if (strcmp(magick,"VICAR") == 0)
  647. X        image=ReadVICARImage(image_info);
  648. X      else
  649. X        image=ReadVIFFImage(image_info);
  650. X      break;
  651. X    }
  652. X    case 'X':
  653. X    {
  654. X      if (strcmp(magick,"X") == 0)
  655. X        image=ReadXImage(image_info->filename,image_info->server_name,False,
  656. X          False,False,True);
  657. X      else
  658. X        if (strcmp(magick,"XC") == 0)
  659. X          image=ReadXCImage(image_info);
  660. X        else
  661. X          if (strcmp(magick,"XBM") == 0)
  662. X            image=ReadXBMImage(image_info);
  663. X          else
  664. X            if (strcmp(magick,"XV") == 0)
  665. X              image=ReadVIFFImage(image_info);
  666. X            else
  667. X              image=ReadXWDImage(image_info);
  668. X      break;
  669. X    }
  670. X    case 'Y':
  671. X    {
  672. X      image=ReadYUVImage(image_info);
  673. X      break;
  674. X    }
  675. X    default:
  676. X      image=ReadMIFFImage(image_info);
  677. X  }
  678. X  if (temporary_file)
  679. X    (void) unlink(image_info->filename);
  680. X  if (image != (Image *) NULL)
  681. X    if (image->status)
  682. X      {
  683. X        Warning("an error has occurred reading from file",image->filename);
  684. X        return((Image *) NULL);
  685. X      }
  686. X  return(image);
  687. }
  688. SHAR_EOF
  689. echo 'File ImageMagick/decode.c is complete' &&
  690. chmod 0644 ImageMagick/decode.c ||
  691. echo 'restore of ImageMagick/decode.c failed'
  692. Wc_c="`wc -c < 'ImageMagick/decode.c'`"
  693. test 230407 -eq "$Wc_c" ||
  694.     echo 'ImageMagick/decode.c: original size 230407, current size' "$Wc_c"
  695. rm -f _shar_wnt_.tmp
  696. fi
  697. # ============= ImageMagick/animate.c ==============
  698. if test -f 'ImageMagick/animate.c' -a X"$1" != X"-c"; then
  699.     echo 'x - skipping ImageMagick/animate.c (File already exists)'
  700.     rm -f _shar_wnt_.tmp
  701. else
  702. > _shar_wnt_.tmp
  703. echo 'x - extracting ImageMagick/animate.c (Text)'
  704. sed 's/^X//' << 'SHAR_EOF' > 'ImageMagick/animate.c' &&
  705. /*
  706. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  707. %                                                                             %
  708. %                                                                             %
  709. %                                                                             %
  710. %              AAA   N   N  IIIII  M   M   AAA   TTTTT  EEEEE                 %
  711. %             A   A  NN  N    I    MM MM  A   A    T    E                     %
  712. %             AAAAA  N N N    I    M M M  AAAAA    T    EEE                   %
  713. %             A   A  N  NN    I    M   M  A   A    T    E                     %
  714. %             A   A  N   N  IIIII  M   M  A   A    T    EEEEE                 %
  715. %                                                                             %
  716. %                                                                             %
  717. %          Animate Machine Independent File Format Image via X11.             %
  718. %                                                                             %
  719. %                                                                             %
  720. %                                                                             %
  721. %                           Software Design                                   %
  722. %                             John Cristy                                     %
  723. %                              July 1992                                      %
  724. %                                                                             %
  725. %                                                                             %
  726. %  Copyright 1993 E. I. du Pont de Nemours & Company                          %
  727. %                                                                             %
  728. %  Permission to use, copy, modify, distribute, and sell this software and    %
  729. %  its documentation for any purpose is hereby granted without fee,           %
  730. %  provided that the above Copyright notice appear in all copies and that     %
  731. %  both that Copyright notice and this permission notice appear in            %
  732. %  supporting documentation, and that the name of E. I. du Pont de Nemours    %
  733. %  & Company not be used in advertising or publicity pertaining to            %
  734. %  distribution of the software without specific, written prior               %
  735. %  permission.  E. I. du Pont de Nemours & Company makes no representations   %
  736. %  about the suitability of this software for any purpose.  It is provided    %
  737. %  "as is" without express or implied warranty.                               %
  738. %                                                                             %
  739. %  E. I. du Pont de Nemours & Company disclaims all warranties with regard    %
  740. %  to this software, including all implied warranties of merchantability      %
  741. %  and fitness, in no event shall E. I. du Pont de Nemours & Company be       %
  742. %  liable for any special, indirect or consequential damages or any           %
  743. %  damages whatsoever resulting from loss of use, data or profits, whether    %
  744. %  in an action of contract, negligence or other tortious action, arising     %
  745. %  out of or in connection with the use or performance of this software.      %
  746. %                                                                             %
  747. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  748. %
  749. %  Animate displays a sequence of images in the MIFF format on any
  750. %  workstation display running an X server.  Animate first determines the
  751. %  hardware capabilities of the workstation.  If the number of unique
  752. %  colors in an image is less than or equal to the number the workstation
  753. %  can support, the image is displayed in an X window.  Otherwise the
  754. %  number of colors in the image is first reduced to match the color
  755. %  resolution of the workstation before it is displayed.
  756. %
  757. %  This means that a continuous-tone 24 bits-per-pixel image can display on a
  758. %  8 bit pseudo-color device or monochrome device.  In most instances the
  759. %  reduced color image closely resembles the original.  Alternatively, a
  760. %  monochrome or pseudo-color image can display on a continuous-tone 24
  761. %  bits-per-pixel device.
  762. %
  763. %  The Animate program command syntax is:
  764. %
  765. %  Usage: animate [options ...] file [ [options ...] file ...]
  766. %
  767. %  Where options include:
  768. %    -backdrop            display image centered on a backdrop
  769. %    -clip geometry       preferred size and location of the clipped image
  770. %    -colormap type       Shared or Private
  771. %    -colors value        preferred number of colors in the image
  772. %    -colorspace type     GRAY, RGB, XYZ, YCbCr, YIQ, or YUV
  773. %    -delay milliseconds  display the next image after pausing
  774. %    -density geometry    vertical and horizonal density of the image
  775. %    -display server      display image to this X server
  776. %    -dither              apply Floyd/Steinberg error diffusion to image
  777. %    -gamma value         level of gamma correction
  778. %    -geometry geometry   preferred size and location of the image window
  779. %    -interlace type      NONE, LINE, or PLANE
  780. %    -map type            display image using this Standard Colormap
  781. %    -monochrome          transform image to black and white
  782. %    -reflect             reverse image scanlines
  783. %    -rotate degrees      apply Paeth rotation to the image
  784. %    -scale geometry      preferred size factors of the image
  785. %    -treedepth value     depth of the color classification tree
  786. %    -verbose             print detailed information about the image
  787. %    -visual type         display image using this visual type
  788. %
  789. %  In addition to those listed above, you can specify these standard X
  790. %  resources as command line options:  -background, -bordercolor,
  791. %  -borderwidth, -font, -foreground, -iconGeometry, -iconic, -name, or
  792. %  -title.
  793. %
  794. %  Change '-' to '+' in any option above to reverse its effect.  For
  795. %  example, specify +compress to store the image as uncompressed.
  796. %
  797. %  By default, the image format of `file' is determined by its magic
  798. %  number.  To specify a particular image format, precede the filename
  799. %  with an image format name and a colon (i.e. ps:image) or specify the
  800. %  image type as the filename suffix (i.e. image.ps).  Specify 'file' as
  801. %  '-' for standard input or output.
  802. %
  803. %  Buttons:
  804. %    1    press and drag to select a command from a pop-up menu
  805. %
  806. %  Keyboard accelerators:
  807. %    p    press to animate the sequence of images
  808. %    s    press to display the next image in the sequence
  809. %    .    press to continually display the sequence of images
  810. %    a    press to automatically reverse the sequence of images
  811. %    <    press to slow the display of the images
  812. %    >    press to speed-up the display of the images
  813. %    f    press to animate in the forward direction
  814. %    r    press to animate in the reverse direction
  815. %    i    press to display information about the image
  816. %    q    press to discard all images and exit program
  817. %
  818. %
  819. */
  820. X
  821. /*
  822. X  Include declarations.
  823. */
  824. #include "display.h"
  825. #include "image.h"
  826. #include "X.h"
  827. #include "compress.h"
  828. X
  829. /*
  830. X  State declarations.
  831. */
  832. #define AutoReverseAnimationState 0x0001
  833. #define ConfigureWindowState  0x0002
  834. #define DefaultState  0x0004
  835. #define ExitState  0x0008
  836. #define ForwardAnimationState 0x0010
  837. #define HighlightState  0x0020
  838. #define InfoMappedState  0x0040
  839. #define PlayAnimationState 0x0080
  840. #define RepeatAnimationState 0x0100
  841. #define StepAnimationState 0x0200
  842. X
  843. /*
  844. X  Global declarations.
  845. */
  846. char
  847. X  *client_name;
  848. X
  849. /*
  850. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  851. %                                                                             %
  852. %                                                                             %
  853. %                                                                             %
  854. %   D e l a y                                                                 %
  855. %                                                                             %
  856. %                                                                             %
  857. %                                                                             %
  858. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  859. %
  860. %  Function Delay suspends animation for the number of milliseconds specified.
  861. %
  862. %  The format of the Delay routine is:
  863. %
  864. %      Delay(milliseconds)
  865. %
  866. %  A description of each parameter follows:
  867. %
  868. %    o milliseconds: Specifies the number of milliseconds to delay before
  869. %      returning.
  870. %
  871. %
  872. */
  873. static void Delay(milliseconds)
  874. unsigned long
  875. X  milliseconds;
  876. {
  877. #ifndef vms
  878. #ifdef SYSV
  879. #include <sys/poll.h>
  880. X  if (milliseconds == 0)
  881. X    return;
  882. X  (void) poll((struct pollfd *) NULL,(unsigned long) NULL,
  883. X    (int) (milliseconds/1000));
  884. #else
  885. X  struct timeval
  886. X    timer;
  887. X
  888. X  if (milliseconds == 0)
  889. X    return;
  890. X  timer.tv_sec=milliseconds/1000;
  891. X  timer.tv_usec=(milliseconds % 1000)*1000;
  892. X  (void) select(0,(fd_set *) NULL,(fd_set *) NULL,(fd_set *) NULL,&timer);
  893. #endif
  894. #endif
  895. }
  896. X
  897. /*
  898. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  899. %                                                                             %
  900. %                                                                             %
  901. %                                                                             %
  902. %   E r r o r                                                                 %
  903. %                                                                             %
  904. %                                                                             %
  905. %                                                                             %
  906. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  907. %
  908. %  Function Error displays an error message and then terminates the program.
  909. %
  910. %  The format of the Error routine is:
  911. %
  912. %      Error(message,qualifier)
  913. %
  914. %  A description of each parameter follows:
  915. %
  916. %    o message: Specifies the message to display before terminating the
  917. %      program.
  918. %
  919. %    o qualifier: Specifies any qualifier to the message.
  920. %
  921. %
  922. */
  923. void Error(message,qualifier)
  924. char
  925. X  *message,
  926. X  *qualifier;
  927. {
  928. X  (void) fprintf(stderr,"%s: %s",client_name,message);
  929. X  if (qualifier != (char *) NULL)
  930. X    (void) fprintf(stderr," (%s)",qualifier);
  931. X  (void) fprintf(stderr,".\n");
  932. X  exit(1);
  933. }
  934. X
  935. /*
  936. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  937. %                                                                             %
  938. %                                                                             %
  939. %                                                                             %
  940. %   U s a g e                                                                 %
  941. %                                                                             %
  942. %                                                                             %
  943. %                                                                             %
  944. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  945. %
  946. %  Function Usage displays the program command syntax.
  947. %
  948. %  The format of the Usage routine is:
  949. %
  950. %      Usage(terminate)
  951. %
  952. %  A description of each parameter follows:
  953. %
  954. %    o terminate: The program will exit if the value is not zero.
  955. %
  956. %
  957. */
  958. static void Usage(terminate)
  959. unsigned int
  960. X  terminate;
  961. {
  962. X  char
  963. X    **p;
  964. X
  965. X  static char
  966. X    *buttons[]=
  967. X    {
  968. X      "1    press and drag to select a command from a pop-up menu",
  969. X      (char *) NULL
  970. X    },
  971. X    *keys[]=
  972. X    {
  973. X      "0-9  press to change the level of delay",
  974. X      "p    press to animate the sequence of images",
  975. X      "s    press to display the next image in the sequence",
  976. X      ".    press to continually display the sequence of images",
  977. X      "a    press to automatically reverse the sequence of images",
  978. X      "<    press to slow the display of the images",
  979. X      ">    press to speed-up the display of images",
  980. X      "f    press to animate in the forward direction",
  981. X      "r    press to animate in the reverse direction",
  982. X      "i    press to display information about the image",
  983. X      "q    press to discard all images and exit program",
  984. X      (char *) NULL
  985. X    },
  986. X    *options[]=
  987. X    {
  988. X      "-backdrop            display image centered on a backdrop",
  989. X      "-clip geometry       preferred size and location of the clipped image",
  990. X      "-colormap type       Shared or Private",
  991. X      "-colors value        preferred number of colors in the image",
  992. X      "-colorspace type     GRAY, RGB, XYZ, YCbCr, YIQ, or YUV",
  993. X      "-delay milliseconds  display the next image after pausing",
  994. X      "-density geometry    vertical and horizonal density of the image",
  995. X      "-display server      display image to this X server",
  996. X      "-dither              apply Floyd/Steinberg error diffusion to image",
  997. X      "-gamma value         level of gamma correction",
  998. X      "-geometry geometry   preferred size and location of the image window",
  999. X      "-interlace type       NONE, LINE, or PLANE",
  1000. X      "-map type            display image using this Standard Colormap",
  1001. X      "-monochrome          transform image to black and white",
  1002. X      "-reflect             reflect the image scanlines",
  1003. X      "-rotate degrees      apply Paeth rotation to the image",
  1004. X      "-scale geometry      preferred size factors of the image",
  1005. X      "-treedepth value     depth of the color classification tree",
  1006. X      "-verbose             print detailed information about the image",
  1007. X      "-visual type         display image using this visual type",
  1008. X      (char *) NULL
  1009. X    };
  1010. X  (void) fprintf(stderr,
  1011. X    "Usage: %s [-options ...] file [ [-options ...] file ...]\n",client_name);
  1012. X  (void) fprintf(stderr,"\nWhere options include: \n");
  1013. X  for (p=options; *p != (char *) NULL; p++)
  1014. X    (void) fprintf(stderr,"  %s\n",*p);
  1015. X  (void) fprintf(stderr,
  1016. X    "\nIn addition to those listed above, you can specify these standard X\n");
  1017. X  (void) fprintf(stderr,
  1018. X    "resources as command line options:  -background, -bordercolor,\n");
  1019. X  (void) fprintf(stderr,
  1020. X    "-borderwidth, -font, -foreground, -iconGeometry, -iconic, -name, or\n");
  1021. X  (void) fprintf(stderr,"-title.\n");
  1022. X  (void) fprintf(stderr,
  1023. X    "\nChange '-' to '+' in any option above to reverse its effect.  For\n");
  1024. X  (void) fprintf(stderr,
  1025. X    "example, specify +compress to store the image as uncompressed.\n");
  1026. X  (void) fprintf(stderr,
  1027. X    "\nBy default, the image format of `file' is determined by its magic\n");
  1028. X  (void) fprintf(stderr,
  1029. X    "number.  To specify a particular image format, precede the filename\n");
  1030. X  (void) fprintf(stderr,
  1031. X    "with an image format name and a colon (i.e. ps:image) or specify the\n");
  1032. X  (void) fprintf(stderr,
  1033. X    "image type as the filename suffix (i.e. image.ps).  Specify 'file' as\n");
  1034. X  (void) fprintf(stderr,"'-' for standard input or output.\n");
  1035. X  (void) fprintf(stderr,"\nButtons: \n");
  1036. X  for (p=buttons; *p != (char *) NULL; p++)
  1037. X    (void) fprintf(stderr,"  %s\n",*p);
  1038. X  (void) fprintf(stderr,"\nKeyboard accelerators: \n");
  1039. X  for (p=keys; *p != (char *) NULL; p++)
  1040. X    (void) fprintf(stderr,"  %s\n",*p);
  1041. X  if (terminate)
  1042. X    exit(1);
  1043. }
  1044. X
  1045. /*
  1046. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  1047. %                                                                             %
  1048. %                                                                             %
  1049. %                                                                             %
  1050. %   U s e r C o m m a n d                                                     %
  1051. %                                                                             %
  1052. %                                                                             %
  1053. %                                                                             %
  1054. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  1055. %
  1056. %  Function UserCommand makes a transform to the image or image window as
  1057. %  specified by a user menu button or keyboard command.
  1058. %
  1059. %  The format of the UserCommand routine is:
  1060. %
  1061. %    UserCommand(display,resource_info,window,image,key_symbol,state);
  1062. %
  1063. %  A description of each parameter follows:
  1064. %
  1065. %    o display: Specifies a connection to an X server; returned from
  1066. %      XOpenDisplay.
  1067. %
  1068. %    o resource_info: Specifies a pointer to a X11 XResourceInfo structure.
  1069. %
  1070. %    o window: Specifies a pointer to a XWindows structure.
  1071. %
  1072. %    o image: Specifies a pointer to a Image structure;  UserCommand
  1073. %      may transform the image and return a new image pointer.
  1074. %
  1075. %    o state: Specifies an unsigned int;  UserCommand may return a
  1076. %      modified state.
  1077. %
  1078. %
  1079. */
  1080. static void UserCommand(display,resource_info,window,key_symbol,image,state)
  1081. Display
  1082. X  *display;
  1083. X
  1084. XXResourceInfo
  1085. X  *resource_info;
  1086. X
  1087. XXWindows
  1088. X  *window;
  1089. X
  1090. KeySym
  1091. X  key_symbol;
  1092. X
  1093. Image
  1094. X  **image;
  1095. X
  1096. unsigned int
  1097. X  *state;
  1098. {
  1099. X  if (*state & InfoMappedState)
  1100. X    XWithdrawWindow(display,window->info.id,window->info.screen);
  1101. X  /*
  1102. X    Process user command.
  1103. X  */
  1104. X  switch (key_symbol)
  1105. X  {
  1106. X    case XK_KP_Space:
  1107. X      break;
  1108. X    case XK_Help:
  1109. X    {
  1110. X      Usage(False);
  1111. X      break;
  1112. X    }
  1113. X    case XK_less:
  1114. X    {
  1115. X      resource_info->delay<<=1;
  1116. X      if (resource_info->delay == 0)
  1117. X        resource_info->delay=1;
  1118. X      break;
  1119. X    }
  1120. X    case XK_greater:
  1121. X    {
  1122. X      resource_info->delay>>=1;
  1123. X      break;
  1124. X    }
  1125. X    case XK_period:
  1126. X    {
  1127. X      *state|=RepeatAnimationState;
  1128. X      *state&=(~AutoReverseAnimationState);
  1129. X      *state|=PlayAnimationState;
  1130. X      break;
  1131. X    }
  1132. X    case XK_a:
  1133. X    {
  1134. X      *state|=AutoReverseAnimationState;
  1135. X      *state&=(~RepeatAnimationState);
  1136. X      *state|=PlayAnimationState;
  1137. X      break;
  1138. X    }
  1139. X    case XK_f:
  1140. X    {
  1141. X      *state=ForwardAnimationState;
  1142. X      *state&=(~AutoReverseAnimationState);
  1143. X      break;
  1144. X    }
  1145. X    case XK_i:
  1146. X    {
  1147. X      char
  1148. X        text[2048];
  1149. X
  1150. X      /*
  1151. X        Display information about the image in the info window.
  1152. X      */
  1153. X      (void) sprintf(text," [%u] %s %ux%u ",(*image)->scene,
  1154. X        (*image)->filename,window->image.width,window->image.height);
  1155. X      if ((*image)->colors > 0)
  1156. X        (void) sprintf(text,"%s%uc ",text,(*image)->colors);
  1157. X      (void) strcat(text,(*image)->magick);
  1158. X      XSetWindowExtents(display,&window->info,text);
  1159. X      XMapWindow(display,window->info.id);
  1160. X      XDisplayInfoString(display,&window->info,text);
  1161. X      break;
  1162. X    }
  1163. X    case XK_p:
  1164. X    {
  1165. X      *state|=PlayAnimationState;
  1166. X      *state&=(~AutoReverseAnimationState);
  1167. X      break;
  1168. X    }
  1169. X    case XK_s:
  1170. X    case XK_Return:
  1171. X    {
  1172. X      *state|=StepAnimationState;
  1173. X      *state&=(~PlayAnimationState);
  1174. X      break;
  1175. X    }
  1176. X    case XK_q:
  1177. X    {
  1178. X      /*
  1179. X        Exit program
  1180. X      */
  1181. X      *state|=ExitState;  /* exit program */
  1182. X      break;
  1183. X    }
  1184. X    case XK_r:
  1185. X    case XK_BackSpace:
  1186. X    {
  1187. X      *state&=(~ForwardAnimationState);
  1188. X      *state&=(~AutoReverseAnimationState);
  1189. X      break;
  1190. X    }
  1191. X    default:
  1192. X    {
  1193. X      if (!IsModifierKey(key_symbol))
  1194. X        XBell(display,0);
  1195. X      break;
  1196. X    }
  1197. X  }
  1198. }
  1199. X
  1200. /*
  1201. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  1202. %                                                                             %
  1203. %                                                                             %
  1204. %                                                                             %
  1205. %   X A n i m a t e I m a g e                                                 %
  1206. %                                                                             %
  1207. %                                                                             %
  1208. %                                                                             %
  1209. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  1210. %
  1211. %  Function XAnimateImage displays an image via X11.
  1212. %
  1213. %  The format of the XAnimateImage routine is:
  1214. %
  1215. %      XAnimateImage(display,resource_info,argv,argc,image,number_scenes)
  1216. %
  1217. %  A description of each parameter follows:
  1218. %
  1219. %    o display: Specifies a connection to an X server;  returned from
  1220. %      XOpenDisplay.
  1221. %
  1222. %    o resource_info: Specifies a pointer to a X11 XResourceInfo structure.
  1223. %
  1224. %    o argv: Specifies the application's argument list.
  1225. %
  1226. %    o argc: Specifies the number of arguments.
  1227. %
  1228. %    o image: Specifies a pointer to a Image structure; returned from
  1229. %      ReadImage.
  1230. %
  1231. %    o number_scenes: Specifies the number of scenes to animate.
  1232. %
  1233. %
  1234. */
  1235. static int LinearCompare(x,y)
  1236. const void
  1237. X  *x,
  1238. X  *y;
  1239. {
  1240. X  Image
  1241. X    **image_1,
  1242. X    **image_2;
  1243. X
  1244. X  image_1=(Image **) x;
  1245. X  image_2=(Image **) y;
  1246. X  return((int) (*image_1)->scene-(int) (*image_2)->scene);
  1247. }
  1248. X
  1249. static void XAnimateImage(display,resource_info,argv,argc,images,number_scenes)
  1250. Display
  1251. X  *display;
  1252. X
  1253. XXResourceInfo
  1254. X  *resource_info;
  1255. X
  1256. char
  1257. X  **argv;
  1258. X
  1259. int
  1260. X  argc;
  1261. X
  1262. Image
  1263. X  **images;
  1264. X
  1265. unsigned int
  1266. X  number_scenes;
  1267. {
  1268. #define MaxWindows  9
  1269. X
  1270. X  Atom
  1271. X    delete_property,
  1272. X    protocols_property;
  1273. X
  1274. X  char
  1275. X    text[2048];
  1276. X
  1277. X  Image
  1278. X    *image;
  1279. X
  1280. X  int
  1281. X    i,
  1282. X    scene;
  1283. X
  1284. X  unsigned int
  1285. X    number_windows,
  1286. X    state,
  1287. X    status;
  1288. X
  1289. X  Window
  1290. X    root_window;
  1291. X
  1292. X  XClassHint
  1293. X    *class_hint;
  1294. X
  1295. X  XEvent
  1296. X    event;
  1297. X
  1298. X  XFontStruct
  1299. X    *font_info;
  1300. X
  1301. X  XGCValues
  1302. X    graphic_context_value;
  1303. X
  1304. X  XPixelInfo
  1305. X    pixel_info,
  1306. X    scene_info;
  1307. X
  1308. X  XStandardColormap
  1309. X    *map_info;
  1310. X
  1311. X  XVisualInfo
  1312. X    *visual_info;
  1313. X
  1314. X  XWindowInfo
  1315. X    *magick_windows[MaxWindows];
  1316. X
  1317. X  XWindows
  1318. X    *window;
  1319. X
  1320. X  XWMHints
  1321. X    *manager_hints;
  1322. X
  1323. X  /*
  1324. X    Allocate standard colormap.
  1325. X  */
  1326. X  if (resource_info->debug)
  1327. X    XSynchronize(display,True);
  1328. X  map_info=XAllocStandardColormap();
  1329. X  if (map_info == (XStandardColormap *) NULL)
  1330. X    Error("unable to create standard colormap","memory allocation failed");
  1331. X  map_info->colormap=(Colormap) NULL;
  1332. X  pixel_info.pixels=(unsigned long *) NULL;
  1333. X  /*
  1334. X    Get the best visual this server supports.
  1335. X  */
  1336. X  visual_info=XBestVisualInfo(display,resource_info->visual_type,
  1337. X    resource_info->map_type,map_info);
  1338. X  if (visual_info == (XVisualInfo *) NULL)
  1339. X    Error("unable to get visual",resource_info->visual_type);
  1340. X  if (resource_info->debug)
  1341. X    {
  1342. X      (void) fprintf(stderr,"Visual:\n");
  1343. X      (void) fprintf(stderr,"  visual id: 0x%lx\n",visual_info->visualid);
  1344. X      (void) fprintf(stderr,"  class: %s\n",XVisualClassName(visual_info));
  1345. X      (void) fprintf(stderr,"  depth: %d planes\n",visual_info->depth);
  1346. X      (void) fprintf(stderr,"  size of colormap: %d entries\n",
  1347. X        visual_info->colormap_size);
  1348. X      (void) fprintf(stderr,"  red, green, blue masks: 0x%lx 0x%lx 0x%lx\n",
  1349. X        visual_info->red_mask,visual_info->green_mask,visual_info->blue_mask);
  1350. X      (void) fprintf(stderr,"  significant bits in color: %d bits\n",
  1351. X        visual_info->bits_per_rgb);
  1352. X    }
  1353. X  /*
  1354. X    Initialize atoms.
  1355. X  */
  1356. X  protocols_property=XInternAtom(display,"WM_PROTOCOLS",False);
  1357. X  delete_property=XInternAtom(display,"WM_DELETE_WINDOW",False);
  1358. X  if ((protocols_property == (Atom) NULL) || (delete_property == (Atom) NULL))
  1359. X    Error("unable to create property",(char *) NULL);
  1360. X  /*
  1361. X    Allocate class and manager hints.
  1362. X  */
  1363. X  class_hint=XAllocClassHint();
  1364. X  manager_hints=XAllocWMHints();
  1365. X  if ((class_hint == (XClassHint *) NULL) ||
  1366. X      (manager_hints == (XWMHints *) NULL))
  1367. X    Error("unable to allocate X hints",(char *) NULL);
  1368. X  /*
  1369. X    Initialize window id's.
  1370. X  */
  1371. X  root_window=XRootWindow(display,visual_info->screen);
  1372. X  window=(XWindows *) malloc(sizeof(XWindows));
  1373. X  if (window == (XWindows *) NULL)
  1374. X    Error("unable to create X windows","memory allocation failed");
  1375. X  number_windows=0;
  1376. X  magick_windows[number_windows++]=(&window->backdrop);
  1377. X  magick_windows[number_windows++]=(&window->icon);
  1378. X  magick_windows[number_windows++]=(&window->image);
  1379. X  magick_windows[number_windows++]=(&window->info);
  1380. X  magick_windows[number_windows++]=(&window->popup);
  1381. X  for (i=0; i < number_windows; i++)
  1382. X    magick_windows[i]->id=(Window) NULL;
  1383. X  /*
  1384. X    Sort images by increasing scene number.
  1385. X  */
  1386. X  i=0;
  1387. X  for (scene=0; scene < number_scenes; scene++)
  1388. X    i+=images[scene]->scene;
  1389. X  if (i > 0)
  1390. X    (void) qsort((void *) images,number_scenes,sizeof(Image *),LinearCompare);
  1391. X  if (resource_info->map_type == (char *) NULL)
  1392. X    if ((visual_info->class != TrueColor) &&
  1393. X        (visual_info->class != DirectColor))
  1394. X      {
  1395. X        unsigned int
  1396. X          identical_colormap;
  1397. X
  1398. X        /*
  1399. X          Determine if the sequence of images has the identical colormap.
  1400. X        */
  1401. X        identical_colormap=True;
  1402. X        for (scene=0; scene < number_scenes; scene++)
  1403. X        {
  1404. X          if ((images[scene]->class == DirectClass) ||
  1405. X              (images[scene]->colors > visual_info->colormap_size))
  1406. X            {
  1407. X              /*
  1408. X                Image has more colors than the visual supports.
  1409. X              */
  1410. X              status=RunlengthDecodeImage(images[scene]);
  1411. X              if (status == False)
  1412. X                Error("unable to unpack image",(char *) NULL);
  1413. X              QuantizeImage(images[scene],(unsigned int)
  1414. X                visual_info->colormap_size,resource_info->tree_depth,
  1415. X                resource_info->dither,resource_info->colorspace,False);
  1416. X            }
  1417. X          if (images[scene]->signature == (char *) NULL)
  1418. X            ColormapSignature(images[scene]);
  1419. X          status=strcmp(images[scene]->signature,images[0]->signature);
  1420. X          if (status != 0)
  1421. X            identical_colormap=False;
  1422. X        }
  1423. X        if (!identical_colormap)
  1424. X          {
  1425. X            /*
  1426. X              Create a single colormap for the sequence of images.
  1427. X            */
  1428. X            for (scene=0; scene < number_scenes; scene++)
  1429. X              if (images[scene]->packed_pixels != (unsigned char *) NULL)
  1430. X                {
  1431. X                  status=RunlengthDecodeImage(images[scene]);
  1432. X                  if (status == False)
  1433. X                    Error("unable to unpack image",(char *) NULL);
  1434. X                }
  1435. X            QuantizeImages(images,number_scenes,(Image *) NULL,(unsigned int)
  1436. X              visual_info->colormap_size,resource_info->tree_depth,
  1437. X              resource_info->dither,resource_info->colorspace,False);
  1438. X          }
  1439. X      }
  1440. X  /*
  1441. X    Initialize Standard Colormap.
  1442. X  */
  1443. X  if (images[0]->packed_pixels != (unsigned char *) NULL)
  1444. X    {
  1445. X      status=RunlengthDecodeImage(images[0]);
  1446. X      if (status == False)
  1447. X        Error("unable to unpack image",(char *) NULL);
  1448. X    }
  1449. X  XMakeStandardColormap(display,visual_info,resource_info,&pixel_info,
  1450. X    images[0],map_info);
  1451. X  /*
  1452. X    Initialize font info.
  1453. X  */
  1454. X  (void) sprintf(text," [%u] %s %ux%u ",images[0]->scene,images[0]->filename,
  1455. X    images[0]->columns,images[0]->rows);
  1456. X  if (images[0]->colors != 0)
  1457. X    (void) sprintf(text,"%s%uc ",text,images[0]->colors);
  1458. X  font_info=XBestFont(display,resource_info,text,images[0]->columns);
  1459. X  if (font_info == (XFontStruct *) NULL)
  1460. X    Error("unable to load font",resource_info->font);
  1461. X  /*
  1462. X    Initialize class hints.
  1463. X  */
  1464. X  if (resource_info->name == (char *) NULL)
  1465. X    class_hint->res_name=client_name;
  1466. X  else
  1467. X    class_hint->res_name=resource_info->name;
  1468. X  class_hint->res_class=(char *) "ImageMagick";
  1469. X  /*
  1470. X    Initialize graphic context.
  1471. X  */
  1472. X  window->context.id=(Window) NULL;
  1473. X  XGetWindowInfo(display,visual_info,map_info,&pixel_info,font_info,
  1474. X    resource_info,&window->context);
  1475. X  manager_hints->flags=InputHint | StateHint;
  1476. X  manager_hints->input=False;
  1477. X  manager_hints->initial_state=WithdrawnState;
  1478. X  XMakeWindow(display,root_window,argv,argc,class_hint,manager_hints,
  1479. X    delete_property,&window->context);
  1480. X  if (resource_info->debug)
  1481. X    (void) fprintf(stderr,"Window id: 0x%lx (context)\n",window->context.id);
  1482. X  graphic_context_value.background=pixel_info.background_color.pixel;
  1483. X  graphic_context_value.foreground=pixel_info.foreground_color.pixel;
  1484. X  graphic_context_value.font=font_info->fid;
  1485. X  graphic_context_value.function=GXcopy;
  1486. X  graphic_context_value.line_width=2;
  1487. X  graphic_context_value.graphics_exposures=False;
  1488. X  graphic_context_value.plane_mask=AllPlanes;
  1489. X  pixel_info.graphic_context=XCreateGC(display,window->context.id,GCBackground |
  1490. X    GCFont | GCForeground | GCFunction | GCGraphicsExposures | GCLineWidth |
  1491. X    GCPlaneMask,&graphic_context_value);
  1492. X  if (pixel_info.graphic_context == (GC) NULL)
  1493. X    Error("unable to create graphic context",(char *) NULL);
  1494. X  graphic_context_value.background=pixel_info.foreground_color.pixel;
  1495. X  graphic_context_value.foreground=pixel_info.background_color.pixel;
  1496. X  pixel_info.highlight_context=XCreateGC(display,window->context.id,
  1497. X    GCBackground | GCFont | GCForeground | GCFunction | GCGraphicsExposures |
  1498. X    GCLineWidth | GCPlaneMask,&graphic_context_value);
  1499. X  if (pixel_info.highlight_context == (GC) NULL)
  1500. X    Error("unable to create graphic context",(char *) NULL);
  1501. X  XDestroyWindow(display,window->context.id);
  1502. X  /*
  1503. X    Initialize icon window.
  1504. X  */
  1505. X  XGetWindowInfo(display,visual_info,map_info,&pixel_info,font_info,
  1506. X    resource_info,&window->icon);
  1507. X  XBestIconSize(display,&window->icon,images[0]);
  1508. X  window->icon.attributes.event_mask=ExposureMask | StructureNotifyMask;
  1509. X  manager_hints->flags=InputHint | StateHint;
  1510. X  manager_hints->input=False;
  1511. X  manager_hints->initial_state=IconicState;
  1512. X  XMakeWindow(display,root_window,argv,argc,class_hint,manager_hints,
  1513. X    delete_property,&window->icon);
  1514. X  if (resource_info->debug)
  1515. X    (void) fprintf(stderr,"Window id: 0x%lx (icon)\n",window->icon.id);
  1516. X  /*
  1517. X    Initialize image window.
  1518. X  */
  1519. X  XGetWindowInfo(display,visual_info,map_info,&pixel_info,font_info,
  1520. X    resource_info,&window->image);
  1521. X  window->image.name=(char *) malloc(2048*sizeof(char));
  1522. X  window->image.icon_name=(char *) malloc(2048*sizeof(char));
  1523. X  if ((window->image.name == NULL) || (window->image.icon_name == NULL))
  1524. X    Error("unable to create image window","memory allocation failed");
  1525. X  if (resource_info->title != (char *) NULL)
  1526. X    {
  1527. X      /*
  1528. X        User specified window name.
  1529. X      */
  1530. X      (void) strcpy(window->image.name,resource_info->title);
  1531. X      (void) strcpy(window->image.icon_name,resource_info->title);
  1532. X    }
  1533. X  else
  1534. X    {
  1535. X      register char
  1536. X        *p;
  1537. X
  1538. X      /*
  1539. X        Window name is the base of the filename.
  1540. X      */
  1541. X      p=images[0]->filename+strlen(images[0]->filename)-1;
  1542. X      while ((p > images[0]->filename) && (*(p-1) != '/'))
  1543. X        p--;
  1544. X      (void) strcpy(window->image.name,"ImageMagick: ");
  1545. X      (void) strcat(window->image.name,p);
  1546. X      p=window->image.name;
  1547. X      while (*p != '\0')
  1548. X      {
  1549. X        if (*p == '.')
  1550. X          {
  1551. X            *p='\0';
  1552. X            break;
  1553. X          }
  1554. X        p++;
  1555. X      }
  1556. X      (void) strcpy(window->image.icon_name,images[0]->filename);
  1557. X      p=window->image.icon_name;
  1558. X      while (*p != '\0')
  1559. X      {
  1560. X        if (*p == '.')
  1561. X          {
  1562. X            *p='\0';
  1563. X            break;
  1564. X          }
  1565. X        p++;
  1566. X      }
  1567. X    }
  1568. X  window->image.geometry=resource_info->image_geometry;
  1569. X  window->image.width=images[0]->columns;
  1570. X  if (window->image.width >= XDisplayWidth(display,visual_info->screen))
  1571. X    window->image.width=XDisplayWidth(display,visual_info->screen);
  1572. X  window->image.height=images[0]->rows;
  1573. X  if (window->image.height >= XDisplayHeight(display,visual_info->screen))
  1574. X    window->image.height=XDisplayHeight(display,visual_info->screen);
  1575. SHAR_EOF
  1576. true || echo 'restore of ImageMagick/animate.c failed'
  1577. fi
  1578. echo 'End of ImageMagick part 18'
  1579. echo 'File ImageMagick/animate.c is continued in part 19'
  1580. echo 19 > _shar_seq_.tmp
  1581. exit 0
  1582.  
  1583. exit 0 # Just in case...
  1584. -- 
  1585.   // chris@Sterling.COM           | Send comp.sources.x submissions to:
  1586. \X/  Amiga - The only way to fly! |    sources-x@sterling.com
  1587.  "It's intuitively obvious to the |
  1588.   most casual observer..."        | GCS d+/-- p+ c++ l+ m+ s++/+ g+ w+ t+ r+ x+
  1589.