home *** CD-ROM | disk | FTP | other *** search
/ Amiga Developer CD 2.1 / Amiga Developer CD v2.1.iso / Reference / DevCon / Washington_1988 / DevCon88.1 / Graphics / readpixelarray.asm < prev    next >
Encoding:
Assembly Source File  |  1992-08-27  |  11.0 KB  |  372 lines

  1. *******************************************************************************
  2. *
  3. *   Source Control
  4. *   --------------
  5. *   $Header: ReadPixelArray.asm,v 35.0 88/04/22 11:50:46 bart Exp $
  6. *
  7. *   by Bart Whitebook
  8. *
  9. * Copyright (c) 1988 Commodore-Amiga, Inc.
  10. *
  11. * Executables based on this information may be used in software
  12. * for Commodore Amiga computers.  All other rights reserved.
  13. *
  14. * This information is provided "as is"; no warranties are made.
  15. * All use is at your own risk, and no liability or responsibility is assumed.
  16. *
  17. *******************************************************************************
  18.  
  19.  
  20.   include 'exec/types.i'        * Required data type definitions
  21.   include 'graphics/gfx.i'      * BitMap structure definition
  22.   include 'exec/nodes.i'
  23.   include 'exec/lists.i'
  24.   include 'exec/interrupts.i'
  25.   include 'exec/ports.i'
  26.   include 'exec/libraries.i'
  27.   include 'graphics/gfxbase.i'
  28.   include 'graphics/clip.i'     * Layer structure definition
  29.   include 'graphics/rastport.i' * RastPort structure definition
  30.   include 'hardware/blit.i'     * Minterm definitions
  31.  
  32.   xdef _ReadPixelArray  * Define public entry points
  33.   xdef _ReadPixelLine
  34.  
  35.   PAGE
  36.  
  37. ******* graphics.library/ReadPixelArray **************************************
  38. *
  39. *   NAME
  40. *       ReadPixelArray -- read the pen number value of a rectangular array 
  41. *           of pixels starting at a specified x,y location and continuing 
  42. *           through to another x,y location within a certain RastPort.
  43. *
  44. *   SYNOPSIS
  45. *     count = ReadPixelArray(rp,xstart,ystart,xstop,ystop,array,defval,temprp)
  46. *      d0                    a0 d0:16  d1:16  d2:16 d3:16  a2    d7:8    a1
  47. *
  48. *   LONG    count;
  49. *   struct  RastPort *rp;
  50. *   SHORT   xstart, ystart;
  51. *   SHORT   xstop, ystop;
  52. *   UBYTE   *array;
  53. *   UBYTE   defval;
  54. *   struct  RastPort *temprp;
  55. *
  56. *   FUNCTION
  57. *       For each pixel in a rectangular region, combine the bits from each
  58. *       of the bit-planes used to describe a particular RastPort into the pen
  59. *       number selector which that bit combination normally forms for the
  60. *       system hardware selection of pixel color.
  61. *
  62. *   INPUTS
  63. *       rp -  pointer to a RastPort structure
  64. *       (xstart,ystart) starting point in the RastPort
  65. *       (xstop,ystop) stopping point in the RastPort
  66. *       array - pointer to an array of uwords in which to store the pixel data
  67. *       temprp - temporary rastport (copy of rp with Layer set == NULL,
  68. *                                   temporary memory allocated for temp BitMap
  69. *                                   temprp->BitMap with Rows set == 1,
  70. *                                   and with BytesPerrow set == 
  71. *                                   ((((xstart-xstop+1)+0xf)>>4)<<1),
  72. *                                   and temporary memory allocated for
  73. *                                   temprp->BitMap->Planes[])
  74. *
  75. *   RESULT
  76. *       For each pixel in the array:
  77. *           Pen - (0..255) number at that position is returned
  78. *                 (defval) is returned if cannot read that pixel
  79. *
  80. *   NOTE
  81. *       xstop must be >= xstart
  82. *       ystop must be >= ystart
  83. *
  84. *   BUGS
  85. *
  86. *   SEE ALSO
  87. *       WritePixel  graphics/rastport.h
  88. *
  89. ******************************************************************************
  90.     xref    _LVOLockLayerRom
  91.     xref    _LVOWaitBlit
  92.     xref    _LVOUnlockLayerRom
  93.     xref    _LVOClipBlit
  94.     xref    _GfxBase
  95.  
  96. _ReadPixelArray:
  97.     movem.l d2/d3/d7/a2/a6,-(sp)
  98.     move.l  _GfxBase,a6
  99.     move.l  24(sp),a0           ; rp
  100.     movem.l 28(sp),d0/d1/d2/d3  ; xstart, ystart, xstop, ystop
  101.     movea.l 44(sp),a2           ; array
  102.     move.l  48(sp),d7           ; defval
  103.     movea.l 52(sp),a1           ; temprp
  104.     jsr readpixelarray
  105.     movem.l (sp)+,d2/d3/d7/a2/a6
  106.     rts
  107.  
  108. readpixelarray:
  109.  
  110.     movem.l d2/d3/d4/d5/d6/d7/a2/a3/a4,-(sp)
  111.  
  112.     sub.w   d0,d2       ; width of rectangle to read
  113.     ext.l   d2
  114.     addq.l  #1,d2
  115.     ble.s   array_error ; width non-positive ?
  116.     move.w  d0,d4       ; temp storage for current x
  117.     move.w  d1,d5       ; temp storage for current y
  118.  
  119.     sub.w   d1,d3       ; height of rectangle to read
  120.     ext.l   d3
  121.     addq.l  #1,d3
  122.     ble.s   array_error ; height non-positive ?
  123.  
  124.     movea.l a0,a3       ; protect rastport pointer -- does not modify cc
  125.     movea.l a1,a4       ; protect temprp pointer -- does not modify cc
  126.  
  127.     moveq.l #0,d6       ; clear count of pixels returned
  128.  
  129.     bra.s   rpxaloop_count
  130.  
  131. rpxaloop_start:
  132.  
  133.     movea.l a3,a0       ; rp
  134.     move.l  d4,d0       ; x
  135.     move.l  d5,d1       ; y (current line)
  136.                         ; width in d2 (see above)
  137.                         ; array in a2 (see above)
  138.     movea.l a4,a1       ; temprp 
  139.  
  140.     jsr readpixelline
  141.  
  142.     addq.l  #1,d5       ; next line
  143.     adda.l  d2,a2       ; increment base pointer to array by width words
  144.     adda.l  d2,a2
  145.     add.l   d2,d6       ; add one line of pixels to pixel count
  146.  
  147. rpxaloop_count:
  148.  
  149.     dbra    d3,rpxaloop_start
  150.  
  151. rpxaloop_end:
  152.  
  153.     move.l  d6,d0       ; return pixel count
  154.     movem.l (sp)+,d2/d3/d4/d5/d6/d7/a2/a3/a4
  155.     rts
  156.  
  157. array_error:
  158.  
  159.     moveq.l #-1,d0
  160.     movem.l (sp)+,d2/d3/d4/d5/d6/d7/a2/a3/a4
  161.     rts
  162.  
  163. ******* graphics.library/ReadPixelLine ***************************************
  164. *
  165. *   NAME
  166. *       ReadPixelLine -- read the pen number value of a horizontal line 
  167. *           of pixels starting at a specified x,y location and continuing 
  168. *           right for count pixels.
  169. *
  170. *   SYNOPSIS
  171. *       count = ReadPixelLine(rp,xstart,ystart,width,array,defval,temprp)
  172. *       d0                    a0 d0:16  d1:16   d2     a2   d7:8    a1 
  173. *
  174. *   LONG    count;
  175. *   struct  RastPort *rp;
  176. *   SHORT   xstart, ystart;
  177. *   LONG    width;
  178. *   UBYTE   *array;
  179. *   UBYTE   defval;
  180. *   struct  RastPort *temprp;
  181. *
  182. *   FUNCTION
  183. *       For each pixel in a rectangular region, combine the bits from each
  184. *       of the bit-planes used to describe a particular RastPort into the pen
  185. *       number selector which that bit combination normally forms for the
  186. *       system hardware selection of pixel color.
  187. *
  188. *   INPUTS
  189. *       rp -  pointer to a RastPort structure
  190. *       (x,y) a point in the RastPort
  191. *       width - count of horizontal pixels to read
  192. *       array - pointer to an array of uwords in which to store the pixel data
  193. *       temprp - temporary rastport (copy of rp with Layer set == NULL,
  194. *                                    temporary memory allocated for
  195. *                                    temprp->BitMap with Rows set == 1,
  196. *                                    and temporary memory allocated for
  197. *                                    temprp->BitMap->Planes[])
  198. *
  199. *   RESULT
  200. *       For each pixel in the array:
  201. *           Pen - (0..255) number at that position is returned
  202. *                 (defval) is returned if cannot read that pixel
  203. *
  204. *   NOTE
  205. *       width must be non negative
  206. *
  207. *   BUGS
  208. *
  209. *   SEE ALSO
  210. *       WritePixel  graphics/rastport.h
  211. *
  212. ******************************************************************************
  213.  
  214. _ReadPixelLine:
  215.     movem.l d2/d7/a2/a6,-(sp)
  216.     move.l  _GfxBase,a6
  217.     move.l  20(sp),a0       ; rp
  218.     movem.l 24(sp),d0/d1/d2 ; xstart, ystart, width
  219.     movea.l 36(sp),a2       ; array
  220.     move.l  40(sp),d7       ; defval
  221.     movea.l 44(sp),a1       ; temprp
  222.     jsr readpixelline
  223.     movem.l (sp)+,d2/d7/a2/a6
  224.     rts
  225.  
  226. readpixelline:
  227.  
  228.     movem.l d2/d3/d4/d5/d6/d7/a2,-(sp)
  229.  
  230.     move.l  d2,d4           ; copy "width" pixels
  231.     moveq.l #1,d5           ; copy one row of pixels
  232.     move.l  #(ABC+ABNC),d6  ; vanilla copy
  233.     moveq.l #0,d2           ; copy to temprp(0,0)
  234.     moveq.l #0,d3
  235.  
  236. ******************************************************************************
  237.  
  238.     jsr tmploop_init        ; initialize tmpras to default value
  239.  
  240. ******************************************************************************
  241.  
  242.     move.l  a1,-(sp)        ; save temprp
  243.     jsr _LVOClipBlit(a6)    ; do it the easy way
  244.     move.l  (sp)+,a1        ; restore temprp
  245.                             ; width now in d5
  246.  
  247.     movea.l rp_BitMap(a1),a1    ; get BitMap pointer
  248.     move.b  bm_Depth(a1),d2     ; Depth in d2
  249.     lea.l   bm_Planes(a1),a1    ; address of first plane pointer in a1
  250.     moveq.l #0,d0               ; source word offset
  251.  
  252. rplloop_init:
  253.  
  254.     moveq.l #$10,d3         ; set counter - 16 bits in a word
  255.  
  256.     bra.s   rplloop_count
  257.  
  258. rplloop_start:
  259.  
  260.     subq.l  #1,d3           ; advance to next bit
  261.     bge.s   same_word       ; not time to move onto next word just yet
  262.  
  263.     moveq.l #$0f,d3         ; reset counter - account for 'subq.l #1' above
  264. ;   addq.l  #4,d0           ; increment source LONGWORD offset
  265.     addq.l  #2,d0           ; increment source WORD offset
  266.  
  267. same_word:
  268.  
  269.     move.l  d2,d1           ; number of planes in d1
  270.     moveq.l #0,d5           ; storage to build pixel desription
  271.  
  272.     lsl.l   #2,d1           ;convert to long index
  273.     bra.s   shift_count
  274.  
  275. *-----------------------------------------------------------------------------
  276.  
  277. shift_start:
  278.  
  279. ;   move.l  d1,d6           ; plane number in d6
  280. ;   lsl.l   #2,d6           ; build plane pointer offset in d6
  281. ;   movea.l 0(a1,d6),a0     ; get plane pointer
  282.     movea.l 0(a1,d1),a0     ; get plane pointer
  283.  
  284.     roxl.l  0(a0,d0)        ; rol high bit left into extend
  285.     roxl.l  #1,d5           ; rol extend bit left into pixel description
  286.  
  287. shift_count:
  288.  
  289.     subq.l  #4,d1           ; decrement long offset
  290.     bge.s   shift_start
  291. ;   dbra    d1,shift_start
  292.  
  293. shift_end:
  294.  
  295.     move.w  d5,(a2)+        ; store pixel description in destination array
  296.  
  297. *-----------------------------------------------------------------------------
  298.  
  299. rplloop_count:
  300.  
  301.     dbra    d4,rplloop_start    ; loop back if not done entire width
  302.  
  303. rplloop_end:
  304.  
  305.     movem.l (sp)+,d2/d3/d4/d5/d6/d7/a2
  306.     rts
  307.  
  308.  
  309. ******************************************************************************
  310.  
  311. tmploop_init:
  312.  
  313.     movem.l d0/d1/d2/d3/d4/d5/d7/a0/a1,-(sp)
  314.  
  315.     movea.l rp_BitMap(a1),a1        ; get BitMap pointer
  316.     move.b  bm_Depth(a1),d2         ; Depth in d2
  317.     moveq.l #0,d3
  318.     move.w  bm_BytesPerRow(a1),d3   ; numbytes in d3
  319.  
  320.     lea.l   bm_Planes(a1),a1    ; address of first plane pointer in a1
  321.  
  322.     move.l  d2,d1               ; number of planes in d1
  323.     subq.l  #1,d2               ; adjust # of planes for low to high count
  324.  
  325.     bra.s   tmpshift_count
  326.  
  327. tmpshift_start: ; fill temprp with defval
  328.  
  329.     moveq.l #0,d0
  330.     roxr.l  #1,d7           ; ror low bit of d7 into extend bit
  331.     roxr.l  #1,d0           ; ror extend bit into high bit of d0
  332.     beq.s   stuff0          ; stuff null
  333.  
  334. stuff1:
  335.  
  336.     moveq.l #-1,d0          ; stuff ~null
  337.  
  338. stuff0:
  339.  
  340.     move.l  d2,d5           ; build plane number in d5
  341.     sub.l   d1,d5           ; plane number in d5 (low to high) 
  342.     lsl.l   #2,d5           ; build plane pointer offset in d5
  343.     movea.l 0(a1,d5),a0     ; get plane pointer
  344.  
  345.     move.l  d3,d4               ; init numbytes
  346.     lsr.l   #1,d4               ; convert to numwords
  347.  
  348.     bra.s   tmploop_count
  349.  
  350. tmploop_start:
  351.  
  352.     move.w  d0,(a0)+        ; stuff proper word into this plane of the tmpras
  353.  
  354. tmploop_count:
  355.  
  356.     dbra    d4,tmploop_start    ; d4 words
  357.  
  358. tmploop_end:
  359.  
  360. tmpshift_count:
  361.  
  362.     dbra    d1,tmpshift_start
  363.  
  364. tmpshift_end:
  365.  
  366.     movem.l (sp)+,d0/d1/d2/d3/d4/d5/d7/a0/a1
  367.     rts
  368. ******************************************************************************
  369.  
  370.     end
  371.  
  372.