home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #27 / NN_1992_27.iso / spool / comp / sys / mac / programm / 18583 < prev    next >
Encoding:
Internet Message Format  |  1992-11-18  |  3.5 KB

  1. Path: sparky!uunet!haven.umd.edu!darwin.sura.net!zaphod.mps.ohio-state.edu!sol.ctr.columbia.edu!usc!elroy.jpl.nasa.gov!ames!agate!doc.ic.ac.uk!doc.ic.ac.uk!not-for-mail
  2. From: avm@doc.ic.ac.uk (Alex V Melidis)
  3. Newsgroups: comp.sys.mac.programmer
  4. Subject: CopyBits() : pmTable field initialisation for PixMap
  5. Date: 18 Nov 1992 14:48:30 -0000
  6. Organization: Department of Computing, Imperial College, University of London, UK.
  7. Lines: 110
  8. Distribution: world
  9. Message-ID: <1edl3uINNqiq@oak22.doc.ic.ac.uk>
  10. NNTP-Posting-Host: oak22.doc.ic.ac.uk
  11.  
  12.  
  13.  
  14. This question is about copying bits from an off-screen 1 or 8-bit deep
  15. PixMap to a window using the CopyBits() call in ThinkC.
  16.  
  17. The situation is as follows : 
  18. - The image contained in the PixMap exists in memory before the PixMap
  19.   is created and is updated without using QuickDraw routines, hence
  20.   there is no off-screen drawing TO a PixMap and there is no color
  21.   grafport associated with it.
  22.   A color window is created (with NewCWindow()) for displaying the contents
  23.   of that image. The image is displayed by using CopyBits() between the
  24.   off-screen PixMap and the window's PixMap.
  25.   
  26.   PROBLEM : After using NewPixMap() to create the off-screen pixmap
  27.          and setting some of its fields to appropriate values (code
  28.         follows) I need to set the pmTable field to the color table
  29.         to be used for the off-screen PixMap :
  30.             :
  31.             :
  32.     pmap = NewPixMap();
  33.     HLock(pmap);
  34.     (*pmap)->baseAddr = (Ptr) start_of_image_data;
  35.     (*pmap)->rowBytes = (precision == 1 ?
  36.                  ((width - 1) / 32 + 1) * 4 :
  37.                  0x8000 | width);
  38.     /* width is the no of pixels in each row of the image */
  39.     SetRect((*pmap)->bounds, 0, 0, width, height);
  40.     /* height is no of rows in image */
  41.  
  42.     /* AND NOW THE PROBLEM */
  43.  
  44.     if ((*pmap)->rowBytes & 0x8000)
  45.     {
  46.         (*pmap)->pmTable = ..................... ???
  47.     }
  48.  
  49.     HUnlock(pmap);
  50.             :
  51.             :
  52.     /* for this I have so far tried two alternatives :
  53.  
  54.     1) get color table from PixMap of window to which the bits
  55.        will be copied
  56.  
  57.        (*pmap)->pmTable = (*(window_record->port.portPixMap))->pmTable;
  58.  
  59.     where window_record is a CWindowPeek
  60.     
  61.     2) get color table from main device
  62.  
  63.       main_device = GetMainDevice();
  64.       HLock(main_device);
  65.       (*pmap)->pmTable = (*((*main_device)->gdPmap))->pmTable;
  66.       HUnlock(main_device);
  67.  
  68.     where main_device is a GDHandle
  69.  
  70.     but none of these ways works consistently : some times CopyBits()
  71.     crashes taking the application with it (but the Mac survives), but
  72.     the usual thing is for the Mac to freeze completely (with some
  73.     color changes to the screen sometimes).
  74.  
  75.     The code for CopyBits() is
  76.             :
  77.             :
  78.     win_pmap = window_record->port.portPixMap;
  79.     SelectWindow(window_record);
  80.     GetPort(&saveport);
  81.     SetPort(window);
  82.         HLock(pmap);
  83.     HLock(win_pmap);
  84.  
  85.     if ((*pmap)->rowBytes & 0x8000)
  86.     {
  87.         CopyBits(*pmap, *win_pmap,
  88.              &(*pmap)->bounds, &(*pmap)->bounds,
  89.              transparent, NULL);
  90.     }
  91.     else
  92.     {
  93.         CopyBits(*pmap, *win_pmap,
  94.                          &(*pmap)->bounds, &(*pmap)->bounds,
  95.                          srcCopy, NULL);
  96.     }
  97.     
  98.     HUnlock(win_pmap);
  99.     HUnlock(pmap);
  100.     SetPort(saveport);
  101.             :
  102.             :
  103.  
  104.     Please note that omission of setting the pmTable field results in
  105.     a working program that uses greyscales for color.
  106.  
  107.     I will be very grateful for any helpful hint, as I am still new to
  108.     ToolBox programming and quite stuck.
  109.     
  110.     If I have not provided enough information in the above description,
  111.     please let me know. I may be also contacted by email.
  112.  
  113.                 Thanks in advance,
  114.                         Alex.
  115.  
  116.  
  117. -- 
  118. Alexander V Melidis,        INTERNET : avm@doc.ic.ac.uk
  119. Department Of Computing,
  120. Imperial College,
  121. LONDON, SW7 2BZ    
  122.