image.ppi 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233
  1. {
  2. $Id$
  3. This file is part of the Free Pascal run time library.
  4. Copyright (c) 1993,97 by the Free Pascal development team.
  5. See the file COPYING.FPC, included in this distribution,
  6. for details about the copyright.
  7. This program is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  10. **********************************************************************}
  11. procedure GetImage(x1,y1,x2,y2 : integer;var BitMap);
  12. var
  13. i,linesize,target : longint;
  14. ofs1,ofs2,bank1,bank2,diff : longint;
  15. begin
  16. _graphresult:=grOk;
  17. if not isgraphmode then
  18. begin
  19. _graphresult:=grnoinitgraph;
  20. exit;
  21. end;
  22. x1:=x1+aktviewport.x1;
  23. y1:=y1+aktviewport.y1;
  24. x2:=x2+aktviewport.x1;
  25. y2:=y2+aktviewport.y1;
  26. if (x1>_maxx) or (y1>_maxy) or (x2<0) or (y2<0) then exit;
  27. target:=longint(@bitmap)+4;
  28. pinteger(@bitmap)^:=x2-x1+1;
  29. pinteger(@bitmap+2)^:=y2-y1+1;
  30. linesize:=(x2-x1+1)*BytesPerPixel;
  31. for i:=y1 to y2 do
  32. begin
  33. ofs1:=Y_ARRAY[i]+X_ARRAY[x1];
  34. ofs2:=Y_ARRAY[i]+X_ARRAY[x2];
  35. bank1:=ofs1 shr WinShift;
  36. bank2:=ofs2 shr WinShift;
  37. if bank1 <> A_BANK then
  38. begin
  39. Switchbank(bank1);
  40. end;
  41. if bank1=bank2
  42. then ScreenToMem(ofs1 and WinLoMask,target,linesize)
  43. else begin
  44. diff:=(bank2 shl winshift)-ofs2;
  45. ScreenToMem(ofs1 and WinLoMask,target,diff-BytesPerPixel);
  46. Switchbank(bank2);
  47. ScreenToMem((ofs1+diff) and WinLoMask,target+diff,linesize-diff);
  48. end;
  49. target:=target+linesize;
  50. end;
  51. end;
  52. procedure PutImage(x,y : integer;var BitMap;BitBlt : word);
  53. var
  54. height,width : integer;
  55. diff : integer;
  56. increment,i : longint;
  57. source,o1,o2 : longint;
  58. offset : longint;
  59. viewport : viewporttype;
  60. begin
  61. _graphresult:=grOk;
  62. if not isgraphmode then
  63. begin
  64. _graphresult:=grnoinitgraph;
  65. exit;
  66. end;
  67. source:=longint(@bitmap)+4;
  68. Width:=pinteger(@bitmap)^;
  69. Increment:=longint(Width);
  70. height:=pinteger(@bitmap+2)^;
  71. { wenn ausserhalb des Screens Procedur verlassen }
  72. x:=x+aktviewport.x1;
  73. y:=y+aktviewport.y1;
  74. if aktviewport.clip then viewport:=aktviewport else viewport:=aktscreen;
  75. if (x > viewport.x2 ) or
  76. (y > viewport.y2 ) or
  77. (x+Increment < viewport.x1) or
  78. (y+height < viewport.y1) then exit;
  79. { Clip oben }
  80. if y < viewport.y1 then
  81. begin
  82. diff:=viewport.y1-y;
  83. height:=height-diff;
  84. source:=source+Increment*diff;
  85. y:=viewport.y1;
  86. end;
  87. { Clip unten }
  88. if y+height > viewport.y2 then
  89. height:=viewport.y2-y;
  90. { Clip links }
  91. if x < viewport.x1 then
  92. begin
  93. diff:=viewport.x1-x;
  94. Width:=Increment-diff;
  95. source:=source+diff;
  96. x:=viewport.x1;
  97. end;
  98. { clip rechts }
  99. if x+width > viewport.x2 then
  100. begin
  101. diff:=x+width-viewport.x2;
  102. Width:=Increment-diff;
  103. end;
  104. Increment:=Increment*BytesPerPixel;
  105. Width:=Width*BytesPerPixel;
  106. for i:=y to y+height-1 do
  107. begin
  108. offset:=Y_ARRAY[i] + X_ARRAY[x];
  109. o1:=offset shr winshift;
  110. o2:=( offset + width ) shr winshift;
  111. if o1 <> A_BANK then
  112. begin
  113. Switchbank(o1);
  114. end;
  115. if o1 = o2 then
  116. begin
  117. case bitblt of
  118. normalput : MemToScreen (source,offset and WinLoMask,width);
  119. andput : MemAndScreen(source,offset and WinLoMask,width);
  120. orput : MemOrScreen (source,offset and WinLoMask,width);
  121. xorput : MemXorScreen(source,offset and WinLoMask,width);
  122. notput : MemNotScreen(source,offset and WinLoMask,width);
  123. end;
  124. end else begin
  125. { Bankswitching }
  126. diff:=((o2 shl winshift)-offset);
  127. case bitblt of
  128. normalput : begin
  129. MemToScreen (source,offset and WinLoMask,diff-BytesPerPixel);
  130. Switchbank(o2);
  131. MemToScreen (source+diff,(offset+diff) and WinLoMask,width-diff);
  132. end;
  133. andput : begin
  134. MemAndScreen (source,offset and WinLoMask,diff-BytesPerPixel);
  135. Switchbank(o2);
  136. MemAndScreen (source+diff,(offset+diff) and WinLoMask,width-diff);
  137. end;
  138. orput : begin
  139. MemOrScreen (source,offset and WinLoMask,diff-BytesPerPixel);
  140. Switchbank(o2);
  141. MemOrScreen (source++diff,(offset+diff) and WinLoMask,width-diff);
  142. end;
  143. xorput : begin
  144. MemXorScreen(source,offset and WinLoMask,diff-BytesPerPixel);
  145. Switchbank(o2);
  146. MemXorScreen(source+diff,(offset+diff) and WinLoMask,width-diff);
  147. end;
  148. notput : begin
  149. MemNotScreen(source,offset and WinLoMask,diff-BytesPerPixel);
  150. Switchbank(o2);
  151. MemNotScreen(source+diff,(offset+diff) and WinLoMask,width-diff);
  152. end;
  153. end; { case }
  154. end; { else }
  155. source:=source+Increment;
  156. end; { for i }
  157. { clear the mmx state }
  158. if is_mmx_cpu then
  159. emms;
  160. end;
  161. function ImageSize(x1,y1,x2,y2 : integer) : longint;
  162. begin
  163. _graphresult:=grOk;
  164. ImageSize:=(x2-x1+1)*(y2-y1+1)*BytesPerPixel+4;
  165. { 4 bytes for Height and width in words at the beginning }
  166. end;
  167. {
  168. $Log$
  169. Revision 1.2 1998-11-18 09:31:36 pierre
  170. * changed color scheme
  171. all colors are in RGB format if more than 256 colors
  172. + added 24 and 32 bits per pixel mode
  173. (compile with -dDEBUG)
  174. 24 bit mode with banked still as problems on pixels across
  175. the bank boundary, but works in LinearFrameBufferMode
  176. Look at install/demo/nmandel.pp
  177. Revision 1.1.1.1 1998/03/25 11:18:42 root
  178. * Restored version
  179. Revision 1.5 1998/03/03 22:48:42 florian
  180. + graph.drawpoly procedure
  181. + putimage with xorput uses mmx if available
  182. Revision 1.4 1998/01/26 11:58:14 michael
  183. + Added log at the end
  184. Working file: rtl/dos/ppi/image.ppi
  185. description:
  186. ----------------------------
  187. revision 1.3
  188. date: 1997/12/19 11:47:08; author: florian; state: Exp; lines: +3 -3
  189. *** empty log message ***
  190. ----------------------------
  191. revision 1.2
  192. date: 1997/12/01 12:21:30; author: michael; state: Exp; lines: +13 -1
  193. + added copyright reference in header.
  194. ----------------------------
  195. revision 1.1
  196. date: 1997/11/27 08:33:51; author: michael; state: Exp;
  197. Initial revision
  198. ----------------------------
  199. revision 1.1.1.1
  200. date: 1997/11/27 08:33:51; author: michael; state: Exp; lines: +0 -0
  201. FPC RTL CVS start
  202. =============================================================================
  203. }