image.ppi 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227
  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 <> AW_BANK then
  38. begin
  39. Switchbank(bank1);
  40. AW_BANK:=bank1;
  41. end;
  42. if bank1=bank2
  43. then ScreenToMem(ofs1 and WinLoMask,target,linesize)
  44. else begin
  45. diff:=(bank2 shl winshift)-ofs2;
  46. ScreenToMem(ofs1 and WinLoMask,target,diff-BytesPerPixel);
  47. Switchbank(bank2);
  48. AW_BANK:=bank2;
  49. ScreenToMem((ofs1+diff) and WinLoMask,target+diff,linesize-diff);
  50. end;
  51. target:=target+linesize;
  52. end;
  53. end;
  54. procedure PutImage(x,y : integer;var BitMap;BitBlt : word);
  55. var
  56. height,width : integer;
  57. diff : integer;
  58. increment,i : longint;
  59. source,o1,o2 : longint;
  60. offset : longint;
  61. viewport : viewporttype;
  62. begin
  63. _graphresult:=grOk;
  64. if not isgraphmode then
  65. begin
  66. _graphresult:=grnoinitgraph;
  67. exit;
  68. end;
  69. source:=longint(@bitmap)+4;
  70. Width:=pinteger(@bitmap)^;
  71. Increment:=longint(Width);
  72. height:=pinteger(@bitmap+2)^;
  73. { wenn ausserhalb des Screens Procedur verlassen }
  74. x:=x+aktviewport.x1;
  75. y:=y+aktviewport.y1;
  76. if aktviewport.clip then viewport:=aktviewport else viewport:=aktscreen;
  77. if (x > viewport.x2 ) or
  78. (y > viewport.y2 ) or
  79. (x+Increment < viewport.x1) or
  80. (y+height < viewport.y1) then exit;
  81. { Clip oben }
  82. if y < viewport.y1 then
  83. begin
  84. diff:=viewport.y1-y;
  85. height:=height-diff;
  86. source:=source+Increment*diff;
  87. y:=viewport.y1;
  88. end;
  89. { Clip unten }
  90. if y+height > viewport.y2 then
  91. height:=viewport.y2-y;
  92. { Clip links }
  93. if x < viewport.x1 then
  94. begin
  95. diff:=viewport.x1-x;
  96. Width:=Increment-diff;
  97. source:=source+diff;
  98. x:=viewport.x1;
  99. end;
  100. { clip rechts }
  101. if x+width > viewport.x2 then
  102. begin
  103. diff:=x+width-viewport.x2;
  104. Width:=Increment-diff;
  105. end;
  106. Increment:=Increment*BytesPerPixel;
  107. Width:=Width*BytesPerPixel;
  108. for i:=y to y+height-1 do
  109. begin
  110. offset:=Y_ARRAY[i] + X_ARRAY[x];
  111. o1:=offset shr winshift;
  112. o2:=( offset + width ) shr winshift;
  113. if o1 <> AW_BANK then
  114. begin
  115. Switchbank(o1);
  116. AW_BANK:=o1;
  117. end;
  118. if o1 = o2 then
  119. begin
  120. case bitblt of
  121. normalput : MemToScreen (source,offset and WinLoMask,width);
  122. andput : MemAndScreen(source,offset and WinLoMask,width);
  123. orput : MemOrScreen (source,offset and WinLoMask,width);
  124. xorput : MemXorScreen(source,offset and WinLoMask,width);
  125. notput : MemNotScreen(source,offset and WinLoMask,width);
  126. end;
  127. end else begin
  128. { Bankswitching }
  129. diff:=((o2 shl winshift)-offset);
  130. case bitblt of
  131. normalput : begin
  132. MemToScreen (source,offset and WinLoMask,diff-BytesPerPixel);
  133. Switchbank(o2); AW_BANK:=o2;
  134. MemToScreen (source+diff,(offset+diff) and WinLoMask,width-diff);
  135. end;
  136. andput : begin
  137. MemAndScreen (source,offset and WinLoMask,diff-BytesPerPixel);
  138. Switchbank(o2); AW_BANK:=o2;
  139. MemAndScreen (source+diff,(offset+diff) and WinLoMask,width-diff);
  140. end;
  141. orput : begin
  142. MemOrScreen (source,offset and WinLoMask,diff-BytesPerPixel);
  143. Switchbank(o2); AW_BANK:=o2;
  144. MemOrScreen (source++diff,(offset+diff) and WinLoMask,width-diff);
  145. end;
  146. xorput : begin
  147. MemXorScreen(source,offset and WinLoMask,diff-BytesPerPixel);
  148. Switchbank(o2); AW_BANK:=o2;
  149. MemXorScreen(source+diff,(offset+diff) and WinLoMask,width-diff);
  150. end;
  151. notput : begin
  152. MemNotScreen(source,offset and WinLoMask,diff-BytesPerPixel);
  153. Switchbank(o2); AW_BANK:=o2;
  154. MemNotScreen(source+diff,(offset+diff) and WinLoMask,width-diff);
  155. end;
  156. end; { case }
  157. end; { else }
  158. source:=source+Increment;
  159. end; { for i }
  160. { clear the mmx state }
  161. if is_mmx_cpu then
  162. emms;
  163. end;
  164. function ImageSize(x1,y1,x2,y2 : integer) : word;
  165. begin
  166. _graphresult:=grOk;
  167. ImageSize:=(x2-x1+1)*(y2-y1+1)*BytesPerPixel+4;
  168. { +4, da Breite und H”he mit abgespeichert werden }
  169. end;
  170. {
  171. $Log$
  172. Revision 1.1 1998-03-25 11:18:42 root
  173. Initial revision
  174. Revision 1.5 1998/03/03 22:48:42 florian
  175. + graph.drawpoly procedure
  176. + putimage with xorput uses mmx if available
  177. Revision 1.4 1998/01/26 11:58:14 michael
  178. + Added log at the end
  179. Working file: rtl/dos/ppi/image.ppi
  180. description:
  181. ----------------------------
  182. revision 1.3
  183. date: 1997/12/19 11:47:08; author: florian; state: Exp; lines: +3 -3
  184. *** empty log message ***
  185. ----------------------------
  186. revision 1.2
  187. date: 1997/12/01 12:21:30; author: michael; state: Exp; lines: +13 -1
  188. + added copyright reference in header.
  189. ----------------------------
  190. revision 1.1
  191. date: 1997/11/27 08:33:51; author: michael; state: Exp;
  192. Initial revision
  193. ----------------------------
  194. revision 1.1.1.1
  195. date: 1997/11/27 08:33:51; author: michael; state: Exp; lines: +0 -0
  196. FPC RTL CVS start
  197. =============================================================================
  198. }