writetruecolordata.pas 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173
  1. Program WriteTrueColorData;
  2. { ***********************************************************************
  3. * This is an example that shows how to use p96WriteTrueColorData
  4. * Program terminates when space bar or any mouse button is pressed!
  5. *
  6. * alx (Mon Dec 30 12:09:35 1996)
  7. *********************************************************************** }
  8. {
  9. Translated to fpc pascal.
  10. 14 Mars 2001.
  11. Updated for fpc 1.0.7
  12. 08 Jan 2003.
  13. [email protected]
  14. }
  15. uses exec, amigados, intuition, agraphics, picasso96api, utility;
  16. Const
  17. DataWidth = 160;
  18. DataHeight = 160;
  19. template : PChar = 'Width=W/N,Height=H/N,Depth=D/N';
  20. vecarray : Array[0..2] of long = (0,0,0);
  21. ltrue : longint = 1;
  22. Var
  23. rda : pRDArgs;
  24. { p96WriteTrueColorData only works on True- and HiColorModes }
  25. Const
  26. HiColorFormats = (RGBFF_R5G6B5 or RGBFF_R5G5B5 or RGBFF_R5G6B5PC or RGBFF_R5G5B5PC or RGBFF_B5G6R5PC or RGBFF_B5G5R5PC);
  27. TrueColorFormats = (RGBFF_R8G8B8 or RGBFF_B8G8R8);
  28. TrueAlphaFormats = (RGBFF_R8G8B8A8 or RGBFF_B8G8R8A8 or RGBFF_A8R8G8B8 or RGBFF_A8B8G8R8);
  29. UsefulFormats = (HiColorFormats or TrueColorFormats or TrueAlphaFormats);
  30. Pens : Array [0..0] Of integer = (NOT(0));
  31. Var
  32. sc : pScreen;
  33. win : pWindow;
  34. i,
  35. DisplayID : Longint;
  36. width,
  37. height,
  38. depth : Longint;
  39. quit : Boolean;
  40. reddata,
  41. greendata,
  42. bluedata : Pointer;
  43. tci : tTrueColorInfo;
  44. fh : FileHandle;
  45. imsg : pIntuiMessage;
  46. procedure CleanUp(why : string);
  47. begin
  48. if assigned(win) then CloseWindow(win);
  49. if assigned(sc) then p96CloseScreen(sc);
  50. if why <> '' then writeln(why);
  51. end;
  52. Begin
  53. if not Assigned(P96Base) then
  54. begin
  55. writeln('Cannot open ', PICASSO96APINAME);
  56. Halt(5);
  57. end;
  58. width:=640;
  59. height:=480;
  60. depth:=24;
  61. rda:=ReadArgs (template,@vecarray,Nil);
  62. If rda<>Nil Then
  63. Begin
  64. If vecarray[0]<>0 then width := long(@vecarray[0]);
  65. If vecarray[1]<>0 then height := long(@vecarray[1]);
  66. If vecarray[2]<>0 then depth := long(@vecarray[2]);
  67. FreeArgs(rda);
  68. End;
  69. DisplayID := p96BestModeIDTags([P96BIDTAG_NominalWidth, width,
  70. P96BIDTAG_NominalHeight, height,
  71. P96BIDTAG_Depth, depth,
  72. P96BIDTAG_FormatsAllowed, UsefulFormats,
  73. TAG_DONE]);
  74. sc := p96OpenScreenTags([P96SA_DisplayID, DisplayID,
  75. P96SA_Width, width,
  76. P96SA_Height, height,
  77. P96SA_Depth, depth,
  78. P96SA_AutoScroll, lTRUE,
  79. P96SA_Pens, AsTag(@Pens),
  80. P96SA_Title, AsTag('WriteTrueColorData Test'),
  81. TAG_DONE]);
  82. if sc = nil then CleanUp('Can''t open screen');
  83. win := OpenWindowTags(Nil,[WA_CustomScreen, AsTag(sc),
  84. WA_Backdrop, lTRUE,
  85. WA_Borderless, lTRUE,
  86. WA_SimpleRefresh, lTRUE,
  87. WA_RMBTrap, lTRUE,
  88. WA_Activate, lTRUE,
  89. WA_IDCMP, IDCMP_RAWKEY or IDCMP_MOUSEBUTTONS,
  90. TAG_END]);
  91. if win = nil then CleanUp('Can''t open window');
  92. quit:=False;
  93. reddata:=AllocVec(DataWidth*DataHeight, MEMF_ANY);
  94. greendata:=AllocVec(DataWidth*DataHeight, MEMF_ANY);
  95. bluedata:=AllocVec(DataWidth*DataHeight, MEMF_ANY);
  96. If (reddata<>Nil) And (greendata<>Nil) And (bluedata<>Nil) Then Begin
  97. tci.PixelDistance:=1;
  98. tci.BytesPerRow:=DataWidth;
  99. tci.RedData:=reddata;
  100. tci.GreenData:=greendata;
  101. tci.BlueData:=bluedata;
  102. fh:=DOSOpen ('Symbol.red',MODE_OLDFILE);
  103. If fh = 0 Then Begin
  104. i:=DOSRead(fh, reddata, DataWidth*DataHeight);
  105. DOSClose(fh);
  106. End;
  107. fh:=DOSOpen ('Symbol.green',MODE_OLDFILE);
  108. If fh = 0 Then Begin
  109. i:=DOSRead(fh, greendata, DataWidth*DataHeight);
  110. DOSClose(fh);
  111. End;
  112. fh:=DOSOpen ('Symbol.blue',MODE_OLDFILE);
  113. If fh = 0 Then Begin
  114. i:=DOSRead(fh, bluedata, DataWidth*DataHeight);
  115. DOSClose(fh);
  116. End;
  117. { paint something on the screen }
  118. p96WriteTrueColorData(@tci,0,0,win^.RPort,50,50,DataWidth,DataHeight);
  119. End;
  120. FreeVec(reddata);
  121. FreeVec(greendata);
  122. FreeVec(bluedata);
  123. { wait for input }
  124. While Not(quit) Do Begin
  125. WaitPort(win^.UserPort);
  126. imsg:=pIntuiMessage(GetMsg (win^.UserPort));
  127. While(imsg<>Nil) Do Begin
  128. If ((imsg^.IClass=IDCMP_MOUSEBUTTONS) or ((imsg^.IClass=IDCMP_RAWKEY) And (imsg^.Code=$40))) Then Begin
  129. { press MOUSEBUTTONS or SPACE bar to end program }
  130. quit:=True;
  131. End;
  132. ReplyMsg(pMessage(imsg));
  133. imsg:=pIntuiMessage(GetMsg (win^.UserPort));
  134. End;
  135. End;
  136. CleanUp('');
  137. End.