home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #30 / NN_1992_30.iso / spool / comp / sources / misc / 4184 < prev    next >
Encoding:
Text File  |  1992-12-14  |  57.5 KB  |  1,888 lines

  1. Newsgroups: comp.sources.misc
  2. Path: sparky!kent
  3. From: cristy@eplrx7.es.duPont.com (John Cristy)
  4. Subject:  v34i044:  imagemagick - X11 image processing and display v2.2, Part16/26
  5. Message-ID: <1992Dec15.035342.21985@sparky.imd.sterling.com>
  6. Followup-To: comp.sources.d
  7. X-Md4-Signature: 67108793785958dbf109fa9f6222b620
  8. Sender: kent@sparky.imd.sterling.com (Kent Landfield)
  9. Organization: Sterling Software
  10. References: <csm-v34i028=imagemagick.141926@sparky.IMD.Sterling.COM>
  11. Date: Tue, 15 Dec 1992 03:53:42 GMT
  12. Approved: kent@sparky.imd.sterling.com
  13. Lines: 1873
  14.  
  15. Submitted-by: cristy@eplrx7.es.duPont.com (John Cristy)
  16. Posting-number: Volume 34, Issue 44
  17. Archive-name: imagemagick/part16
  18. Environment: UNIX, VMS, X11, SGI, DEC, Cray, Sun, Vax
  19.  
  20. #!/bin/sh
  21. # this is Part.16 (part 16 of a multipart archive)
  22. # do not concatenate these parts, unpack them in order with /bin/sh
  23. # file ImageMagick/X.c continued
  24. #
  25. if test ! -r _shar_seq_.tmp; then
  26.     echo 'Please unpack part 1 first!'
  27.     exit 1
  28. fi
  29. (read Scheck
  30.  if test "$Scheck" != 16; then
  31.     echo Please unpack part "$Scheck" next!
  32.     exit 1
  33.  else
  34.     exit 0
  35.  fi
  36. ) < _shar_seq_.tmp || exit 1
  37. if test ! -f _shar_wnt_.tmp; then
  38.     echo 'x - still skipping ImageMagick/X.c'
  39. else
  40. echo 'x - continuing file ImageMagick/X.c'
  41. sed 's/^X//' << 'SHAR_EOF' >> 'ImageMagick/X.c' &&
  42. X  }
  43. X  pixel_info->annotate_color=pixel_info->foreground_color;
  44. X  if (image != (Image *) NULL)
  45. X    if (image->class == PseudoClass)
  46. X      {
  47. X        /*
  48. X          Initialize pixel array for images of type PseudoClass.
  49. X        */
  50. X        for (i=0; i < image->colors; i++)
  51. X          pixel_info->pixels[i]=XStandardPixel(map_info,image->colormap[i],8);
  52. X        for (i=0; i < MaxNumberPens; i++)
  53. X          pixel_info->pixels[image->colors+i]=pixel_info->pen_color[i].pixel;
  54. X        pixel_info->colors+=MaxNumberPens;
  55. X      }
  56. }
  57. X
  58. /*
  59. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  60. %                                                                             %
  61. %                                                                             %
  62. %                                                                             %
  63. %   X G e t R e s o u r c e                                                   %
  64. %                                                                             %
  65. %                                                                             %
  66. %                                                                             %
  67. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  68. %
  69. %  Function XGetResource queries the X server for the specified resource name
  70. %  or class.  If the resource name or class is not defined in the database, the
  71. %  supplied default value is returned.
  72. %
  73. %  The format of the XGetResource routine is:
  74. %
  75. %      value=XGetResource(database,application_name,name,class,resource_default)
  76. %
  77. %  A description of each parameter follows:
  78. %
  79. %    o value: Function XGetResource returns the resource value associated with
  80. %      the name or class.  If none is found, the supplied default value is
  81. %      returned.
  82. %
  83. %    o database: Specifies a resource database; returned from
  84. %      XrmGetStringDatabase.
  85. %
  86. %    o application_name:  Specifies the application name used to retrieve
  87. %      resource info from the X server database.
  88. %
  89. %    o name: Specifies the name of the value being retrieved.
  90. %
  91. %    o class: Specifies the class of the value being retrieved.
  92. %
  93. %    o resource_default: Specifies the default value to return if the query
  94. %      fails to find the specified name/class.
  95. %
  96. %
  97. */
  98. char *XGetResource(database,application_name,name,class,resource_default)
  99. XXrmDatabase
  100. X  database;
  101. X
  102. char
  103. X  *application_name,
  104. X  *name,
  105. X  *class,
  106. X  *resource_default;
  107. {
  108. X  char
  109. X    *resource_type,
  110. X    resource_class[2048],
  111. X    resource_name[2048];
  112. X
  113. X  int
  114. X    status;
  115. X
  116. X  XrmValue
  117. X    resource_value;
  118. X
  119. X  if (database == (XrmDatabase) NULL)
  120. X    return(resource_default);
  121. X  *resource_name='\0';
  122. X  if (name != (char *) NULL)
  123. X    (void) sprintf(resource_name,"%s.%s\0",application_name,name);
  124. X  *resource_class='\0';
  125. X  if (class != (char *) NULL)
  126. X    (void) sprintf(resource_class,"%s.%s\0",application_name,class);
  127. X  status=XrmGetResource(database,resource_name,resource_class,&resource_type,
  128. X    &resource_value);
  129. X  if (status == False)
  130. X    return(resource_default);
  131. X  return(resource_value.addr);
  132. }
  133. X
  134. /*
  135. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  136. %                                                                             %
  137. %                                                                             %
  138. %                                                                             %
  139. %   X G e t R e s o u r c e I n f o                                           %
  140. %                                                                             %
  141. %                                                                             %
  142. %                                                                             %
  143. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  144. %
  145. %  Function XGetResourceInfo initializes the ResourceInfo structure.
  146. %
  147. %  The format of the XGetResourceInfo routine is:
  148. %
  149. %      XGetResourceInfo(resource_database,application_name,resource_info)
  150. %
  151. %  A description of each parameter follows:
  152. %
  153. %    o resource_database: Specifies a resource database; returned from
  154. %      XrmGetStringDatabase.
  155. %
  156. %    o application_name:  Specifies the application name used to retrieve
  157. %      resource info from the X server database.
  158. %
  159. %    o resource_info: Specifies a pointer to a X11 XResourceInfo structure.
  160. %
  161. %
  162. */
  163. void XGetResourceInfo(resource_database,application_name,resource_info)
  164. XXrmDatabase
  165. X  resource_database;
  166. X
  167. char
  168. X  *application_name;
  169. X
  170. XXResourceInfo
  171. X  *resource_info;
  172. {
  173. X  char
  174. X    *resource_value;
  175. X
  176. X  /*
  177. X    Initialize resource info fields.
  178. X  */
  179. X  resource_value=XGetResource(resource_database,application_name,"backdrop",
  180. X    (char *) NULL,"False");
  181. X  resource_info->backdrop=IsTrue(resource_value);
  182. X  resource_info->background_color=XGetResource(resource_database,
  183. X    application_name,"background","Background","black");
  184. X  resource_info->border_color=XGetResource(resource_database,application_name,
  185. X    "borderColor","BorderColor","white");
  186. X  resource_value=XGetResource(resource_database,application_name,"borderWidth",
  187. X    "BorderWidth","2");
  188. X  resource_info->border_width=atoi(resource_value);
  189. X  resource_value=XGetResource(resource_database,application_name,"colormap",
  190. X    (char *) NULL,"shared");
  191. X  resource_info->colormap=UndefinedColormap;
  192. X  if (Latin1Compare("private",resource_value) == 0)
  193. X    resource_info->colormap=PrivateColormap;
  194. X  if (Latin1Compare("shared",resource_value) == 0)
  195. X    resource_info->colormap=SharedColormap;
  196. X  if (resource_info->colormap == UndefinedColormap)
  197. X    Warning("unrecognized colormap type",resource_value);
  198. X  resource_value=XGetResource(resource_database,application_name,"colors",
  199. X    (char *) NULL,"0");
  200. X  resource_info->number_colors=atoi(resource_value);
  201. X  resource_value=XGetResource(resource_database,application_name,"colorspace",
  202. X    (char *) NULL,"rgb");
  203. X  resource_info->colorspace=UndefinedColorspace;
  204. X  if (Latin1Compare("gray",resource_value) == 0)
  205. X    resource_info->colorspace=GRAYColorspace;
  206. X  if (Latin1Compare("rgb",resource_value) == 0)
  207. X    resource_info->colorspace=RGBColorspace;
  208. X  if (Latin1Compare("yiq",resource_value) == 0)
  209. X    resource_info->colorspace=YIQColorspace;
  210. X  if (Latin1Compare("yuv",resource_value) == 0)
  211. X    resource_info->colorspace=YUVColorspace;
  212. X  if (Latin1Compare("xyz",resource_value) == 0)
  213. X    resource_info->colorspace=XYZColorspace;
  214. X  if (resource_info->colorspace == UndefinedColorspace)
  215. X    Warning("unrecognized colorspace type",resource_value);
  216. X  resource_value=XGetResource(resource_database,application_name,"debug",
  217. X    (char *) NULL,"False");
  218. X  resource_info->debug=IsTrue(resource_value);
  219. X  resource_value=XGetResource(resource_database,application_name,"delay",
  220. X    (char *) NULL,"0");
  221. X  resource_info->delay=atoi(resource_value);
  222. X  resource_value=XGetResource(resource_database,application_name,"dither",
  223. X    (char *) NULL,"False");
  224. X  resource_info->dither=IsTrue(resource_value);
  225. X  resource_info->font=XGetResource(resource_database,application_name,
  226. X    "font","Font",(char *) NULL);
  227. X  resource_info->font_name[0]=XGetResource(resource_database,application_name,
  228. X    "font1","Font1","fixed");
  229. X  resource_info->font_name[1]=XGetResource(resource_database,application_name,
  230. X    "font2","Font2","variable");
  231. X  resource_info->font_name[2]=XGetResource(resource_database,application_name,
  232. X    "font3","Font3","5x8");
  233. X  resource_info->font_name[3]=XGetResource(resource_database,application_name,
  234. X    "font4","Font4","6x10");
  235. X  resource_info->font_name[4]=XGetResource(resource_database,application_name,
  236. X    "font5","Font5","7x13bold");
  237. X  resource_info->font_name[5]=XGetResource(resource_database,application_name,
  238. X    "font6","Font6","8x13bold");
  239. X  resource_info->font_name[6]=XGetResource(resource_database,application_name,
  240. X    "font7","Font7","9x15bold");
  241. X  resource_info->font_name[7]=XGetResource(resource_database,application_name,
  242. X    "font8","Font8","10x20");
  243. X  resource_info->font_name[8]=XGetResource(resource_database,application_name,
  244. X    "font9","Font9","12x24");
  245. X  resource_info->foreground_color=XGetResource(resource_database,
  246. X    application_name,"foreground","Foreground","white");
  247. X  resource_info->icon_geometry=XGetResource(resource_database,
  248. X    application_name,"iconGeometry","IconGeometry",(char *) NULL);
  249. X  resource_value=XGetResource(resource_database,application_name,"gravity",
  250. X    (char *) NULL,"Center");
  251. X  resource_info->gravity=(-1);
  252. X  if (Latin1Compare("Forget",resource_value) == 0)
  253. X    resource_info->gravity=ForgetGravity;
  254. X  if (Latin1Compare("NorthWest",resource_value) == 0)
  255. X    resource_info->gravity=NorthWestGravity;
  256. X  if (Latin1Compare("North",resource_value) == 0)
  257. X    resource_info->gravity=NorthGravity;
  258. X  if (Latin1Compare("NorthEast",resource_value) == 0)
  259. X    resource_info->gravity=NorthEastGravity;
  260. X  if (Latin1Compare("West",resource_value) == 0)
  261. X    resource_info->gravity=WestGravity;
  262. X  if (Latin1Compare("Center",resource_value) == 0)
  263. X    resource_info->gravity=CenterGravity;
  264. X  if (Latin1Compare("East",resource_value) == 0)
  265. X    resource_info->gravity=EastGravity;
  266. X  if (Latin1Compare("SouthWest",resource_value) == 0)
  267. X    resource_info->gravity=SouthWestGravity;
  268. X  if (Latin1Compare("South",resource_value) == 0)
  269. X    resource_info->gravity=SouthGravity;
  270. X  if (Latin1Compare("SouthEast",resource_value) == 0)
  271. X    resource_info->gravity=SouthEastGravity;
  272. X  if (Latin1Compare("Static",resource_value) == 0)
  273. X    resource_info->gravity=StaticGravity;
  274. X  if (resource_info->gravity == (-1))
  275. X    Warning("unrecognized gravity type",resource_value);
  276. X  resource_value=XGetResource(resource_database,application_name,"iconic",
  277. X    "Iconic","False");
  278. X  resource_info->iconic=IsTrue(resource_value);
  279. X  resource_info->image_geometry=XGetResource(resource_database,
  280. X    application_name,"imageGeometry","ImageGeometry",(char *) NULL);
  281. X  resource_value=XGetResource(resource_database,application_name,"magnify",
  282. X    (char *) NULL,"2");
  283. X  resource_info->magnify=atoi(resource_value);
  284. X  resource_info->map_type=XGetResource(resource_database,application_name,"map",
  285. X    "Map",(char *) NULL);
  286. X  resource_value=XGetResource(resource_database,application_name,"monochrome",
  287. X    (char *) NULL,"False");
  288. X  resource_info->monochrome=IsTrue(resource_value);
  289. X  resource_info->name=XGetResource(resource_database,application_name,"name",
  290. X    "Name",(char *) NULL);
  291. X  resource_info->pen_color[0]=XGetResource(resource_database,application_name,
  292. X    "pen1","Pen1","black");
  293. X  resource_info->pen_color[1]=XGetResource(resource_database,application_name,
  294. X    "pen2","Pen2","blue");
  295. X  resource_info->pen_color[2]=XGetResource(resource_database,application_name,
  296. X    "pen3","Pen3","cyan");
  297. X  resource_info->pen_color[3]=XGetResource(resource_database,application_name,
  298. X    "pen4","Pen4","green");
  299. X  resource_info->pen_color[4]=XGetResource(resource_database,application_name,
  300. X    "pen5","Pen5","gray");
  301. X  resource_info->pen_color[5]=XGetResource(resource_database,application_name,
  302. X    "pen6","Pen6","red");
  303. X  resource_info->pen_color[6]=XGetResource(resource_database,application_name,
  304. X    "pen7","Pen7","magenta");
  305. X  resource_info->pen_color[7]=XGetResource(resource_database,application_name,
  306. X    "pen8","Pen8","yellow");
  307. X  resource_info->pen_color[8]=XGetResource(resource_database,application_name,
  308. X    "pen9","Pen9","white");
  309. X  resource_info->print_filename=XGetResource(resource_database,application_name,
  310. X    "printFilename",(char *) NULL,(char *) NULL);
  311. X  resource_info->title=XGetResource(resource_database,application_name,"title",
  312. X    "Title",(char *) NULL);
  313. X  resource_value=XGetResource(resource_database,application_name,"treeDepth",
  314. X    (char *) NULL,"0");
  315. X  resource_info->tree_depth=atoi(resource_value);
  316. X  resource_info->write_filename=XGetResource(resource_database,application_name,
  317. X    "writeFilename",(char *) NULL,(char *) NULL);
  318. X  resource_info->visual_type=XGetResource(resource_database,application_name,
  319. X    "visual","Visual",(char *) NULL);
  320. }
  321. X
  322. /*
  323. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  324. %                                                                             %
  325. %                                                                             %
  326. %                                                                             %
  327. %   X G e t W i n d o w I n f o                                               %
  328. %                                                                             %
  329. %                                                                             %
  330. %                                                                             %
  331. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  332. %
  333. %  Function XGetWindowInfo initializes the XWindowInfo structure.
  334. %
  335. %  The format of the XGetWindowInfo routine is:
  336. %
  337. %      XGetWindowInfo(superclass,window)
  338. %
  339. %  A description of each parameter follows:
  340. %
  341. %    o superclass_window: Specifies a pointer to a XWindowInfo structure.
  342. %
  343. %    o window: Specifies a pointer to a XWindowInfo structure.
  344. %
  345. %
  346. */
  347. void XGetWindowInfo(superclass_window,window)
  348. XXWindowInfo
  349. X  *superclass_window,
  350. X  *window;
  351. {
  352. X  Window
  353. X    id;
  354. X
  355. X  /*
  356. X    Window is initialized from superclass-- protect window ID.
  357. X  */
  358. X  id=window->id;
  359. X  if (id == (Window) NULL)
  360. X    *window=(*superclass_window);
  361. X  else
  362. X    {
  363. X      Pixmap
  364. X        pixmap;
  365. X
  366. X      XImage
  367. X        *ximage;
  368. X
  369. X      /*
  370. X        Protect X image, and pixmap.
  371. X      */
  372. X      ximage=window->ximage;
  373. X      pixmap=window->pixmap;
  374. X      *window=(*superclass_window);
  375. X      window->ximage=ximage;
  376. X      window->pixmap=pixmap;
  377. X    }
  378. X  window->id=id;
  379. }
  380. X
  381. /*
  382. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  383. %                                                                             %
  384. %                                                                             %
  385. %                                                                             %
  386. %   X M a k e I m a g e                                                       %
  387. %                                                                             %
  388. %                                                                             %
  389. %                                                                             %
  390. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  391. %
  392. %  Function XMakeImage creates an X11 image.  If the image size differs from
  393. %  the X11 image size, the image is first resized.
  394. %
  395. %  The format of the XMakeImage routine is:
  396. %
  397. %      status=XMakeImage(display,resource_info,window,image,width,height)
  398. %
  399. %  A description of each parameter follows:
  400. %
  401. %    o status: Function XMakeImage returns True if the X image is
  402. %      successfully created.  False is returned is there is a memory shortage.
  403. %
  404. %    o display: Specifies a connection to an X server; returned from
  405. %      XOpenDisplay.
  406. %
  407. %    o resource_info: Specifies a pointer to a X11 XResourceInfo structure.
  408. %
  409. %    o window: Specifies a pointer to a XWindowInfo structure.
  410. %
  411. %    o image: Specifies a pointer to a Image structure;  returned from
  412. %      ReadImage.
  413. %
  414. %    o width: Specifies the width in pixels of the rectangular area to
  415. %      display.
  416. %
  417. %    o height: Specifies the height in pixels of the rectangular area to
  418. %      display.
  419. %
  420. %
  421. */
  422. unsigned int XMakeImage(display,resource_info,window,image,width,height)
  423. Display
  424. X  *display;
  425. X
  426. XXResourceInfo
  427. X  *resource_info;
  428. X
  429. XXWindowInfo
  430. X  *window;
  431. X
  432. Image
  433. X  *image;
  434. X
  435. unsigned int
  436. X  width,
  437. X  height;
  438. {
  439. X  Image
  440. X    *transformed_image;
  441. X
  442. X  int
  443. X    format;
  444. X
  445. X  XImage
  446. X    *ximage;
  447. X
  448. X  if ((window->width == 0) || (window->height == 0))
  449. X    return(False);
  450. X  /*
  451. X    Display busy cursor.
  452. X  */
  453. X  XDefineCursor(display,window->id,window->busy_cursor);
  454. X  XFlush(display);
  455. X  if (image != (Image *) NULL)
  456. X    {
  457. X      /*
  458. X        Apply user transforms to the image.
  459. X      */
  460. X      image->orphan=True;
  461. X      transformed_image=image;
  462. X      if (window->clip_geometry)
  463. X        {
  464. X          Image
  465. X            *clipped_image;
  466. X
  467. X          int
  468. X            clip_x,
  469. X            clip_y;
  470. X
  471. X          unsigned
  472. X            clip_height,
  473. X            clip_width;
  474. X
  475. X          /*
  476. X            Clip image.
  477. X          */
  478. X          (void) XParseGeometry(window->clip_geometry,&clip_x,&clip_y,
  479. X            &clip_width,&clip_height);
  480. X          clipped_image=
  481. X            ClipImage(transformed_image,clip_x,clip_y,clip_width,clip_height);
  482. X          if (clipped_image != (Image *) NULL)
  483. X            {
  484. X              if (transformed_image != image)
  485. X                DestroyImage(transformed_image);
  486. X              transformed_image=clipped_image;
  487. X            }
  488. X        }
  489. X      if ((width != transformed_image->columns) ||
  490. X          (height != transformed_image->rows))
  491. X        {
  492. X          Image
  493. X            *scaled_image;
  494. X
  495. X          /*
  496. X            Scale image.
  497. X          */
  498. X          scaled_image=ScaleImage(transformed_image,width,height);
  499. X          if (scaled_image != (Image *) NULL)
  500. X            {
  501. X              if (transformed_image != image)
  502. X                DestroyImage(transformed_image);
  503. X              transformed_image=scaled_image;
  504. X            }
  505. X        }
  506. X      width=transformed_image->columns;
  507. X      height=transformed_image->rows;
  508. X      image->orphan=False;
  509. X    }
  510. X  /*
  511. X    Create X image.
  512. X  */
  513. X  format=(window->depth == 1) ? XYBitmap : ZPixmap;
  514. X  ximage=XCreateImage(display,window->visual_info->visual,window->depth,format,
  515. X    0,(char *) NULL,width,height,XBitmapPad(display),0);
  516. X  if (ximage == (XImage *) NULL)
  517. X    {
  518. X      /*
  519. X        Unable to create X image.
  520. X      */
  521. X      XDefineCursor(display,window->id,window->cursor);
  522. X      return(False);
  523. X    }
  524. X  if (resource_info->debug)
  525. X    {
  526. X      (void) fprintf(stderr,"XImage:\n");
  527. X      (void) fprintf(stderr,"  width, height: %dx%d\n",ximage->width,
  528. X        ximage->height);
  529. X      (void) fprintf(stderr,"  format: %d\n",ximage->format);
  530. X      (void) fprintf(stderr,"  byte order: %d\n",ximage->byte_order);
  531. X      (void) fprintf(stderr,"  bitmap unit, bit order, pad: %d %d %d\n",
  532. X        ximage->bitmap_unit,ximage->bitmap_bit_order,ximage->bitmap_pad);
  533. X      (void) fprintf(stderr,"  depth: %d\n",ximage->depth);
  534. X      (void) fprintf(stderr,"  bytes per line: %d\n",ximage->bytes_per_line);
  535. X      (void) fprintf(stderr,"  bits per pixel: %d\n",ximage->bits_per_pixel);
  536. X      (void) fprintf(stderr,"  red, green, blue masks: 0x%lx 0x%lx 0x%lx\n",
  537. X        ximage->red_mask,ximage->green_mask,ximage->blue_mask);
  538. X    }
  539. X  /*
  540. X    Allocate X image pixel data.
  541. X  */
  542. X  if (ximage->format == XYBitmap)
  543. X    ximage->data=(char *)
  544. X      malloc(ximage->bytes_per_line*ximage->height*ximage->depth);
  545. X  else
  546. X    ximage->data=(char *) malloc(ximage->bytes_per_line*ximage->height);
  547. X  if (ximage->data == (char *) NULL)
  548. X    {
  549. X      /*
  550. X        Unable to allocate pixel data.
  551. X      */
  552. X      XDestroyImage(ximage);
  553. X      XDefineCursor(display,window->id,window->cursor);
  554. X      return(False);
  555. X    }
  556. X  if (window->ximage != (XImage *) NULL)
  557. X    XDestroyImage(window->ximage);
  558. X  window->ximage=ximage;
  559. X  if (image == (Image *) NULL)
  560. X    {
  561. X      XDefineCursor(display,window->id,window->cursor);
  562. X      return(True);
  563. X    }
  564. X  /*
  565. X    Convert runlength-encoded pixels to X image data.
  566. X  */
  567. X  if ((ximage->byte_order == LSBFirst) ||
  568. X      ((ximage->format == XYBitmap) && (ximage->bitmap_bit_order == LSBFirst)))
  569. X    XMakeImageLSBFirst(window,transformed_image,ximage);
  570. X  else
  571. X    XMakeImageMSBFirst(window,transformed_image,ximage);
  572. X  if (transformed_image != image)
  573. X    DestroyImage(transformed_image);
  574. X  /*
  575. X    Restore cursor.
  576. X  */
  577. X  XDefineCursor(display,window->id,window->cursor);
  578. X  return(True);
  579. }
  580. X
  581. /*
  582. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  583. %                                                                             %
  584. %                                                                             %
  585. %                                                                             %
  586. %   X M a k e I m a g e L S B F i r s t                                       %
  587. %                                                                             %
  588. %                                                                             %
  589. %                                                                             %
  590. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  591. %
  592. %  Function XMakeImageLSBFirst initializes the pixel data of an X11 Image.
  593. %  The X image pixels are copied in least-significant bit and byte first
  594. %  order.  The server's scanline pad is respected.  Rather than using one or
  595. %  two general cases, many special cases are found here to help speed up the
  596. %  image conversion.
  597. %
  598. %  The format of the XMakeImageLSBFirst routine is:
  599. %
  600. %      XMakeImageLSBFirst(window,image,ximage)
  601. %
  602. %  A description of each parameter follows:
  603. %
  604. %    o window: Specifies a pointer to a XWindowInfo structure.
  605. %
  606. %    o image: Specifies a pointer to a Image structure;  returned from
  607. %      ReadImage.
  608. %
  609. %    o ximage: Specifies a pointer to a XImage structure;  returned from
  610. %      XCreateImage.
  611. %
  612. %
  613. */
  614. static void XMakeImageLSBFirst(window,image,ximage)
  615. XXWindowInfo
  616. X  *window;
  617. X
  618. Image
  619. X  *image;
  620. X
  621. XXImage
  622. X  *ximage;
  623. {
  624. X  register int
  625. X    i,
  626. X    j,
  627. X    x;
  628. X
  629. X  register RunlengthPacket
  630. X    *p;
  631. X
  632. X  register unsigned char
  633. X    *q;
  634. X
  635. X  register unsigned long
  636. X    pixel;
  637. X
  638. X  unsigned int
  639. X    scanline_pad;
  640. X
  641. X  unsigned long
  642. X    *pixels;
  643. X
  644. X  pixels=window->pixel_info->pixels;
  645. X  p=image->pixels;
  646. X  q=(unsigned char *) ximage->data;
  647. X  x=0;
  648. X  if (ximage->format == XYBitmap)
  649. X    {
  650. X      register unsigned char
  651. X        background,
  652. X        bit,
  653. X        byte,
  654. X        foreground;
  655. X
  656. X      register unsigned short
  657. X        polarity;
  658. X
  659. X      /*
  660. X        Convert image to big-endian bitmap.
  661. X      */
  662. X      background=(Intensity(window->pixel_info->foreground_color) >
  663. X        Intensity(window->pixel_info->background_color) ? 1 : 0) << 7;
  664. X      foreground=(Intensity(window->pixel_info->background_color) >
  665. X        Intensity(window->pixel_info->foreground_color) ? 1 : 0) << 7;
  666. X      polarity=Intensity(image->colormap[0]) > Intensity(image->colormap[1]);
  667. X      scanline_pad=ximage->bytes_per_line-(ximage->width >> 3);
  668. X      bit=0;
  669. X      byte=0;
  670. X      for (i=0; i < image->packets; i++)
  671. X      {
  672. X        for (j=0; j <= ((int) p->length); j++)
  673. X        {
  674. X          byte>>=1;
  675. X          if (p->index == polarity)
  676. X            byte|=foreground;
  677. X          else
  678. X            byte|=background;
  679. X          bit++;
  680. X          if (bit == 8)
  681. X            {
  682. X              *q++=byte;
  683. X              bit=0;
  684. X              byte=0;
  685. X            }
  686. X          x++;
  687. X          if (x == ximage->width)
  688. X            {
  689. X              /*
  690. X                Advance to the next scanline.
  691. X              */
  692. X              if (bit > 0)
  693. X                *q=byte >> (8-bit);
  694. X              q+=scanline_pad;
  695. X              bit=0;
  696. X              byte=0;
  697. X              x=0;
  698. X            }
  699. X        }
  700. X        p++;
  701. X      }
  702. X    }
  703. X  else
  704. X    {
  705. X      XStandardColormap
  706. X        *map_info;
  707. X
  708. X      /*
  709. X        Convert image to little-endian color-mapped X image.
  710. X      */
  711. X      map_info=window->map_info;
  712. X      scanline_pad=ximage->bytes_per_line-
  713. X        ((ximage->width*ximage->bits_per_pixel) >> 3);
  714. X      if (window->pixel_info->colors > 0)
  715. X        switch (ximage->bits_per_pixel)
  716. X        {
  717. X          case 2:
  718. X          {
  719. X            register unsigned int
  720. X              nibble;
  721. X
  722. X            /*
  723. X              Convert to 2 bit color-mapped X image.
  724. X            */
  725. X            nibble=0;
  726. X            for (i=0; i < image->packets; i++)
  727. X            {
  728. X              pixel=pixels[p->index] & 0xf;
  729. X              for (j=0; j <= ((int) p->length); j++)
  730. X              {
  731. X                switch (nibble)
  732. X                {
  733. X                  case 0:
  734. X                  {
  735. X                    *q=(unsigned char) pixel;
  736. X                    nibble++;
  737. X                    break;
  738. X                  }
  739. X                  case 1:
  740. X                  {
  741. X                    *q|=(unsigned char) (pixel << 2);
  742. X                    nibble++;
  743. X                    break;
  744. X                  }
  745. X                  case 2:
  746. X                  {
  747. X                    *q|=(unsigned char) (pixel << 4);
  748. X                    nibble++;
  749. X                    break;
  750. X                  }
  751. X                  case 3:
  752. X                  {
  753. X                    *q|=(unsigned char) (pixel << 6);
  754. X                    q++;
  755. X                    nibble=0;
  756. X                    break;
  757. X                  }
  758. X                }
  759. X                x++;
  760. X                if (x == ximage->width)
  761. X                  {
  762. X                    x=0;
  763. X                    nibble=0;
  764. X                    q+=scanline_pad;
  765. X                  }
  766. X              }
  767. X              p++;
  768. X            }
  769. X            break;
  770. X          }
  771. X          case 4:
  772. X          {
  773. X            register unsigned int
  774. X              nibble;
  775. X
  776. X            /*
  777. X              Convert to 4 bit color-mapped X image.
  778. X            */
  779. X            nibble=0;
  780. X            for (i=0; i < image->packets; i++)
  781. X            {
  782. X              pixel=pixels[p->index] & 0xf;
  783. X              for (j=0; j <= ((int) p->length); j++)
  784. X              {
  785. X                switch (nibble)
  786. X                {
  787. X                  case 0:
  788. X                  {
  789. X                    *q=(unsigned char) pixel;
  790. X                    nibble++;
  791. X                    break;
  792. X                  }
  793. X                  case 1:
  794. X                  {
  795. X                    *q|=(unsigned char) (pixel << 4);
  796. X                    q++;
  797. X                    nibble=0;
  798. X                    break;
  799. X                  }
  800. X                }
  801. X                x++;
  802. X                if (x == ximage->width)
  803. X                  {
  804. X                    x=0;
  805. X                    nibble=0;
  806. X                    q+=scanline_pad;
  807. X                  }
  808. X              }
  809. X              p++;
  810. X            }
  811. X            break;
  812. X          }
  813. X          case 6:
  814. X          case 8:
  815. X          {
  816. X            /*
  817. X              Convert to 8 bit color-mapped X image.
  818. X            */
  819. X            for (i=0; i < image->packets; i++)
  820. X            {
  821. X              pixel=pixels[p->index];
  822. X              for (j=0; j <= ((int) p->length); j++)
  823. X              {
  824. X                *q++=(unsigned char) pixel;
  825. X                x++;
  826. X                if (x == ximage->width)
  827. X                  {
  828. X                    x=0;
  829. X                    q+=scanline_pad;
  830. X                  }
  831. X              }
  832. X              p++;
  833. X            }
  834. X            break;
  835. X          }
  836. X          default:
  837. X          {
  838. X            register int
  839. X              k;
  840. X
  841. X            register unsigned int
  842. X              bytes_per_pixel;
  843. X
  844. X            unsigned char
  845. X              channel[sizeof(unsigned long)];
  846. X
  847. X            /*
  848. X              Convert to multi-byte color-mapped X image.
  849. X            */
  850. X            bytes_per_pixel=ximage->bits_per_pixel >> 3;
  851. X            for (i=0; i < image->packets; i++)
  852. X            {
  853. X              pixel=pixels[p->index];
  854. X              for (k=0; k < bytes_per_pixel; k++)
  855. X              {
  856. X                channel[k]=(unsigned char) pixel;
  857. X                pixel>>=8;
  858. X              }
  859. X              for (j=0; j <= ((int) p->length); j++)
  860. X              {
  861. X                for (k=0; k < bytes_per_pixel; k++)
  862. X                  *q++=channel[k];
  863. X                x++;
  864. X                if (x == ximage->width)
  865. X                  {
  866. X                    x=0;
  867. X                    q+=scanline_pad;
  868. X                  }
  869. X              }
  870. X              p++;
  871. X            }
  872. X            break;
  873. X          }
  874. X        }
  875. X      else
  876. X        {
  877. X          /*
  878. X            Convert image to little-endian continuous-tone X image.
  879. X          */
  880. X          switch (ximage->bits_per_pixel)
  881. X          {
  882. X            case 2:
  883. X            {
  884. X              register unsigned int
  885. X                nibble;
  886. X
  887. X              /*
  888. X                Convert to contiguous 2 bit continuous-tone X image.
  889. X              */
  890. X              nibble=0;
  891. X              for (i=0; i < image->packets; i++)
  892. X              {
  893. X                pixel=XStandardPixel(map_info,(*p),8);
  894. X                pixel&=0xf;
  895. X                for (j=0; j <= ((int) p->length); j++)
  896. X                {
  897. X                  switch (nibble)
  898. X                  {
  899. X                    case 0:
  900. X                    {
  901. X                      *q=(unsigned char) pixel;
  902. X                      nibble++;
  903. X                      break;
  904. X                    }
  905. X                    case 1:
  906. X                    {
  907. X                      *q|=(unsigned char) (pixel << 2);
  908. X                      nibble++;
  909. X                      break;
  910. X                    }
  911. X                    case 2:
  912. X                    {
  913. X                      *q|=(unsigned char) (pixel << 4);
  914. X                      nibble++;
  915. X                      break;
  916. X                    }
  917. X                    case 3:
  918. X                    {
  919. X                      *q|=(unsigned char) (pixel << 6);
  920. X                      q++;
  921. X                      nibble=0;
  922. X                      break;
  923. X                    }
  924. X                  }
  925. X                  x++;
  926. X                  if (x == ximage->width)
  927. X                    {
  928. X                      x=0;
  929. X                      nibble=0;
  930. X                      q+=scanline_pad;
  931. X                    }
  932. X                }
  933. X                p++;
  934. X              }
  935. X              break;
  936. X            }
  937. X            case 4:
  938. X            {
  939. X              register unsigned int
  940. X                nibble;
  941. X
  942. X              /*
  943. X                Convert to contiguous 4 bit continuous-tone X image.
  944. X              */
  945. X              nibble=0;
  946. X              for (i=0; i < image->packets; i++)
  947. X              {
  948. X                pixel=XStandardPixel(map_info,(*p),8);
  949. X                pixel&=0xf;
  950. X                for (j=0; j <= ((int) p->length); j++)
  951. X                {
  952. X                  switch (nibble)
  953. X                  {
  954. X                    case 0:
  955. X                    {
  956. X                      *q=(unsigned char) pixel;
  957. X                      nibble++;
  958. X                      break;
  959. X                    }
  960. X                    case 1:
  961. X                    {
  962. X                      *q|=(unsigned char) (pixel << 4);
  963. X                      q++;
  964. X                      nibble=0;
  965. X                      break;
  966. X                    }
  967. X                  }
  968. X                  x++;
  969. X                  if (x == ximage->width)
  970. X                    {
  971. X                      x=0;
  972. X                      nibble=0;
  973. X                      q+=scanline_pad;
  974. X                    }
  975. X                }
  976. X                p++;
  977. X              }
  978. X              break;
  979. X            }
  980. X            case 6:
  981. X            case 8:
  982. X            {
  983. X              /*
  984. X                Convert to contiguous 8 bit continuous-tone X image.
  985. X              */
  986. X              for (i=0; i < image->packets; i++)
  987. X              {
  988. X                pixel=XStandardPixel(map_info,(*p),8);
  989. X                for (j=0; j <= ((int) p->length); j++)
  990. X                {
  991. X                  *q++=(unsigned char) pixel;
  992. X                  x++;
  993. X                  if (x == ximage->width)
  994. X                    {
  995. X                      x=0;
  996. X                      q+=scanline_pad;
  997. X                    }
  998. X                }
  999. X                p++;
  1000. X              }
  1001. X              break;
  1002. X            }
  1003. X            default:
  1004. X            {
  1005. X              if ((ximage->bits_per_pixel == 32) &&
  1006. X                  (map_info->red_max == 255) &&
  1007. X                  (map_info->green_max == 255) &&
  1008. X                  (map_info->blue_max == 255) &&
  1009. X                  (map_info->red_mult == 65536) &&
  1010. X                  (map_info->green_mult == 256) &&
  1011. X                  (map_info->blue_mult == 1))
  1012. X                {
  1013. X                  /*
  1014. X                    Convert to 32 bit continuous-tone X image.
  1015. X                  */
  1016. X                  for (i=0; i < image->packets; i++)
  1017. X                  {
  1018. X                    for (j=0; j <= ((int) p->length); j++)
  1019. X                    {
  1020. X                      *q++=p->blue;
  1021. X                      *q++=p->green;
  1022. X                      *q++=p->red;
  1023. X                      *q++=0;
  1024. X                    }
  1025. X                    p++;
  1026. X                  }
  1027. X                }
  1028. X              else
  1029. X                {
  1030. X                  register int
  1031. X                    k;
  1032. X
  1033. X                  register unsigned int
  1034. X                    bytes_per_pixel;
  1035. X
  1036. X                  unsigned char
  1037. X                    channel[sizeof(unsigned long)];
  1038. X
  1039. X                  /*
  1040. X                    Convert to multi-byte continuous-tone X image.
  1041. X                  */
  1042. X                  bytes_per_pixel=ximage->bits_per_pixel >> 3;
  1043. X                  for (i=0; i < image->packets; i++)
  1044. X                  {
  1045. X                    pixel=XStandardPixel(map_info,(*p),8);
  1046. X                    for (k=0; k < bytes_per_pixel; k++)
  1047. X                    {
  1048. X                      channel[k]=(unsigned char) pixel;
  1049. X                      pixel>>=8;
  1050. X                    }
  1051. X                    for (j=0; j <= ((int) p->length); j++)
  1052. X                    {
  1053. X                      for (k=0; k < bytes_per_pixel; k++)
  1054. X                        *q++=channel[k];
  1055. X                      x++;
  1056. X                      if (x == ximage->width)
  1057. X                        {
  1058. X                          x=0;
  1059. X                          q+=scanline_pad;
  1060. X                        }
  1061. X                    }
  1062. X                    p++;
  1063. X                  }
  1064. X                }
  1065. X              break;
  1066. X            }
  1067. X          }
  1068. X        }
  1069. X    }
  1070. }
  1071. X
  1072. /*
  1073. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  1074. %                                                                             %
  1075. %                                                                             %
  1076. %                                                                             %
  1077. %   X M a k e I m a g e M S B F i r s t                                       %
  1078. %                                                                             %
  1079. %                                                                             %
  1080. %                                                                             %
  1081. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  1082. %
  1083. %  Function XMakeImageMSBFirst initializes the pixel data of an X11 Image.
  1084. %  The X image pixels are copied in most-significant bit and byte first order.
  1085. %  The server's scanline pad is also resprected. Rather than using one or two
  1086. %  general cases, many special cases are found here to help speed up the image
  1087. %  conversion.
  1088. %
  1089. %  The format of the XMakeImageMSBFirst routine is:
  1090. %
  1091. %      XMakeImageMSBFirst(window,image,ximage)
  1092. %
  1093. %  A description of each parameter follows:
  1094. %
  1095. %    o window: Specifies a pointer to a XWindowInfo structure.
  1096. %
  1097. %    o image: Specifies a pointer to a Image structure;  returned from
  1098. %      ReadImage.
  1099. %
  1100. %    o ximage: Specifies a pointer to a XImage structure;  returned from
  1101. %      XCreateImage.
  1102. %
  1103. %
  1104. */
  1105. static void XMakeImageMSBFirst(window,image,ximage)
  1106. XXWindowInfo
  1107. X  *window;
  1108. X
  1109. Image
  1110. X  *image;
  1111. X
  1112. XXImage
  1113. X  *ximage;
  1114. {
  1115. X  register int
  1116. X    i,
  1117. X    j,
  1118. X    x;
  1119. X
  1120. X  register RunlengthPacket
  1121. X    *p;
  1122. X
  1123. X  register unsigned char
  1124. X    *q;
  1125. X
  1126. X  register unsigned long
  1127. X    pixel;
  1128. X
  1129. X  unsigned int
  1130. X    scanline_pad;
  1131. X
  1132. X  unsigned long
  1133. X    *pixels;
  1134. X
  1135. X  pixels=window->pixel_info->pixels;
  1136. X  p=image->pixels;
  1137. X  q=(unsigned char *) ximage->data;
  1138. X  x=0;
  1139. X  if (ximage->format == XYBitmap)
  1140. X    {
  1141. X      register unsigned char
  1142. X        background,
  1143. X        bit,
  1144. X        byte,
  1145. X        foreground;
  1146. X
  1147. X      register unsigned short
  1148. X        polarity;
  1149. X
  1150. X      /*
  1151. X        Convert image to big-endian bitmap.
  1152. X      */
  1153. X      background=(Intensity(window->pixel_info->foreground_color) >
  1154. X        Intensity(window->pixel_info->background_color));
  1155. X      foreground=(Intensity(window->pixel_info->background_color) >
  1156. X        Intensity(window->pixel_info->foreground_color));
  1157. X      polarity=Intensity(image->colormap[0]) > Intensity(image->colormap[1]);
  1158. X      scanline_pad=ximage->bytes_per_line-(ximage->width >> 3);
  1159. X      bit=0;
  1160. X      byte=0;
  1161. X      for (i=0; i < image->packets; i++)
  1162. X      {
  1163. X        for (j=0; j <= ((int) p->length); j++)
  1164. X        {
  1165. X          byte<<=1;
  1166. X          if (p->index == polarity)
  1167. X            byte|=foreground;
  1168. X          else
  1169. X            byte|=background;
  1170. X          bit++;
  1171. X          if (bit == 8)
  1172. X            {
  1173. X              *q++=byte;
  1174. X              bit=0;
  1175. X              byte=0;
  1176. X            }
  1177. X          x++;
  1178. X          if (x == ximage->width)
  1179. X            {
  1180. X              /*
  1181. X                Advance to the next scanline.
  1182. X              */
  1183. X              if (bit > 0)
  1184. X                *q=byte << (8-bit);
  1185. X              q+=scanline_pad;
  1186. X              bit=0;
  1187. X              byte=0;
  1188. X              x=0;
  1189. X            }
  1190. X        }
  1191. X        p++;
  1192. X      }
  1193. X    }
  1194. X  else
  1195. X    {
  1196. X      XStandardColormap
  1197. X        *map_info;
  1198. X
  1199. X      /*
  1200. X        Convert image to big-endian X image.
  1201. X      */
  1202. X      map_info=window->map_info;
  1203. X      scanline_pad=ximage->bytes_per_line-
  1204. X        ((ximage->width*ximage->bits_per_pixel) >> 3);
  1205. X      if (window->pixel_info->colors > 0)
  1206. X        switch (ximage->bits_per_pixel)
  1207. X        {
  1208. X          case 2:
  1209. X          {
  1210. X            register unsigned int
  1211. X              nibble;
  1212. X
  1213. X            /*
  1214. X              Convert to 2 bit color-mapped X image.
  1215. X            */
  1216. X            nibble=0;
  1217. X            for (i=0; i < image->packets; i++)
  1218. X            {
  1219. X              pixel=pixels[p->index] & 0xf;
  1220. X              for (j=0; j <= ((int) p->length); j++)
  1221. X              {
  1222. X                switch (nibble)
  1223. X                {
  1224. X                  case 0:
  1225. X                  {
  1226. X                    *q=(unsigned char) (pixel << 6);
  1227. X                    nibble++;
  1228. X                    break;
  1229. X                  }
  1230. X                  case 1:
  1231. X                  {
  1232. X                    *q|=(unsigned char) (pixel << 4);
  1233. X                    nibble++;
  1234. X                    break;
  1235. X                  }
  1236. X                  case 2:
  1237. X                  {
  1238. X                    *q|=(unsigned char) (pixel << 2);
  1239. X                    nibble++;
  1240. X                    break;
  1241. X                  }
  1242. X                  case 3:
  1243. X                  {
  1244. X                    *q|=(unsigned char) pixel;
  1245. X                    q++;
  1246. X                    nibble=0;
  1247. X                    break;
  1248. X                  }
  1249. X                }
  1250. X                x++;
  1251. X                if (x == ximage->width)
  1252. X                  {
  1253. X                    x=0;
  1254. X                    nibble=0;
  1255. X                    q+=scanline_pad;
  1256. X                  }
  1257. X              }
  1258. X              p++;
  1259. X            }
  1260. X            break;
  1261. X          }
  1262. X          case 4:
  1263. X          {
  1264. X            register unsigned int
  1265. X              nibble;
  1266. X
  1267. X            /*
  1268. X              Convert to 4 bit color-mapped X image.
  1269. X            */
  1270. X            nibble=0;
  1271. X            for (i=0; i < image->packets; i++)
  1272. X            {
  1273. X              pixel=pixels[p->index] & 0xf;
  1274. X              for (j=0; j <= ((int) p->length); j++)
  1275. X              {
  1276. X                switch (nibble)
  1277. X                {
  1278. X                  case 0:
  1279. X                  {
  1280. X                    *q=(unsigned char) (pixel << 4);
  1281. X                    nibble++;
  1282. X                    break;
  1283. X                  }
  1284. X                  case 1:
  1285. X                  {
  1286. X                    *q|=(unsigned char) pixel;
  1287. X                    q++;
  1288. X                    nibble=0;
  1289. X                    break;
  1290. X                  }
  1291. X                }
  1292. X                x++;
  1293. X                if (x == ximage->width)
  1294. X                  {
  1295. X                    x=0;
  1296. X                    nibble=0;
  1297. X                    q+=scanline_pad;
  1298. X                  }
  1299. X              }
  1300. X              p++;
  1301. X            }
  1302. X            break;
  1303. X          }
  1304. X          case 8:
  1305. X          {
  1306. X            /*
  1307. X              Convert to 8 bit color-mapped X image.
  1308. X            */
  1309. X            for (i=0; i < image->packets; i++)
  1310. X            {
  1311. X              pixel=pixels[p->index];
  1312. X              for (j=0; j <= ((int) p->length); j++)
  1313. X              {
  1314. X                *q++=(unsigned char) pixel;
  1315. X                x++;
  1316. X                if (x == ximage->width)
  1317. X                  {
  1318. X                    x=0;
  1319. X                    q+=scanline_pad;
  1320. X                  }
  1321. X              }
  1322. X              p++;
  1323. X            }
  1324. X            break;
  1325. X          }
  1326. X          default:
  1327. X          {
  1328. X            register int
  1329. X              k;
  1330. X
  1331. X            register unsigned int
  1332. X              bytes_per_pixel;
  1333. X
  1334. X            unsigned char
  1335. X              channel[sizeof(unsigned long)];
  1336. X
  1337. X            /*
  1338. X              Convert to 8 bit color-mapped X image.
  1339. X            */
  1340. X            bytes_per_pixel=ximage->bits_per_pixel >> 3;
  1341. X            for (i=0; i < image->packets; i++)
  1342. X            {
  1343. X              pixel=pixels[p->index];
  1344. X              for (k=bytes_per_pixel-1; k >= 0; k--)
  1345. X              {
  1346. X                channel[k]=(unsigned char) pixel;
  1347. X                pixel>>=8;
  1348. X              }
  1349. X              for (j=0; j <= ((int) p->length); j++)
  1350. X              {
  1351. X                for (k=0; k < bytes_per_pixel; k++)
  1352. X                  *q++=channel[k];
  1353. X                x++;
  1354. X                if (x == ximage->width)
  1355. X                  {
  1356. X                    x=0;
  1357. X                    q+=scanline_pad;
  1358. X                  }
  1359. X              }
  1360. X              p++;
  1361. X            }
  1362. X            break;
  1363. X          }
  1364. X        }
  1365. X      else
  1366. X        {
  1367. X          /*
  1368. X            Convert to big-endian continuous-tone X image.
  1369. X          */
  1370. X          switch (ximage->bits_per_pixel)
  1371. X          {
  1372. X            case 2:
  1373. X            {
  1374. X              register unsigned int
  1375. X                nibble;
  1376. X
  1377. X              /*
  1378. X                Convert to 4 bit continuous-tone X image.
  1379. X              */
  1380. X              nibble=0;
  1381. X              for (i=0; i < image->packets; i++)
  1382. X              {
  1383. X                pixel=XStandardPixel(map_info,(*p),8);
  1384. X                pixel&=0xf;
  1385. X                for (j=0; j <= ((int) p->length); j++)
  1386. X                {
  1387. X                  switch (nibble)
  1388. X                  {
  1389. X                    case 0:
  1390. X                    {
  1391. X                      *q=(unsigned char) (pixel << 6);
  1392. X                      nibble++;
  1393. X                      break;
  1394. X                    }
  1395. X                    case 1:
  1396. X                    {
  1397. X                      *q|=(unsigned char) (pixel << 4);
  1398. X                      nibble++;
  1399. X                      break;
  1400. X                    }
  1401. X                    case 2:
  1402. X                    {
  1403. X                      *q|=(unsigned char) (pixel << 2);
  1404. X                      nibble++;
  1405. X                      break;
  1406. X                    }
  1407. X                    case 3:
  1408. X                    {
  1409. X                      *q|=(unsigned char) pixel;
  1410. X                      q++;
  1411. X                      nibble=0;
  1412. X                      break;
  1413. X                    }
  1414. X                  }
  1415. X                  x++;
  1416. X                  if (x == ximage->width)
  1417. X                    {
  1418. X                      x=0;
  1419. X                      nibble=0;
  1420. X                      q+=scanline_pad;
  1421. X                    }
  1422. X                }
  1423. X                p++;
  1424. X              }
  1425. X              break;
  1426. X            }
  1427. X            case 4:
  1428. X            {
  1429. X              register unsigned int
  1430. X                nibble;
  1431. X
  1432. X              /*
  1433. X                Convert to 4 bit continuous-tone X image.
  1434. X              */
  1435. X              nibble=0;
  1436. X              for (i=0; i < image->packets; i++)
  1437. X              {
  1438. X                pixel=XStandardPixel(map_info,(*p),8);
  1439. X                pixel&=0xf;
  1440. X                for (j=0; j <= ((int) p->length); j++)
  1441. X                {
  1442. X                  switch (nibble)
  1443. X                  {
  1444. X                    case 0:
  1445. X                    {
  1446. X                      *q=(unsigned char) (pixel << 4);
  1447. X                      nibble++;
  1448. X                      break;
  1449. X                    }
  1450. X                    case 1:
  1451. X                    {
  1452. X                      *q|=(unsigned char) pixel;
  1453. X                      q++;
  1454. X                      nibble=0;
  1455. X                      break;
  1456. X                    }
  1457. X                  }
  1458. X                  x++;
  1459. X                  if (x == ximage->width)
  1460. X                    {
  1461. X                      x=0;
  1462. X                      nibble=0;
  1463. X                      q+=scanline_pad;
  1464. X                    }
  1465. X                }
  1466. X                p++;
  1467. X              }
  1468. X              break;
  1469. X            }
  1470. X            case 8:
  1471. X            {
  1472. X              /*
  1473. X                Convert to 8 bit continuous-tone X image.
  1474. X              */
  1475. X              for (i=0; i < image->packets; i++)
  1476. X              {
  1477. X                pixel=XStandardPixel(map_info,(*p),8);
  1478. X                for (j=0; j <= ((int) p->length); j++)
  1479. X                {
  1480. X                  *q++=(unsigned char) pixel;
  1481. X                  x++;
  1482. X                  if (x == ximage->width)
  1483. X                    {
  1484. X                      x=0;
  1485. X                      q+=scanline_pad;
  1486. X                    }
  1487. X                }
  1488. X                p++;
  1489. X              }
  1490. X              break;
  1491. X            }
  1492. X            default:
  1493. X            {
  1494. X              if ((ximage->bits_per_pixel == 32) &&
  1495. X                  (map_info->red_max == 255) &&
  1496. X                  (map_info->green_max == 255) &&
  1497. X                  (map_info->blue_max == 255) &&
  1498. X                  (map_info->red_mult == 65536) &&
  1499. X                  (map_info->green_mult == 256) &&
  1500. X                  (map_info->blue_mult == 1))
  1501. X                {
  1502. X                  /*
  1503. X                    Convert to 32 bit continuous-tone X image.
  1504. X                  */
  1505. X                  for (i=0; i < image->packets; i++)
  1506. X                  {
  1507. X                    for (j=0; j <= ((int) p->length); j++)
  1508. X                    {
  1509. X                      *q++=0;
  1510. X                      *q++=p->red;
  1511. X                      *q++=p->green;
  1512. X                      *q++=p->blue;
  1513. X                    }
  1514. X                    p++;
  1515. X                  }
  1516. X                }
  1517. X              else
  1518. X                {
  1519. X                  register int
  1520. X                    k;
  1521. X
  1522. X                  register unsigned int
  1523. X                    bytes_per_pixel;
  1524. X
  1525. X                  unsigned char
  1526. X                    channel[sizeof(unsigned long)];
  1527. X
  1528. X                  /*
  1529. X                    Convert to multi-byte continuous-tone X image.
  1530. X                  */
  1531. X                  bytes_per_pixel=ximage->bits_per_pixel >> 3;
  1532. X                  for (i=0; i < image->packets; i++)
  1533. X                  {
  1534. X                    pixel=XStandardPixel(map_info,(*p),8);
  1535. X                    for (k=bytes_per_pixel-1; k >= 0; k--)
  1536. X                    {
  1537. X                      channel[k]=(unsigned char) pixel;
  1538. X                      pixel>>=8;
  1539. X                    }
  1540. X                    for (j=0; j <= ((int) p->length); j++)
  1541. X                    {
  1542. X                      for (k=0; k < bytes_per_pixel; k++)
  1543. X                        *q++=channel[k];
  1544. X                      x++;
  1545. X                      if (x == ximage->width)
  1546. X                        {
  1547. X                          x=0;
  1548. X                          q+=scanline_pad;
  1549. X                        }
  1550. X                    }
  1551. X                    p++;
  1552. X                  }
  1553. X                }
  1554. X              break;
  1555. X            }
  1556. X          }
  1557. X        }
  1558. X    }
  1559. }
  1560. X
  1561. /*
  1562. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  1563. %                                                                             %
  1564. %                                                                             %
  1565. %                                                                             %
  1566. %   X M a k e I n v i s i b l e C u r s o r                                   %
  1567. %                                                                             %
  1568. %                                                                             %
  1569. %                                                                             %
  1570. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  1571. %
  1572. %  Function XMakeInvisibleCursor creates an invisible X11 cursor.
  1573. %
  1574. %  The format of the XMakeInvisibleCursor routine is:
  1575. %
  1576. %      XMakeInvisibleCursor(display,window)
  1577. %
  1578. %  A description of each parameter follows:
  1579. %
  1580. %    o display: Specifies a connection to an X server;  returned from
  1581. %      XOpenDisplay.
  1582. %
  1583. %    o window: Specifies the ID of the window for which the cursor is
  1584. %      assigned.
  1585. %
  1586. %
  1587. */
  1588. Cursor XMakeInvisibleCursor(display,window)
  1589. Display
  1590. X  *display;
  1591. X
  1592. Window
  1593. X  window;
  1594. {
  1595. X  Cursor
  1596. X    cursor;
  1597. X
  1598. X  Pixmap
  1599. X    pixmap;
  1600. X
  1601. X  XColor
  1602. X    color;
  1603. X
  1604. X  static char
  1605. X    bits[]={0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00};
  1606. X
  1607. X  color.red=0;
  1608. X  color.green=0;
  1609. X  color.blue=0;
  1610. X  pixmap=XCreateBitmapFromData(display,window,bits,8,8);
  1611. X  cursor=XCreatePixmapCursor(display,pixmap,pixmap,&color,&color,0,0);
  1612. X  XFreePixmap(display,pixmap);
  1613. X  return(cursor);
  1614. }
  1615. X
  1616. /*
  1617. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  1618. %                                                                             %
  1619. %                                                                             %
  1620. %                                                                             %
  1621. %   X M a k e P i x m a p                                                     %
  1622. %                                                                             %
  1623. %                                                                             %
  1624. %                                                                             %
  1625. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  1626. %
  1627. %  Function XMakePixmap creates an X11 pixmap.
  1628. %
  1629. %  The format of the XMakePixmap routine is:
  1630. %
  1631. %      status=XMakePixmap(display,resource_info,window)
  1632. %
  1633. %  A description of each parameter follows:
  1634. %
  1635. %    o status: Function XMakePixmap returns True if the X pixmap is
  1636. %      successfully created.  False is returned is there is a memory shortage.
  1637. %
  1638. %    o resource_info: Specifies a pointer to a X11 XResourceInfo structure.
  1639. %
  1640. %    o display: Specifies a connection to an X server; returned from
  1641. %      XOpenDisplay.
  1642. %
  1643. %    o window: Specifies a pointer to a XWindowInfo structure.
  1644. %
  1645. %
  1646. */
  1647. unsigned int XMakePixmap(display,resource_info,window)
  1648. Display
  1649. X  *display;
  1650. X
  1651. XXResourceInfo
  1652. X  *resource_info;
  1653. X
  1654. XXWindowInfo
  1655. X  *window;
  1656. {
  1657. X  if (window->ximage == (XImage *) NULL)
  1658. X    return(False);
  1659. X  /*
  1660. X    Display busy cursor.
  1661. X  */
  1662. X  XDefineCursor(display,window->id,window->busy_cursor);
  1663. X  XFlush(display);
  1664. X  /*
  1665. X    Create pixmap.
  1666. X  */
  1667. X  if (window->pixmap != (Pixmap) NULL)
  1668. X    XFreePixmap(display,window->pixmap);
  1669. X  window->pixmap=XCreatePixmap(display,window->id,(unsigned int)
  1670. X    window->ximage->width,(unsigned int) window->ximage->height,window->depth);
  1671. X  if (window->pixmap == (Pixmap) NULL)
  1672. X    {
  1673. X      /*
  1674. X        Unable to allocate pixmap.
  1675. X      */
  1676. X      XDefineCursor(display,window->id,window->cursor);
  1677. X      return(False);
  1678. X    }
  1679. X  /*
  1680. X    Copy X image to pixmap.
  1681. X  */
  1682. X  XPutImage(display,window->pixmap,window->graphic_context,window->ximage,
  1683. X    0,0,0,0,(unsigned int) window->ximage->width,
  1684. X    (unsigned int) window->ximage->height);
  1685. X  if (resource_info->debug)
  1686. X    {
  1687. X      (void) fprintf(stderr,"Pixmap:\n");
  1688. X      (void) fprintf(stderr,"  width, height: %dx%d\n",window->ximage->width,
  1689. X        window->ximage->height);
  1690. X    }
  1691. X  /*
  1692. X    Restore cursor.
  1693. X  */
  1694. X  XDefineCursor(display,window->id,window->cursor);
  1695. X  return(True);
  1696. }
  1697. X
  1698. /*
  1699. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  1700. %                                                                             %
  1701. %                                                                             %
  1702. %                                                                             %
  1703. %   X M a k e S t a n d a r d C o l o r m a p                                 %
  1704. %                                                                             %
  1705. %                                                                             %
  1706. %                                                                             %
  1707. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  1708. %
  1709. %  Function XMakeStandardColormap creates an X11 Standard Colormap.
  1710. %
  1711. %  The format of the XMakeStandardColormap routine is:
  1712. %
  1713. %      XMakeStandardColormap(display,visual_info,resource_info,pixel_info,
  1714. %        image,map_info)
  1715. %
  1716. %  A description of each parameter follows:
  1717. %
  1718. %    o display: Specifies a connection to an X server; returned from
  1719. %      XOpenDisplay.
  1720. %
  1721. %    o visual_info: Specifies a pointer to a X11 XVisualInfo structure;
  1722. %      returned from XGetVisualInfo.
  1723. %
  1724. %    o resource_info: Specifies a pointer to a X11 XResourceInfo structure.
  1725. %
  1726. %    o pixel_info: Specifies a pointer to a XPixelInfo structure.
  1727. %
  1728. %    o image: Specifies a pointer to a Image structure;  returned from
  1729. %      ReadImage.
  1730. %
  1731. %    o map_info: If a Standard Colormap type is specified, this structure is
  1732. %      initialized with info from the Standard Colormap.
  1733. %
  1734. %
  1735. */
  1736. static int IntensityCompare(x,y)
  1737. const void
  1738. X  *x,
  1739. X  *y;
  1740. {
  1741. X  DiversityPacket
  1742. X    *color_1,
  1743. X    *color_2;
  1744. X  color_1=(DiversityPacket *) x;
  1745. X  color_2=(DiversityPacket *) y;
  1746. X  return((int) Intensity(*color_2)-(int) Intensity(*color_1));
  1747. }
  1748. X
  1749. static int PopularityCompare(x,y)
  1750. const void
  1751. X  *x,
  1752. X  *y;
  1753. {
  1754. X  DiversityPacket
  1755. X    *color_1,
  1756. X    *color_2;
  1757. X
  1758. X  color_1=(DiversityPacket *) x;
  1759. X  color_2=(DiversityPacket *) y;
  1760. X  return((int) color_2->count-(int) color_1->count);
  1761. }
  1762. X
  1763. void XMakeStandardColormap(display,visual_info,resource_info,pixel_info,image,
  1764. X  map_info)
  1765. Display
  1766. X  *display;
  1767. X
  1768. XXVisualInfo
  1769. X  *visual_info;
  1770. X
  1771. XXResourceInfo
  1772. X  *resource_info;
  1773. X
  1774. XXPixelInfo
  1775. X  *pixel_info;
  1776. X
  1777. Image
  1778. X  *image;
  1779. X
  1780. XXStandardColormap
  1781. X  *map_info;
  1782. {
  1783. X  Colormap
  1784. X    colormap;
  1785. X
  1786. X  int
  1787. X    status;
  1788. X
  1789. X  register int
  1790. X    i;
  1791. X
  1792. X  unsigned int
  1793. X    gray_value,
  1794. X    number_colors,
  1795. X    retain_colors;
  1796. X
  1797. X  XColor
  1798. X    color,
  1799. X    *colors,
  1800. X    *p;
  1801. X
  1802. X  if (resource_info->map_type != (char *) NULL)
  1803. X    {
  1804. X      /*
  1805. X        Standard Colormap is already defined (i.e. xstdcmap).
  1806. X      */
  1807. X      if (pixel_info->pixels != (unsigned long *) NULL)
  1808. X        (void) free((char *) pixel_info->pixels);
  1809. X      XGetPixelInfo(display,visual_info,map_info,resource_info,image,
  1810. X        pixel_info);
  1811. X      return;
  1812. X    }
  1813. X  if ((visual_info->class != DirectColor) && (visual_info->class != TrueColor))
  1814. X    if ((image->class == DirectClass) ||
  1815. X        (image->colors > visual_info->colormap_size))
  1816. X      {
  1817. X        /*
  1818. X          Image has more colors than the visual supports.
  1819. X        */
  1820. X        QuantizeImage(image,(unsigned int) visual_info->colormap_size,
  1821. X          resource_info->tree_depth,resource_info->dither,
  1822. X          resource_info->colorspace,False);
  1823. X        image->class=DirectClass;  /* promote to DirectClass */
  1824. X      }
  1825. X  /*
  1826. X    Free previous and create new colormap.
  1827. X  */
  1828. X  XFreeStandardColormap(display,visual_info,pixel_info,map_info);
  1829. X  colormap=XDefaultColormap(display,visual_info->screen);
  1830. X  if (visual_info->visual != XDefaultVisual(display,visual_info->screen))
  1831. X    colormap=XCreateColormap(display,
  1832. X      XRootWindow(display,visual_info->screen),visual_info->visual,
  1833. X      visual_info->class == DirectColor ? AllocAll : AllocNone);
  1834. X  if (colormap == (Colormap) NULL)
  1835. X    Error("unable to create colormap",(char *) NULL);
  1836. X  /*
  1837. X    Initialize the Standard Colormap attributes.
  1838. X  */
  1839. X  map_info->colormap=colormap;
  1840. X  map_info->red_max=visual_info->red_mask;
  1841. X  map_info->red_mult=map_info->red_max > 0 ? 1 : 0;
  1842. X  if (map_info->red_max > 0)
  1843. X    while ((map_info->red_max & 0x01) == 0)
  1844. X    {
  1845. X      map_info->red_max>>=1;
  1846. X      map_info->red_mult<<=1;
  1847. X    }
  1848. X  map_info->green_max=visual_info->green_mask;
  1849. X  map_info->green_mult=map_info->green_max > 0 ? 1 : 0;
  1850. X  if (map_info->green_max > 0)
  1851. X    while ((map_info->green_max & 0x01) == 0)
  1852. X    {
  1853. X      map_info->green_max>>=1;
  1854. X      map_info->green_mult<<=1;
  1855. X    }
  1856. X  map_info->blue_max=visual_info->blue_mask;
  1857. X  map_info->blue_mult=map_info->blue_max > 0 ? 1 : 0;
  1858. X  if (map_info->blue_max > 0)
  1859. X    while ((map_info->blue_max & 0x01) == 0)
  1860. X    {
  1861. X      map_info->blue_max>>=1;
  1862. X      map_info->blue_mult<<=1;
  1863. X    }
  1864. X  map_info->base_pixel=0;
  1865. X  XGetPixelInfo(display,visual_info,map_info,resource_info,image,pixel_info);
  1866. X  /*
  1867. X    Allocating colors in server colormap is based on visual class.
  1868. X  */
  1869. X  switch (visual_info->class)
  1870. X  {
  1871. X    case StaticGray:
  1872. X    case StaticColor:
  1873. X    {
  1874. X      /*
  1875. X        Define Standard Colormap for StaticGray or StaticColor visual.
  1876. X      */
  1877. X      number_colors=image->colors;
  1878. X      colors=(XColor *) malloc(visual_info->colormap_size*sizeof(XColor));
  1879. SHAR_EOF
  1880. true || echo 'restore of ImageMagick/X.c failed'
  1881. fi
  1882. echo 'End of  part 16'
  1883. echo 'File ImageMagick/X.c is continued in part 17'
  1884. echo 17 > _shar_seq_.tmp
  1885. exit 0
  1886. exit 0 # Just in case...
  1887.