home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #30 / NN_1992_30.iso / spool / comp / windows / x / 20211 < prev    next >
Encoding:
Internet Message Format  |  1992-12-15  |  2.8 KB

  1. Path: sparky!uunet!mcsun!uknet!lsl!snail
  2. From: snail@lsl.co.uk
  3. Newsgroups: comp.windows.x
  4. Subject: Re: Why the program cannot work?
  5. Message-ID: <1992Dec15.123014.2838@lsl.co.uk>
  6. Date: 15 Dec 92 11:30:14 GMT
  7. References: <1992Dec14.112849.21727@sparc4.ncu.edu.tw>
  8. Organization: Laser-Scan Ltd., Cambridge
  9. Lines: 83
  10.  
  11. In article <1992Dec14.112849.21727@sparc4.ncu.edu.tw>, u438813@imux120.ncu.edu.tw (Lin Wei-Ting) writes:
  12.  
  13. Well, I'll have a stab at this. Some of the code below isn't needed, see
  14. comments in the code. Also this code appears to be moving bytes from left to
  15. right and vice versa.
  16.  
  17. > void inverse(item, event)
  18. >     Panel_item    item;
  19. >     Event        *event;
  20. > {
  21. >     t_window1_objects    *ip = (t_window1_objects *) xv_get(item, XV_KEY_DATA, INSTANCE);
  22. >     unsigned long p1,p2;
  23. >     int    y;
  24. >     int    lx,rx;
  25. >     int    i,j;
  26. >     unsigned int k;
  27.  
  28. >     width=xv_get(obj,CANVAS_WIDTH);
  29. >     height=xv_get(obj,CANVAS_HEIGHT);
  30.  
  31. /* The next two lines are not needed, since the XGetImage sets everything up */
  32. >DELETE     ximage=XCreateImage(theDisplay,theVisual,theDepth,ZPixmap,
  33. >DELETE                         0,0,width,height,8,0);
  34. >DELETE     ximage->data=(char *)malloc(sizeof(char)*width*height);
  35.  
  36. >     ximage=XGetImage(theDisplay,xwin,0,0,width,height,AllPlanes,ZPixmap);
  37. >     for(i=0;i<height;i++)
  38. >         {
  39. >         data1=(char *)(ximage->data)+i*width;
  40.  
  41. ZPixmap lists the pixels in scan line order with ximage->bits_per_pixel bits
  42. used per pixel.
  43.  
  44. Having never done anything with ZPixmap I can't be sure, but I doubt if the
  45. following is correct. For a definate result you could use the XGetPixel() and
  46. XPutPixel() routines here, but they would be slow. Heres the code any way
  47.  
  48. use this (SLOW):-
  49. This is coded for demonstration, not practice. Easy to optimise anyway.
  50.  
  51. >         for(j=0;j < (width * 8) /2;j++) /* 8 bits/byte*/
  52. >             {
  53.  
  54.             temp_pixel1 = XGetPixel(ximage, j, i);
  55.                         temp_pixel2 = XGetPixel(ximage, j + (width * 8) / 2,i);
  56.             XPutPixel(ximage, j, i, temp_pixel2);
  57.                         XPutPixel(ximage, j + (width * 8) / 2, i, temp_pixel1);
  58.  
  59. in place of this (which I'm not sure about):-
  60.  
  61. >         for(j=0;j<width/2;j++)
  62. >             {
  63. >             k=*(data1+j);
  64. >             *(data1+j)=*(data1+width-1-j);
  65. >             *(data1+width-1-j)=k;
  66.  
  67. >             }
  68. >         }
  69. >     XPutImage(theDisplay,xwin,theGC,ximage,0,0,0,0,width,height);
  70.  
  71. /* I doubt if this next line is needed */
  72. >     XFlush(theDisplay);
  73.  
  74. /* Next line not needed, never allocated anyway (I think it refered to
  75. ximage->data, which was never allocated by the user anyway - I deleted that
  76. line */
  77.  
  78. >DELETE     free(data);
  79.  
  80. >     XDestroyImage(ximage);
  81.  
  82. /* I doubt if this next line is needed*/
  83. >     XFlush(theDisplay);
  84. > }
  85.  
  86. Thats my stab at it, if someone can shed some light on the ZPixmap stuff, great.
  87. -- 
  88. snail@lsl.co.uk      
  89.  
  90. muso/unix joke: "which debugger do you use?"
  91.                 "I use dbx..."
  92.                 "Oh really, we use Dolby C..."
  93. Motorola inside.
  94.