home *** CD-ROM | disk | FTP | other *** search
/ ftp.mactech.com 2010 / ftp.mactech.com.tar / ftp.mactech.com / csmpdigest / csmp-digest-v3-074 < prev    next >
Text File  |  2010-09-21  |  55KB  |  1,503 lines

  1. Received-Date: Tue, 6 Dec 1994 17:53:06 +0100
  2. From: pottier@clipper.ens.fr (Francois Pottier)
  3. Subject: csmp-digest-v3-074
  4. To: csmp-digest@ens.fr
  5. Date: Tue, 6 Dec 1994 17:53:07 +0100 (MET)
  6. X-Mailer: ELM [version 2.4 PL23]
  7. Mime-Version: 1.0
  8. Content-Type: text/plain; charset=ISO-8859-1
  9. Content-Transfer-Encoding: 8bit
  10. Errors-To: listman@ens.fr
  11. Reply-To: pottier@clipper.ens.fr
  12. X-Sequence: 80
  13.  
  14. C.S.M.P. Digest             Tue, 06 Dec 94       Volume 3 : Issue 74
  15.  
  16. Today's Topics:
  17.  
  18.         Faster SetCPixel Alternatives?
  19.         Newbie Q Regarding Window Updates
  20.         Pascal ProcPtr Example?
  21.         QDGX and Pict resources
  22.         TransSkel 3.18 (THINK C, Metrowerks) now available
  23.         how can I implement-program Plug-Ins?
  24.         using HLock before memcpy
  25.  
  26.  
  27.  
  28. The Comp.Sys.Mac.Programmer Digest is moderated by Francois Pottier
  29. (pottier@clipper.ens.fr).
  30.  
  31. The digest is a collection of article threads from the internet newsgroup
  32. comp.sys.mac.programmer.  It is designed for people who read c.s.m.p. semi-
  33. regularly and want an archive of the discussions.  If you don't know what a
  34. newsgroup is, you probably don't have access to it.  Ask your systems
  35. administrator(s) for details.  If you don't have access to news, you may
  36. still be able to post messages to the group by using a mail server like
  37. anon.penet.fi (mail help@anon.penet.fi for more information).
  38.  
  39. Each issue of the digest contains one or more sets of articles (called
  40. threads), with each set corresponding to a 'discussion' of a particular
  41. subject.  The articles are not edited; all articles included in this digest
  42. are in their original posted form (as received by our news server at
  43. nef.ens.fr).  Article threads are not added to the digest until the last
  44. article added to the thread is at least two weeks old (this is to ensure that
  45. the thread is dead before adding it to the digest).  Article threads that
  46. consist of only one message are generally not included in the digest.
  47.  
  48. The digest is officially distributed by two means, by email and ftp.
  49.  
  50. If you want to receive the digest by mail, send email to listserv@ens.fr
  51. with no subject and one of the following commands as body:
  52.     help                        Sends you a summary of commands
  53.     subscribe csmp-digest Your Name    Adds you to the mailing list
  54.     signoff csmp-digest            Removes you from the list
  55. Once you have subscribed, you will automatically receive each new
  56. issue as it is created.
  57.  
  58. The official ftp info is //ftp.dartmouth.edu/pub/csmp-digest.
  59. Questions related to the ftp site should be directed to
  60. scott.silver@dartmouth.edu. Currently no previous volumes of the CSMP
  61. digest are available there.
  62.  
  63. Also, the digests are available to WAIS users.  To search back issues
  64. with WAIS, use comp.sys.mac.programmer.src. With Mosaic, use
  65. http://www.wais.com/wais-dbs/comp.sys.mac.programmer.html.
  66.  
  67.  
  68. -------------------------------------------------------
  69.  
  70. >From smithab@hydra.syr.edu (Core Dumped)
  71. Subject: Faster SetCPixel Alternatives?
  72. Date: 12 Nov 1994 18:27:26 GMT
  73. Organization: Syracuse University, Syracuse, NY
  74.  
  75. Hi. I am working on a fractal program which has to assemble a 640 by 480 
  76. picture pixel by pixel.  Currently I am using SetCPixel since the color 
  77. of each pixel I set is different from the previous.  What I would like to 
  78. know, is how to draw directly into the GWorld PixMap.
  79.  
  80. I have tried this:
  81.     
  82.     I am trying to use 'baseAddr' to find the PixMap location, and 
  83. write to it directly, but my colors get messed up, and can't get rowBytes 
  84. to give me any information.  I am writing to a 40 by 40 GWorld, which is 
  85. 16-bit color.  Seems to me that rowBytes should be 80, but it's zero!?
  86. Also, if I remove rowBytes from my assignment, and manually replace it 
  87. with 80, that results in a skewing of the picture. Even more curiously, 
  88. using 96 for the offset to the next line gives perfect alignment, but 
  89. crashes the program with Error 11 at the end of the GWorld.  
  90.  
  91. Do powermac GWorlds have 16 bytes of some extra information in each line?
  92.  
  93. Perhaps my color structure is wrong also. I was assuming that 16bit color 
  94. looks like this in memory (each letter = 1 bit):
  95.  
  96.         GGGGGRRRRRBBBBBM
  97.                 ^
  98.                 Least sig. bit at the left.
  99.  
  100. Is this correct?
  101.  
  102. If so, why can't I write a short word directly into memory? I am having 
  103. to do this write in two calls, one for each byte.
  104.  
  105.  
  106. Any info on the above would be great.
  107.  
  108. -Adam Smith
  109. smithab@mailbox.syr.edu
  110.  
  111.  
  112.  
  113. +++++++++++++++++++++++++++
  114.  
  115. >From mjew@dnai.com (Matthew Jew)
  116. Date: Wed, 16 Nov 1994 11:09:01 -0800
  117. Organization: Bold Print Inc.
  118.  
  119. In article <3a31ee$n1c@newstand.syr.edu>, smithab@hydra.syr.edu (Core
  120. Dumped) wrote:
  121.  
  122. > Hi. I am working on a fractal program which has to assemble a 640 by 480 
  123. > picture pixel by pixel.  Currently I am using SetCPixel since the color 
  124. > of each pixel I set is different from the previous.  What I would like to 
  125. > know, is how to draw directly into the GWorld PixMap.
  126.  
  127. Yes, SetCPixel is not the fastest thing in the world, but I was always 
  128. taught that mucking around with the pixmap directly was very very very bad idea.
  129. Your drawing routine (as described) sounds like it would work *only* with 
  130. 16-bit color pixmaps. Will your program need to handle other color depths?
  131. Tread carefully. Doing things like this will almost guarantee your program will
  132. break when the system software changes.
  133.  
  134. +++++++++++++++++++++++++++
  135.  
  136. >From kenp@tuli (Kenneth Prehoda)
  137. Date: 16 Nov 1994 20:33:09 GMT
  138. Organization: Division of Information Technology
  139.  
  140. Matthew Jew (mjew@dnai.com) wrote:
  141. : In article <3a31ee$n1c@newstand.syr.edu>, smithab@hydra.syr.edu (Core
  142. : Dumped) wrote:
  143.  
  144. : > Hi. I am working on a fractal program which has to assemble a 640 by 480 
  145. : > picture pixel by pixel.  Currently I am using SetCPixel since the color 
  146. : > of each pixel I set is different from the previous.  What I would like to 
  147. : > know, is how to draw directly into the GWorld PixMap.
  148. : > 
  149.  
  150. : Yes, SetCPixel is not the fastest thing in the world, but I was always 
  151. : taught that mucking around with the pixmap directly was very very
  152. : very bad idea.
  153.  
  154. Then you were taught incorrectly.  It is true that mucking around 
  155. with a windows's pixmap, or anything else that would draw directly
  156. to the screen is asking for trouble.  However, there is absolutely
  157. nothing wrong with drawing directly into an offscreen pixmap.  In
  158. fact, this is the Apple sanctioned way to do fast drawing:  Do all
  159. of your direct drawing to an offscreen GWorld and copybits that
  160. to the screen.
  161.  
  162. : Your drawing routine (as described) sounds like it would work *only* with 
  163. : 16-bit color pixmaps. Will your program need to handle other color depths?
  164. : Tread carefully. Doing things like this will almost guarantee your
  165. : program will break when the system software changes.
  166.  
  167. If your program needs to handle different color depths, then it can
  168. make gworlds with different depths.  Not complicated.  
  169.  
  170. Your warnings are not necessary.  This WILL NOT break when system software
  171. changes.  If it does, then a lot of currently well-behaved programs
  172. will.
  173.  
  174. -Ken Prehoda
  175. Department of Biochemistry
  176. University of Wisconsin-Madison
  177. kenp@nmrfam.wisc.edu
  178.  
  179. +++++++++++++++++++++++++++
  180.  
  181. >From mjew@dnai.com (Matthew Jew)
  182. Date: Wed, 16 Nov 1994 16:46:57 -0800
  183. Organization: Bold Print Inc.
  184.  
  185. In article <3adqa5$7ti@news.doit.wisc.edu>, kenp@tuli (Kenneth Prehoda) wrote:
  186.  
  187. > : Yes, SetCPixel is not the fastest thing in the world, but I was always 
  188. > : taught that mucking around with the pixmap directly was very very
  189. > : very bad idea.
  190. > Then you were taught incorrectly.  It is true that mucking around 
  191. > with a windows's pixmap, or anything else that would draw directly
  192. > to the screen is asking for trouble.  However, there is absolutely
  193. > nothing wrong with drawing directly into an offscreen pixmap.  In
  194. > fact, this is the Apple sanctioned way to do fast drawing:  Do all
  195. > of your direct drawing to an offscreen GWorld and copybits that
  196. > to the screen.
  197.  
  198. Yes, you are right. I wrote before I thought carefully about what he was asking.
  199. Thanks for pointing that out.
  200.  
  201. > If your program needs to handle different color depths, then it can
  202. > make gworlds with different depths.  Not complicated.  
  203.  
  204. However, in his original question, he was asking *specifically* about the
  205. format for 16-bit color pixmaps, and how to write to them. Therefore, even
  206. if he did make a pixmap of a different depth (not complicated), the
  207. routine would have to be rewritten to handle the differently formatted
  208. pixmap (more complicated).
  209.  
  210. +++++++++++++++++++++++++++
  211.  
  212. >From macneils@aol.com (MacneilS)
  213. Date: 16 Nov 1994 22:05:13 -0500
  214. Organization: America Online, Inc. (1-800-827-6364)
  215.  
  216. In article <mjew-1611941109010001@dynamic-206.dnai.com>, mjew@dnai.com
  217. (Matthew Jew) writes:
  218.  
  219. >>>>>>
  220. but I was always taught that mucking around with the pixmap directly was
  221. very very very bad idea.
  222. <<<<<<
  223.  
  224. develop Issue 17 says that it's 100% OK to change the pixmap of a GWorld
  225. directly, and that doing such will be supported on ALL future machines.
  226. The article also tells you the best way to do it, and when to do it.
  227.  
  228. Take Care,
  229. MacneilS@aol.com
  230.  
  231. +++++++++++++++++++++++++++
  232.  
  233. >From smithab@hydra.syr.edu (Core Dumped)
  234. Date: 17 Nov 1994 12:49:49 GMT
  235. Organization: Syracuse University
  236.  
  237. >> If your program needs to handle different color depths, then it can
  238. >> make gworlds with different depths.  Not complicated.  
  239. >> 
  240. >
  241. >However, in his original question, he was asking *specifically* about the
  242. >format for 16-bit color pixmaps, and how to write to them. Therefore, even
  243. >if he did make a pixmap of a different depth (not complicated), the
  244. >routine would have to be rewritten to handle the differently formatted
  245. >pixmap (more complicated).
  246.  
  247.     Yes, I did ask specifically about 16-bit GWorlds. I am using 16bit
  248. because it is a nice compromise of GWorld size and image quality.  Having 
  249. my routine only write to 16-bit GWorlds also means that I don't have to 
  250. use any conditionals or function pointers to switch between separate 
  251. drawing routines for each possible bit-depth GWorld, which makes for a 
  252. simpler, faster program.  I just let copybits take care of the color 
  253. translation, so my program is optimized for 16-bit monitors (though 
  254. performance doesn't suffer much at 32-bits).  It's just a fractal 
  255. program, and it doesn't ever use the full 32768 colors anyways :) 
  256.  
  257. Thanks to everyone who helped me out with this! I'm currently trying to
  258. track down some of these past 'Develop's.
  259.  
  260. -Adam
  261. smithab@mailbox.syr.edu
  262.  
  263. +++++++++++++++++++++++++++
  264.  
  265. >From Bruce@hoult.actrix.gen.nz (Bruce Hoult)
  266. Date: Sat, 19 Nov 1994 12:56:58 +1300 (NZDT)
  267. Organization: (none)
  268.  
  269. mjew@dnai.com (Matthew Jew) writes:
  270. > In article <3a31ee$n1c@newstand.syr.edu>, smithab@hydra.syr.edu (Core
  271. > Dumped) wrote:
  272. > > Hi. I am working on a fractal program which has to assemble a 640 by 480 
  273. > > picture pixel by pixel.  Currently I am using SetCPixel since the color 
  274. > > of each pixel I set is different from the previous.  What I would like to 
  275. > > know, is how to draw directly into the GWorld PixMap.
  276. > > 
  277. > Yes, SetCPixel is not the fastest thing in the world, but I was always 
  278. > taught that mucking around with the pixmap directly was very very very bad idea.
  279. > Your drawing routine (as described) sounds like it would work *only* with 
  280. > 16-bit color pixmaps. Will your program need to handle other color depths?
  281. > Tread carefully. Doing things like this will almost guarantee your program will
  282. > break when the system software changes.
  283.  
  284. No, GWorlds are guarenteed always to work.  If he creates a 4-bit deep GWorld
  285. then he will always get a 4-bit deep GWorld, even in the far distant future,
  286. and the layout of the pixmap will always be the same.  And no matter what Apple
  287. does to the screen hardware, CopyBits will always know how to copy from a
  288. 4-bit GWorld to whatever the new screen format is -- it may not always be
  289. optimally fast, but it will always work.
  290.  
  291. -- Bruce
  292.  
  293. +++++++++++++++++++++++++++
  294.  
  295. >From bhamlin@netcom.com (Brian Hamlin)
  296. Date: Mon, 21 Nov 1994 00:33:04 GMT
  297. Organization: NETCOM On-line Communication Services (408 261-4700 guest)
  298.  
  299.   If you want to set pixels directly in GWorlds:
  300.   - use the flag 'keepLocal' when calling NewGWorld
  301.   - use routines GetGWorldPixMap(), then GetPixBaseAddr() to 
  302.      find pixels
  303.   - LockPixels whenever accessing bits
  304.   - remember to clear the high bit of rowBytes when calc' bit positions !
  305.  
  306.   When CopyBits()'ing from a GWorld
  307.   - don't mix GetPort()/SetPort() with GetGWorld()/SetGWorld()
  308.   - always SetGWorld to the dst GrafPort
  309.   - set ForeColor(blackColor) BackColor(whiteColor) in dst Port ! 
  310.  
  311. -- 
  312. --
  313. Brian M. Hamlin                          noEsis software construction
  314. bhamlin@netcom.com                                    +1 510 271-7971
  315.  
  316.  
  317. +++++++++++++++++++++++++++
  318.  
  319. >From 103t_english@west.cscwc.pima.edu
  320. Date: 21 Nov 94 17:21:31 MST
  321. Organization: (none)
  322.  
  323. In article <bhamlinCzLDJ4.Lq9@netcom.com>, bhamlin@netcom.com (Brian Hamlin) writes:
  324. >   If you want to set pixels directly in GWorlds:
  325. >   - use the flag 'keepLocal' when calling NewGWorld
  326.  
  327. I thought that one could draw to graphics card cache as well if one wanted?
  328.  
  329.  
  330. Lawson
  331.  
  332. ---------------------------
  333.  
  334. >From ineluki@u.washington.edu (Paul McElroy)
  335. Subject: Newbie Q Regarding Window Updates
  336. Date: 22 Nov 1994 20:01:40 GMT
  337. Organization: University of Washington
  338.  
  339. I have a simple question.  What is the correct procedure to make sure the 
  340. correct window is updated on an updateEvt?  My WaitNextEvent loop 
  341. includes:
  342.  
  343.     switch(event)
  344.     {
  345.         case updateEvt:
  346.             HandleUpdate((WindowPtr)event->message);
  347.             break;
  348.  
  349. Ok, and down here in HandleUpdate, I get 'window', the Window Pointer 
  350. that was passed from above, and the usual stuff:
  351.  
  352.     GetPort(&savePort);
  353.     SetPort(window);
  354.  
  355.     BeginUpdate(window);
  356.     DrawControls(window);
  357.     ...etc...
  358.     EndUpdate(window);
  359.     SetPort(savePort);
  360.  
  361. Now, how do I distinguish between one window and another here?  My app 
  362. has two windows displayed at once, one with a pic and a control, the 
  363. other with a different pic and controls.  What is the procedure to update 
  364. the correct window with the correct pic and controls?  Is it with a 
  365. switch(window) or if(window)?  Thanks for any replies.
  366.  
  367. ineluki@u.washington.edu
  368.  
  369. +++++++++++++++++++++++++++
  370.  
  371. >From Eric Kidd <emk@dartmouth.edu>
  372. Date: 22 Nov 1994 22:25:47 GMT
  373. Organization: Dartmouth College
  374.  
  375. In article <3atin4$m6a@nntp1.u.washington.edu> Paul McElroy,
  376. ineluki@u.washington.edu writes:
  377. > Now, how do I distinguish between one window and another here?  My app 
  378. > has two windows displayed at once, one with a pic and a control, the 
  379. > other with a different pic and controls.  What is the procedure to
  380. update 
  381. > the correct window with the correct pic and controls?  Is it with a 
  382. > switch(window) or if(window)?  Thanks for any replies.
  383.  
  384. In general, you can identify windows on screen by using the refCon field
  385. in the window record. Assign some unique value to this when the window
  386. is created (perhaps a pointer to the data describing the window) and
  387. use this to identify your windows. (Either switch or if can be used,
  388. depending on the situation and your style.) In the following code, I
  389. assign refCon a pointer to data which:
  390.     1) identifies the type of window
  391.     2) provides info on drawing it
  392. The latter varies, so I create two different data records with the ID
  393. field at the top of each.
  394.  
  395. For example (from memory, my IM books are packed--check your header files
  396.     for spelling errors and whatnot if this won't compile):
  397.  
  398. typedef struct {
  399.     short id;
  400.     ControlHandle myControl;
  401.     PictHandle myPict;
  402. } myWinData1;
  403.  
  404. typedef struct {
  405.     short id;
  406.     ControlHandle myControl;
  407.     ControlHandle myOtherControl;
  408.     PictHandle myPict;
  409. } myWinData2;        /* Yes, unions work as well. */
  410.  
  411. # define    WINTYPE1    (1)
  412. # define    WINTYPE2    (2)
  413.  
  414. .... at window creation (of the first type)
  415.  
  416.     // create window here
  417.     
  418.     myWinData1* data = (myWinData1*) NewPtr( sizeof(myWinData1) );
  419.         // Handles     work,     too
  420.         // check to see if data == 0. Don't proceed if it does,
  421.         // because that means the system couldn't allocate
  422.         // memory.
  423.     win->refCon = (long) data;
  424.     data->id = WINTYPE1;
  425.     
  426.     // fill out rest of info
  427.  
  428.  
  429. .... at drawing time
  430.  
  431.         // since the ID is in the same place in both structures
  432.         //    we can pick either type to check it. Once we know
  433.         //    what it is, the doDrawWinTypeX functions can coerce
  434.         //    the refCon to the right pointer type internally.
  435.         
  436.         // There is a way to identify DA refCons, but it has become
  437.         //    mostly irrelevant under System 7. See the manual.
  438.     switch ( ((myWinData1*) theWindow->refCon)->id )
  439.     {
  440.         case WINTYPE1:
  441.             doDrawWinType1( theWindow );
  442.             break;
  443.         
  444.         case WINTYPE2:
  445.             doDrawWinType2( theWindow );
  446.             break;
  447.     };
  448.     
  449.  
  450. That's very rough, but it may point you in the correct direction. If
  451. you'd like a better presentation of this, mail me at emk@dartmouth.edu,
  452. (or wait for someone else to elaborate). My books will be unpacked
  453. when I return from Thanksgiving (I'm headed home tomorrow morning).
  454.  
  455. Have fun programming and consider getting Inside Macintosh: Toolbox
  456. Essentials for a more enjoyable experience. The sample code is very good,
  457. and helped me to implement a great number of things that would have kept
  458. me up all night otherwise.
  459.  
  460. ---------------------------
  461.  
  462. >From pzwiefel@students.wisc.edu (Zwiefelhofer)
  463. Subject: Pascal ProcPtr Example?
  464. Date: Sat, 19 Nov 1994 14:20:41 -0600
  465. Organization: Division of Information Technology
  466.  
  467. I'd like to give the user the ability to choose between several transfer
  468. functions in a program. I would like to use functions as procedure
  469. pointers for convenience. 
  470.  
  471. Does anyone have any Pascal examples of how to declare my procedures or
  472. functions so that I can use the @ operator on them and then pass a pointer
  473. to them depending on which function the user chose?
  474.  
  475. Thanks.
  476.  
  477. Dave
  478.  
  479. +++++++++++++++++++++++++++
  480.  
  481. >From pottier@drakkar.ens.fr (Francois Pottier)
  482. Date: 21 Nov 1994 12:56:48 GMT
  483. Organization: Ecole Normale Superieure, PARIS, France
  484.  
  485. In article <pzwiefel-1911941420410001@f181-092.net.wisc.edu>,
  486. Zwiefelhofer <pzwiefel@students.wisc.edu> wrote:
  487. >I'd like to give the user the ability to choose between several transfer
  488. >functions in a program. I would like to use functions as procedure
  489. >pointers for convenience. 
  490.  
  491. If you want to use function pointers, then you will have to use some
  492. inline assembly. Not much, but it can be a problem if you don't assembly
  493. at all.
  494.  
  495. There is a way to do it in pure Think Pascal without pointers. I don't know
  496. what you mean by a transfer function; let's say it's a function from reals
  497. to reals. You can declare
  498.  
  499. function Transfer1 (x : real) : real;
  500. blah blah...
  501.  
  502. function Transfer2 (x : real) : real;
  503. more blah blah...
  504.  
  505. procedure ComputeUsingTransferFunction (function f (x : real) : real);
  506. begin
  507.   ... use f ...
  508. end;
  509.  
  510. and finally you can call ComputeUsingTransferFunction(Transfer1)
  511. or ComputeUsingTransferFunction(Transfer2).
  512.  
  513. Unfortunately, as far as I know, you have to pass function names as
  514. parameters to ComputeUsingTransferFunction; I mean, you can't use a variable
  515. of type "function (x : real) : real".
  516.  
  517. The Think Pascal doc should explain all this in detail...
  518.  
  519. Hope this helps
  520.  
  521.  
  522.  
  523.  
  524. -- 
  525. Francois Pottier                                            pottier@dmi.ens.fr
  526. - ----------------------------------------------------------------------------
  527. Check my WWW page at http://acacia.ens.fr:8080/home/pottier/index.html ...
  528.  
  529. +++++++++++++++++++++++++++
  530.  
  531. >From pzwiefel@students.wisc.edu (Zwiefelhofer)
  532. Date: Sun, 20 Nov 1994 19:28:27 -0600
  533. Organization: Division of Information Technology
  534.  
  535. In article <Jaeger-2011941747210001@slip-2-40.ots.utexas.edu>,
  536. Jaeger@fquest.com (Brian Stern) wrote:
  537.  
  538. > Here's an example of jumping to a procedure that takes no parameters:
  539. >  procedure JumpToOldFilter (theFilterProc: ProcPtr);
  540. > {Move the procptr to the stack and JSR to it }
  541. >  inline
  542. >   $205F, $4E90;      {MoveA.L  (A7)+, A0 ;   JSR (A0) }
  543. > You can modify this based on the parameters that you need to pass and/or
  544. > return.  Look at the disassembled code that the compiler generates to call
  545. > a procedure like the one you want to call.  Model your inline procedure
  546. > after that code.  Obviously this example won't work on the PPC.
  547.  
  548. I'm afraid this is beyond me. Do I really need to muck about with
  549. assembly? I thought that there would be a comparatively simple method of
  550. declaring a specific type of procPtr for functions that take one extended
  551. and return one extended.
  552.  
  553. Is this possible? Any examples? Ideas?
  554.  
  555. Thanks.
  556.  
  557. -Dave
  558.  
  559. +++++++++++++++++++++++++++
  560.  
  561. >From greg@cosc.canterbury.ac.nz (Greg Ewing)
  562. Date: 21 Nov 1994 04:36:59 GMT
  563. Organization: University of Canterbury, Christchurch, New Zealand
  564.  
  565.  
  566. In article <pzwiefel-2011941928270001@f180-222.net.wisc.edu>, pzwiefel@students.wisc.edu (Zwiefelhofer) writes:
  567. |> I thought that there would be a comparatively simple method of
  568. |> declaring a specific type of procPtr for functions that take one extended
  569. |> and return one extended.
  570.  
  571. Unfortunately, in Pascal there is no such method.
  572. Pascal has no notion of a pointer to a procedure
  573. the way C has. Applying @ to a procedure is just
  574. a kludge that was added to provide a way of passing
  575. procedures to the toolbox. The Pascal compiler
  576. has no idea what type of pointer this is, and
  577. doesn't have the concepts to understand even if
  578. you tried to explain to it.
  579.  
  580. If you are using Object Pascal there is a much
  581. better method of achieving what you want.
  582. Define an object type which has a method for
  583. carrying out whatever it is you want to do,
  584. and define subtypes which implement it in
  585. different ways. e.g.
  586.  
  587.   type
  588.  
  589.     Transformer = object
  590.       procedure MungeIt(inp: MyStuff; var out: MyStuff);
  591.     end;
  592.  
  593.     FirstTransformer = object(Transformer)
  594.       procedure MungeIt(inp: MyStuff; var out: MyStuff); override;
  595.     end;
  596.  
  597.     SecondTransformer = object(Transformer)
  598.       procedure MungeIt(inp: MyStuff; var out: MyStuff); override;
  599.     end;
  600.  
  601.     {etc...}
  602.  
  603.     procedure FirstTransformer.MungeIt(inp: MyStuff; var out: MyStuff);
  604.     begin
  605.       {Munge your stuff the first way}
  606.     end;
  607.  
  608.     procedure SecondTransformer.MungeIt(inp: MyStuff; var out: MyStuff);
  609.     begin
  610.       {Munge your stuff the second way}
  611.     end;
  612.  
  613.     {etc...}
  614.  
  615. Now make an instance of each of these objects and
  616. let the user choose one of them somehow, e.g.
  617.  
  618.   var
  619.     transformers: array[1..numTransformers] of Transformer;
  620.  
  621.   procedure InitialiseTransformers;
  622.   {Call this when you're initialising your application}
  623.   var
  624.     t1: FirstTransformer;
  625.     t2: SecondTransformer;
  626.     {etc}
  627.   begin
  628.     new(t1);
  629.     transformers[1] := t1;
  630.     new(t2);
  631.     transformers[2] := t2;
  632.     {etc}
  633.   end;
  634.  
  635.   procedure ApplyATransformer(whichOne: integer; inp: MyStuff; var out: MyStuff);
  636.   begin
  637.     transformers[whichOne].MungeIt(inp, out);
  638.   end;
  639.  
  640. There are many ways you use this stuff. The point is that
  641. you can pass around Transformers the same way you would
  642. procedure pointers, and call them easily and safely.
  643.  
  644. If you don't know about Object Pascal, find out -
  645. it makes a lot of things much easier, and is the
  646. basis of some very powerful GUI frameworks like
  647. MacApp and the Think Class Library.
  648.  
  649. |> -Dave
  650.  
  651. Greg Ewing, Computer Science Dept, +--------------------------------------+
  652. University of Canterbury,       | A citizen of NewZealandCorp, a      |
  653. Christchurch, New Zealand       | wholly-owned subsidiary of Japan Inc.|
  654. greg@cosc.canterbury.ac.nz       +--------------------------------------+
  655.  
  656. +++++++++++++++++++++++++++
  657.  
  658. >From ldo@waikato.ac.nz (Lawrence D'Oliveiro, Waikato University)
  659. Date: 22 Nov 94 10:06:44 +1300
  660. Organization: University of Waikato, Hamilton, New Zealand
  661.  
  662. In article <pzwiefel-2011941928270001@f180-222.net.wisc.edu>, pzwiefel@students.wisc.edu (Zwiefelhofer) writes:
  663. > In article <Jaeger-2011941747210001@slip-2-40.ots.utexas.edu>,
  664. > Jaeger@fquest.com (Brian Stern) wrote:
  665. >
  666. >> Here's an example of jumping to a procedure that takes no parameters:
  667. >>
  668. >>  procedure JumpToOldFilter (theFilterProc: ProcPtr);
  669. >> {Move the procptr to the stack and JSR to it }
  670. >>  inline
  671. >>   $205F, $4E90;      {MoveA.L  (A7)+, A0 ;   JSR (A0) }
  672. >>
  673. >>
  674. >> You can modify this based on the parameters that you need to pass and/or
  675. >> return.  Look at the disassembled code that the compiler generates to call
  676. >> a procedure like the one you want to call.  Model your inline procedure
  677. >> after that code.  Obviously this example won't work on the PPC.
  678. >
  679. > I'm afraid this is beyond me. Do I really need to muck about with
  680. > assembly? I thought that there would be a comparatively simple method of
  681. > declaring a specific type of procPtr for functions that take one extended
  682. > and return one extended.
  683.  
  684. Stay cool! The above two words of machine code are all you will need. You
  685. can use them to call any Pascal procedure or function, regardless of the
  686. arguments or function result type. For example, you want to call a function
  687. like
  688.  
  689.     Function F
  690.       (
  691.     X : Extended
  692.       ) : Extended;
  693.  
  694. You can do it like this:
  695.  
  696.     Function Call_F
  697.       (
  698.     X : Extended;
  699.     F : ProcPtr
  700.       ) : Extended;
  701.  
  702.     Inline
  703.         $205F,    { move.l (sp)+, a0 }
  704.         $4E90;    { jsr (a0) }
  705.  
  706. eg
  707.  
  708.     FPtr := @F;
  709.     Y := Call_F(X, FPtr)
  710.  
  711. The only rule to remember when defining the "Call_F" routine is that the
  712. argument list and function result types must match those of the routine you're
  713. going to call, except that Call_F takes an extra argument, which is the
  714. address of the routine to call. This must be the last argument. The inline
  715. code is always the same!
  716.  
  717. Lawrence D'Oliveiro                       fone: +64-7-856-2889
  718. Computer Services Dept                     fax: +64-7-838-4066
  719. University of Waikato            electric mail: ldo@waikato.ac.nz
  720. Hamilton, New Zealand    37^ 47' 26" S, 175^ 19' 7" E, GMT+13:00
  721.  
  722. +++++++++++++++++++++++++++
  723.  
  724. >From greg@cosc.canterbury.ac.nz (Greg Ewing)
  725. Date: 22 Nov 1994 01:50:21 GMT
  726. Organization: University of Canterbury, Christchurch, New Zealand
  727.  
  728.  
  729. In article <pzwiefel-2111940914280001@f180-163.net.wisc.edu>, pzwiefel@students.wisc.edu (Zwiefelhofer) writes:
  730. |> I really don't
  731. |> want to go through several if-then statements in a procedure that may be
  732. |> called several 100K times per session if I don't absolutely have to.
  733.  
  734. Have you considered using a case statement switching
  735. on an integer or enumerated type? If the range of
  736. cases is contiguous this should compile into a
  737. table lookup, which will be faster than a chain
  738. of if-thens if there are enough cases.
  739.  
  740. |> -Dave
  741.  
  742. Greg Ewing, Computer Science Dept, +--------------------------------------+
  743. University of Canterbury,       | A citizen of NewZealandCorp, a      |
  744. Christchurch, New Zealand       | wholly-owned subsidiary of Japan Inc.|
  745. greg@cosc.canterbury.ac.nz       +--------------------------------------+
  746.  
  747. +++++++++++++++++++++++++++
  748.  
  749. >From pzwiefel@students.wisc.edu (Zwiefelhofer)
  750. Date: Mon, 21 Nov 1994 21:30:49 -0600
  751. Organization: Division of Information Technology
  752.  
  753. In article <1994Nov22.100645.35467@waikato.ac.nz>, ldo@waikato.ac.nz
  754. (Lawrence D'Oliveiro, Waikato University) wrote:
  755.  
  756. > Stay cool! The above two words of machine code are all you will need.
  757.  
  758. Okay, I'll give it a go! Thanks.
  759.  
  760. -Dave
  761.  
  762. +++++++++++++++++++++++++++
  763.  
  764. >From obo@dec59.ruk.cuni.cz (Ondrej Bojar)
  765. Date: 21 Nov 1994 13:21:55 GMT
  766. Organization: Charles University Prague, Computer Center
  767.  
  768. When I wanted to do this (for updating windows), I had to ask a friend to
  769. create an MPW .o file of a C routine calling my proc (at procptr) with some
  770. params. I think pascal has only some routine called DOJSR (don't quote me)
  771. that doesn't allow to pass any parameters.
  772.  I think it's easier to use objects...
  773.  
  774.  
  775. ---------------------------
  776.  
  777. >From jaks@netcom.com (Eric Jackson)
  778. Subject: QDGX and Pict resources
  779. Date: Wed, 16 Nov 1994 20:47:07 GMT
  780. Organization: NETCOM On-line Communication Services (408 261-4700 guest)
  781.  
  782. I would like to be able to read in  a 'pict' recource from a resource
  783. file into my Quick Draw GX application.  This pict consists of a
  784. color bit map image.
  785.  
  786. In all of the examples that I have seen in the Quick Draw GX Developer CD
  787. the bit maps are of a type called 'pxmp'.
  788.  
  789. What I would like to do is to read my pict into a BitMapShape and them clip it.
  790. Any suggestions would be nice.
  791.  
  792. Eric Jaskson
  793. jaks@netcom.com
  794.  
  795.  
  796. +++++++++++++++++++++++++++
  797.  
  798. >From jaks@netcom.com (Eric Jackson)
  799. Date: Wed, 16 Nov 1994 22:57:09 GMT
  800. Organization: NETCOM On-line Communication Services (408 261-4700 guest)
  801.  
  802. In article <jaksCzDoEK.EHG@netcom.com>, Eric Jackson <jaks@netcom.com> wrote:
  803. >I would like to be able to read in  a 'pict' recource from a resource
  804. >file into my Quick Draw GX application.  This pict consists of a
  805. >color bit map image.
  806. >
  807. >In all of the examples that I have seen in the Quick Draw GX Developer CD
  808. >the bit maps are of a type called 'pxmp'.
  809. >
  810. >What I would like to do is to read my pict into a BitMapShape and them clip it.
  811. >Any suggestions would be nice.
  812. >
  813. >Eric Jaskson
  814. >jaks@netcom.com
  815. >
  816.  
  817. Well I have been able to draw my first gxShape that was imported from a
  818. picture.  There is a good discussion of how to do this in QuickDraw GX
  819. environment and utilities.
  820.  
  821. Here is some sample code that works:
  822.  
  823. void DoInitialization(gWindow)
  824. WindowPtr gWindow;
  825. {
  826.     gxTransform    PerspectiveTransform;
  827.     gxMapping        PerspectiveTransformMapping;
  828.     PicHandle        Picture = (PicHandle) GetResource ('PICT',128);
  829.     gxShape        aPictureShape;
  830.     Rect            PictureBox;
  831.     Point            styleStrech;
  832.  
  833.     PictureBox = (**Picture).picFrame;
  834.     
  835.     aPictureShape = GXNewShape(gxPictureType);
  836.     
  837.     styleStrech.v = 1;
  838.     styleStrech.h = 1;
  839.     
  840.     GXConvertPICTToShape(Picture, gxDefaultOptionsTranslation,&PictureBox,&PictureBox,
  841.                         styleStrech,aPictureShape, nil);
  842.                         
  843.     gShape = aPictureShape;
  844.  
  845. }
  846.  
  847. This code works with the *graphics shell.c* program shell that comes with
  848. the QuickDraw GX SDK, later on it will draw gShape for me automatically.
  849.  
  850. I still don't really understand how to get this into a BitMap shape yet
  851. but I will keep working. Shure does not seem to be a lot of discussion
  852. about Quick Draw GX basics on here yet.
  853.  
  854. Eric Jackson
  855. jaks@netcom.com
  856.  
  857.  
  858. +++++++++++++++++++++++++++
  859.  
  860. >From ldo@waikato.ac.nz (Lawrence D'Oliveiro, Waikato University)
  861. Date: 17 Nov 94 16:56:39 +1300
  862. Organization: University of Waikato, Hamilton, New Zealand
  863.  
  864. In article <jaksCzDoEK.EHG@netcom.com>, jaks@netcom.com (Eric Jackson) writes:
  865. > I would like to be able to read in  a 'pict' recource from a resource
  866. > file into my Quick Draw GX application.  This pict consists of a
  867. > color bit map image.
  868. >
  869. > In all of the examples that I have seen in the Quick Draw GX Developer CD
  870. > the bit maps are of a type called 'pxmp'.
  871. >
  872. > What I would like to do is to read my pict into a BitMapShape and them clip it.
  873. > Any suggestions would be nice.
  874.  
  875. Are you trying to
  876.  
  877.   a) read QuickDraw pictures in from PICT resources and convert them to
  878.      GX shapes, or
  879.   b) read flattened GX shapes in from resources and unflatten them?
  880.  
  881. The first is easy, the second is only slightly harder.
  882.  
  883. To convert a QuickDraw picture to a GX shape, you use GXConvertPICTToShape.
  884.  
  885. To unflatten a GX shape, you use GXUnflattenShape. There is source code for
  886. a routine called HandleToShape in the GX libraries, that should do exactly
  887. what you want.
  888.  
  889. By the way, Apple seems to have standardized on 'qdgx' as the OSType type
  890. code for GX shapes (as opposed to 'grfx', which some pre-release utilities
  891. used, and which I prefer :-)). So if you want to store a flattened GX shape
  892. in a resource, make it a resource of type 'qdgx'. Then when you copy it to
  893. the clipboard from ResEdit, it will display properly in other GX-savvy programs.
  894. And conversely, you can create the shape in another program, and paste it
  895. into your resource forks with ResEdit.
  896.  
  897. Lawrence D'Oliveiro                       fone: +64-7-856-2889
  898. Computer Services Dept                     fax: +64-7-838-4066
  899. University of Waikato            electric mail: ldo@waikato.ac.nz
  900. Hamilton, New Zealand    37^ 47' 26" S, 175^ 19' 7" E, GMT+13:00
  901.  
  902. +++++++++++++++++++++++++++
  903.  
  904. >From jaks@netcom.com (Eric Jackson)
  905. Date: Mon, 21 Nov 1994 05:32:36 GMT
  906. Organization: NETCOM On-line Communication Services (408 261-4700 guest)
  907.  
  908. In article <1994Nov17.165639.35369@waikato.ac.nz>,
  909. Lawrence D'Oliveiro, Waikato University <ldo@waikato.ac.nz> wrote:
  910. >In article <jaksCzDoEK.EHG@netcom.com>, jaks@netcom.com (Eric Jackson) writes:
  911. >> I would like to be able to read in  a 'pict' recource from a resource
  912. >> file into my Quick Draw GX application.  This pict consists of a
  913. >> color bit map image.
  914. >>
  915. >> In all of the examples that I have seen in the Quick Draw GX Developer CD
  916. >> the bit maps are of a type called 'pxmp'.
  917. >>
  918. >> What I would like to do is to read my pict into a BitMapShape and them clip it.
  919. >> Any suggestions would be nice.
  920. >
  921. >Are you trying to
  922. >
  923. >  a) read QuickDraw pictures in from PICT resources and convert them to
  924. >     GX shapes, or
  925. >  b) read flattened GX shapes in from resources and unflatten them?
  926. >
  927. >The first is easy, the second is only slightly harder.
  928. >
  929. >To convert a QuickDraw picture to a GX shape, you use GXConvertPICTToShape.
  930. >
  931. >To unflatten a GX shape, you use GXUnflattenShape. There is source code for
  932. >a routine called HandleToShape in the GX libraries, that should do exactly
  933. >what you want.
  934. >
  935. >By the way, Apple seems to have standardized on 'qdgx' as the OSType type
  936. >code for GX shapes (as opposed to 'grfx', which some pre-release utilities
  937. >used, and which I prefer :-)). So if you want to store a flattened GX shape
  938. >in a resource, make it a resource of type 'qdgx'. Then when you copy it to
  939. >the clipboard from ResEdit, it will display properly in other GX-savvy programs.
  940. >And conversely, you can create the shape in another program, and paste it
  941. >into your resource forks with ResEdit.
  942. >
  943. >Lawrence D'Oliveiro                       fone: +64-7-856-2889
  944. >Computer Services Dept                     fax: +64-7-838-4066
  945. >University of Waikato            electric mail: ldo@waikato.ac.nz
  946. >Hamilton, New Zealand    37^ 47' 26" S, 175^ 19' 7" E, GMT+13:00
  947.  
  948. Actually I got that far already.  That is I read in my picture and then
  949. converted it into a gxPictureType shape.  Now what I wanted to do was to
  950. change my PictureShape into a gxBitmapShape.
  951.  
  952. I was able to do this as well but I seem to have lost all of my color
  953. information in doing this.
  954.  
  955. The way I did this was by calling
  956.  
  957. GXSetShapeType(PictureShapeThatWillBecomeBitMapShape,gxBitmapShape);
  958.  
  959. When I put my picture that I have created by exactly the method that you
  960. discribed what happend is that I get a black and white bit map and all of
  961. my color gets lost.  What I would like to do is to keep my color information.
  962. For now what I have been doing is to just move forward and work with a picture
  963. shape and not convert it into a bitmap.  Maybe what I should be doing is to
  964. just draw my picture shape into a bitmap but I have not gotten around to trying
  965. this just yet since there is so much other stuff that I have been working with.
  966.  
  967. I can report that I think that QuickDraw GX is really fun to work with and
  968. has a lot of nice features.
  969.  
  970. Eric Jackson
  971. jaks@netcom.com
  972.  
  973.  
  974. +++++++++++++++++++++++++++
  975.  
  976. >From ldo@waikato.ac.nz (Lawrence D'Oliveiro, Waikato University)
  977. Date: 22 Nov 94 10:26:20 +1300
  978. Organization: University of Waikato, Hamilton, New Zealand
  979.  
  980. In article <jaksCzLrEC.74s@netcom.com>, jaks@netcom.com (Eric Jackson) writes:
  981. >
  982. > Actually I got that far already.  That is I read in my picture and then
  983. > converted it into a gxPictureType shape.  Now what I wanted to do was to
  984. > change my PictureShape into a gxBitmapShape.
  985. >
  986. > I was able to do this as well but I seem to have lost all of my color
  987. > information in doing this.
  988. >
  989. > The way I did this was by calling
  990. >
  991. > GXSetShapeType(PictureShapeThatWillBecomeBitMapShape,gxBitmapShape);
  992. >
  993. > When I put my picture that I have created by exactly the method that you
  994. > discribed what happend is that I get a black and white bit map and all of
  995. > my color gets lost.  What I would like to do is to keep my color information.
  996. > For now what I have been doing is to just move forward and work with a picture
  997. > shape and not convert it into a bitmap.  Maybe what I should be doing is to
  998. > just draw my picture shape into a bitmap but I have not gotten around to trying
  999. > this just yet since there is so much other stuff that I have been working with.
  1000.  
  1001. I guess if GXSetShapeType is changing the picture to a black-and-white bitmap,
  1002. then you really have to draw the shape into a bitmap of the depth you need,
  1003. if you want to keep the colours.
  1004.  
  1005. The good news is, it's not much harder than QuickDraw GWorld calls. Here's
  1006. an outline of the steps:
  1007.  
  1008.   1) Set up a gxBitmap record describing the bitmap shape you want to create,
  1009.      initializing the fields as follows:
  1010.     image := nil (* let GX allocate the pixels for you *)
  1011.     width := the desired width in pixels
  1012.     height := the desired height in pixels
  1013.     rowBytes := (width + 31) DIV 32 * 4
  1014.     pixelSize := 32
  1015.     space := gxRGB32Space
  1016.     set := nil (* ignored for direct depths *)
  1017.     profile := nil.
  1018.   2) Create a bitmap shape from the gxBitmap record, using GXNewBitmap.
  1019.   3) Create an offscreen viewgroup using GXNewViewGroup.
  1020.   4) Create an offscreen view device, using GXNewViewDevice, passing the
  1021.      bitmap you created in step 2, and the view group you created in step 3.
  1022.   5) Create a viewport attached to the viewgroup you created in step 3.
  1023.  
  1024. Now all you have to do is draw your shape into the viewport you created in
  1025. step 5.
  1026.  
  1027. Tip: you should create a full shape with an appropriate background colour
  1028. (eg white) and draw it into the offscreen viewport first, to initialize all
  1029. the pixels to a known value, before drawing your picture shape.
  1030.  
  1031. Once you've finished with the offscreen structures, you can dispose of them
  1032. by calling GXDisposeViewGroup on the offscreen viewgroup. This will
  1033. automatically dispose of the attached view device and viewport as well. All
  1034. that will be left is the bitmap shape.
  1035.  
  1036. > I can report that I think that QuickDraw GX is really fun to work with and
  1037. > has a lot of nice features.
  1038.  
  1039. Same here!
  1040.  
  1041. Lawrence D'Oliveiro                       fone: +64-7-856-2889
  1042. Computer Services Dept                     fax: +64-7-838-4066
  1043. University of Waikato            electric mail: ldo@waikato.ac.nz
  1044. Hamilton, New Zealand    37^ 47' 26" S, 175^ 19' 7" E, GMT+13:00
  1045.  
  1046. +++++++++++++++++++++++++++
  1047.  
  1048. >From ldo@waikato.ac.nz (Lawrence D'Oliveiro, Waikato University)
  1049. Date: 22 Nov 94 13:06:37 +1300
  1050. Organization: University of Waikato, Hamilton, New Zealand
  1051.  
  1052. In article <1994Nov22.102621.35468@waikato.ac.nz>, I wrote:
  1053.  
  1054. >   1) Set up a gxBitmap record describing the bitmap shape you want to create,
  1055. ..
  1056. >     rowBytes := (width + 31) DIV 32 * 4
  1057.  
  1058. Oops! This calculation is only correct for a 1-bit-deep pixmap. For 32 bits
  1059. per pixel, it should of course be
  1060.  
  1061.     rowBytes := width * 4
  1062.  
  1063. Lawrence D'Oliveiro                       fone: +64-7-856-2889
  1064. Computer Services Dept                     fax: +64-7-838-4066
  1065. University of Waikato            electric mail: ldo@waikato.ac.nz
  1066. Hamilton, New Zealand    37^ 47' 26" S, 175^ 19' 7" E, GMT+13:00
  1067.  
  1068. ---------------------------
  1069.  
  1070. >From dubois@uakari.primate.wisc.edu (Paul DuBois)
  1071. Subject: TransSkel 3.18 (THINK C, Metrowerks) now available
  1072. Date: 21 Nov 1994 10:56:42 -0600
  1073. Organization: Castra Parvulorum
  1074.  
  1075. Release 3.18 of TransSkel, a skeleton for Macintosh application development
  1076. under THINK C or Metrowerks C, is now available.
  1077.  
  1078. This release is quite similar to release 3.17, with the following differences:
  1079.  
  1080. - It compiles under either the universal headers or the old Apple headers.
  1081. Prior releases compiled only under the old headers.
  1082. - It compiles under THINK C or Metrowerks C.  Prior releases were written
  1083. for THINK C only.
  1084. - It can be used to generate either 68K or PowerPC code.  Prior releases
  1085. worked only for 68K code.  PowerPC code generation has been tested only
  1086. with Metrowerks C
  1087. - 3.17 broke compatibility of the THINK C library with THINK Pascal programs.
  1088. 3.18 fixes that.
  1089.  
  1090. TransDisplay 3.06 and TransEdit 3.06 are also available now, and have been
  1091. updated in similar ways.  TransDisplay and TransEdit are modules that can
  1092. be dropped into TransSkel-based projects to provide display-only or editable
  1093. text windows.
  1094.  
  1095. TransSkel, TransDisplay, and TransEdit are available via any of the following:
  1096.  
  1097. anonymous ftp to ftp.primate.wisc.edu (under /pub/mac/TransSkel)
  1098.  
  1099. gopher to gopher.primate.wisc.edu (select "Primate Center Software Archives")
  1100.  
  1101. WWW using URL http://www.primate.wisc.edu/ (select "Primate Center Software
  1102. Archives")
  1103.  
  1104.  
  1105. -- 
  1106. Paul DuBois
  1107. dubois@primate.wisc.edu
  1108.  
  1109. ---------------------------
  1110.  
  1111. >From juez@informatik.fh-augsburg.de (Juez Markus)
  1112. Subject: how can I implement-program Plug-Ins?
  1113. Date: 9 Nov 1994 13:23:04 GMT
  1114. Organization: Fachhochschule Augsburg, Germany
  1115.  
  1116. How can I implement Plug-Ins into my program (like filters in the Photoshop)?
  1117. What kind of data-structures and functions do I need? 
  1118. Will I need an extra program to generate the moduls (like the filters)?
  1119.  
  1120. Many Thanks for hints
  1121.  
  1122.  
  1123. +++++++++++++++++++++++++++
  1124.  
  1125. >From nick+@pitt.edu ( nick.c )
  1126. Date: Wed, 09 Nov 1994 12:59:24 -0500
  1127. Organization: The Pitt, Chemistry
  1128.  
  1129. In article <39qifo$7ju@av2.rz.fh-augsburg.de>,
  1130. juez@informatik.fh-augsburg.de (Juez Markus) wrote:
  1131.  
  1132. > How can I implement Plug-Ins into my program (like filters in the Photoshop)?
  1133. > What kind of data-structures and functions do I need? 
  1134. > Will I need an extra program to generate the moduls (like the filters)?
  1135. > Many Thanks for hints
  1136.  
  1137.  
  1138.    Don't really know, but can think of a few possibilities.
  1139.       If it's simple, you can create "preferences" like files,
  1140.       that toggle on or off or configure pre-made functionality
  1141.       it the program.  That would be the easiest, and if your just
  1142.       need file translation filters, it would be doable.  If not,
  1143.       compile code resources (an option in the compiler in both
  1144.       CW & SC++), imbed those resources in files with the type and
  1145.       creator set for your app, then have the app scan a certain
  1146.       folder in the same folder (or in the preference folder) as
  1147.       your app on startup, and load those code resources that
  1148.       it finds.  Not sure about the interface between those resources
  1149.       and your app's code.  Maybe just call a function with the same name
  1150.       as the module as it loads them, and that function tells your
  1151.       program what functions in your app the module interfaces to.
  1152.       Then you'd have to do negotiation within your program to 
  1153.       make sure two modules don't step on each others feet.
  1154.       Hmm...
  1155.  
  1156.     Might be easier if you mentioned what the modules are supposed to
  1157.       do.  Are they just file translation filters, or do they have
  1158.       to have functionality of some kind?
  1159.  
  1160.  
  1161.  Internet: nick+@pitt.edu            _/   _/  _/  _/_/_/   _/   _/  
  1162.    eWorld: nick                     _/_/ _/  _/  _/   _/  _/_/_/ 
  1163.       CIS: 71232,766               _/ _/_/  _/  _/       _/ _/    
  1164.      http://www.pitt.edu/~nick/   _/   _/  _/   _/_/_/  _/   _/     
  1165.                     
  1166.  
  1167. +++++++++++++++++++++++++++
  1168.  
  1169. >From oster@netcom.com (David Phillip Oster)
  1170. Date: Wed, 9 Nov 1994 20:57:52 GMT
  1171. Organization: Netcom Online Communications Services (408-241-9760 login: guest)
  1172.  
  1173.  
  1174. Here is what you need to do:
  1175. 1.) Define a storage location for the plug-ins. such as, for an application
  1176. called Foo, a folder called "Foo Pouch", which your installer creates,
  1177. and which you search for in the same folder as your application, the
  1178. preferences folder, and the System Folder (for System 6 (no preferences))
  1179. the name of the pouch folder should be in a 'STR ' or 'STR#' resource for
  1180. easy internationalization.
  1181.  
  1182. 2.) Define a resource type to hold your plug-in exectuable code. You
  1183. should allow any resID number, since some development systems have
  1184. restrictions on which id numbers can be used for multi-segment code resources.
  1185.  
  1186. Decide whether you will allow multiple code resources per file.
  1187. For example, Photoshop lets you bundle an import resource, an export
  1188. resource, and a filter into the same file, each is its own resource type.
  1189. It uses the resource name to tell the user, so each has its own name.
  1190.  
  1191. 3.) Decide on the user interface to plug-ins. Commonly, at program
  1192. start-up, you scan the pouch and collect all the files of the correct
  1193. types. Then you scan for appropriate code resources, then put the names
  1194. of the resources in the menus. You can also use the file names, or
  1195. run the code resources and ask them for the correct name.
  1196.  
  1197. 4.) decide on the programmer's interface. MPW likes to pass parameters
  1198. as longs, and pascal development systems usually can't generate C
  1199. interfaces, so your best bet is to have the entry point of your code 
  1200. resource be something like:
  1201.  
  1202. extern pascal long PlugIn(long selector, CallbackPtr callback, 
  1203.     long param1, long param2, long param3, long refcon);
  1204.  
  1205. where params 1 through 3 will have specific meanings depending upon
  1206. which function selector is asking to be performed.
  1207.  
  1208. CallbackPtr is something like this:
  1209. typedef struct CallbackRec{
  1210.     DrawFunc    erase;
  1211.     DrawFunc    paint;
  1212. }CallbackRec, *CallbackPtr;
  1213.  
  1214. where DrawFunc is something like:
  1215. typedef pascal void (*DrawFunc)(Rect *);
  1216.  
  1217. This is the place where you define services that your application will
  1218. perform when asked to by the code resource of the plug-in.
  1219.  
  1220. You'll need to define a bunch of selectors for what you want the plug-in
  1221. to do.
  1222.  
  1223. You should definately give the plug-in an Init selector, and a 
  1224. dispose selector, and have Init return an error or a refcon, which
  1225. will be passed back to the plug-in on each call, so the plug-in
  1226. can have some persistent storage.  You should definately set the
  1227. CurResFile to the plug-in's file while it is running, so it can 
  1228. easily get at any resources it needs.
  1229.  
  1230. The Init selector should pass the interface version in param1
  1231. and the program version in param2, so that the plug-in can cope
  1232. with different versions of your program.
  1233.  
  1234. The actual call to the plug-in looks like:
  1235.     h = GetResource('PLUG', 1);
  1236.     HLock(h);
  1237.     xh = StripAddress(h);
  1238.     ((PlugInFunc) *xh)(kInit, callbacks, kInterfaceVer1, kProgVer1, 0, 0);
  1239.     HUnlock(h);
  1240. -- 
  1241. - ------- oster@netcom.com ----------
  1242. "A man hears what he wants to hear and misremembers the rest."
  1243.      -- Paul Simon, ("The Boxer")
  1244.  
  1245.  
  1246. +++++++++++++++++++++++++++
  1247.  
  1248. >From jonasw@lysator.liu.se (Jonas Wallden)
  1249. Date: 10 Nov 1994 10:22:19 GMT
  1250. Organization: (none)
  1251.  
  1252. juez@informatik.fh-augsburg.de (Juez Markus) writes:
  1253.  
  1254. >How can I implement Plug-Ins into my program (like filters in the Photoshop)?
  1255. >What kind of data-structures and functions do I need? 
  1256. >Will I need an extra program to generate the moduls (like the filters)?
  1257. >
  1258. >Many Thanks for hints
  1259.  
  1260. Plug-in code is not too hard to write. Basically you load resources
  1261. from external files and call them with a predefined set of parameters.
  1262.  
  1263. If you are writing your own application you are free to design this
  1264. calling interface any way you like, but if you are writing e.g. BBEdit
  1265. externals you should read the documentation to see what the application
  1266. requires from your code.
  1267.  
  1268. Now, you asked for the first case, and here are some hints:
  1269.  
  1270. * Keep a list of external files that you open so you can set the
  1271.   correct resource file before calling the code. This will make life
  1272.   easier for the external in case it needs to access resources in it's
  1273.   own file.
  1274.  
  1275. * Define an API that can be extended in future versions. Parameter blocks
  1276.   are great for this; just place a version number first in the parameter
  1277.   block so the extension knows which fields in the pb that are available.
  1278.   When you call you simply pass a pointer to this block (whose size can
  1279.   vary among different versions).
  1280.  
  1281. * Provide a parameter block with callbacks. This is a list of function
  1282.   pointers that point to routines in your application that the extension
  1283.   can call to request services from you. This can e.g. be window handling
  1284.   in case you need to handle floating windows.
  1285.  
  1286. * Make sure the resources are locked down while you call them. Also call
  1287.   StripAddress on the handle to ensure compatibility with 24-bit systems.
  1288.  
  1289. * Define a number of messages that you pass to the extension. Look at some
  1290.   of Apple's xDEF docs to get inspiration. It is very useful for the
  1291.   extension to know when it's called the first time, and when it's about
  1292.   to be closed down so it can allocate and dispose of memory that it needs.
  1293.  
  1294.   Also define error messages, or use the error codes already defined for
  1295.   other Toolbox managers.
  1296.  
  1297. * Write a header file that you ship together with your application so
  1298.   other programmers can compile their extensions. Declare all C routines
  1299.   as 'pascal'.
  1300.  
  1301. * Document required resources, file types/creators and other stuff that
  1302.   your application expects to find in the external resource files as well.
  1303.  
  1304. There are a number of sample applications that you can look at. E.g., check
  1305. out the CodeWarrior CD which includes instructions on how to write code that
  1306. work on PowerPC Macs, and how to call PPC from 68K and vice versa.
  1307.  
  1308. BBEdit is also a good place to start. Read the programmer documentation that
  1309. is included to get an idea of how things work.
  1310.  
  1311. Finally, writing externals is just like writing any other code resource
  1312. and can be done in Pascal or C. Note though that Pascal is not as flexible
  1313. so you might need some inline assembly to use e.g. callback routines.
  1314.  
  1315. Disclaimer: those who have seen my shareware application PowerScan knows
  1316. that I don't follow all of the recommendations myself. This is because I've
  1317. learned most things by doing it the wrong way... :-)
  1318.  
  1319. ...............   .......................   ...........   ...............
  1320.  jonas wallden           internet            applelink       phone/fax
  1321.    mac hacker      jonasw@lysator.liu.se      sw1369       +46-13-176084
  1322.  
  1323. +++++++++++++++++++++++++++
  1324.  
  1325. >From sandvik@apple.com (Kent Sandvik)
  1326. Date: Mon, 21 Nov 1994 18:05:51 -0800
  1327. Organization: Apple Computer, Inc. Developer Technical Support
  1328.  
  1329. I would like to know why developers in general are not interested to use
  1330. the Component Manager for plug-in material. Let me know more of the pros
  1331. and cons so I could provide feedback to engineering and marketing about
  1332. this all.
  1333.  
  1334. Cheers, Kent
  1335.  
  1336. -- 
  1337. Kent Sandvik   sandvik@apple.com   New Media Analyst/Programmer
  1338. Private activities on Internet.
  1339.  
  1340. +++++++++++++++++++++++++++
  1341.  
  1342. >From spencerl@crl.com (Spencer Low)
  1343. Date: 21 Nov 1994 22:08:01 -0800
  1344. Organization: LowTek Creations
  1345.  
  1346. Kent Sandvik (sandvik@apple.com) wrote:
  1347. > I would like to know why developers in general are not interested to use
  1348. > the Component Manager for plug-in material. Let me know more of the pros
  1349. > and cons so I could provide feedback to engineering and marketing about
  1350. > this all.
  1351.  
  1352. I just got into this thread, but...
  1353.  
  1354. One reason I'm reluctant to use the Component Manager is all the 
  1355. UniversalProcPtr stuff needed for use with the Universal Headers. It's 
  1356. not as easy as, say a Control Strip plug-in. I do think that components 
  1357. are easier to use in an application (OpenComponent, call the stuff, 
  1358. CloseComponent). Another con is the glue necessary for PowerMac native 
  1359. components (I've read about this in the Component Manager 3 Q/A Tech Note).
  1360.  
  1361. Spencer
  1362. -- 
  1363. ________________________________________________________________________
  1364.     Spencer Low ------- LowTek Creations ------- spencerl@crl.com
  1365.  
  1366. ---------------------------
  1367.  
  1368. >From tjb@acpub.duke.edu (Thomas J. Bryce)
  1369. Subject: using HLock before memcpy
  1370. Date: 19 Nov 1994 03:04:19 GMT
  1371. Organization: Duke University, Durham, NC, USA
  1372.  
  1373.  
  1374. I notice people usually surround a memcpy statement of a handle or
  1375. pointer with HLock and HUnlock. Is this necessary always? 
  1376.  
  1377. I'm inclined to believe, YES, but I'd like to hear it stated directly rather
  1378. than assuming it from seeing it done all the time.
  1379.  
  1380. It seems you can't rely on the memory to not be moved if you copy the
  1381. pointer from the handle and use it for a while, as in memcpy (*handle1,
  1382. *handle2,size);
  1383.  
  1384. Could someone verify this for me?
  1385.  
  1386. Tom
  1387.  
  1388.  
  1389. +++++++++++++++++++++++++++
  1390.  
  1391. >From wem53067@uxa.cso.uiuc.edu (TheBard)
  1392. Date: Fri, 18 Nov 1994 21:52:29 -0600
  1393. Organization: Bard 'O Matic Software
  1394.  
  1395. In article <3ajpvj$49l@news.duke.edu>, tjb@acpub.duke.edu (Thomas J.
  1396. Bryce) wrote:
  1397. > It seems you can't rely on the memory to not be moved if you copy the
  1398. > pointer from the handle and use it for a while, as in memcpy (*handle1,
  1399. > *handle2,size);
  1400. > Could someone verify this for me?
  1401.  
  1402. I'll verify it. :) You see, the whole idea of using handles is to let the
  1403. ystem move memory around. That way you don't get a swiss-cheese looking
  1404. memory map. Now, if for some reason you don't lock the handles, and then
  1405. you try to copy.. the one you are copying to or from may move and then you
  1406. are writting to or from  some other place than you wanted to. Yuk.
  1407.  
  1408. Lock your handles :)
  1409.  
  1410. Wayde
  1411.  
  1412. -- 
  1413. =====================================================================
  1414. --=The Bard=--
  1415. "Just remember, no matter where you go, there you are!"
  1416. - -------------------------------------------------------------------
  1417. PGP Public Key available upon request
  1418.  
  1419. +++++++++++++++++++++++++++
  1420.  
  1421. >From Jaeger@fquest.com (Brian Stern)
  1422. Date: 19 Nov 1994 05:52:41 GMT
  1423. Organization: The University of Texas at Austin, Austin, Texas
  1424.  
  1425. In article <3ajpvj$49l@news.duke.edu>, tjb@acpub.duke.edu (Thomas J.
  1426. Bryce) wrote:
  1427.  
  1428. < I notice people usually surround a memcpy statement of a handle or
  1429. < pointer with HLock and HUnlock. Is this necessary always? 
  1430. < I'm inclined to believe, YES, but I'd like to hear it stated directly rather
  1431. < than assuming it from seeing it done all the time.
  1432. < It seems you can't rely on the memory to not be moved if you copy the
  1433. < pointer from the handle and use it for a while, as in memcpy (*handle1,
  1434. < *handle2,size);
  1435. < Could someone verify this for me?
  1436. < Tom
  1437.  
  1438. If the memcopy routine is in a non-resident segment then calling it could
  1439. cause the segment to be loaded.  I assume that it's in the ANSI lib.  If
  1440. you make sure that the segment containing ANSI is loaded before you call
  1441. memcopy and is never unloaded then you're probably safe and don't need to
  1442. lock the handle.  
  1443.  
  1444. I don't know how memcopy is implemented.  It's probably a bytewise copy,
  1445. something like *dest++ = *src++.  Code like that won't cause memory to
  1446. move.  
  1447.  
  1448. Many people would rather be safe than sorry.  If other people are likely
  1449. to use your code in other projects where ANSI may not be loaded and locked
  1450. then you're better off locking the handle.
  1451.  
  1452. Good luck,
  1453.  
  1454. -- 
  1455. Brian  Stern  :-{)}
  1456. Toolbox commando and Menu bard
  1457. Jaeger@fquest.com
  1458.  
  1459. +++++++++++++++++++++++++++
  1460.  
  1461. >From pgontier@novell.com (Pete Gontier)
  1462. Date: Mon, 21 Nov 1994 12:29:07 -0700
  1463. Organization: Novell, Inc., Walnut Creek/Macintosh Site
  1464.  
  1465. In article <3ajpvj$49l@news.duke.edu>, tjb@acpub.duke.edu (Thomas J.
  1466. Bryce) wrote:
  1467.  
  1468. > I notice people usually surround a memcpy statement of a handle or
  1469. > pointer with HLock and HUnlock. Is this necessary always? 
  1470.  
  1471. Depends on what code segment 'memcpy' lives in. If it's in another
  1472. segment, the handle might move when that segment is loaded. Since there
  1473. isn't a good way to tell if 'memcpy' is in the same segement as the code
  1474. calling it, 'HLock' is a good idea. I just call 'BlockMoveData'; it's a
  1475. trap call, so no segment will load. The net savings are one, maybe two,
  1476. trap calls over the usual 'HGetState'/'HLock'/'HUnlock' sequence, and
  1477. 'BlockMoveData' is generally much faster for surprisingly small blocks.
  1478.  
  1479. -- 
  1480.  
  1481.  Views expressed here do not necessarily reflect those of my employer.
  1482.  
  1483. ---------------------------
  1484.  
  1485. End of C.S.M.P. Digest
  1486. **********************
  1487.  
  1488.  
  1489.