Image.cpp 88 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126
  1. //---Include---
  2. #include "Image.h"
  3. #ifdef WIN32
  4. # include <objidl.h>
  5. #endif
  6. #include "AlphaField.h"
  7. #include "FileSystem.h"
  8. #include "Globals.h"
  9. #include "MouseEvent.h"
  10. #include "Border.h"
  11. #include "Scroll.h"
  12. #include "Text.h"
  13. #include "ToolTip.h"
  14. #ifdef WIN32
  15. # include <gdiplus.h>
  16. # pragma comment(lib, "gdiplus.lib")
  17. #endif
  18. #ifndef WIN32
  19. # include <math.h>
  20. # include <stdlib.h>
  21. # include <string.h>
  22. # ifndef max
  23. # define max(a, b) (((a) > (b)) ? (a) : (b))
  24. # endif
  25. # ifndef min
  26. # define min(a, b) (((a) < (b)) ? (a) : (b))
  27. # endif
  28. #endif
  29. using namespace Framework;
  30. // Contents of the Image class from Image.h
  31. // Constructor
  32. Image::Image(bool options)
  33. : ReferenceCounter(),
  34. fc(0),
  35. delFc(1),
  36. size(0, 0),
  37. drawOff(options ? new Punkt[2000] : new Punkt[1]),
  38. dPosA(options ? new Punkt[2000] : new Punkt[1]),
  39. dSizeA(options ? new Punkt[2000] : new Punkt[1]),
  40. doa(0),
  41. alpha(options ? new unsigned char[1000] : new unsigned char[1]),
  42. alphaAnzahl(0),
  43. rend(0),
  44. alpha3D(0)
  45. {
  46. alpha[0] = 0;
  47. }
  48. // Destructor
  49. Image::~Image()
  50. {
  51. if (delFc)
  52. {
  53. delete[] fc;
  54. fc = 0;
  55. }
  56. delete[] dPosA;
  57. delete[] dSizeA;
  58. delete[] alpha;
  59. delete[] drawOff;
  60. }
  61. // privat
  62. inline void Image::alphaPixelP(int x, int y, int f)
  63. {
  64. alphaPixelP(fc[x + y * size.x], f);
  65. }
  66. inline void Image::alphaPixelP3D(int x, int y, int f)
  67. {
  68. alphaPixelP3D(fc[x + y * size.x], f);
  69. }
  70. inline void Image::alphaPixelAssozP(int& fc, int f)
  71. {
  72. unsigned char* fc1 = (unsigned char*)&fc;
  73. unsigned char* fc2 = (unsigned char*)&f;
  74. unsigned char na = (unsigned char)~fc2[3];
  75. unsigned char a = (unsigned char)(fc2[3] + ((na * fc1[3]) >> 8));
  76. if (a == 0) return;
  77. fc1[2] = (unsigned char)((fc2[2] * fc2[3] + ((fc1[2] * na * fc1[3]) >> 8))
  78. / a);
  79. fc1[1] = (unsigned char)((fc2[1] * fc2[3] + ((fc1[1] * na * fc1[3]) >> 8))
  80. / a);
  81. fc1[0] = (unsigned char)((fc2[0] * fc2[3] + ((fc1[0] * na * fc1[3]) >> 8))
  82. / a);
  83. fc1[3] = a;
  84. }
  85. inline void Image::alphaPixelP3D(int& fc, int colorb)
  86. {
  87. int alpha = ((colorb >> 24) & 0xFF);
  88. int oldAlpha = ((fc >> 24) & 0xFF);
  89. bool newAlpha = alpha > oldAlpha;
  90. int na = (0x100 - alpha);
  91. fc = (((((na * (fc & 0xFF00FF)) >> 8)
  92. + ((alpha * (colorb & 0xFF00FF)) >> 8))
  93. & 0xFF00FF)
  94. | ((((na * (fc & 0x00FF00)) >> 8)
  95. + ((alpha * (colorb & 0x00FF00)) >> 8))
  96. & 0x00FF00)
  97. | ((colorb & 0xFF000000) * newAlpha)
  98. | ((fc & 0xFF000000) * !newAlpha))
  99. * (fc != 0)
  100. | (fc == 0) * colorb;
  101. }
  102. inline void Image::alphaPixelP(int& fc, int colorb)
  103. {
  104. int alpha = ((colorb >> 24) & 0xFF);
  105. int na = (0x100 - alpha);
  106. fc = ((((na * (fc & 0xFF00FF)) >> 8) + ((alpha * (colorb & 0xFF00FF)) >> 8))
  107. & 0xFF00FF)
  108. | ((((na * (fc & 0x00FF00)) >> 8) + ((alpha * (colorb & 0x00FF00)) >> 8))
  109. & 0x00FF00)
  110. | ((fc & 0xFF000000));
  111. }
  112. char Image::getOutCode(Punkt p) const
  113. {
  114. char ret = 0;
  115. if (p.x < dPosA[doa].x) ret = 1;
  116. if (p.x >= dSizeA[doa].x) ret = 2;
  117. if (p.y < dPosA[doa].y) ret |= 4;
  118. if (p.y >= dSizeA[doa].y) ret |= 8;
  119. return ret;
  120. }
  121. void Image::drawFlatDreieck(
  122. int y1, int y2, float m1, float b1, float m2, float b2, int farbe)
  123. {
  124. const int yStart = max(y1, dPosA[doa].y);
  125. const int yEnd = min(y2, dSizeA[doa].y);
  126. for (int y = yStart; y < yEnd; y++)
  127. {
  128. const int xStart = max((int)(m1 * (float)y + b1 + 0.5f), dPosA[doa].x);
  129. const int xEnd = min((int)(m2 * (float)y + b2 + 0.5f), dSizeA[doa].x);
  130. for (int x = xStart; x < xEnd; x++)
  131. fc[x + y * size.x] = farbe;
  132. }
  133. }
  134. void Image::drawFlatDreieckTextur(int y1,
  135. int y2,
  136. double m1,
  137. double b1,
  138. double m2,
  139. double b2,
  140. double tx1,
  141. double ty1,
  142. double tx2,
  143. double ty2,
  144. double tx_1o,
  145. double ty_1o,
  146. double tx_2o,
  147. double ty_2o,
  148. double txf,
  149. double tyf,
  150. const Image& textur)
  151. {
  152. const double yStart = max(y1, dPosA[doa].y);
  153. const double yEnd = min(y2, dSizeA[doa].y);
  154. double tx_1 = tx1 + tx_1o * (yStart - y1),
  155. ty_1 = ty1 + ty_1o * (yStart - y1),
  156. tx_2 = tx2 + tx_2o * (yStart - y1),
  157. ty_2 = ty2 + ty_2o * (yStart - y1);
  158. for (double y = yStart; y < yEnd;
  159. y++, tx_1 += tx_1o, ty_1 += ty_1o, tx_2 += tx_2o, ty_2 += ty_2o)
  160. {
  161. const double xStart = m1 * y + b1;
  162. const double xEnd = m2 * y + b2;
  163. drawLinieHTextur(Vec2<double>(xStart, y),
  164. xEnd - xStart,
  165. Vec2<double>(tx_1, ty_1),
  166. Vec2<double>(tx_2, ty_2),
  167. txf,
  168. tyf,
  169. textur);
  170. }
  171. }
  172. void Image::drawFlatDreieckAlpha(
  173. int y1, int y2, float m1, float b1, float m2, float b2, int farbe)
  174. {
  175. const int yStart = max((int)(y1 + 0.5), dPosA[doa].y);
  176. const int yEnd = min((int)(y2 + 0.5), dSizeA[doa].y);
  177. if (alpha3D)
  178. {
  179. for (int y = yStart; y < yEnd; y++)
  180. {
  181. const int xStart
  182. = max((int)(m1 * ((float)y + 0.5f) + b1 + 0.5f), dPosA[doa].x);
  183. const int xEnd
  184. = min((int)(m2 * ((float)y + 0.5) + b2 + 0.5f), dSizeA[doa].x);
  185. for (int x = xStart; x < xEnd; x++)
  186. alphaPixelP3D(fc[x + y * size.x], farbe);
  187. }
  188. }
  189. else
  190. {
  191. for (int y = yStart; y < yEnd; y++)
  192. {
  193. const int xStart
  194. = max((int)(m1 * ((float)y + 0.5f) + b1 + 0.5f), dPosA[doa].x);
  195. const int xEnd
  196. = min((int)(m2 * ((float)y + 0.5) + b2 + 0.5f), dSizeA[doa].x);
  197. for (int x = xStart; x < xEnd; x++)
  198. alphaPixelP(fc[x + y * size.x], farbe);
  199. }
  200. }
  201. }
  202. void Image::drawFlatDreieckTexturAlpha(int y1,
  203. int y2,
  204. double m1,
  205. double b1,
  206. double m2,
  207. double b2,
  208. double tx1,
  209. double ty1,
  210. double tx2,
  211. double ty2,
  212. double tx_1o,
  213. double ty_1o,
  214. double tx_2o,
  215. double ty_2o,
  216. double txf,
  217. double tyf,
  218. const Image& textur)
  219. {
  220. const double yStart = max(y1, dPosA[doa].y);
  221. const double yEnd = min(y2, dSizeA[doa].y);
  222. double tx_1 = tx1 + tx_1o * (yStart - y1),
  223. ty_1 = ty1 + ty_1o * (yStart - y1),
  224. tx_2 = tx2 + tx_2o * (yStart - y1),
  225. ty_2 = ty2 + ty_2o * (yStart - y1);
  226. for (double y = yStart; y < yEnd;
  227. y++, tx_1 += tx_1o, ty_1 += ty_1o, tx_2 += tx_2o, ty_2 += ty_2o)
  228. {
  229. const double xStart = m1 * y + b1;
  230. const double xEnd = m2 * y + b2;
  231. drawLineHTextureAlpha(Vec2<double>(xStart, y),
  232. xEnd - xStart,
  233. Vec2<double>(tx_1, ty_1),
  234. Vec2<double>(tx_2, ty_2),
  235. txf,
  236. tyf,
  237. textur);
  238. }
  239. }
  240. void Image::drawLinieHTextur(Vec2<double> p,
  241. double len,
  242. Vec2<double> ta,
  243. Vec2<double> tb,
  244. double txo,
  245. double tyo,
  246. const Image& textur) // draws a horizontal line
  247. {
  248. if (alpha[alphaAnzahl] == 0xFF) return;
  249. if (alpha[alphaAnzahl])
  250. {
  251. drawLineHTextureAlpha(p, len, ta, tb, txo, tyo, textur);
  252. return;
  253. }
  254. if (len < 0)
  255. {
  256. p.x += len;
  257. len = -len;
  258. ta.Swap(tb);
  259. }
  260. int dpx = dPosA[doa].x;
  261. int dpy = dPosA[doa].y;
  262. int dgx = dSizeA[doa].x;
  263. int dgy = dSizeA[doa].y;
  264. if (p.y < dpy || p.y >= dgy) return;
  265. double off = 0;
  266. if (p.x < dpx)
  267. {
  268. off = dpx - p.x;
  269. len -= dpx - p.x;
  270. if (len <= 0) return;
  271. p.x = dpx;
  272. }
  273. if (p.x + len >= dgx)
  274. {
  275. len -= p.x - dgx + len;
  276. if (len <= 0) return;
  277. }
  278. int br = size.x;
  279. int* fc = this->fc + (int)(p.x + (int)p.y * br);
  280. double x = ta.x + txo * off, y = ta.y + tyo * off;
  281. int* buffer = textur.getBuffer();
  282. int txtBr = textur.getBreite();
  283. for (int i = 0; i < len; ++i, ++fc)
  284. {
  285. *fc = buffer[(int)((int)(x + 0.5) + (int)(y + 0.5) * txtBr)];
  286. x += txo, y += tyo;
  287. }
  288. rend = 1;
  289. }
  290. void Image::drawLineHTextureAlpha(Vec2<double> p,
  291. double len,
  292. Vec2<double> ta,
  293. Vec2<double> tb,
  294. double txo,
  295. double tyo,
  296. const Image& textur) // draws a horizontal line
  297. {
  298. if (alpha[alphaAnzahl] == 0xFF) return;
  299. if (len < 0)
  300. {
  301. p.x += len;
  302. len = -len;
  303. ta.Swap(tb);
  304. }
  305. int dpx = dPosA[doa].x;
  306. int dpy = dPosA[doa].y;
  307. int dgx = dSizeA[doa].x;
  308. int dgy = dSizeA[doa].y;
  309. if (p.y < dpy || p.y >= dgy) return;
  310. double off = 0;
  311. if (p.x < dpx)
  312. {
  313. off = dpx - p.x;
  314. len -= dpx - p.x;
  315. if (len <= 0) return;
  316. p.x = dpx;
  317. }
  318. if (p.x + len >= dgx)
  319. {
  320. len -= p.x - dgx + len;
  321. if (len <= 0) return;
  322. }
  323. int br = size.x;
  324. int* fc = this->fc + (int)(p.x + (int)p.y * br);
  325. double x = ta.x + txo * off, y = ta.y + tyo * off;
  326. int* buffer = textur.getBuffer();
  327. int txtBr = textur.getBreite();
  328. int f;
  329. if (alpha3D)
  330. {
  331. for (int i = 0; i < len; ++i, ++fc)
  332. {
  333. f = buffer[(int)((int)(x + 0.5) + (int)(y + 0.5) * txtBr)];
  334. if (alpha[alphaAnzahl])
  335. {
  336. unsigned char* cf = (unsigned char*)&f;
  337. cf[3] = (unsigned char)((cf[3] > alpha[alphaAnzahl])
  338. * (cf[3] - alpha[alphaAnzahl]));
  339. }
  340. alphaPixelP3D(*fc, f);
  341. x += txo, y += tyo;
  342. }
  343. }
  344. else
  345. {
  346. for (int i = 0; i < len; ++i, ++fc)
  347. {
  348. f = buffer[(int)((int)(x + 0.5) + (int)(y + 0.5) * txtBr)];
  349. if (alpha[alphaAnzahl])
  350. {
  351. unsigned char* cf = (unsigned char*)&f;
  352. cf[3] = (unsigned char)((cf[3] > alpha[alphaAnzahl])
  353. * (cf[3] - alpha[alphaAnzahl]));
  354. }
  355. alphaPixelP(*fc, f);
  356. x += txo, y += tyo;
  357. }
  358. }
  359. rend = 1;
  360. }
  361. // non-constant
  362. // Checks if a rectangle is fully or partially within the drawing area.
  363. // return 0 if the rectangle is not in the drawing area, 1 otherwise
  364. bool Image::isAreaDrawable(int x, int y, int b, int h)
  365. {
  366. int dpx = dPosA[doa].x;
  367. int dpy = dPosA[doa].y;
  368. int dgx = dSizeA[doa].x;
  369. int dgy = dSizeA[doa].y;
  370. x += drawOff[doa].x;
  371. y += drawOff[doa].y;
  372. if (x + b < dpx || y + h < dpy || x >= dgx || y >= dgy) return 0;
  373. return 1;
  374. }
  375. // When this flag is set, during alpha blending if the previous
  376. // color is 0, only the new one is copied with its alpha value. This is useful
  377. // for use in the 3D screen, where the drawn image is later displayed using alpha
  378. // blending
  379. void Image::setAlpha3D(bool erlaubt)
  380. {
  381. alpha3D = erlaubt;
  382. }
  383. void Image::setAlpha(
  384. unsigned char alpha) // sets the transparency for subsequent drawings
  385. {
  386. int last = this->alpha[alphaAnzahl];
  387. ++alphaAnzahl;
  388. assert(alphaAnzahl < 1000);
  389. this->alpha[alphaAnzahl]
  390. = (unsigned char)((255 - alpha) > last ? (255 - alpha) : last);
  391. }
  392. void Image::releaseAlpha() // Releases alpha
  393. {
  394. --alphaAnzahl;
  395. }
  396. void Image::setPixelBuffer(int* buffer,
  397. bool deleteBuffer,
  398. int breite,
  399. int height) // sets the pointer to the image pixels
  400. {
  401. if (delFc) delete[] fc;
  402. fc = buffer;
  403. delFc = deleteBuffer;
  404. size.x = breite;
  405. size.y = height;
  406. drawOff[0].x = 0;
  407. drawOff[0].y = 0;
  408. dPosA[0].x = 0;
  409. dPosA[0].y = 0;
  410. dSizeA[0] = size;
  411. alphaAnzahl = 0;
  412. alpha[0] = 0;
  413. doa = 0;
  414. rend = 1;
  415. }
  416. void Image::neuImage(int breite, int height, int fillColor)
  417. {
  418. if (fc && delFc) delete[] fc;
  419. size.x = breite;
  420. size.y = height;
  421. fc = new int[size.x * size.y];
  422. setFarbe(fillColor);
  423. drawOff[0].x = 0;
  424. drawOff[0].y = 0;
  425. dPosA[0].x = 0;
  426. dPosA[0].y = 0;
  427. dSizeA[0] = size;
  428. alphaAnzahl = 0;
  429. alpha[0] = 0;
  430. doa = 0;
  431. rend = 1;
  432. }
  433. void Image::setFarbe(int f)
  434. {
  435. if ((f & 0xFF) == ((f >> 8) & 0xFF) && (f & 0xFF) == ((f >> 16) & 0xFF)
  436. && (f & 0xFF) == ((f >> 24) & 0xFF))
  437. memset(fc, f, size.x * size.y * 4);
  438. else
  439. {
  440. for (int *i = fc, *end = i + size.x * size.y; i < end; i++)
  441. *i = f;
  442. }
  443. rend = 1;
  444. }
  445. void Image::fillRegion(int x, int y, int b, int h, int ff)
  446. {
  447. if (alpha[alphaAnzahl] == 0xFF) return;
  448. if (alpha[alphaAnzahl])
  449. {
  450. alphaRegion(x, y, b, h, ff);
  451. return;
  452. }
  453. int dpx = dPosA[doa].x;
  454. int dpy = dPosA[doa].y;
  455. int dgx = dSizeA[doa].x;
  456. int dgy = dSizeA[doa].y;
  457. x += drawOff[doa].x;
  458. y += drawOff[doa].y;
  459. if (x + b < dpx || y + h < dpy || x >= dgx || y >= dgy) return;
  460. if (x < dpx)
  461. {
  462. b -= dpx - x;
  463. x = dpx;
  464. }
  465. if (y < dpy)
  466. {
  467. h -= dpy - y;
  468. y = dpy;
  469. }
  470. b = (x + b) >= dgx ? (dgx - x) : b;
  471. h = (y + h) >= dgy ? (dgy - y) : h;
  472. int* pixel = fc + y * size.x + x;
  473. int* rowEnd = pixel + b;
  474. for (int i = 0; i < h; pixel += size.x - b, ++i, rowEnd += size.x)
  475. {
  476. for (; pixel < rowEnd; ++pixel)
  477. *pixel = ff;
  478. }
  479. rend = 1;
  480. }
  481. void Image::alphaRegion(int x, int y, int b, int h, int ff)
  482. {
  483. if (alpha[alphaAnzahl] == 0xFF) return;
  484. int dpx = dPosA[doa].x;
  485. int dpy = dPosA[doa].y;
  486. int dgx = dSizeA[doa].x;
  487. int dgy = dSizeA[doa].y;
  488. x += drawOff[doa].x;
  489. y += drawOff[doa].y;
  490. if (x + b < dpx || y + h < dpy || x >= dgx || y >= dgy) return;
  491. if (x < dpx)
  492. {
  493. b -= dpx - x;
  494. x = dpx;
  495. }
  496. if (y < dpy)
  497. {
  498. h -= dpy - y;
  499. y = dpy;
  500. }
  501. b = (x + b) >= dgx ? (dgx - x) : b;
  502. h = (y + h) >= dgy ? (dgy - y) : h;
  503. if (alpha[alphaAnzahl])
  504. {
  505. unsigned char* cf = (unsigned char*)&ff;
  506. cf[3] = (unsigned char)((cf[3] > alpha[alphaAnzahl])
  507. * (cf[3] - alpha[alphaAnzahl]));
  508. }
  509. int* pixel = fc + y * size.x + x;
  510. int* rowEnd = pixel + b;
  511. if (alpha3D)
  512. {
  513. for (int i = 0; i < h; pixel += size.x - b, ++i, rowEnd += size.x)
  514. {
  515. for (; pixel < rowEnd; ++pixel)
  516. {
  517. alphaPixelP3D(*pixel, ff);
  518. }
  519. }
  520. }
  521. else
  522. {
  523. for (int i = 0; i < h; pixel += size.x - b, ++i, rowEnd += size.x)
  524. {
  525. for (; pixel < rowEnd; ++pixel)
  526. {
  527. alphaPixelP(*pixel, ff);
  528. }
  529. }
  530. }
  531. rend = 1;
  532. }
  533. void Image::alphaPixel2D(int i, int f)
  534. {
  535. if (!alpha[alphaAnzahl])
  536. alphaPixelP(fc[i], f);
  537. else
  538. {
  539. unsigned char* cf = (unsigned char*)&f;
  540. cf[3] = (unsigned char)((cf[3] > alpha[alphaAnzahl])
  541. * (cf[3] - alpha[alphaAnzahl]));
  542. alphaPixelP(fc[i], f);
  543. rend = 1;
  544. }
  545. }
  546. void Image::alphaPixel3D(int i, int f)
  547. {
  548. if (!alpha[alphaAnzahl])
  549. alphaPixelP3D(fc[i], f);
  550. else
  551. {
  552. unsigned char* cf = (unsigned char*)&f;
  553. cf[3] = (unsigned char)((cf[3] > alpha[alphaAnzahl])
  554. * (cf[3] - alpha[alphaAnzahl]));
  555. alphaPixelP3D(fc[i], f);
  556. rend = 1;
  557. }
  558. }
  559. void Image::alphaPixel2D(int x, int y, int f)
  560. {
  561. if (!alpha[alphaAnzahl]) alphaPixelP(fc[x + y * size.x], f);
  562. if (alpha[alphaAnzahl] < 0xFF)
  563. {
  564. unsigned char* cf = (unsigned char*)&f;
  565. cf[3] = (unsigned char)((cf[3] > alpha[alphaAnzahl])
  566. * (cf[3] - alpha[alphaAnzahl]));
  567. alphaPixelP(fc[x + y * size.x], f);
  568. rend = 1;
  569. }
  570. }
  571. void Image::alphaPixel3D(int x, int y, int f)
  572. {
  573. if (!alpha[alphaAnzahl]) alphaPixelP3D(fc[x + y * size.x], f);
  574. if (alpha[alphaAnzahl] < 0xFF)
  575. {
  576. unsigned char* cf = (unsigned char*)&f;
  577. cf[3] = (unsigned char)((cf[3] > alpha[alphaAnzahl])
  578. * (cf[3] - alpha[alphaAnzahl]));
  579. alphaPixelP3D(fc[x + y * size.x], f);
  580. rend = 1;
  581. }
  582. }
  583. void Image::alphaPixelDP2D(int x, int y, int f)
  584. {
  585. if (alpha[alphaAnzahl] == 0xFF) return;
  586. int dpx = dPosA[doa].x;
  587. int dpy = dPosA[doa].y;
  588. int dgx = dSizeA[doa].x;
  589. int dgy = dSizeA[doa].y;
  590. x += drawOff[doa].x;
  591. y += drawOff[doa].y;
  592. if (x < dpx || y < dpy || x >= dgx || y >= dgy) return;
  593. if (alpha[alphaAnzahl])
  594. {
  595. unsigned char* cf = (unsigned char*)&f;
  596. cf[3] = (unsigned char)((cf[3] > alpha[alphaAnzahl])
  597. * (cf[3] - alpha[alphaAnzahl]));
  598. }
  599. alphaPixelP(fc[x + y * size.x], f);
  600. rend = 1;
  601. }
  602. void Image::alphaPixelDP3D(int x, int y, int f)
  603. {
  604. if (alpha[alphaAnzahl] == 0xFF) return;
  605. int dpx = dPosA[doa].x;
  606. int dpy = dPosA[doa].y;
  607. int dgx = dSizeA[doa].x;
  608. int dgy = dSizeA[doa].y;
  609. x += drawOff[doa].x;
  610. y += drawOff[doa].y;
  611. if (x < dpx || y < dpy || x >= dgx || y >= dgy) return;
  612. if (alpha[alphaAnzahl])
  613. {
  614. unsigned char* cf = (unsigned char*)&f;
  615. cf[3] = (unsigned char)((cf[3] > alpha[alphaAnzahl])
  616. * (cf[3] - alpha[alphaAnzahl]));
  617. }
  618. alphaPixelP3D(fc[x + y * size.x], f);
  619. rend = 1;
  620. }
  621. void Image::alphaPixelDP2D(int i, int f)
  622. {
  623. int x = i % size.x;
  624. int y = i / size.x;
  625. alphaPixelDP2D(x, y, f);
  626. rend = 1;
  627. }
  628. void Image::alphaPixelDP3D(int i, int f)
  629. {
  630. int x = i % size.x;
  631. int y = i / size.x;
  632. alphaPixelDP3D(x, y, f);
  633. rend = 1;
  634. }
  635. void Image::setPixelDP(int x, int y, int f)
  636. {
  637. if (alpha[alphaAnzahl] == 0xFF) return;
  638. if (alpha[alphaAnzahl])
  639. {
  640. if (alpha3D)
  641. alphaPixelDP3D(x, y, f);
  642. else
  643. alphaPixelDP2D(x, y, f);
  644. return;
  645. }
  646. int dpx = dPosA[doa].x;
  647. int dpy = dPosA[doa].y;
  648. int dgx = dSizeA[doa].x;
  649. int dgy = dSizeA[doa].y;
  650. x += drawOff[doa].x;
  651. y += drawOff[doa].y;
  652. if (x < dpx || y < dpy || x >= dgx || y >= dgy) return;
  653. fc[x + y * size.x] = f;
  654. rend = 1;
  655. }
  656. void Image::setPixelDP(int i, int f)
  657. {
  658. int x = i % size.x;
  659. int y = i / size.x;
  660. setPixelDP(x, y, f);
  661. rend = 1;
  662. }
  663. void Image::drawLinieH(
  664. int x, int y, int len, int f) // draws a horizontal line
  665. {
  666. if (alpha[alphaAnzahl] == 0xFF) return;
  667. if (alpha[alphaAnzahl])
  668. {
  669. drawLinieHAlpha(x, y, len, f);
  670. return;
  671. }
  672. int dpx = dPosA[doa].x;
  673. int dpy = dPosA[doa].y;
  674. int dgx = dSizeA[doa].x;
  675. int dgy = dSizeA[doa].y;
  676. x += drawOff[doa].x;
  677. y += drawOff[doa].y;
  678. if (y < dpy || y >= dgy) return;
  679. if (x < dpx)
  680. {
  681. len -= dpx - x;
  682. if (len <= 0) return;
  683. x = dpx;
  684. }
  685. if (x + len >= dgx)
  686. {
  687. len -= x - dgx + len;
  688. if (len <= 0) return;
  689. }
  690. int br = size.x;
  691. int* fc = this->fc + x + y * br;
  692. int pval = len < 0 ? -1 : 1;
  693. len = len > 0 ? len : -len;
  694. for (int i = 0; i < len; ++i, fc += pval)
  695. *fc = f;
  696. rend = 1;
  697. }
  698. void Image::drawLinieV(
  699. int x, int y, int len, int f) // draws a vertical line
  700. {
  701. if (alpha[alphaAnzahl] == 0xFF) return;
  702. if (alpha[alphaAnzahl])
  703. {
  704. drawLinieVAlpha(x, y, len, f);
  705. return;
  706. }
  707. int dpx = dPosA[doa].x;
  708. int dpy = dPosA[doa].y;
  709. int dgx = dSizeA[doa].x;
  710. int dgy = dSizeA[doa].y;
  711. x += drawOff[doa].x;
  712. y += drawOff[doa].y;
  713. if (x < dpx || x >= dgx) return;
  714. if (y < dpy)
  715. {
  716. len -= dpy - y;
  717. if (len <= 0) return;
  718. y = dpy;
  719. }
  720. if (y + len >= dgy)
  721. {
  722. len -= y - dgy + len;
  723. if (len < 0) return;
  724. }
  725. int br = size.x;
  726. int* fc = this->fc + x + y * br;
  727. int pval = len < 0 ? -br : br;
  728. len = len > 0 ? len : -len;
  729. for (int i = 0; i < len; ++i, fc += pval)
  730. *fc = f;
  731. rend = 1;
  732. }
  733. void Image::drawLinieHAlpha(
  734. int x, int y, int len, int f) // draws a horizontal line
  735. {
  736. if (alpha[alphaAnzahl] == 0xFF) return;
  737. int dpx = dPosA[doa].x;
  738. int dpy = dPosA[doa].y;
  739. int dgx = dSizeA[doa].x;
  740. int dgy = dSizeA[doa].y;
  741. x += drawOff[doa].x;
  742. y += drawOff[doa].y;
  743. if (y < dpy || y >= dgy) return;
  744. if (x < dpx)
  745. {
  746. len -= dpx - x;
  747. if (len <= 0) return;
  748. x = dpx;
  749. }
  750. if (x + len >= dgx)
  751. {
  752. len -= x - dgx + len;
  753. if (len <= 0) return;
  754. }
  755. int br = size.x;
  756. int pval = len < 0 ? -1 : 1;
  757. len = len > 0 ? len : -len;
  758. int end = 0;
  759. if (alpha[alphaAnzahl])
  760. {
  761. unsigned char* cf = (unsigned char*)&f;
  762. cf[3] = (unsigned char)((cf[3] > alpha[alphaAnzahl])
  763. * (cf[3] - alpha[alphaAnzahl]));
  764. }
  765. if (alpha3D)
  766. {
  767. for (int i = x + y * br; end < len; ++end, i += pval)
  768. {
  769. alphaPixelP3D(fc[i], f);
  770. }
  771. }
  772. else
  773. {
  774. for (int i = x + y * br; end < len; ++end, i += pval)
  775. {
  776. alphaPixelP(fc[i], f);
  777. }
  778. }
  779. rend = 1;
  780. }
  781. void Image::drawLinieVAlpha(
  782. int x, int y, int len, int f) // draws a vertical line
  783. {
  784. if (alpha[alphaAnzahl] == 0xFF) return;
  785. int dpx = dPosA[doa].x;
  786. int dpy = dPosA[doa].y;
  787. int dgx = dSizeA[doa].x;
  788. int dgy = dSizeA[doa].y;
  789. x += drawOff[doa].x;
  790. y += drawOff[doa].y;
  791. if (x < dpx || x >= dgx) return;
  792. if (y < dpy)
  793. {
  794. len -= dpy - y;
  795. if (len <= 0) return;
  796. y = dpy;
  797. }
  798. if (y + len >= dgy)
  799. {
  800. len -= y - dgy + len;
  801. if (len < 0) return;
  802. }
  803. int br = size.x;
  804. int pval = len < 0 ? -br : br;
  805. len = len > 0 ? len : -len;
  806. int end = 0;
  807. if (alpha[alphaAnzahl])
  808. {
  809. unsigned char* cf = (unsigned char*)&f;
  810. cf[3] = (unsigned char)((cf[3] > alpha[alphaAnzahl])
  811. * (cf[3] - alpha[alphaAnzahl]));
  812. }
  813. if (alpha3D)
  814. {
  815. for (int i = x + y * br; end < len; ++end, i += pval)
  816. {
  817. alphaPixelP3D(fc[i], f);
  818. }
  819. }
  820. else
  821. {
  822. for (int i = x + y * br; end < len; ++end, i += pval)
  823. {
  824. alphaPixelP(fc[i], f);
  825. }
  826. }
  827. rend = 1;
  828. }
  829. void Image::drawLinieBordered(Punkt a, Punkt b, int bc, int fc)
  830. {
  831. if (alpha[alphaAnzahl] == 0xFF) return;
  832. if (alpha[alphaAnzahl])
  833. {
  834. drawLinieBorderedAlpha(a, b, bc, fc);
  835. return;
  836. }
  837. a += drawOff[doa];
  838. b += drawOff[doa];
  839. char outCode1 = getOutCode(a);
  840. char outCode2 = getOutCode(b);
  841. bool ok = 0;
  842. while (1)
  843. {
  844. int xMax = dSizeA[doa].x - 1;
  845. int yMax = dSizeA[doa].y - 1;
  846. if (!(outCode1 | outCode2))
  847. {
  848. ok = 1;
  849. break;
  850. }
  851. else if (outCode1 & outCode2)
  852. break;
  853. else
  854. {
  855. int x = 0, y = 0;
  856. char outCodeOut = outCode1 ? outCode1 : outCode2;
  857. if (outCodeOut & 8)
  858. {
  859. x = (int)(a.x + (b.x - a.x) * (yMax - a.y) / (b.y - a.y) + 0.5);
  860. y = yMax;
  861. }
  862. else if (outCodeOut & 4)
  863. {
  864. x = (int)(a.x + (b.x - a.x) * (dPosA[doa].y - a.y) / (b.y - a.y)
  865. + 0.5);
  866. y = dPosA[doa].y;
  867. }
  868. else if (outCodeOut & 2)
  869. {
  870. y = (int)(a.y + (b.y - a.y) * (xMax - a.x) / (b.x - a.x) + 0.5);
  871. x = xMax;
  872. }
  873. else if (outCodeOut & 1)
  874. {
  875. y = (int)(a.y + (b.y - a.y) * (dPosA[doa].x - a.x) / (b.x - a.x)
  876. + 0.5);
  877. x = dPosA[doa].x;
  878. }
  879. if (outCodeOut == outCode1)
  880. {
  881. a.x = x;
  882. a.y = y;
  883. outCode1 = getOutCode(a);
  884. }
  885. else
  886. {
  887. b.x = x;
  888. b.y = y;
  889. outCode2 = getOutCode(b);
  890. }
  891. }
  892. }
  893. if (ok)
  894. {
  895. int xlen = b.x - a.x, axlen = abs(xlen);
  896. int ylen = b.y - a.y, aylen = abs(ylen);
  897. double xf = (double)xlen / (aylen ? aylen : 1);
  898. double yf = (double)ylen / (axlen ? axlen : 1);
  899. if (axlen > aylen)
  900. xf = xf < 0 ? -1 : 1;
  901. else
  902. yf = yf < 0 ? -1 : 1;
  903. double x = (double)a.x, y = (double)a.y;
  904. int maxP = (int)(sqrt((float)(xlen * xlen + ylen * ylen)) + 0.5);
  905. int count = 0;
  906. int maxPixel = size.x * size.y;
  907. while (
  908. !((int)(x + 0.5) == b.x && (int)(y + 0.5) == b.y) && count < maxP)
  909. {
  910. ++count;
  911. this->fc[(int)((int)(x + 0.5) + (int)(y + 0.5) * size.x)] = fc;
  912. if ((int)((int)(x - 0.5) + (int)(y + 0.5) * size.x) < maxPixel
  913. && this->fc[(int)((int)(x - 0.5) + (int)(y + 0.5) * size.x)]
  914. != fc)
  915. this->fc[(int)((int)(x - 0.5) + (int)(y + 0.5) * size.x)] = bc;
  916. if ((int)((int)(x + 1.5) + (int)(y + 0.5) * size.x) < maxPixel
  917. && this->fc[(int)((int)(x + 1.5) + (int)(y + 0.5) * size.x)]
  918. != fc)
  919. this->fc[(int)((int)(x + 1.5) + (int)(y + 0.5) * size.x)] = bc;
  920. if ((int)((int)(x + 0.5) + (int)(y - 0.5) * size.x) < maxPixel
  921. && this->fc[(int)((int)(x + 0.5) + (int)(y - 0.5) * size.x)]
  922. != fc)
  923. this->fc[(int)((int)(x + 0.5) + (int)(y - 0.5) * size.x)] = bc;
  924. if ((int)((int)(x + 0.5) + (int)(y + 1.5) * size.x) < maxPixel
  925. && this->fc[(int)((int)(x + 0.5) + (int)(y + 1.5) * size.x)]
  926. != fc)
  927. this->fc[(int)((int)(x + 0.5) + (int)(y + 1.5) * size.x)] = bc;
  928. x += xf, y += yf;
  929. }
  930. rend = 1;
  931. }
  932. }
  933. void Image::drawLinieBorderedAlpha(Punkt a, Punkt b, int bc, int fc)
  934. {
  935. if (alpha[alphaAnzahl] == 0xFF) return;
  936. a += drawOff[doa];
  937. b += drawOff[doa];
  938. char outCode1 = getOutCode(a);
  939. char outCode2 = getOutCode(b);
  940. bool ok = 0;
  941. while (1)
  942. {
  943. int xMax = dSizeA[doa].x - 1;
  944. int yMax = dSizeA[doa].y - 1;
  945. if (!(outCode1 | outCode2))
  946. {
  947. ok = 1;
  948. break;
  949. }
  950. else if (outCode1 & outCode2)
  951. break;
  952. else
  953. {
  954. int x = 0, y = 0;
  955. char outCodeOut = outCode1 ? outCode1 : outCode2;
  956. if (outCodeOut & 8)
  957. {
  958. x = (int)(a.x + (b.x - a.x) * (yMax - a.y) / (b.y - a.y) + 0.5);
  959. y = yMax;
  960. }
  961. else if (outCodeOut & 4)
  962. {
  963. x = (int)(a.x + (b.x - a.x) * (dPosA[doa].y - a.y) / (b.y - a.y)
  964. + 0.5);
  965. y = dPosA[doa].y;
  966. }
  967. else if (outCodeOut & 2)
  968. {
  969. y = (int)(a.y + (b.y - a.y) * (xMax - a.x) / (b.x - a.x) + 0.5);
  970. x = xMax;
  971. }
  972. else if (outCodeOut & 1)
  973. {
  974. y = (int)(a.y + (b.y - a.y) * (dPosA[doa].x - a.x) / (b.x - a.x)
  975. + 0.5);
  976. x = dPosA[doa].x;
  977. }
  978. if (outCodeOut == outCode1)
  979. {
  980. a.x = x;
  981. a.y = y;
  982. outCode1 = getOutCode(a);
  983. }
  984. else
  985. {
  986. b.x = x;
  987. b.y = y;
  988. outCode2 = getOutCode(b);
  989. }
  990. }
  991. }
  992. if (ok)
  993. {
  994. int xlen = b.x - a.x, axlen = abs(xlen);
  995. int ylen = b.y - a.y, aylen = abs(ylen);
  996. double xf = (double)xlen / (aylen ? aylen : 1);
  997. double yf = (double)ylen / (axlen ? axlen : 1);
  998. if (axlen > aylen)
  999. xf = xf < 0 ? -1 : 1;
  1000. else
  1001. yf = yf < 0 ? -1 : 1;
  1002. double x = (double)a.x, y = (double)a.y;
  1003. if (alpha[alphaAnzahl])
  1004. {
  1005. unsigned char* cf = (unsigned char*)&fc;
  1006. cf[3] = (unsigned char)((cf[3] > alpha[alphaAnzahl])
  1007. * (cf[3] - alpha[alphaAnzahl]));
  1008. }
  1009. int maxP = (int)(sqrt((float)(xlen * xlen + ylen * ylen)) + 0.5);
  1010. int count = 0;
  1011. int maxPixel = size.x * size.y;
  1012. if (alpha3D)
  1013. {
  1014. while (!((int)(x + 0.5) == b.x && (int)(y + 0.5) == b.y)
  1015. && count < maxP)
  1016. {
  1017. ++count;
  1018. if ((int)((int)(x - 0.5) + (int)(y + 0.5) * size.x) < maxPixel)
  1019. {
  1020. int& pixel
  1021. = this->fc[(int)(x - 0.5) + (int)(y + 0.5) * size.x];
  1022. alphaPixelP3D(pixel, bc);
  1023. }
  1024. if ((int)((int)(x + 1.5) + (int)(y + 0.5) * size.x) < maxPixel)
  1025. {
  1026. int& pixel
  1027. = this->fc[(int)(x + 1.5) + (int)(y + 0.5) * size.x];
  1028. alphaPixelP3D(pixel, bc);
  1029. }
  1030. if ((int)((int)(x + 0.5) + (int)(y - 0.5) * size.x) < maxPixel)
  1031. {
  1032. int& pixel
  1033. = this->fc[(int)(x + 0.5) + (int)(y - 0.5) * size.x];
  1034. alphaPixelP3D(pixel, bc);
  1035. }
  1036. if ((int)((int)(x + 0.5) + (int)(y + 1.5) * size.x) < maxPixel)
  1037. {
  1038. int& pixel
  1039. = this->fc[(int)(x + 0.5) + (int)(y + 1.5) * size.x];
  1040. alphaPixelP3D(pixel, bc);
  1041. }
  1042. x += xf, y += yf;
  1043. }
  1044. count = 0;
  1045. while (!((int)(x + 0.5) == b.x && (int)(y + 0.5) == b.y)
  1046. && count < maxP)
  1047. {
  1048. ++count;
  1049. int& pixel = this->fc[(int)(x + 0.5) + (int)(y + 0.5) * size.x];
  1050. alphaPixelP3D(pixel, fc);
  1051. x += xf, y += yf;
  1052. }
  1053. }
  1054. else
  1055. {
  1056. while (!((int)(x + 0.5) == b.x && (int)(y + 0.5) == b.y)
  1057. && count < maxP)
  1058. {
  1059. ++count;
  1060. if ((int)((int)(x - 0.5) + (int)(y + 0.5) * size.x) < maxPixel)
  1061. {
  1062. int& pixel
  1063. = this->fc[(int)(x - 0.5) + (int)(y + 0.5) * size.x];
  1064. alphaPixelP(pixel, bc);
  1065. }
  1066. if ((int)((int)(x + 1.5) + (int)(y + 0.5) * size.x) < maxPixel)
  1067. {
  1068. int& pixel
  1069. = this->fc[(int)(x + 1.5) + (int)(y + 0.5) * size.x];
  1070. alphaPixelP(pixel, bc);
  1071. }
  1072. if ((int)((int)(x + 0.5) + (int)(y - 0.5) * size.x) < maxPixel)
  1073. {
  1074. int& pixel
  1075. = this->fc[(int)(x + 0.5) + (int)(y - 0.5) * size.x];
  1076. alphaPixelP(pixel, bc);
  1077. }
  1078. if ((int)((int)(x + 0.5) + (int)(y + 1.5) * size.x) < maxPixel)
  1079. {
  1080. int& pixel
  1081. = this->fc[(int)(x + 0.5) + (int)(y + 1.5) * size.x];
  1082. alphaPixelP(pixel, bc);
  1083. }
  1084. x += xf, y += yf;
  1085. }
  1086. count = 0;
  1087. while (!((int)(x + 0.5) == b.x && (int)(y + 0.5) == b.y)
  1088. && count < maxP)
  1089. {
  1090. ++count;
  1091. int& pixel = this->fc[(int)(x + 0.5) + (int)(y + 0.5) * size.x];
  1092. alphaPixelP(pixel, fc);
  1093. x += xf, y += yf;
  1094. }
  1095. }
  1096. rend = 1;
  1097. }
  1098. }
  1099. void Image::drawLinie(Punkt a,
  1100. Punkt b,
  1101. int fc) // draws a line from Point(x1, y1) to Point(x2, y2)
  1102. {
  1103. if (alpha[alphaAnzahl] == 0xFF) return;
  1104. if (alpha[alphaAnzahl])
  1105. {
  1106. drawLinieAlpha(a, b, fc);
  1107. return;
  1108. }
  1109. a += drawOff[doa];
  1110. b += drawOff[doa];
  1111. char outCode1 = getOutCode(a);
  1112. char outCode2 = getOutCode(b);
  1113. bool ok = 0;
  1114. while (1)
  1115. {
  1116. int xMax = dSizeA[doa].x - 1;
  1117. int yMax = dSizeA[doa].y - 1;
  1118. if (!(outCode1 | outCode2))
  1119. {
  1120. ok = 1;
  1121. break;
  1122. }
  1123. else if (outCode1 & outCode2)
  1124. break;
  1125. else
  1126. {
  1127. int x = 0, y = 0;
  1128. char outCodeOut = outCode1 ? outCode1 : outCode2;
  1129. if (outCodeOut & 8)
  1130. {
  1131. x = (int)(a.x + (b.x - a.x) * (yMax - a.y) / (b.y - a.y) + 0.5);
  1132. y = yMax;
  1133. }
  1134. else if (outCodeOut & 4)
  1135. {
  1136. x = (int)(a.x + (b.x - a.x) * (dPosA[doa].y - a.y) / (b.y - a.y)
  1137. + 0.5);
  1138. y = dPosA[doa].y;
  1139. }
  1140. else if (outCodeOut & 2)
  1141. {
  1142. y = (int)(a.y + (b.y - a.y) * (xMax - a.x) / (b.x - a.x) + 0.5);
  1143. x = xMax;
  1144. }
  1145. else if (outCodeOut & 1)
  1146. {
  1147. y = (int)(a.y + (b.y - a.y) * (dPosA[doa].x - a.x) / (b.x - a.x)
  1148. + 0.5);
  1149. x = dPosA[doa].x;
  1150. }
  1151. if (outCodeOut == outCode1)
  1152. {
  1153. a.x = x;
  1154. a.y = y;
  1155. outCode1 = getOutCode(a);
  1156. }
  1157. else
  1158. {
  1159. b.x = x;
  1160. b.y = y;
  1161. outCode2 = getOutCode(b);
  1162. }
  1163. }
  1164. }
  1165. if (ok)
  1166. {
  1167. int xlen = b.x - a.x, axlen = abs(xlen);
  1168. int ylen = b.y - a.y, aylen = abs(ylen);
  1169. double xf = (double)xlen / (aylen ? aylen : 1);
  1170. double yf = (double)ylen / (axlen ? axlen : 1);
  1171. if (axlen > aylen)
  1172. xf = xf < 0 ? -1 : 1;
  1173. else
  1174. yf = yf < 0 ? -1 : 1;
  1175. double x = (double)a.x, y = (double)a.y;
  1176. int maxP = (int)(sqrt((float)(xlen * xlen + ylen * ylen)) + 0.5);
  1177. int count = 0;
  1178. while (
  1179. !((int)(x + 0.5) == b.x && (int)(y + 0.5) == b.y) && count < maxP)
  1180. {
  1181. ++count;
  1182. this->fc[(int)((int)(x + 0.5) + (int)(y + 0.5) * size.x)] = fc;
  1183. x += xf, y += yf;
  1184. }
  1185. this->fc[(int)((int)(x + 0.5) + (int)(y + 0.5) * size.x)] = fc;
  1186. rend = 1;
  1187. }
  1188. }
  1189. void Image::drawLinieAlpha(Punkt a, Punkt b, int fc)
  1190. {
  1191. if (alpha[alphaAnzahl] == 0xFF) return;
  1192. a += drawOff[doa];
  1193. b += drawOff[doa];
  1194. char outCode1 = getOutCode(a);
  1195. char outCode2 = getOutCode(b);
  1196. bool ok = 0;
  1197. while (1)
  1198. {
  1199. int xMax = dSizeA[doa].x - 1;
  1200. int yMax = dSizeA[doa].y - 1;
  1201. if (!(outCode1 | outCode2))
  1202. {
  1203. ok = 1;
  1204. break;
  1205. }
  1206. else if (outCode1 & outCode2)
  1207. break;
  1208. else
  1209. {
  1210. int x = 0, y = 0;
  1211. char outCodeOut = outCode1 ? outCode1 : outCode2;
  1212. if (outCodeOut & 8)
  1213. {
  1214. x = (int)(a.x + (b.x - a.x) * (yMax - a.y) / (b.y - a.y) + 0.5);
  1215. y = yMax;
  1216. }
  1217. else if (outCodeOut & 4)
  1218. {
  1219. x = (int)(a.x + (b.x - a.x) * (dPosA[doa].y - a.y) / (b.y - a.y)
  1220. + 0.5);
  1221. y = dPosA[doa].y;
  1222. }
  1223. else if (outCodeOut & 2)
  1224. {
  1225. y = (int)(a.y + (b.y - a.y) * (xMax - a.x) / (b.x - a.x) + 0.5);
  1226. x = xMax;
  1227. }
  1228. else if (outCodeOut & 1)
  1229. {
  1230. y = (int)(a.y + (b.y - a.y) * (dPosA[doa].x - a.x) / (b.x - a.x)
  1231. + 0.5);
  1232. x = dPosA[doa].x;
  1233. }
  1234. if (outCodeOut == outCode1)
  1235. {
  1236. a.x = x;
  1237. a.y = y;
  1238. outCode1 = getOutCode(a);
  1239. }
  1240. else
  1241. {
  1242. b.x = x;
  1243. b.y = y;
  1244. outCode2 = getOutCode(b);
  1245. }
  1246. }
  1247. }
  1248. if (ok)
  1249. {
  1250. int xlen = b.x - a.x, axlen = abs(xlen);
  1251. int ylen = b.y - a.y, aylen = abs(ylen);
  1252. double xf = (double)xlen / (aylen ? aylen : 1);
  1253. double yf = (double)ylen / (axlen ? axlen : 1);
  1254. if (axlen > aylen)
  1255. xf = xf < 0 ? -1 : 1;
  1256. else
  1257. yf = yf < 0 ? -1 : 1;
  1258. double x = (double)a.x, y = (double)a.y;
  1259. if (alpha[alphaAnzahl])
  1260. {
  1261. unsigned char* cf = (unsigned char*)&fc;
  1262. cf[3] = (unsigned char)((cf[3] > alpha[alphaAnzahl])
  1263. * (cf[3] - alpha[alphaAnzahl]));
  1264. }
  1265. int maxP = (int)(sqrt((float)(xlen * xlen + ylen * ylen)) + 0.5);
  1266. int count = 0;
  1267. if (alpha3D)
  1268. {
  1269. while (!((int)(x + 0.5) == b.x && (int)(y + 0.5) == b.y)
  1270. && count < maxP)
  1271. {
  1272. ++count;
  1273. int& pixel = this->fc[(int)(x + 0.5) + (int)(y + 0.5) * size.x];
  1274. alphaPixelP3D(pixel, fc);
  1275. x += xf, y += yf;
  1276. }
  1277. int& pixel = this->fc[(int)(x + 0.5) + (int)(y + 0.5) * size.x];
  1278. alphaPixelP3D(pixel, fc);
  1279. }
  1280. else
  1281. {
  1282. while (!((int)(x + 0.5) == b.x && (int)(y + 0.5) == b.y)
  1283. && count < maxP)
  1284. {
  1285. ++count;
  1286. int& pixel = this->fc[(int)(x + 0.5) + (int)(y + 0.5) * size.x];
  1287. alphaPixelP(pixel, fc);
  1288. x += xf, y += yf;
  1289. }
  1290. int& pixel = this->fc[(int)(x + 0.5) + (int)(y + 0.5) * size.x];
  1291. alphaPixelP(pixel, fc);
  1292. }
  1293. rend = 1;
  1294. }
  1295. }
  1296. void Image::fillCircle(int xOff,
  1297. int yOff,
  1298. int r,
  1299. int fc) // fills a circle around Point(xOff, yOff) with radius r
  1300. {
  1301. if (alpha[alphaAnzahl] == 0xFF) return;
  1302. for (int i = r; i > 0; i--)
  1303. drawKreis(xOff, yOff, i, fc);
  1304. }
  1305. void Image::drawKreis(int xOff,
  1306. int yOff,
  1307. int r,
  1308. int fc) // draws a circle around Point(xOff, yOff) with radius r
  1309. {
  1310. if (alpha[alphaAnzahl] == 0xFF) return;
  1311. if (alpha[alphaAnzahl])
  1312. {
  1313. drawKreisAlpha(xOff, yOff, r, fc);
  1314. return;
  1315. }
  1316. int dpx = dPosA[doa].x;
  1317. int dpy = dPosA[doa].y;
  1318. int dgx = dSizeA[doa].x;
  1319. int dgy = dSizeA[doa].y;
  1320. xOff += drawOff[doa].x;
  1321. yOff += drawOff[doa].y;
  1322. if (xOff + r < dpx || xOff - r >= dgx || yOff + r < dpy || yOff - r >= dgy)
  1323. return;
  1324. for (int a = 0; a < r; ++a)
  1325. {
  1326. int b = (int)(sqrt((float)(long)(r * r - a * a)) + 0.5);
  1327. if (xOff + a < dgx && xOff + a > dpx && yOff + b < dgy
  1328. && yOff + b > dpy)
  1329. this->fc[xOff + a + (yOff + b) * size.x] = fc;
  1330. if (xOff - a < dgx && xOff - a > dpx && yOff + b < dgy
  1331. && yOff + b > dpy)
  1332. this->fc[xOff - a + (yOff + b) * size.x] = fc;
  1333. if (xOff + a < dgx && xOff + a > dpx && yOff - b < dgy
  1334. && yOff - b > dpy)
  1335. this->fc[xOff + a + (yOff - b) * size.x] = fc;
  1336. if (xOff - a < dgx && xOff - a > dpx && yOff - b < dgy
  1337. && yOff - b > dpy)
  1338. this->fc[xOff - a + (yOff - b) * size.x] = fc;
  1339. if (xOff + b < dgx && xOff + b > dpx && yOff + a < dgy
  1340. && yOff + a > dpy)
  1341. this->fc[xOff + b + (yOff + a) * size.x] = fc;
  1342. if (xOff - b < dgx && xOff - b > dpx && yOff + a < dgy
  1343. && yOff + a > dpy)
  1344. this->fc[xOff - b + (yOff + a) * size.x] = fc;
  1345. if (xOff + b < dgx && xOff + b > dpx && yOff - a < dgy
  1346. && yOff - a > dpy)
  1347. this->fc[xOff + b + (yOff - a) * size.x] = fc;
  1348. if (xOff - b < dgx && xOff - b > dpx && yOff - a < dgy
  1349. && yOff - a > dpy)
  1350. this->fc[xOff - b + (yOff - a) * size.x] = fc;
  1351. }
  1352. rend = 1;
  1353. }
  1354. void Image::drawKreisAlpha(int xOff, int yOff, int r, int fc)
  1355. {
  1356. if (alpha[alphaAnzahl] == 0xFF) return;
  1357. int dpx = dPosA[doa].x;
  1358. int dpy = dPosA[doa].y;
  1359. int dgx = dSizeA[doa].x;
  1360. int dgy = dSizeA[doa].y;
  1361. xOff += drawOff[doa].x;
  1362. yOff += drawOff[doa].y;
  1363. if (xOff + r < dpx || xOff - r >= dgx || yOff + r < dpy || yOff - r >= dgy)
  1364. return;
  1365. if (alpha[alphaAnzahl] < 0xFF)
  1366. {
  1367. unsigned char* cf = (unsigned char*)&fc;
  1368. cf[3] = (unsigned char)((cf[3] > alpha[alphaAnzahl])
  1369. * (cf[3] - alpha[alphaAnzahl]));
  1370. }
  1371. if (alpha3D)
  1372. {
  1373. for (int a = 0; a < r; ++a)
  1374. {
  1375. int b = (int)(sqrt((float)(long)(r * r - a * a)) + 0.5);
  1376. int* pixel = 0;
  1377. if (xOff + a < dgx && xOff + a > dpx && yOff + b < dgy
  1378. && yOff + b > dpy)
  1379. {
  1380. pixel = &this->fc[xOff + a + (yOff + b) * size.x];
  1381. alphaPixelP3D(*pixel, fc);
  1382. }
  1383. if (xOff - a < dgx && xOff - a > dpx && yOff + b < dgy
  1384. && yOff + b > dpy)
  1385. {
  1386. pixel = &this->fc[xOff - a + (yOff + b) * size.x];
  1387. alphaPixelP3D(*pixel, fc);
  1388. }
  1389. if (xOff + a < dgx && xOff + a > dpx && yOff - b < dgy
  1390. && yOff - b > dpy)
  1391. {
  1392. pixel = &this->fc[xOff + a + (yOff - b) * size.x];
  1393. alphaPixelP3D(*pixel, fc);
  1394. }
  1395. if (xOff - a < dgx && xOff - a > dpx && yOff - b < dgy
  1396. && yOff - b > dpy)
  1397. {
  1398. pixel = &this->fc[xOff - a + (yOff - b) * size.x];
  1399. alphaPixelP3D(*pixel, fc);
  1400. }
  1401. if (xOff + b < dgx && xOff + b > dpx && yOff + a < dgy
  1402. && yOff + a > dpy)
  1403. {
  1404. pixel = &this->fc[xOff + b + (yOff + a) * size.x];
  1405. alphaPixelP3D(*pixel, fc);
  1406. }
  1407. if (xOff - b < dgx && xOff - b > dpx && yOff + a < dgy
  1408. && yOff + a > dpy)
  1409. {
  1410. pixel = &this->fc[xOff - b + (yOff + a) * size.x];
  1411. alphaPixelP3D(*pixel, fc);
  1412. }
  1413. if (xOff + b < dgx && xOff + b > dpx && yOff - a < dgy
  1414. && yOff - a > dpy)
  1415. {
  1416. pixel = &this->fc[xOff + b + (yOff - a) * size.x];
  1417. alphaPixelP3D(*pixel, fc);
  1418. }
  1419. if (xOff - b < dgx && xOff - b > dpx && yOff - a < dgy
  1420. && yOff - a > dpy)
  1421. {
  1422. pixel = &this->fc[xOff - b + (yOff - a) * size.x];
  1423. alphaPixelP3D(*pixel, fc);
  1424. }
  1425. }
  1426. }
  1427. else
  1428. {
  1429. for (int a = 0; a < r; ++a)
  1430. {
  1431. int b = (int)(sqrt((float)(long)(r * r - a * a)) + 0.5);
  1432. int* pixel = 0;
  1433. if (xOff + a < dgx && xOff + a > dpx && yOff + b < dgy
  1434. && yOff + b > dpy)
  1435. {
  1436. pixel = &this->fc[xOff + a + (yOff + b) * size.x];
  1437. alphaPixelP(*pixel, fc);
  1438. }
  1439. if (xOff - a < dgx && xOff - a > dpx && yOff + b < dgy
  1440. && yOff + b > dpy)
  1441. {
  1442. pixel = &this->fc[xOff - a + (yOff + b) * size.x];
  1443. alphaPixelP(*pixel, fc);
  1444. }
  1445. if (xOff + a < dgx && xOff + a > dpx && yOff - b < dgy
  1446. && yOff - b > dpy)
  1447. {
  1448. pixel = &this->fc[xOff + a + (yOff - b) * size.x];
  1449. alphaPixelP(*pixel, fc);
  1450. }
  1451. if (xOff - a < dgx && xOff - a > dpx && yOff - b < dgy
  1452. && yOff - b > dpy)
  1453. {
  1454. pixel = &this->fc[xOff - a + (yOff - b) * size.x];
  1455. alphaPixelP(*pixel, fc);
  1456. }
  1457. if (xOff + b < dgx && xOff + b > dpx && yOff + a < dgy
  1458. && yOff + a > dpy)
  1459. {
  1460. pixel = &this->fc[xOff + b + (yOff + a) * size.x];
  1461. alphaPixelP(*pixel, fc);
  1462. }
  1463. if (xOff - b < dgx && xOff - b > dpx && yOff + a < dgy
  1464. && yOff + a > dpy)
  1465. {
  1466. pixel = &this->fc[xOff - b + (yOff + a) * size.x];
  1467. alphaPixelP(*pixel, fc);
  1468. }
  1469. if (xOff + b < dgx && xOff + b > dpx && yOff - a < dgy
  1470. && yOff - a > dpy)
  1471. {
  1472. pixel = &this->fc[xOff + b + (yOff - a) * size.x];
  1473. alphaPixelP(*pixel, fc);
  1474. }
  1475. if (xOff - b < dgx && xOff - b > dpx && yOff - a < dgy
  1476. && yOff - a > dpy)
  1477. {
  1478. pixel = &this->fc[xOff - b + (yOff - a) * size.x];
  1479. alphaPixelP(*pixel, fc);
  1480. }
  1481. }
  1482. }
  1483. rend = 1;
  1484. }
  1485. void Image::drawImage(
  1486. int x, int y, int br, int hi, const Image& zImage) // draws zImage
  1487. {
  1488. if (alpha[alphaAnzahl] == 0xFF) return;
  1489. if (alpha[alphaAnzahl])
  1490. {
  1491. alphaImage(x, y, br, hi, zImage);
  1492. return;
  1493. }
  1494. int dpx = dPosA[doa].x;
  1495. int dpy = dPosA[doa].y;
  1496. int dgx = dSizeA[doa].x;
  1497. int dgy = dSizeA[doa].y;
  1498. x += drawOff[doa].x;
  1499. y += drawOff[doa].y;
  1500. if (x + br < dpx || y + hi < dpy || x >= dgx || y >= dgy) return;
  1501. br = minInt(br, zImage.getBreite());
  1502. hi = minInt(hi, zImage.getHeight());
  1503. int xst = maxInt(dpx - x, 0);
  1504. int yst = maxInt(dpy - y, 0);
  1505. int xst2 = maxInt(x, dpx);
  1506. int yst2 = maxInt(y, dpy);
  1507. dgx = minInt(x + br, dgx);
  1508. dgy = minInt(y + hi, dgy);
  1509. int bb = zImage.getBreite();
  1510. int* ff = zImage.getBuffer();
  1511. int xx, ygr, ygr2;
  1512. for (int yy = yst2; yy < dgy; ++yy)
  1513. {
  1514. ygr = yy * size.x;
  1515. ygr2 = (yy - yst2 + yst) * bb;
  1516. for (xx = xst2; xx < dgx; ++xx)
  1517. fc[xx + ygr] = ff[(xx - xst2 + xst) + ygr2];
  1518. }
  1519. rend = 1;
  1520. }
  1521. void Image::alphaImageAssoz(int x, int y, int br, int hi, const Image& zImage)
  1522. {
  1523. if (alpha[alphaAnzahl] == 0xFF) return;
  1524. int dpx = dPosA[doa].x;
  1525. int dpy = dPosA[doa].y;
  1526. int dgx = dSizeA[doa].x;
  1527. int dgy = dSizeA[doa].y;
  1528. x += drawOff[doa].x;
  1529. y += drawOff[doa].y;
  1530. if (x + br < dpx || y + hi < dpy || x >= dgx || y >= dgy) return;
  1531. br = minInt(br, zImage.getBreite());
  1532. hi = minInt(hi, zImage.getHeight());
  1533. int xst = maxInt(dpx - x, 0);
  1534. int yst = maxInt(dpy - y, 0);
  1535. int xst2 = maxInt(x, dpx);
  1536. int yst2 = maxInt(y, dpy);
  1537. dgx = minInt(x + br, dgx);
  1538. dgy = minInt(y + hi, dgy);
  1539. int bb = zImage.getBreite();
  1540. int* ff = zImage.getBuffer();
  1541. if (!alpha[alphaAnzahl])
  1542. {
  1543. int xx, ygr, ygr2;
  1544. for (int yy = yst2; yy < dgy; ++yy)
  1545. {
  1546. ygr = yy * size.x;
  1547. ygr2 = (yy - yst2 + yst) * bb;
  1548. for (xx = xst2; xx < dgx; ++xx)
  1549. alphaPixelAssozP(fc[xx + ygr], ff[(xx - xst2 + xst) + ygr2]);
  1550. }
  1551. }
  1552. else
  1553. {
  1554. int xx, ygr, ygr2;
  1555. for (int yy = yst2; yy < dgy; ++yy)
  1556. {
  1557. ygr = yy * size.x;
  1558. ygr2 = (yy - yst2 + yst) * bb;
  1559. for (xx = xst2; xx < dgx; ++xx)
  1560. {
  1561. int fc = ff[(xx - xst2 + xst) + ygr2];
  1562. unsigned char* cf = (unsigned char*)&fc;
  1563. cf[3] = (unsigned char)((cf[3] > alpha[alphaAnzahl])
  1564. * (cf[3] - alpha[alphaAnzahl]));
  1565. alphaPixelAssozP(this->fc[xx + ygr], fc);
  1566. }
  1567. }
  1568. }
  1569. rend = 1;
  1570. }
  1571. void Image::alphaImage(int x, int y, int br, int hi, const Image& zImage)
  1572. {
  1573. if (alpha[alphaAnzahl] == 0xFF) return;
  1574. int dpx = dPosA[doa].x;
  1575. int dpy = dPosA[doa].y;
  1576. int dgx = dSizeA[doa].x;
  1577. int dgy = dSizeA[doa].y;
  1578. x += drawOff[doa].x;
  1579. y += drawOff[doa].y;
  1580. if (x + br < dpx || y + hi < dpy || x >= dgx || y >= dgy) return;
  1581. br = minInt(br, zImage.getBreite());
  1582. hi = minInt(hi, zImage.getHeight());
  1583. int xst = maxInt(dpx - x, 0);
  1584. int yst = maxInt(dpy - y, 0);
  1585. int xst2 = maxInt(x, dpx);
  1586. int yst2 = maxInt(y, dpy);
  1587. dgx = minInt(x + br, dgx);
  1588. dgy = minInt(y + hi, dgy);
  1589. int bb = zImage.getBreite();
  1590. int* ff = zImage.getBuffer();
  1591. if (!alpha[alphaAnzahl])
  1592. {
  1593. int xx, ygr, ygr2;
  1594. if (alpha3D)
  1595. {
  1596. for (int yy = yst2; yy < dgy; ++yy)
  1597. {
  1598. ygr = yy * size.x;
  1599. ygr2 = (yy - yst2 + yst) * bb;
  1600. int fci = xst2 + ygr;
  1601. int ffi = xst + ygr2;
  1602. for (xx = xst2; xx < dgx; ++xx, ++fci, ++ffi)
  1603. alphaPixelP3D(fc[fci], ff[ffi]);
  1604. }
  1605. }
  1606. else
  1607. {
  1608. for (int yy = yst2; yy < dgy; ++yy)
  1609. {
  1610. ygr = yy * size.x;
  1611. ygr2 = (yy - yst2 + yst) * bb;
  1612. int fci = xst2 + ygr;
  1613. int ffi = xst + ygr2;
  1614. for (xx = xst2; xx < dgx; ++xx, ++fci, ++ffi)
  1615. alphaPixelP(fc[fci], ff[ffi]);
  1616. }
  1617. }
  1618. }
  1619. else
  1620. {
  1621. int xx, ygr, ygr2;
  1622. if (alpha3D)
  1623. {
  1624. for (int yy = yst2; yy < dgy; ++yy)
  1625. {
  1626. ygr = yy * size.x;
  1627. ygr2 = (yy - yst2 + yst) * bb;
  1628. for (xx = xst2; xx < dgx; ++xx)
  1629. {
  1630. int fc = ff[(xx - xst2 + xst) + ygr2];
  1631. unsigned char* cf = (unsigned char*)&fc;
  1632. cf[3] = (unsigned char)((cf[3] > alpha[alphaAnzahl])
  1633. * (cf[3] - alpha[alphaAnzahl]));
  1634. alphaPixelP3D(this->fc[xx + ygr], fc);
  1635. }
  1636. }
  1637. }
  1638. else
  1639. {
  1640. for (int yy = yst2; yy < dgy; ++yy)
  1641. {
  1642. ygr = yy * size.x;
  1643. ygr2 = (yy - yst2 + yst) * bb;
  1644. for (xx = xst2; xx < dgx; ++xx)
  1645. {
  1646. int fc = ff[(xx - xst2 + xst) + ygr2];
  1647. unsigned char* cf = (unsigned char*)&fc;
  1648. cf[3] = (unsigned char)((cf[3] > alpha[alphaAnzahl])
  1649. * (cf[3] - alpha[alphaAnzahl]));
  1650. alphaPixelP(this->fc[xx + ygr], fc);
  1651. }
  1652. }
  1653. }
  1654. }
  1655. rend = 1;
  1656. }
  1657. void Image::drawImage90(int x,
  1658. int y,
  1659. int br,
  1660. int hi,
  1661. const Image& zImage) // Draws an image rotated 90 degrees to the right
  1662. {
  1663. if (alpha[alphaAnzahl] == 0xFF) return;
  1664. if (alpha[alphaAnzahl])
  1665. {
  1666. alphaImage90(x, y, br, hi, zImage);
  1667. return;
  1668. }
  1669. int dpx = dPosA[doa].x;
  1670. int dpy = dPosA[doa].y;
  1671. int dgx = dSizeA[doa].x;
  1672. int dgy = dSizeA[doa].y;
  1673. x += drawOff[doa].x;
  1674. y += drawOff[doa].y;
  1675. if (x + hi < dpx || y + br < dpy || x >= dgx || y >= dgy) return;
  1676. br = minInt(br, zImage.getHeight());
  1677. hi = minInt(hi, zImage.getBreite());
  1678. int xst = maxInt(dpx - x, 0);
  1679. int yst = maxInt(dpy - y, 0);
  1680. int xst2 = maxInt(x, dpx);
  1681. int yst2 = maxInt(y, dpy);
  1682. dgx = minInt(x + br, dgx);
  1683. dgy = minInt(y + hi, dgy);
  1684. int bb = zImage.getBreite();
  1685. int* ff = zImage.getBuffer();
  1686. int yy, xbb;
  1687. for (int xx = xst2; xx < dgx; ++xx)
  1688. {
  1689. xbb = (zImage.getHeight() - (xx - xst2 + xst + 1)) * bb;
  1690. for (yy = yst2; yy < dgy; ++yy)
  1691. fc[xx + yy * size.x] = ff[(yy - yst2 + yst) + xbb];
  1692. }
  1693. rend = 1;
  1694. }
  1695. void Image::alphaImage90(int x, int y, int br, int hi, const Image& zImage)
  1696. {
  1697. if (alpha[alphaAnzahl] == 0xFF) return;
  1698. int dpx = dPosA[doa].x;
  1699. int dpy = dPosA[doa].y;
  1700. int dgx = dSizeA[doa].x;
  1701. int dgy = dSizeA[doa].y;
  1702. x += drawOff[doa].x;
  1703. y += drawOff[doa].y;
  1704. if (x + hi < dpx || y + br < dpy || x >= dgx || y >= dgy) return;
  1705. br = minInt(br, zImage.getHeight());
  1706. hi = minInt(hi, zImage.getBreite());
  1707. int xst = maxInt(dpx - x, 0);
  1708. int yst = maxInt(dpy - y, 0);
  1709. int xst2 = maxInt(x, dpx);
  1710. int yst2 = maxInt(y, dpy);
  1711. dgx = minInt(x + br, dgx);
  1712. dgy = minInt(y + hi, dgy);
  1713. int bb = zImage.getBreite();
  1714. int* ff = zImage.getBuffer();
  1715. if (!alpha[alphaAnzahl])
  1716. {
  1717. int yy, xbb;
  1718. if (alpha3D)
  1719. {
  1720. for (int xx = xst2; xx < dgx; ++xx)
  1721. {
  1722. xbb = (zImage.getHeight() - (xx - xst2 + xst + 1)) * bb;
  1723. for (yy = yst2; yy < dgy; ++yy)
  1724. alphaPixelP3D(xx, yy, ff[(yy - yst2 + yst) + xbb]);
  1725. }
  1726. }
  1727. else
  1728. {
  1729. for (int xx = xst2; xx < dgx; ++xx)
  1730. {
  1731. xbb = (zImage.getHeight() - (xx - xst2 + xst + 1)) * bb;
  1732. for (yy = yst2; yy < dgy; ++yy)
  1733. alphaPixelP(xx, yy, ff[(yy - yst2 + yst) + xbb]);
  1734. }
  1735. }
  1736. }
  1737. else
  1738. {
  1739. int yy, xbb;
  1740. if (alpha3D)
  1741. {
  1742. for (int xx = xst2; xx < dgx; ++xx)
  1743. {
  1744. xbb = (zImage.getHeight() - (xx - xst2 + xst + 1)) * bb;
  1745. for (yy = yst2; yy < dgy; ++yy)
  1746. {
  1747. int fc = ff[(yy - yst2 + yst) + xbb];
  1748. unsigned char* cf = (unsigned char*)&fc;
  1749. cf[3] = (unsigned char)((cf[3] > alpha[alphaAnzahl])
  1750. * (cf[3] - alpha[alphaAnzahl]));
  1751. alphaPixelP3D(xx, yy, fc);
  1752. }
  1753. }
  1754. }
  1755. else
  1756. {
  1757. for (int xx = xst2; xx < dgx; ++xx)
  1758. {
  1759. xbb = (zImage.getHeight() - (xx - xst2 + xst + 1)) * bb;
  1760. for (yy = yst2; yy < dgy; ++yy)
  1761. {
  1762. int fc = ff[(yy - yst2 + yst) + xbb];
  1763. unsigned char* cf = (unsigned char*)&fc;
  1764. cf[3] = (unsigned char)((cf[3] > alpha[alphaAnzahl])
  1765. * (cf[3] - alpha[alphaAnzahl]));
  1766. alphaPixelP(xx, yy, fc);
  1767. }
  1768. }
  1769. }
  1770. }
  1771. rend = 1;
  1772. }
  1773. void Image::drawImage180(int x,
  1774. int y,
  1775. int br,
  1776. int hi,
  1777. const Image& zImage) // Draws an image rotated 180 degrees to the right
  1778. {
  1779. if (alpha[alphaAnzahl] == 0xFF) return;
  1780. if (alpha[alphaAnzahl])
  1781. {
  1782. alphaImage180(x, y, br, hi, zImage);
  1783. return;
  1784. }
  1785. int dpx = dPosA[doa].x;
  1786. int dpy = dPosA[doa].y;
  1787. int dgx = dSizeA[doa].x;
  1788. int dgy = dSizeA[doa].y;
  1789. x += drawOff[doa].x;
  1790. y += drawOff[doa].y;
  1791. if (x + br < dpx || y + hi < dpy || x >= dgx || y >= dgy) return;
  1792. br = minInt(br, zImage.getBreite());
  1793. hi = minInt(hi, zImage.getHeight());
  1794. int xst = maxInt(dpx - x, 0);
  1795. int yst = maxInt(dpy - y, 0);
  1796. int xst2 = maxInt(x, dpx);
  1797. int yst2 = maxInt(y, dpy);
  1798. dgx = minInt(x + br, dgx);
  1799. dgy = minInt(y + hi, dgy);
  1800. int bb = zImage.getBreite();
  1801. int* ff = zImage.getBuffer();
  1802. int xx, ygr, ybb;
  1803. for (int yy = yst2; yy < dgy; ++yy)
  1804. {
  1805. ygr = yy * size.x;
  1806. ybb = (zImage.getHeight() - (yy - yst2 + yst + 1)) * bb;
  1807. for (xx = xst2; xx < dgx; ++xx)
  1808. fc[xx + ygr] = ff[(bb - (xx - xst2 + xst + 1)) + ybb];
  1809. }
  1810. rend = 1;
  1811. }
  1812. void Image::alphaImage180(int x, int y, int br, int hi, const Image& zImage)
  1813. {
  1814. if (alpha[alphaAnzahl] == 0xFF) return;
  1815. int dpx = dPosA[doa].x;
  1816. int dpy = dPosA[doa].y;
  1817. int dgx = dSizeA[doa].x;
  1818. int dgy = dSizeA[doa].y;
  1819. x += drawOff[doa].x;
  1820. y += drawOff[doa].y;
  1821. if (x + br < dpx || y + hi < dpy || x >= dgx || y >= dgy) return;
  1822. br = minInt(br, zImage.getHeight());
  1823. hi = minInt(hi, zImage.getBreite());
  1824. int xst = maxInt(dpx - x, 0);
  1825. int yst = maxInt(dpy - y, 0);
  1826. int xst2 = maxInt(x, dpx);
  1827. int yst2 = maxInt(y, dpy);
  1828. dgx = minInt(x + br, dgx);
  1829. dgy = minInt(y + hi, dgy);
  1830. int bb = zImage.getBreite();
  1831. int* ff = zImage.getBuffer();
  1832. if (!alpha[alphaAnzahl])
  1833. {
  1834. int xx, ygr, ybb;
  1835. if (alpha3D)
  1836. {
  1837. for (int yy = yst2; yy < dgy; ++yy)
  1838. {
  1839. ygr = yy * size.x;
  1840. ybb = (zImage.getHeight() - (yy - yst2 + yst + 1)) * bb;
  1841. for (xx = xst2; xx < dgx; ++xx)
  1842. alphaPixelP3D(
  1843. fc[xx + ygr], ff[(bb - (xx - xst2 + xst + 1)) + ybb]);
  1844. }
  1845. }
  1846. else
  1847. {
  1848. for (int yy = yst2; yy < dgy; ++yy)
  1849. {
  1850. ygr = yy * size.x;
  1851. ybb = (zImage.getHeight() - (yy - yst2 + yst + 1)) * bb;
  1852. for (xx = xst2; xx < dgx; ++xx)
  1853. alphaPixelP(
  1854. fc[xx + ygr], ff[(bb - (xx - xst2 + xst + 1)) + ybb]);
  1855. }
  1856. }
  1857. }
  1858. else
  1859. {
  1860. int xx, ygr, ybb;
  1861. if (alpha3D)
  1862. {
  1863. for (int yy = yst2; yy < dgy; ++yy)
  1864. {
  1865. ygr = yy * size.x;
  1866. ybb = (zImage.getHeight() - (yy - yst2 + yst + 1)) * bb;
  1867. for (xx = xst2; xx < dgx; ++xx)
  1868. {
  1869. int fc = ff[(bb - (xx - xst2 + xst + 1)) + ybb];
  1870. unsigned char* cf = (unsigned char*)&fc;
  1871. cf[3] = (unsigned char)((cf[3] > alpha[alphaAnzahl])
  1872. * (cf[3] - alpha[alphaAnzahl]));
  1873. alphaPixelP3D(this->fc[xx + ygr], fc);
  1874. }
  1875. }
  1876. }
  1877. else
  1878. {
  1879. for (int yy = yst2; yy < dgy; ++yy)
  1880. {
  1881. ygr = yy * size.x;
  1882. ybb = (zImage.getHeight() - (yy - yst2 + yst + 1)) * bb;
  1883. for (xx = xst2; xx < dgx; ++xx)
  1884. {
  1885. int fc = ff[(bb - (xx - xst2 + xst + 1)) + ybb];
  1886. unsigned char* cf = (unsigned char*)&fc;
  1887. cf[3] = (unsigned char)((cf[3] > alpha[alphaAnzahl])
  1888. * (cf[3] - alpha[alphaAnzahl]));
  1889. alphaPixelP(this->fc[xx + ygr], fc);
  1890. }
  1891. }
  1892. }
  1893. }
  1894. rend = 1;
  1895. }
  1896. void Image::drawImage270(int x,
  1897. int y,
  1898. int br,
  1899. int hi,
  1900. const Image& zImage) // Draws an image rotated 270 degrees to the right
  1901. {
  1902. if (alpha[alphaAnzahl] == 0xFF) return;
  1903. if (alpha[alphaAnzahl])
  1904. {
  1905. alphaImage270(x, y, br, hi, zImage);
  1906. return;
  1907. }
  1908. int dpx = dPosA[doa].x;
  1909. int dpy = dPosA[doa].y;
  1910. int dgx = dSizeA[doa].x;
  1911. int dgy = dSizeA[doa].y;
  1912. x += drawOff[doa].x;
  1913. y += drawOff[doa].y;
  1914. if (x + hi < dpx || y + br < dpy || x >= dgx || y >= dgy) return;
  1915. br = minInt(br, zImage.getHeight());
  1916. hi = minInt(hi, zImage.getBreite());
  1917. int xst = maxInt(dpx - x, 0);
  1918. int yst = maxInt(dpy - y, 0);
  1919. int xst2 = maxInt(x, dpx);
  1920. int yst2 = maxInt(y, dpy);
  1921. dgx = minInt(x + br, dgx);
  1922. dgy = minInt(y + hi, dgy);
  1923. int bb = zImage.getBreite();
  1924. int* ff = zImage.getBuffer();
  1925. int yy, xbb;
  1926. for (int xx = xst2; xx < dgx; ++xx)
  1927. {
  1928. xbb = (xx - xst2 + xst) * bb;
  1929. for (yy = yst2; yy < dgy; ++yy)
  1930. fc[xx + yy * size.x] = ff[(bb - (yy - yst2 + yst + 1)) + xbb];
  1931. }
  1932. rend = 1;
  1933. }
  1934. void Image::alphaImage270(int x, int y, int br, int hi, const Image& zImage)
  1935. {
  1936. if (alpha[alphaAnzahl] == 0xFF) return;
  1937. int dpx = dPosA[doa].x;
  1938. int dpy = dPosA[doa].y;
  1939. int dgx = dSizeA[doa].x;
  1940. int dgy = dSizeA[doa].y;
  1941. x += drawOff[doa].x;
  1942. y += drawOff[doa].y;
  1943. if (x + hi < dpx || y + br < dpy || x >= dgx || y >= dgy) return;
  1944. br = minInt(br, zImage.getHeight());
  1945. hi = minInt(hi, zImage.getBreite());
  1946. int xst = maxInt(dpx - x, 0);
  1947. int yst = maxInt(dpy - y, 0);
  1948. int xst2 = maxInt(x, dpx);
  1949. int yst2 = maxInt(y, dpy);
  1950. dgx = minInt(x + br, dgx);
  1951. dgy = minInt(y + hi, dgy);
  1952. int bb = zImage.getBreite();
  1953. int* ff = zImage.getBuffer();
  1954. if (!alpha[alphaAnzahl])
  1955. {
  1956. int yy, xbb;
  1957. if (alpha3D)
  1958. {
  1959. for (int xx = xst2; xx < dgx; ++xx)
  1960. {
  1961. xbb = (xx - xst2 + xst) * bb;
  1962. for (yy = yst2; yy < dgy; ++yy)
  1963. alphaPixelP3D(
  1964. xx, yy, ff[(bb - (yy - yst2 + yst + 1)) + xbb]);
  1965. }
  1966. }
  1967. else
  1968. {
  1969. for (int xx = xst2; xx < dgx; ++xx)
  1970. {
  1971. xbb = (xx - xst2 + xst) * bb;
  1972. for (yy = yst2; yy < dgy; ++yy)
  1973. alphaPixelP(xx, yy, ff[(bb - (yy - yst2 + yst + 1)) + xbb]);
  1974. }
  1975. }
  1976. }
  1977. else
  1978. {
  1979. int yy, xbb;
  1980. if (alpha3D)
  1981. {
  1982. for (int xx = xst2; xx < dgx; ++xx)
  1983. {
  1984. xbb = (xx - xst2 + xst) * bb;
  1985. for (yy = yst2; yy < dgy; ++yy)
  1986. {
  1987. int fc = ff[(bb - (yy - yst2 + yst + 1)) + xbb];
  1988. unsigned char* cf = (unsigned char*)&fc;
  1989. cf[3] = (unsigned char)((cf[3] > alpha[alphaAnzahl])
  1990. * (cf[3] - alpha[alphaAnzahl]));
  1991. alphaPixelP3D(xx, yy, fc);
  1992. }
  1993. }
  1994. }
  1995. else
  1996. {
  1997. for (int xx = xst2; xx < dgx; ++xx)
  1998. {
  1999. xbb = (xx - xst2 + xst) * bb;
  2000. for (yy = yst2; yy < dgy; ++yy)
  2001. {
  2002. int fc = ff[(bb - (yy - yst2 + yst + 1)) + xbb];
  2003. unsigned char* cf = (unsigned char*)&fc;
  2004. cf[3] = (unsigned char)((cf[3] > alpha[alphaAnzahl])
  2005. * (cf[3] - alpha[alphaAnzahl]));
  2006. alphaPixelP(xx, yy, fc);
  2007. }
  2008. }
  2009. }
  2010. }
  2011. rend = 1;
  2012. }
  2013. void Image::drawImageSkall(
  2014. int x, int y, int br, int hi, const Image& zImage) // draws zImage scaled
  2015. {
  2016. if (alpha[alphaAnzahl] == 0xFF) return;
  2017. if (alpha[alphaAnzahl])
  2018. {
  2019. alphaImageSkall(x, y, br, hi, zImage);
  2020. return;
  2021. }
  2022. int dpx = dPosA[doa].x;
  2023. int dpy = dPosA[doa].y;
  2024. int dgx = dSizeA[doa].x;
  2025. int dgy = dSizeA[doa].y;
  2026. x += drawOff[doa].x;
  2027. y += drawOff[doa].y;
  2028. if (x + br < dpx || y + hi < dpy || x >= dgx || y >= dgy) return;
  2029. double xo = zImage.getBreite() / (double)br;
  2030. double yo = zImage.getHeight() / (double)hi;
  2031. int xst = maxInt(dpx - x, 0);
  2032. int yst = maxInt(dpy - y, 0);
  2033. int xst2 = maxInt(x, dpx);
  2034. int yst2 = maxInt(y, dpy);
  2035. dgx = minInt(x + br, dgx);
  2036. dgy = minInt(y + hi, dgy);
  2037. int bb = zImage.getBreite();
  2038. int* ff = zImage.getBuffer();
  2039. int xx, ygr, ygr2;
  2040. double xb = 0, yb = yst * yo;
  2041. for (int yy = yst2; yy < dgy; ++yy, yb += yo)
  2042. {
  2043. ygr = yy * size.x;
  2044. ygr2 = (int)((yy - yst2 + yst) * yo) * bb;
  2045. for (xx = xst2, xb = xst * xo; xx < dgx; ++xx, xb += xo)
  2046. fc[xx + ygr] = ff[(int)xb + ygr2];
  2047. }
  2048. rend = 1;
  2049. }
  2050. void Image::alphaImageSkall(int x, int y, int br, int hi, const Image& zImage)
  2051. {
  2052. if (alpha[alphaAnzahl] == 0xFF) return;
  2053. int dpx = dPosA[doa].x;
  2054. int dpy = dPosA[doa].y;
  2055. int dgx = dSizeA[doa].x;
  2056. int dgy = dSizeA[doa].y;
  2057. x += drawOff[doa].x;
  2058. y += drawOff[doa].y;
  2059. if (x + br < dpx || y + hi < dpy || x >= dgx || y >= dgy) return;
  2060. double xo = zImage.getBreite() / (double)br;
  2061. double yo = zImage.getHeight() / (double)hi;
  2062. int xst = maxInt(dpx - x, 0);
  2063. int yst = maxInt(dpy - y, 0);
  2064. int xst2 = maxInt(x, dpx);
  2065. int yst2 = maxInt(y, dpy);
  2066. dgx = minInt(x + br, dgx);
  2067. dgy = minInt(y + hi, dgy);
  2068. int bb = zImage.getBreite();
  2069. int* ff = zImage.getBuffer();
  2070. int xx, ygr, ygr2;
  2071. double xb = 0;
  2072. if (alpha3D)
  2073. {
  2074. for (int yy = yst2; yy < dgy; ++yy)
  2075. {
  2076. ygr = yy * size.x;
  2077. ygr2 = (int)((yy - yst2 + yst) * yo) * bb;
  2078. for (xx = xst2, xb = xst * xo; xx < dgx; ++xx, xb += xo)
  2079. {
  2080. int f = ff[(int)xb + ygr2];
  2081. unsigned char* cf = (unsigned char*)&f;
  2082. cf[3] = (unsigned char)((cf[3] > alpha[alphaAnzahl])
  2083. * (cf[3] - alpha[alphaAnzahl]));
  2084. alphaPixelP3D(fc[xx + ygr], f);
  2085. }
  2086. }
  2087. }
  2088. else
  2089. {
  2090. for (int yy = yst2; yy < dgy; ++yy)
  2091. {
  2092. ygr = yy * size.x;
  2093. ygr2 = (int)((yy - yst2 + yst) * yo) * bb;
  2094. for (xx = xst2, xb = xst * xo; xx < dgx; ++xx, xb += xo)
  2095. {
  2096. int f = ff[(int)xb + ygr2];
  2097. unsigned char* cf = (unsigned char*)&f;
  2098. cf[3] = (unsigned char)((cf[3] > alpha[alphaAnzahl])
  2099. * (cf[3] - alpha[alphaAnzahl]));
  2100. alphaPixelP(fc[xx + ygr], f);
  2101. }
  2102. }
  2103. }
  2104. rend = 1;
  2105. }
  2106. void Image::drawDreieck(
  2107. Punkt a, Punkt b, Punkt c, int farbe) // fills a triangle
  2108. {
  2109. if (alpha[alphaAnzahl] == 0xFF) return;
  2110. if (alpha[alphaAnzahl])
  2111. {
  2112. drawDreieckAlpha(a, b, c, farbe);
  2113. return;
  2114. }
  2115. int dpx = dPosA[doa].x;
  2116. int dpy = dPosA[doa].y;
  2117. int dgx = dSizeA[doa].x;
  2118. int dgy = dSizeA[doa].y;
  2119. a += drawOff[doa];
  2120. b += drawOff[doa];
  2121. c += drawOff[doa];
  2122. if ((a.x < dpx && b.x < dpx && c.x < dpx)
  2123. || (a.y < dpy && b.y < dpy && c.y < dpy)
  2124. || (a.x >= dgx && b.x >= dgx && c.x >= dgx)
  2125. || (a.y >= dgy && b.y >= dgy && c.y >= dgy))
  2126. return;
  2127. if (b.y < a.y) a.Swap(b);
  2128. if (c.y < b.y) b.Swap(c);
  2129. if (b.y < a.y) a.Swap(b);
  2130. if (a.y == b.y)
  2131. {
  2132. if (b.x < a.x) a.Swap(b);
  2133. const float m2 = (float)(a.x - c.x) / (float)(a.y - c.y);
  2134. const float m3 = (float)(b.x - c.x) / (float)(b.y - c.y);
  2135. float b2 = (float)a.x - m2 * (float)a.y;
  2136. float b3 = (float)b.x - m3 * (float)b.y;
  2137. drawFlatDreieck(b.y, c.y, m2, b2, m3, b3, farbe);
  2138. }
  2139. else if (b.y == c.y)
  2140. {
  2141. if (c.x < b.x) b.Swap(c);
  2142. const float m1 = (float)(a.x - b.x) / (float)(a.y - b.y);
  2143. const float m2 = (float)(a.x - c.x) / (float)(a.y - c.y);
  2144. float b1 = (float)a.x - m1 * (float)a.y;
  2145. float b2 = (float)a.x - m2 * (float)a.y;
  2146. drawFlatDreieck(a.y, b.y, m1, b1, m2, b2, farbe);
  2147. }
  2148. else
  2149. {
  2150. const float m1 = (float)(a.x - b.x) / (float)(a.y - b.y);
  2151. const float m2 = (float)(a.x - c.x) / (float)(a.y - c.y);
  2152. const float m3 = (float)(b.x - c.x) / (float)(b.y - c.y);
  2153. float b1 = (float)a.x - m1 * (float)a.y;
  2154. float b2 = (float)a.x - m2 * (float)a.y;
  2155. float b3 = (float)b.x - m3 * (float)b.y;
  2156. const float qx = m2 * (float)b.y + b2;
  2157. if (qx < (float)b.x)
  2158. {
  2159. drawFlatDreieck(a.y, b.y, m2, b2, m1, b1, farbe);
  2160. drawFlatDreieck(b.y, c.y, m2, b2, m3, b3, farbe);
  2161. }
  2162. else
  2163. {
  2164. drawFlatDreieck(a.y, b.y, m1, b1, m2, b2, farbe);
  2165. drawFlatDreieck(b.y, c.y, m3, b3, m2, b2, farbe);
  2166. }
  2167. }
  2168. rend = 1;
  2169. }
  2170. void Image::drawDreieckTextur(Punkt a,
  2171. Punkt b,
  2172. Punkt c,
  2173. Punkt ta,
  2174. Punkt tb,
  2175. Punkt tc,
  2176. const Image& textur) // fills a triangle
  2177. {
  2178. if (alpha[alphaAnzahl] == 0xFF) return;
  2179. if (alpha[alphaAnzahl])
  2180. {
  2181. drawTriangleTextureAlpha(a, b, c, ta, tb, tc, textur);
  2182. return;
  2183. }
  2184. int dpx = dPosA[doa].x;
  2185. int dpy = dPosA[doa].y;
  2186. int dgx = dSizeA[doa].x;
  2187. int dgy = dSizeA[doa].y;
  2188. a += drawOff[doa];
  2189. b += drawOff[doa];
  2190. c += drawOff[doa];
  2191. if ((a.x < dpx && b.x < dpx && c.x < dpx)
  2192. || (a.y < dpy && b.y < dpy && c.y < dpy)
  2193. || (a.x >= dgx && b.x >= dgx && c.x >= dgx)
  2194. || (a.y >= dgy && b.y >= dgy && c.y >= dgy))
  2195. return;
  2196. if (b.y < a.y)
  2197. {
  2198. a.Swap(b);
  2199. ta.Swap(tb);
  2200. }
  2201. if (c.y < b.y)
  2202. {
  2203. b.Swap(c);
  2204. tb.Swap(tc);
  2205. }
  2206. if (b.y < a.y)
  2207. {
  2208. a.Swap(b);
  2209. ta.Swap(tb);
  2210. }
  2211. const double m1 = (double)(a.x - b.x) / (a.y - b.y);
  2212. const double m2 = (double)(a.x - c.x) / (a.y - c.y);
  2213. const double m3 = (double)(b.x - c.x) / (b.y - c.y);
  2214. double b1 = a.x - m1 * a.y;
  2215. double b2 = a.x - m2 * a.y;
  2216. double b3 = b.x - m3 * b.y;
  2217. const double qx = m2 * b.y + b2;
  2218. if (qx < b.x)
  2219. {
  2220. double tx1o, ty1o, tx2o, ty2o;
  2221. if (c.y - a.y)
  2222. {
  2223. tx1o = (double)(tc.x - ta.x) / (c.y - a.y);
  2224. ty1o = (double)(tc.y - ta.y) / (c.y - a.y);
  2225. }
  2226. else
  2227. {
  2228. tx1o = 0;
  2229. ty1o = 0;
  2230. }
  2231. if (b.y - a.y)
  2232. {
  2233. tx2o = (double)(tb.x - ta.x) / (b.y - a.y);
  2234. ty2o = (double)(tb.y - ta.y) / (b.y - a.y);
  2235. }
  2236. else
  2237. {
  2238. tx2o = 0;
  2239. ty2o = 0;
  2240. }
  2241. Vec2<double> q(ta.x + tx1o * (b.y - a.y), ta.y + ty1o * (b.y - a.y));
  2242. double txf, tyf;
  2243. if (b.x - qx)
  2244. {
  2245. txf = (tb.x - q.x) / (b.x - qx);
  2246. tyf = (tb.y - q.y) / (b.x - qx);
  2247. }
  2248. else
  2249. {
  2250. txf = 0;
  2251. tyf = 0;
  2252. }
  2253. drawFlatDreieckTextur(a.y,
  2254. b.y,
  2255. m2,
  2256. b2,
  2257. m1,
  2258. b1,
  2259. ta.x,
  2260. ta.y,
  2261. ta.x,
  2262. ta.y,
  2263. tx1o,
  2264. ty1o,
  2265. tx2o,
  2266. ty2o,
  2267. txf,
  2268. tyf,
  2269. textur);
  2270. if (c.y - b.y)
  2271. {
  2272. tx2o = (double)(tc.x - tb.x) / (c.y - b.y);
  2273. ty2o = (double)(tc.y - tb.y) / (c.y - b.y);
  2274. }
  2275. else
  2276. {
  2277. tx2o = 0;
  2278. ty2o = 0;
  2279. }
  2280. drawFlatDreieckTextur(b.y,
  2281. c.y,
  2282. m2,
  2283. b2,
  2284. m3,
  2285. b3,
  2286. q.x,
  2287. q.y,
  2288. tb.x,
  2289. tb.y,
  2290. tx1o,
  2291. ty1o,
  2292. tx2o,
  2293. ty2o,
  2294. txf,
  2295. tyf,
  2296. textur);
  2297. }
  2298. else
  2299. {
  2300. double tx1o, ty1o, tx2o, ty2o;
  2301. if (b.y - a.y)
  2302. {
  2303. tx1o = (double)(tb.x - ta.x) / (b.y - a.y);
  2304. ty1o = (double)(tb.y - ta.y) / (b.y - a.y);
  2305. }
  2306. else
  2307. {
  2308. tx1o = 0;
  2309. ty1o = 0;
  2310. }
  2311. if (c.y - a.y)
  2312. {
  2313. tx2o = (double)(tc.x - ta.x) / (c.y - a.y);
  2314. ty2o = (double)(tc.y - ta.y) / (c.y - a.y);
  2315. }
  2316. else
  2317. {
  2318. tx2o = 0;
  2319. ty2o = 0;
  2320. }
  2321. Vec2<double> q(ta.x + tx2o * (b.y - a.y), ta.y + ty2o * (b.y - a.y));
  2322. double txf, tyf;
  2323. if (qx - b.x)
  2324. {
  2325. txf = (q.x - tb.x) / (qx - b.x);
  2326. tyf = (q.y - tb.y) / (qx - b.x);
  2327. }
  2328. else
  2329. {
  2330. txf = 0;
  2331. tyf = 0;
  2332. }
  2333. drawFlatDreieckTextur(a.y,
  2334. b.y,
  2335. m1,
  2336. b1,
  2337. m2,
  2338. b2,
  2339. ta.x,
  2340. ta.y,
  2341. ta.x,
  2342. ta.y,
  2343. tx1o,
  2344. ty1o,
  2345. tx2o,
  2346. ty2o,
  2347. txf,
  2348. tyf,
  2349. textur);
  2350. if (c.y - b.y)
  2351. {
  2352. tx1o = (double)(tc.x - tb.x) / (c.y - b.y);
  2353. ty1o = (double)(tc.y - tb.y) / (c.y - b.y);
  2354. }
  2355. else
  2356. {
  2357. tx1o = 0;
  2358. ty1o = 0;
  2359. }
  2360. drawFlatDreieckTextur(b.y,
  2361. c.y,
  2362. m3,
  2363. b3,
  2364. m2,
  2365. b2,
  2366. tb.x,
  2367. tb.y,
  2368. q.x,
  2369. q.y,
  2370. tx1o,
  2371. ty1o,
  2372. tx2o,
  2373. ty2o,
  2374. txf,
  2375. tyf,
  2376. textur);
  2377. }
  2378. rend = 1;
  2379. }
  2380. void Image::drawDreieckAlpha(
  2381. Punkt a, Punkt b, Punkt c, int farbe) // fills a triangle
  2382. {
  2383. if (alpha[alphaAnzahl] == 0xFF) return;
  2384. int dpx = dPosA[doa].x;
  2385. int dpy = dPosA[doa].y;
  2386. int dgx = dSizeA[doa].x;
  2387. int dgy = dSizeA[doa].y;
  2388. a += drawOff[doa];
  2389. b += drawOff[doa];
  2390. c += drawOff[doa];
  2391. if ((a.x < dpx && b.x < dpx && c.x < dpx)
  2392. || (a.y < dpy && b.y < dpy && c.y < dpy)
  2393. || (a.x >= dgx && b.x >= dgx && c.x >= dgx)
  2394. || (a.y >= dgy && b.y >= dgy && c.y >= dgy))
  2395. return;
  2396. if (alpha[alphaAnzahl])
  2397. {
  2398. unsigned char* cf = (unsigned char*)&farbe;
  2399. cf[3] = (unsigned char)((cf[3] > alpha[alphaAnzahl])
  2400. * (cf[3] - alpha[alphaAnzahl]));
  2401. }
  2402. if (b.y < a.y) a.Swap(b);
  2403. if (c.y < b.y) b.Swap(c);
  2404. if (b.y < a.y) a.Swap(b);
  2405. if (a.y == b.y)
  2406. {
  2407. if (b.x < a.x) a.Swap(b);
  2408. const float m2 = (float)(a.x - c.x) / (float)(a.y - c.y);
  2409. const float m3 = (float)(b.x - c.x) / (float)(b.y - c.y);
  2410. float b2 = (float)a.x - m2 * (float)a.y;
  2411. float b3 = (float)b.x - m3 * (float)b.y;
  2412. drawFlatDreieckAlpha(b.y, c.y, m2, b2, m3, b3, farbe);
  2413. }
  2414. else if (b.y == c.y)
  2415. {
  2416. if (c.x < b.x) b.Swap(c);
  2417. const float m1 = (float)(a.x - b.x) / (float)(a.y - b.y);
  2418. const float m2 = (float)(a.x - c.x) / (float)(a.y - c.y);
  2419. float b1 = (float)a.x - m1 * (float)a.y;
  2420. float b2 = (float)a.x - m2 * (float)a.y;
  2421. drawFlatDreieckAlpha(a.y, b.y, m1, b1, m2, b2, farbe);
  2422. }
  2423. else
  2424. {
  2425. const float m1 = (float)(a.x - b.x) / (float)(a.y - b.y);
  2426. const float m2 = (float)(a.x - c.x) / (float)(a.y - c.y);
  2427. const float m3 = (float)(b.x - c.x) / (float)(b.y - c.y);
  2428. float b1 = (float)a.x - m1 * (float)a.y;
  2429. float b2 = (float)a.x - m2 * (float)a.y;
  2430. float b3 = (float)b.x - m3 * (float)b.y;
  2431. const float qx = m2 * (float)b.y + b2;
  2432. if (qx < (float)b.x)
  2433. {
  2434. drawFlatDreieckAlpha(a.y, b.y, m2, b2, m1, b1, farbe);
  2435. drawFlatDreieckAlpha(b.y, c.y, m2, b2, m3, b3, farbe);
  2436. }
  2437. else
  2438. {
  2439. drawFlatDreieckAlpha(a.y, b.y, m1, b1, m2, b2, farbe);
  2440. drawFlatDreieckAlpha(b.y, c.y, m3, b3, m2, b2, farbe);
  2441. }
  2442. }
  2443. rend = 1;
  2444. }
  2445. void Image::drawTriangleTextureAlpha(Punkt a,
  2446. Punkt b,
  2447. Punkt c,
  2448. Punkt ta,
  2449. Punkt tb,
  2450. Punkt tc,
  2451. const Image& textur) // fills a triangle
  2452. {
  2453. if (alpha[alphaAnzahl] == 0xFF) return;
  2454. int dpx = dPosA[doa].x;
  2455. int dpy = dPosA[doa].y;
  2456. int dgx = dSizeA[doa].x;
  2457. int dgy = dSizeA[doa].y;
  2458. a += drawOff[doa];
  2459. b += drawOff[doa];
  2460. c += drawOff[doa];
  2461. if ((a.x < dpx && b.x < dpx && c.x < dpx)
  2462. || (a.y < dpy && b.y < dpy && c.y < dpy)
  2463. || (a.x >= dgx && b.x >= dgx && c.x >= dgx)
  2464. || (a.y >= dgy && b.y >= dgy && c.y >= dgy))
  2465. return;
  2466. if (b.y < a.y)
  2467. {
  2468. a.Swap(b);
  2469. ta.Swap(tb);
  2470. }
  2471. if (c.y < b.y)
  2472. {
  2473. b.Swap(c);
  2474. tb.Swap(tc);
  2475. }
  2476. if (b.y < a.y)
  2477. {
  2478. a.Swap(b);
  2479. ta.Swap(tb);
  2480. }
  2481. const double m1 = (double)(a.x - b.x) / (a.y - b.y);
  2482. const double m2 = (double)(a.x - c.x) / (a.y - c.y);
  2483. const double m3 = (double)(b.x - c.x) / (b.y - c.y);
  2484. double b1 = a.x - m1 * a.y;
  2485. double b2 = a.x - m2 * a.y;
  2486. double b3 = b.x - m3 * b.y;
  2487. const double qx = m2 * b.y + b2;
  2488. if (qx < b.x)
  2489. {
  2490. double tx1o, ty1o, tx2o, ty2o;
  2491. if (c.y - a.y)
  2492. {
  2493. tx1o = (double)(tc.x - ta.x) / (c.y - a.y);
  2494. ty1o = (double)(tc.y - ta.y) / (c.y - a.y);
  2495. }
  2496. else
  2497. {
  2498. tx1o = 0;
  2499. ty1o = 0;
  2500. }
  2501. if (b.y - a.y)
  2502. {
  2503. tx2o = (double)(tb.x - ta.x) / (b.y - a.y);
  2504. ty2o = (double)(tb.y - ta.y) / (b.y - a.y);
  2505. }
  2506. else
  2507. {
  2508. tx2o = 0;
  2509. ty2o = 0;
  2510. }
  2511. Vec2<double> q(ta.x + tx1o * (b.y - a.y), ta.y + ty1o * (b.y - a.y));
  2512. double txf, tyf;
  2513. if (b.x - qx)
  2514. {
  2515. txf = (tb.x - q.x) / (b.x - qx);
  2516. tyf = (tb.y - q.y) / (b.x - qx);
  2517. }
  2518. else
  2519. {
  2520. txf = 0;
  2521. tyf = 0;
  2522. }
  2523. drawFlatDreieckTexturAlpha(a.y,
  2524. b.y,
  2525. m2,
  2526. b2,
  2527. m1,
  2528. b1,
  2529. ta.x,
  2530. ta.y,
  2531. ta.x,
  2532. ta.y,
  2533. tx1o,
  2534. ty1o,
  2535. tx2o,
  2536. ty2o,
  2537. txf,
  2538. tyf,
  2539. textur);
  2540. if (c.y - b.y)
  2541. {
  2542. tx2o = (double)(tc.x - tb.x) / (c.y - b.y);
  2543. ty2o = (double)(tc.y - tb.y) / (c.y - b.y);
  2544. }
  2545. else
  2546. {
  2547. tx2o = 0;
  2548. ty2o = 0;
  2549. }
  2550. drawFlatDreieckTexturAlpha(b.y,
  2551. c.y,
  2552. m2,
  2553. b2,
  2554. m3,
  2555. b3,
  2556. q.x,
  2557. q.y,
  2558. tb.x,
  2559. tb.y,
  2560. tx1o,
  2561. ty1o,
  2562. tx2o,
  2563. ty2o,
  2564. txf,
  2565. tyf,
  2566. textur);
  2567. }
  2568. else
  2569. {
  2570. double tx1o, ty1o, tx2o, ty2o;
  2571. if (b.y - a.y)
  2572. {
  2573. tx1o = (double)(tb.x - ta.x) / (b.y - a.y);
  2574. ty1o = (double)(tb.y - ta.y) / (b.y - a.y);
  2575. }
  2576. else
  2577. {
  2578. tx1o = 0;
  2579. ty1o = 0;
  2580. }
  2581. if (c.y - a.y)
  2582. {
  2583. tx2o = (double)(tc.x - ta.x) / (c.y - a.y);
  2584. ty2o = (double)(tc.y - ta.y) / (c.y - a.y);
  2585. }
  2586. else
  2587. {
  2588. tx2o = 0;
  2589. ty2o = 0;
  2590. }
  2591. Vec2<double> q(ta.x + tx2o * (b.y - a.y), ta.y + ty2o * (b.y - a.y));
  2592. double txf, tyf;
  2593. if (qx - b.x)
  2594. {
  2595. txf = (q.x - tb.x) / (qx - b.x);
  2596. tyf = (q.y - tb.y) / (qx - b.x);
  2597. }
  2598. else
  2599. {
  2600. txf = 0;
  2601. tyf = 0;
  2602. }
  2603. drawFlatDreieckTexturAlpha(a.y,
  2604. b.y,
  2605. m1,
  2606. b1,
  2607. m2,
  2608. b2,
  2609. ta.x,
  2610. ta.y,
  2611. ta.x,
  2612. ta.y,
  2613. tx1o,
  2614. ty1o,
  2615. tx2o,
  2616. ty2o,
  2617. txf,
  2618. tyf,
  2619. textur);
  2620. if (c.y - b.y)
  2621. {
  2622. tx1o = (double)(tc.x - tb.x) / (c.y - b.y);
  2623. ty1o = (double)(tc.y - tb.y) / (c.y - b.y);
  2624. }
  2625. else
  2626. {
  2627. tx1o = 0;
  2628. ty1o = 0;
  2629. }
  2630. drawFlatDreieckTexturAlpha(b.y,
  2631. c.y,
  2632. m3,
  2633. b3,
  2634. m2,
  2635. b2,
  2636. tb.x,
  2637. tb.y,
  2638. q.x,
  2639. q.y,
  2640. tx1o,
  2641. ty1o,
  2642. tx2o,
  2643. ty2o,
  2644. txf,
  2645. tyf,
  2646. textur);
  2647. }
  2648. rend = 1;
  2649. }
  2650. void Image::replaceColorWithAlpha(int color)
  2651. {
  2652. int r = (color & 0xFF0000) >> 16;
  2653. int g = (color & 0xFF00) >> 8;
  2654. int b = color & 0xFF;
  2655. int dx = drawOff[doa].x, dy = drawOff[doa].y;
  2656. int xx = dPosA[doa].x, yy = dPosA[doa].y;
  2657. int bb = dSizeA[doa].x, hh = dSizeA[doa].y;
  2658. for (int y = dy + yy; y < hh; y++)
  2659. {
  2660. int ygr = y * size.x;
  2661. for (int x = dx + xx; x < bb; x++)
  2662. {
  2663. unsigned char* cf = (unsigned char*)&(fc[x + ygr]);
  2664. int abstand = (int)sqrt(
  2665. (float)((r - cf[2]) * (r - cf[2]) + (g - cf[1]) * (g - cf[1])
  2666. + (b - cf[0]) * (b - cf[0])));
  2667. if (abstand > 255) abstand = 255;
  2668. cf[3] = (unsigned char)(abstand);
  2669. }
  2670. }
  2671. }
  2672. bool Image::setDrawOptions(
  2673. const Punkt& pos, const Punkt& gr) // sets the draw options
  2674. {
  2675. int dx = drawOff[doa].x, dy = drawOff[doa].y;
  2676. int xx = dPosA[doa].x, yy = dPosA[doa].y;
  2677. int bb = dSizeA[doa].x, hh = dSizeA[doa].y;
  2678. if (dx + pos.x + gr.x < 0 || dy + pos.y + gr.y < 0 || dx + pos.x >= size.x
  2679. || dy + pos.y >= size.y)
  2680. return 0;
  2681. if (pos.x + gr.x + dx < xx || pos.y + gr.y + dy < yy || dx + pos.x >= bb
  2682. || dy + pos.y >= hh)
  2683. return 0;
  2684. ++doa;
  2685. assert(doa < 2000);
  2686. dPosA[doa].x = maxInt(pos.x + dx, xx);
  2687. dPosA[doa].y = maxInt(pos.y + dy, yy);
  2688. dSizeA[doa].x = minInt(pos.x + gr.x + dx, bb);
  2689. dSizeA[doa].y = minInt(pos.y + gr.y + dy, hh);
  2690. drawOff[doa].x = dx + pos.x;
  2691. drawOff[doa].y = dy + pos.y;
  2692. return 1;
  2693. }
  2694. bool Image::setDrawOptions(int x, int y, int br, int hi)
  2695. {
  2696. int dx = drawOff[doa].x, dy = drawOff[doa].y;
  2697. int xx = dPosA[doa].x, yy = dPosA[doa].y;
  2698. int bb = dSizeA[doa].x, hh = dSizeA[doa].y;
  2699. if (dx + x + br < 0 || dy + y + hi < 0 || dx + x >= size.x
  2700. || dy + y >= size.y)
  2701. return 0;
  2702. if (x + br + dx < xx || y + hi + dy < yy || dx + x >= bb || dy + y >= hh)
  2703. return 0;
  2704. ++doa;
  2705. assert(doa < 2000);
  2706. dPosA[doa].x = maxInt(x + dx, xx);
  2707. dPosA[doa].y = maxInt(y + dy, yy);
  2708. dSizeA[doa].x = minInt(x + br + dx, bb);
  2709. dSizeA[doa].y = minInt(y + hi + dy, hh);
  2710. drawOff[doa].x = dx + x;
  2711. drawOff[doa].y = dy + y;
  2712. return 1;
  2713. }
  2714. bool Image::setDrawOptionsErzwingen(
  2715. const Punkt& pos, const Punkt& gr) // sets the draw options
  2716. {
  2717. int dx = drawOff[doa].x, dy = drawOff[doa].y;
  2718. if (dx + pos.x + gr.x < 0 || dy + pos.y + gr.y < 0 || dx + pos.x >= size.x
  2719. || dy + pos.y >= size.y)
  2720. return 0;
  2721. ++doa;
  2722. assert(doa < 2000);
  2723. dPosA[doa].x = maxInt(pos.x + dx, 0);
  2724. dPosA[doa].y = maxInt(pos.y + dy, 0);
  2725. dSizeA[doa].x = minInt(pos.x + gr.x + dx, size.x);
  2726. dSizeA[doa].y = minInt(pos.y + gr.y + dy, size.y);
  2727. drawOff[doa].x = dx + pos.x;
  2728. drawOff[doa].y = dy + pos.y;
  2729. return 1;
  2730. }
  2731. bool Image::setDrawOptionsErzwingen(
  2732. int x, int y, int br, int hi) // sets the draw options
  2733. {
  2734. int dx = drawOff[doa].x, dy = drawOff[doa].y;
  2735. if (dx + x + br < 0 || dy + y + hi < 0 || dx + x >= size.x
  2736. || dy + y >= size.y)
  2737. return 0;
  2738. ++doa;
  2739. assert(doa < 2000);
  2740. dPosA[doa].x = maxInt(x + dx, 0);
  2741. dPosA[doa].y = maxInt(y + dy, 0);
  2742. dSizeA[doa].x = minInt(x + br + dx, size.x);
  2743. dSizeA[doa].y = minInt(y + hi + dy, size.y);
  2744. drawOff[doa].x = dx + x;
  2745. drawOff[doa].y = dy + y;
  2746. return 1;
  2747. }
  2748. void Image::setDrawOptionsReset()
  2749. {
  2750. ++doa;
  2751. dPosA[doa].x = 0;
  2752. dPosA[doa].y = 0;
  2753. dSizeA[doa].x = size.x;
  2754. dSizeA[doa].y = size.y;
  2755. drawOff[doa].x = 0;
  2756. drawOff[doa].y = 0;
  2757. }
  2758. void Image::addScrollOffset(int xOff, int yOff) // sets scroll offset
  2759. {
  2760. drawOff[doa].x -= xOff;
  2761. drawOff[doa].y -= yOff;
  2762. }
  2763. void Image::releaseDrawOptions() // resets the draw options
  2764. {
  2765. --doa;
  2766. }
  2767. bool Image::getRend()
  2768. {
  2769. bool ret = rend;
  2770. rend = 0;
  2771. return ret;
  2772. }
  2773. // constant
  2774. int* Image::getBuffer() const // returns the buffer
  2775. {
  2776. return fc;
  2777. }
  2778. int Image::getPixel(int x, int y) const
  2779. {
  2780. if (x < 0 || y < 0 || x >= size.x || y >= size.y) return 0;
  2781. return fc[x + y * size.x];
  2782. }
  2783. const Punkt& Image::getSize() const // returns the size
  2784. {
  2785. return size;
  2786. }
  2787. int Image::getBreite() const // returns the width
  2788. {
  2789. return size.x;
  2790. }
  2791. int Image::getHeight() const // returns the height
  2792. {
  2793. return size.y;
  2794. }
  2795. unsigned char Image::getAlpha() const // returns the alpha value
  2796. {
  2797. return (unsigned char)(255 - alpha[alphaAnzahl]);
  2798. }
  2799. const Punkt& Image::getDrawPos() const
  2800. {
  2801. return dPosA[doa];
  2802. }
  2803. const Punkt& Image::getDrawGr() const
  2804. {
  2805. return dSizeA[doa];
  2806. }
  2807. const Punkt& Image::getDrawOff() const
  2808. {
  2809. return drawOff[doa];
  2810. }
  2811. bool Image::hasAlpha3D() const
  2812. {
  2813. return alpha3D;
  2814. }
  2815. int Image::getAverageColor() const
  2816. {
  2817. double a = 0;
  2818. double r = 0;
  2819. double g = 0;
  2820. double b = 0;
  2821. for (int i = 0; i < size.x * size.y; i++)
  2822. {
  2823. float currentA = (float)(fc[i] >> 24) / 255.f;
  2824. a = a + currentA;
  2825. r = r + (double)((float)((fc[i] >> 16) & 0xFF) * currentA);
  2826. g = g + (double)((float)((fc[i] >> 8) & 0xFF) * currentA);
  2827. b = b + (double)((float)(fc[i] & 0xFF) * currentA);
  2828. }
  2829. a = a / (size.x * size.y);
  2830. r = (r / (size.x * size.y)) / a;
  2831. g = (g / (size.x * size.y)) / a;
  2832. b = (b / (size.x * size.y)) / a;
  2833. a = a * 255;
  2834. return ((((int)a) & 0xFF) << 24) | ((((int)r) & 0xFF) << 16)
  2835. | ((((int)g) & 0xFF) << 8) | (((int)b) & 0xFF);
  2836. }
  2837. // Contents of the ImageView class from Image.h
  2838. // Constructor
  2839. ImageView::ImageView()
  2840. : DrawableBackground(),
  2841. bild(0)
  2842. {
  2843. style = Style::MELockDrawable;
  2844. mak = _ret1ME;
  2845. }
  2846. // Destructor
  2847. ImageView::~ImageView()
  2848. {
  2849. if (bild) bild->release();
  2850. }
  2851. void ImageView::doMouseEvent(MouseEvent& me, bool userRet) // calls Mak
  2852. {
  2853. if (userRet)
  2854. {
  2855. int rbr = 0;
  2856. if (hatStyle(Style::Border) && rahmen) rbr = rahmen->getRBreite();
  2857. bool vs = hatStyle(Style::VScroll) && vertikalScrollBar;
  2858. bool hs = hatStyle(Style::HScroll) && horizontalScrollBar;
  2859. if (vs)
  2860. {
  2861. if (hs)
  2862. horizontalScrollBar->doMausMessage(
  2863. rbr, gr.y - rbr - 15, gr.x - rbr * 2 - 15, 15, me);
  2864. vertikalScrollBar->doMausMessage(
  2865. gr.x - rbr - 15, rbr, 15, gr.y - rbr * 2, me);
  2866. }
  2867. else if (hs)
  2868. horizontalScrollBar->doMausMessage(
  2869. rbr, gr.y - rbr - 15, gr.x - rbr * 2, 15, me);
  2870. }
  2871. me.verarbeitet = userRet;
  2872. }
  2873. // non-constant
  2874. void ImageView::setImageZ(Image* b) // sets the image
  2875. {
  2876. if (bild) bild->release();
  2877. bild = b;
  2878. if (!vertikalScrollBar) vertikalScrollBar = new VScrollBar();
  2879. if (!horizontalScrollBar) horizontalScrollBar = new HScrollBar();
  2880. if (b)
  2881. {
  2882. horizontalScrollBar->getScrollData()->max = b->getBreite();
  2883. vertikalScrollBar->getScrollData()->max = b->getHeight();
  2884. }
  2885. rend = 1;
  2886. }
  2887. void ImageView::setImage(Image* b)
  2888. {
  2889. if (!bild) bild = new Image();
  2890. bild->neuImage(b->getBreite(), b->getHeight(), 0);
  2891. bild->drawImage(0, 0, b->getBreite(), b->getHeight(), *b);
  2892. if (!vertikalScrollBar) vertikalScrollBar = new VScrollBar();
  2893. if (!horizontalScrollBar) horizontalScrollBar = new HScrollBar();
  2894. horizontalScrollBar->getScrollData()->max = b->getBreite();
  2895. vertikalScrollBar->getScrollData()->max = b->getHeight();
  2896. b->release();
  2897. rend = 1;
  2898. }
  2899. bool ImageView::tick(double tickVal) // tick
  2900. {
  2901. return DrawableBackground::tick(tickVal);
  2902. }
  2903. void ImageView::render(Image& zRObj) // draws to zRObj
  2904. {
  2905. if (hatStyle(Style::Sichtbar))
  2906. {
  2907. DrawableBackground::render(zRObj);
  2908. lockDrawable();
  2909. if (!zRObj.setDrawOptions(innenPosition, innenSize))
  2910. {
  2911. unlockDrawable();
  2912. return;
  2913. }
  2914. if (bild)
  2915. {
  2916. int x = 0;
  2917. int y = 0;
  2918. int br = innenSize.x;
  2919. int hi = innenSize.y;
  2920. if (!(vertikalScrollBar && hatStyle(Style::VScroll))
  2921. && !(horizontalScrollBar && hatStyle(Style::HScroll)))
  2922. {
  2923. if (hatStyle(Style::Alpha))
  2924. {
  2925. if (hatStyle(Style::Skalliert))
  2926. zRObj.alphaImageSkall(x, y, br, hi, *bild);
  2927. else
  2928. zRObj.alphaImage(x, y, br, hi, *bild);
  2929. }
  2930. else
  2931. {
  2932. if (hatStyle(Style::Skalliert))
  2933. zRObj.drawImageSkall(x, y, br, hi, *bild);
  2934. else
  2935. zRObj.drawImage(x, y, br, hi, *bild);
  2936. }
  2937. }
  2938. else
  2939. {
  2940. if (!zRObj.setDrawOptions(x, y, br, hi))
  2941. {
  2942. zRObj.releaseDrawOptions();
  2943. unlockDrawable();
  2944. return;
  2945. }
  2946. if (hatStyle(Style::Alpha))
  2947. zRObj.alphaImage(-horizontalScrollBar->getScroll(),
  2948. -vertikalScrollBar->getScroll(),
  2949. bild->getBreite(),
  2950. bild->getHeight(),
  2951. *bild);
  2952. else
  2953. zRObj.drawImage(-horizontalScrollBar->getScroll(),
  2954. -vertikalScrollBar->getScroll(),
  2955. bild->getBreite(),
  2956. bild->getHeight(),
  2957. *bild);
  2958. zRObj.releaseDrawOptions();
  2959. }
  2960. }
  2961. zRObj.releaseDrawOptions();
  2962. unlockDrawable();
  2963. }
  2964. }
  2965. // constant
  2966. Image* ImageView::getImage() const // returns the image
  2967. {
  2968. if (bild) return dynamic_cast<Image*>(bild->getThis());
  2969. return 0;
  2970. }
  2971. Image* ImageView::zImage() const
  2972. {
  2973. return bild;
  2974. }
  2975. Drawable* ImageView::dublizieren() const // creates a copy of the drawing
  2976. {
  2977. ImageView* obj = new ImageView();
  2978. obj->setPosition(pos);
  2979. obj->setSize(gr);
  2980. obj->setMouseEventParameter(makParam);
  2981. obj->setKeyboardEventParameter(takParam);
  2982. obj->setMouseEvent(mak);
  2983. obj->setKeyboardEvent(tak);
  2984. if (toolTip) obj->setToolTipZ((ToolTip*)toolTip->dublizieren());
  2985. obj->setStyle(style);
  2986. obj->setHintergrundFarbe(hintergrundFarbe);
  2987. if (hintergrundFeld)
  2988. obj->setAlphaFieldZ((AlphaField*)hintergrundFeld->dublizieren());
  2989. if (rahmen) obj->setBorderZ((Border*)rahmen->dublizieren());
  2990. if (hintergrundImage)
  2991. obj->setHintergrundImage(
  2992. dynamic_cast<Image*>(hintergrundImage->getThis()));
  2993. if (bild) obj->setImage(dynamic_cast<Image*>(bild->getThis()));
  2994. obj->setStyle(style);
  2995. return obj;
  2996. }
  2997. #ifdef WIN32
  2998. Image* Framework::ladeImage(const char* pfad, Text* zError)
  2999. {
  3000. Text p = pfad;
  3001. Text* txt = p.getTeilText(p.positionVon('.', p.anzahlVon('.') - 1));
  3002. if (!(txt->istGleich(".bmp") || txt->istGleich(".jpg")
  3003. || txt->istGleich(".gif") || txt->istGleich(".png")))
  3004. {
  3005. zError->setText("Die Angegebene File ist keine gueltige ImageFile!");
  3006. txt->release();
  3007. return 0;
  3008. }
  3009. txt->release();
  3010. wchar_t* name = new wchar_t[p.getLength() + 1];
  3011. for (int i = 0; i < p.getLength(); i++)
  3012. name[i] = (wchar_t)p.getText()[i];
  3013. name[p.getLength()] = '\0';
  3014. Gdiplus::Bitmap bitmap(name);
  3015. Gdiplus::Color pix;
  3016. delete[] name;
  3017. Image* ret = new Image();
  3018. ret->neuImage(bitmap.GetWidth(), bitmap.GetHeight(), 0);
  3019. int* buff = ret->getBuffer();
  3020. for (unsigned int i = 0; i < bitmap.GetWidth() * bitmap.GetHeight(); i++)
  3021. {
  3022. bitmap.GetPixel(i % bitmap.GetWidth(), i / bitmap.GetWidth(), &pix);
  3023. buff[i] = pix.GetValue();
  3024. }
  3025. return ret;
  3026. }
  3027. #endif