fbblit.c 59 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228
  1. /*
  2. * GRUB -- GRand Unified Bootloader
  3. * Copyright (C) 2006,2007,2008 Free Software Foundation, Inc.
  4. *
  5. * GRUB is free software: you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License as published by
  7. * the Free Software Foundation, either version 3 of the License, or
  8. * (at your option) any later version.
  9. *
  10. * GRUB is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU General Public License
  16. * along with GRUB. If not, see <http://www.gnu.org/licenses/>.
  17. */
  18. /* SPECIAL NOTES!
  19. Please note following when reading the code below:
  20. - In this driver we assume that every memory can be accessed by same memory
  21. bus. If there are different address spaces do not use this code as a base
  22. code for other archs.
  23. - Every function in this code assumes that bounds checking has been done in
  24. previous phase and they are opted out in here. */
  25. #include <grub/video_fb.h>
  26. #include <grub/fbblit.h>
  27. #include <grub/fbutil.h>
  28. #include <grub/misc.h>
  29. #include <grub/types.h>
  30. #include <grub/video.h>
  31. /* Generic replacing blitter (slow). Works for every supported format. */
  32. static void
  33. grub_video_fbblit_replace (struct grub_video_fbblit_info *dst,
  34. struct grub_video_fbblit_info *src,
  35. int x, int y, int width, int height,
  36. int offset_x, int offset_y)
  37. {
  38. int i;
  39. int j;
  40. grub_uint8_t src_red;
  41. grub_uint8_t src_green;
  42. grub_uint8_t src_blue;
  43. grub_uint8_t src_alpha;
  44. grub_video_color_t src_color;
  45. grub_video_color_t dst_color;
  46. for (j = 0; j < height; j++)
  47. {
  48. for (i = 0; i < width; i++)
  49. {
  50. src_color = get_pixel (src, i + offset_x, j + offset_y);
  51. grub_video_fb_unmap_color_int (src, src_color, &src_red, &src_green,
  52. &src_blue, &src_alpha);
  53. dst_color = grub_video_fb_map_rgba (src_red, src_green,
  54. src_blue, src_alpha);
  55. set_pixel (dst, x + i, y + j, dst_color);
  56. }
  57. }
  58. }
  59. /* Block copy replacing blitter. Works with modes multiple of 8 bits. */
  60. static void
  61. grub_video_fbblit_replace_directN (struct grub_video_fbblit_info *dst,
  62. struct grub_video_fbblit_info *src,
  63. int x, int y, int width, int height,
  64. int offset_x, int offset_y)
  65. {
  66. int j;
  67. grub_uint32_t *srcptr;
  68. grub_uint32_t *dstptr;
  69. int bpp;
  70. bpp = src->mode_info->bytes_per_pixel;
  71. srcptr = grub_video_fb_get_video_ptr (src, offset_x, offset_y);
  72. dstptr = grub_video_fb_get_video_ptr (dst, x, y);
  73. for (j = 0; j < height; j++)
  74. {
  75. grub_memmove (dstptr, srcptr, width * bpp);
  76. GRUB_VIDEO_FB_ADVANCE_POINTER (srcptr, src->mode_info->pitch);
  77. GRUB_VIDEO_FB_ADVANCE_POINTER (dstptr, dst->mode_info->pitch);
  78. }
  79. }
  80. /* Optimized replacing blitter for 1-bit to 32bit. */
  81. static void
  82. grub_video_fbblit_replace_32bit_1bit (struct grub_video_fbblit_info *dst,
  83. struct grub_video_fbblit_info *src,
  84. int x, int y,
  85. int width, int height,
  86. int offset_x, int offset_y)
  87. {
  88. int i;
  89. int j;
  90. grub_uint8_t *srcptr;
  91. grub_uint32_t *dstptr;
  92. grub_uint8_t srcmask;
  93. unsigned int dstrowskip;
  94. unsigned int srcrowskipbyte, srcrowskipbit;
  95. grub_uint32_t fgcolor, bgcolor;
  96. int bit_index;
  97. /* Calculate the number of bytes to advance from the end of one line
  98. to the beginning of the next line. */
  99. dstrowskip = dst->mode_info->pitch - dst->mode_info->bytes_per_pixel * width;
  100. srcrowskipbyte = (src->mode_info->width - width) >> 3;
  101. srcrowskipbit = (src->mode_info->width - width) & 7;
  102. bit_index = offset_y * src->mode_info->width + offset_x;
  103. srcptr = (grub_uint8_t *) src->data + (bit_index >> 3);
  104. srcmask = 1 << (~bit_index & 7);
  105. dstptr = grub_video_fb_get_video_ptr (dst, x, y);
  106. fgcolor = grub_video_fb_map_rgba (src->mode_info->fg_red,
  107. src->mode_info->fg_green,
  108. src->mode_info->fg_blue,
  109. src->mode_info->fg_alpha);
  110. bgcolor = grub_video_fb_map_rgba (src->mode_info->bg_red,
  111. src->mode_info->bg_green,
  112. src->mode_info->bg_blue,
  113. src->mode_info->bg_alpha);
  114. for (j = 0; j < height; j++)
  115. {
  116. for (i = 0; i < width; i++)
  117. {
  118. if (*srcptr & srcmask)
  119. *dstptr = fgcolor;
  120. else
  121. *dstptr = bgcolor;
  122. srcmask >>= 1;
  123. if (!srcmask)
  124. {
  125. srcptr++;
  126. srcmask = 0x80;
  127. }
  128. dstptr++;
  129. }
  130. srcptr += srcrowskipbyte;
  131. if (srcmask >> srcrowskipbit)
  132. srcmask >>= srcrowskipbit;
  133. else
  134. {
  135. srcptr++;
  136. srcmask <<= 8 - srcrowskipbit;
  137. }
  138. GRUB_VIDEO_FB_ADVANCE_POINTER (dstptr, dstrowskip);
  139. }
  140. }
  141. #ifdef GRUB_HAVE_UNALIGNED_ACCESS
  142. /* Optimized replacing blitter for 1-bit to 24-bit. */
  143. static void
  144. grub_video_fbblit_replace_24bit_1bit (struct grub_video_fbblit_info *dst,
  145. struct grub_video_fbblit_info *src,
  146. int x, int y,
  147. int width, int height,
  148. int offset_x, int offset_y)
  149. {
  150. int i;
  151. int j;
  152. grub_uint8_t *srcptr;
  153. grub_uint8_t *dstptr;
  154. grub_uint8_t srcmask;
  155. unsigned int dstrowskip;
  156. unsigned int srcrowskipbyte, srcrowskipbit;
  157. grub_uint32_t fgcolor, bgcolor;
  158. int bit_index;
  159. /* Calculate the number of bytes to advance from the end of one line
  160. to the beginning of the next line. */
  161. dstrowskip = dst->mode_info->pitch - dst->mode_info->bytes_per_pixel * width;
  162. srcrowskipbyte = (src->mode_info->width - width) >> 3;
  163. srcrowskipbit = (src->mode_info->width - width) & 7;
  164. bit_index = offset_y * src->mode_info->width + offset_x;
  165. srcptr = (grub_uint8_t *) src->data + (bit_index >> 3);
  166. srcmask = 1 << (~bit_index & 7);
  167. dstptr = grub_video_fb_get_video_ptr (dst, x, y);
  168. fgcolor = grub_video_fb_map_rgba (src->mode_info->fg_red,
  169. src->mode_info->fg_green,
  170. src->mode_info->fg_blue,
  171. src->mode_info->fg_alpha);
  172. bgcolor = grub_video_fb_map_rgba (src->mode_info->bg_red,
  173. src->mode_info->bg_green,
  174. src->mode_info->bg_blue,
  175. src->mode_info->bg_alpha);
  176. for (j = 0; j < height; j++)
  177. {
  178. for (i = 0; i < width - 1; i++)
  179. {
  180. if (*srcptr & srcmask)
  181. *(grub_uint32_t *) dstptr = fgcolor;
  182. else
  183. *(grub_uint32_t *) dstptr = bgcolor;
  184. srcmask >>= 1;
  185. if (!srcmask)
  186. {
  187. srcptr++;
  188. srcmask = 0x80;
  189. }
  190. dstptr += 3;
  191. }
  192. if (*srcptr & srcmask)
  193. {
  194. *dstptr++ = fgcolor & 0xff;
  195. *dstptr++ = (fgcolor & 0xff00) >> 8;
  196. *dstptr++ = (fgcolor & 0xff0000) >> 16;
  197. }
  198. else
  199. {
  200. *dstptr++ = bgcolor & 0xff;
  201. *dstptr++ = (bgcolor & 0xff00) >> 8;
  202. *dstptr++ = (bgcolor & 0xff0000) >> 16;
  203. }
  204. srcmask >>= 1;
  205. if (!srcmask)
  206. {
  207. srcptr++;
  208. srcmask = 0x80;
  209. }
  210. srcptr += srcrowskipbyte;
  211. if (srcmask >> srcrowskipbit)
  212. srcmask >>= srcrowskipbit;
  213. else
  214. {
  215. srcptr++;
  216. srcmask <<= 8 - srcrowskipbit;
  217. }
  218. dstptr += dstrowskip;
  219. }
  220. }
  221. #endif
  222. /* Optimized replacing blitter for 1-bit to 16-bit. */
  223. static void
  224. grub_video_fbblit_replace_16bit_1bit (struct grub_video_fbblit_info *dst,
  225. struct grub_video_fbblit_info *src,
  226. int x, int y,
  227. int width, int height,
  228. int offset_x, int offset_y)
  229. {
  230. int i;
  231. int j;
  232. grub_uint8_t *srcptr;
  233. grub_uint16_t *dstptr;
  234. grub_uint8_t srcmask;
  235. unsigned int dstrowskip;
  236. unsigned int srcrowskipbyte, srcrowskipbit;
  237. grub_uint16_t fgcolor, bgcolor;
  238. int bit_index;
  239. /* Calculate the number of bytes to advance from the end of one line
  240. to the beginning of the next line. */
  241. dstrowskip = dst->mode_info->pitch - dst->mode_info->bytes_per_pixel * width;
  242. srcrowskipbyte = (src->mode_info->width - width) >> 3;
  243. srcrowskipbit = (src->mode_info->width - width) & 7;
  244. bit_index = offset_y * src->mode_info->width + offset_x;
  245. srcptr = (grub_uint8_t *) src->data + (bit_index >> 3);
  246. srcmask = 1 << (~bit_index & 7);
  247. dstptr = grub_video_fb_get_video_ptr (dst, x, y);
  248. fgcolor = grub_video_fb_map_rgba (src->mode_info->fg_red,
  249. src->mode_info->fg_green,
  250. src->mode_info->fg_blue,
  251. src->mode_info->fg_alpha);
  252. bgcolor = grub_video_fb_map_rgba (src->mode_info->bg_red,
  253. src->mode_info->bg_green,
  254. src->mode_info->bg_blue,
  255. src->mode_info->bg_alpha);
  256. for (j = 0; j < height; j++)
  257. {
  258. for (i = 0; i < width; i++)
  259. {
  260. if (*srcptr & srcmask)
  261. *dstptr = fgcolor;
  262. else
  263. *dstptr = bgcolor;
  264. srcmask >>= 1;
  265. if (!srcmask)
  266. {
  267. srcptr++;
  268. srcmask = 0x80;
  269. }
  270. dstptr++;
  271. }
  272. srcptr += srcrowskipbyte;
  273. if (srcmask >> srcrowskipbit)
  274. srcmask >>= srcrowskipbit;
  275. else
  276. {
  277. srcptr++;
  278. srcmask <<= 8 - srcrowskipbit;
  279. }
  280. GRUB_VIDEO_FB_ADVANCE_POINTER (dstptr, dstrowskip);
  281. }
  282. }
  283. /* Optimized replacing blitter for 1-bit to 8-bit. */
  284. static void
  285. grub_video_fbblit_replace_8bit_1bit (struct grub_video_fbblit_info *dst,
  286. struct grub_video_fbblit_info *src,
  287. int x, int y,
  288. int width, int height,
  289. int offset_x, int offset_y)
  290. {
  291. int i;
  292. int j;
  293. grub_uint8_t *srcptr;
  294. grub_uint8_t *dstptr;
  295. grub_uint8_t srcmask;
  296. unsigned int dstrowskip;
  297. unsigned int srcrowskipbyte, srcrowskipbit;
  298. grub_uint8_t fgcolor, bgcolor;
  299. int bit_index;
  300. /* Calculate the number of bytes to advance from the end of one line
  301. to the beginning of the next line. */
  302. dstrowskip = dst->mode_info->pitch - dst->mode_info->bytes_per_pixel * width;
  303. srcrowskipbyte = (src->mode_info->width - width) >> 3;
  304. srcrowskipbit = (src->mode_info->width - width) & 7;
  305. bit_index = offset_y * src->mode_info->width + offset_x;
  306. srcptr = (grub_uint8_t *) src->data + (bit_index >> 3);
  307. srcmask = 1 << (~bit_index & 7);
  308. dstptr = grub_video_fb_get_video_ptr (dst, x, y);
  309. fgcolor = grub_video_fb_map_rgba (src->mode_info->fg_red,
  310. src->mode_info->fg_green,
  311. src->mode_info->fg_blue,
  312. src->mode_info->fg_alpha);
  313. bgcolor = grub_video_fb_map_rgba (src->mode_info->bg_red,
  314. src->mode_info->bg_green,
  315. src->mode_info->bg_blue,
  316. src->mode_info->bg_alpha);
  317. for (j = 0; j < height; j++)
  318. {
  319. for (i = 0; i < width; i++)
  320. {
  321. if (*srcptr & srcmask)
  322. *dstptr = fgcolor;
  323. else
  324. *dstptr = bgcolor;
  325. srcmask >>= 1;
  326. if (!srcmask)
  327. {
  328. srcptr++;
  329. srcmask = 0x80;
  330. }
  331. dstptr++;
  332. }
  333. srcptr += srcrowskipbyte;
  334. if (srcmask >> srcrowskipbit)
  335. srcmask >>= srcrowskipbit;
  336. else
  337. {
  338. srcptr++;
  339. srcmask <<= 8 - srcrowskipbit;
  340. }
  341. dstptr += dstrowskip;
  342. }
  343. }
  344. static void
  345. grub_video_fbblit_replace_32bit_indexa (struct grub_video_fbblit_info *dst,
  346. struct grub_video_fbblit_info *src,
  347. int x, int y,
  348. int width, int height,
  349. int offset_x, int offset_y)
  350. {
  351. int i;
  352. int j;
  353. grub_uint8_t *srcptr;
  354. grub_uint32_t *dstptr;
  355. unsigned int dstrowskip;
  356. unsigned int srcrowskip;
  357. grub_uint32_t palette[17];
  358. srcptr = grub_video_fb_get_video_ptr (src, offset_x, offset_y);
  359. dstptr = grub_video_fb_get_video_ptr (dst, x, y);
  360. /* Calculate the number of bytes to advance from the end of one line
  361. to the beginning of the next line. */
  362. dstrowskip = dst->mode_info->pitch - dst->mode_info->bytes_per_pixel * width;
  363. srcrowskip = src->mode_info->pitch - width;
  364. for (i = 0; i < 16; i++)
  365. palette[i] = grub_video_fb_map_color (i);
  366. palette[16] = grub_video_fb_map_rgba (0, 0, 0, 0);
  367. for (j = 0; j < height; j++)
  368. {
  369. for (i = 0; i < width; i++)
  370. {
  371. if (*srcptr == 0xf0)
  372. *dstptr = palette[16];
  373. else
  374. *dstptr = palette[*srcptr & 0xf];
  375. srcptr++;
  376. dstptr++;
  377. }
  378. srcptr += srcrowskip;
  379. GRUB_VIDEO_FB_ADVANCE_POINTER (dstptr, dstrowskip);
  380. }
  381. }
  382. /* Optimized replacing blitter for 1-bit to 16bit. */
  383. static void
  384. grub_video_fbblit_replace_24bit_indexa (struct grub_video_fbblit_info *dst,
  385. struct grub_video_fbblit_info *src,
  386. int x, int y,
  387. int width, int height,
  388. int offset_x, int offset_y)
  389. {
  390. int i;
  391. int j;
  392. grub_uint8_t *srcptr;
  393. grub_uint8_t *dstptr;
  394. unsigned int dstrowskip;
  395. unsigned int srcrowskip;
  396. grub_uint32_t palette[17];
  397. srcptr = grub_video_fb_get_video_ptr (src, offset_x, offset_y);
  398. dstptr = grub_video_fb_get_video_ptr (dst, x, y);
  399. /* Calculate the number of bytes to advance from the end of one line
  400. to the beginning of the next line. */
  401. dstrowskip = dst->mode_info->pitch - dst->mode_info->bytes_per_pixel * width;
  402. srcrowskip = src->mode_info->pitch - width;
  403. for (i = 0; i < 16; i++)
  404. palette[i] = grub_video_fb_map_color (i);
  405. palette[16] = grub_video_fb_map_rgba (0, 0, 0, 0);
  406. for (j = 0; j < height; j++)
  407. {
  408. for (i = 0; i < width; i++)
  409. {
  410. register grub_uint32_t col;
  411. if (*srcptr == 0xf0)
  412. col = palette[16];
  413. else
  414. col = palette[*srcptr & 0xf];
  415. #ifdef GRUB_CPU_WORDS_BIGENDIAN
  416. *dstptr++ = col >> 16;
  417. *dstptr++ = col >> 8;
  418. *dstptr++ = col >> 0;
  419. #else
  420. *dstptr++ = col >> 0;
  421. *dstptr++ = col >> 8;
  422. *dstptr++ = col >> 16;
  423. #endif
  424. srcptr++;
  425. }
  426. srcptr += srcrowskip;
  427. dstptr += dstrowskip;
  428. }
  429. }
  430. /* Optimized replacing blitter for 1-bit to 16bit. */
  431. static void
  432. grub_video_fbblit_replace_16bit_indexa (struct grub_video_fbblit_info *dst,
  433. struct grub_video_fbblit_info *src,
  434. int x, int y,
  435. int width, int height,
  436. int offset_x, int offset_y)
  437. {
  438. int i;
  439. int j;
  440. grub_uint8_t *srcptr;
  441. grub_uint16_t *dstptr;
  442. unsigned int dstrowskip;
  443. unsigned int srcrowskip;
  444. grub_uint16_t palette[17];
  445. srcptr = grub_video_fb_get_video_ptr (src, offset_x, offset_y);
  446. dstptr = grub_video_fb_get_video_ptr (dst, x, y);
  447. /* Calculate the number of bytes to advance from the end of one line
  448. to the beginning of the next line. */
  449. dstrowskip = dst->mode_info->pitch - dst->mode_info->bytes_per_pixel * width;
  450. srcrowskip = src->mode_info->pitch - width;
  451. for (i = 0; i < 16; i++)
  452. palette[i] = grub_video_fb_map_color (i);
  453. palette[16] = grub_video_fb_map_rgba (0, 0, 0, 0);
  454. for (j = 0; j < height; j++)
  455. {
  456. for (i = 0; i < width; i++)
  457. {
  458. if (*srcptr == 0xf0)
  459. *dstptr = palette[16];
  460. else
  461. *dstptr = palette[*srcptr & 0xf];
  462. srcptr++;
  463. dstptr++;
  464. }
  465. srcptr += srcrowskip;
  466. GRUB_VIDEO_FB_ADVANCE_POINTER (dstptr, dstrowskip);
  467. }
  468. }
  469. /* Optimized replacing blitter for 1-bit to 8bit. */
  470. static void
  471. grub_video_fbblit_replace_8bit_indexa (struct grub_video_fbblit_info *dst,
  472. struct grub_video_fbblit_info *src,
  473. int x, int y,
  474. int width, int height,
  475. int offset_x, int offset_y)
  476. {
  477. int i;
  478. int j;
  479. grub_uint8_t *srcptr;
  480. grub_uint8_t *dstptr;
  481. unsigned int dstrowskip;
  482. unsigned int srcrowskip;
  483. grub_uint8_t palette[17];
  484. srcptr = grub_video_fb_get_video_ptr (src, offset_x, offset_y);
  485. dstptr = grub_video_fb_get_video_ptr (dst, x, y);
  486. /* Calculate the number of bytes to advance from the end of one line
  487. to the beginning of the next line. */
  488. dstrowskip = dst->mode_info->pitch - dst->mode_info->bytes_per_pixel * width;
  489. srcrowskip = src->mode_info->pitch - width;
  490. for (i = 0; i < 16; i++)
  491. palette[i] = grub_video_fb_map_color (i);
  492. palette[16] = grub_video_fb_map_rgba (0, 0, 0, 0);
  493. for (j = 0; j < height; j++)
  494. {
  495. for (i = 0; i < width; i++)
  496. {
  497. if (*srcptr == 0xf0)
  498. *dstptr = palette[16];
  499. else
  500. *dstptr = palette[*srcptr & 0xf];
  501. srcptr++;
  502. dstptr++;
  503. }
  504. srcptr += srcrowskip;
  505. dstptr += dstrowskip;
  506. }
  507. }
  508. static void
  509. grub_video_fbblit_blend_32bit_indexa (struct grub_video_fbblit_info *dst,
  510. struct grub_video_fbblit_info *src,
  511. int x, int y,
  512. int width, int height,
  513. int offset_x, int offset_y)
  514. {
  515. int i;
  516. int j;
  517. grub_uint8_t *srcptr;
  518. grub_uint32_t *dstptr;
  519. unsigned int dstrowskip;
  520. unsigned int srcrowskip;
  521. grub_uint32_t palette[16];
  522. srcptr = grub_video_fb_get_video_ptr (src, offset_x, offset_y);
  523. dstptr = grub_video_fb_get_video_ptr (dst, x, y);
  524. /* Calculate the number of bytes to advance from the end of one line
  525. to the beginning of the next line. */
  526. dstrowskip = dst->mode_info->pitch - dst->mode_info->bytes_per_pixel * width;
  527. srcrowskip = src->mode_info->pitch - width;
  528. for (i = 0; i < 16; i++)
  529. palette[i] = grub_video_fb_map_color (i);
  530. for (j = 0; j < height; j++)
  531. {
  532. for (i = 0; i < width; i++)
  533. {
  534. if (*srcptr != 0xf0)
  535. *dstptr = palette[*srcptr & 0xf];
  536. srcptr++;
  537. dstptr++;
  538. }
  539. srcptr += srcrowskip;
  540. GRUB_VIDEO_FB_ADVANCE_POINTER (dstptr, dstrowskip);
  541. }
  542. }
  543. /* Optimized replacing blitter for 1-bit to 16bit. */
  544. static void
  545. grub_video_fbblit_blend_24bit_indexa (struct grub_video_fbblit_info *dst,
  546. struct grub_video_fbblit_info *src,
  547. int x, int y,
  548. int width, int height,
  549. int offset_x, int offset_y)
  550. {
  551. int i;
  552. int j;
  553. grub_uint8_t *srcptr;
  554. grub_uint8_t *dstptr;
  555. unsigned int dstrowskip;
  556. unsigned int srcrowskip;
  557. grub_uint32_t palette[16];
  558. srcptr = grub_video_fb_get_video_ptr (src, offset_x, offset_y);
  559. dstptr = grub_video_fb_get_video_ptr (dst, x, y);
  560. /* Calculate the number of bytes to advance from the end of one line
  561. to the beginning of the next line. */
  562. dstrowskip = dst->mode_info->pitch - dst->mode_info->bytes_per_pixel * width;
  563. srcrowskip = src->mode_info->pitch - width;
  564. for (i = 0; i < 16; i++)
  565. palette[i] = grub_video_fb_map_color (i);
  566. for (j = 0; j < height; j++)
  567. {
  568. for (i = 0; i < width; i++)
  569. {
  570. register grub_uint32_t col;
  571. if (*srcptr != 0xf0)
  572. {
  573. col = palette[*srcptr & 0xf];
  574. #ifdef GRUB_CPU_WORDS_BIGENDIAN
  575. *dstptr++ = col >> 16;
  576. *dstptr++ = col >> 8;
  577. *dstptr++ = col >> 0;
  578. #else
  579. *dstptr++ = col >> 0;
  580. *dstptr++ = col >> 8;
  581. *dstptr++ = col >> 16;
  582. #endif
  583. }
  584. else
  585. dstptr += 3;
  586. srcptr++;
  587. }
  588. srcptr += srcrowskip;
  589. dstptr += dstrowskip;
  590. }
  591. }
  592. /* Optimized replacing blitter for 1-bit to 16bit. */
  593. static void
  594. grub_video_fbblit_blend_16bit_indexa (struct grub_video_fbblit_info *dst,
  595. struct grub_video_fbblit_info *src,
  596. int x, int y,
  597. int width, int height,
  598. int offset_x, int offset_y)
  599. {
  600. int i;
  601. int j;
  602. grub_uint8_t *srcptr;
  603. grub_uint16_t *dstptr;
  604. unsigned int dstrowskip;
  605. unsigned int srcrowskip;
  606. grub_uint16_t palette[17];
  607. srcptr = grub_video_fb_get_video_ptr (src, offset_x, offset_y);
  608. dstptr = grub_video_fb_get_video_ptr (dst, x, y);
  609. /* Calculate the number of bytes to advance from the end of one line
  610. to the beginning of the next line. */
  611. dstrowskip = dst->mode_info->pitch - dst->mode_info->bytes_per_pixel * width;
  612. srcrowskip = src->mode_info->pitch - width;
  613. for (i = 0; i < 16; i++)
  614. palette[i] = grub_video_fb_map_color (i);
  615. for (j = 0; j < height; j++)
  616. {
  617. for (i = 0; i < width; i++)
  618. {
  619. if (*srcptr != 0xf0)
  620. *dstptr = palette[*srcptr & 0xf];
  621. srcptr++;
  622. dstptr++;
  623. }
  624. srcptr += srcrowskip;
  625. GRUB_VIDEO_FB_ADVANCE_POINTER (dstptr, dstrowskip);
  626. }
  627. }
  628. /* Optimized replacing blitter for 1-bit to 8bit. */
  629. static void
  630. grub_video_fbblit_blend_8bit_indexa (struct grub_video_fbblit_info *dst,
  631. struct grub_video_fbblit_info *src,
  632. int x, int y,
  633. int width, int height,
  634. int offset_x, int offset_y)
  635. {
  636. int i;
  637. int j;
  638. grub_uint8_t *srcptr;
  639. grub_uint8_t *dstptr;
  640. unsigned int dstrowskip;
  641. unsigned int srcrowskip;
  642. grub_uint8_t palette[16];
  643. srcptr = grub_video_fb_get_video_ptr (src, offset_x, offset_y);
  644. dstptr = grub_video_fb_get_video_ptr (dst, x, y);
  645. /* Calculate the number of bytes to advance from the end of one line
  646. to the beginning of the next line. */
  647. dstrowskip = dst->mode_info->pitch - dst->mode_info->bytes_per_pixel * width;
  648. srcrowskip = src->mode_info->pitch - width;
  649. for (i = 0; i < 16; i++)
  650. palette[i] = grub_video_fb_map_color (i);
  651. for (j = 0; j < height; j++)
  652. {
  653. for (i = 0; i < width; i++)
  654. {
  655. if (*srcptr != 0xf0)
  656. *dstptr = palette[*srcptr & 0xf];
  657. srcptr++;
  658. dstptr++;
  659. }
  660. srcptr += srcrowskip;
  661. dstptr += dstrowskip;
  662. }
  663. }
  664. /* Optimized replacing blitter for RGBX8888 to BGRX8888. */
  665. static void
  666. grub_video_fbblit_replace_BGRX8888_RGBX8888 (struct grub_video_fbblit_info *dst,
  667. struct grub_video_fbblit_info *src,
  668. int x, int y,
  669. int width, int height,
  670. int offset_x, int offset_y)
  671. {
  672. int i;
  673. int j;
  674. grub_uint8_t *srcptr;
  675. grub_uint8_t *dstptr;
  676. unsigned int srcrowskip;
  677. unsigned int dstrowskip;
  678. /* Calculate the number of bytes to advance from the end of one line
  679. to the beginning of the next line. */
  680. srcrowskip = src->mode_info->pitch - src->mode_info->bytes_per_pixel * width;
  681. dstrowskip = dst->mode_info->pitch - dst->mode_info->bytes_per_pixel * width;
  682. srcptr = grub_video_fb_get_video_ptr (src, offset_x, offset_y);
  683. dstptr = grub_video_fb_get_video_ptr (dst, x, y);
  684. for (j = 0; j < height; j++)
  685. {
  686. for (i = 0; i < width; i++)
  687. {
  688. #ifdef GRUB_CPU_WORDS_BIGENDIAN
  689. grub_uint8_t a = *srcptr++;
  690. #endif
  691. grub_uint8_t r = *srcptr++;
  692. grub_uint8_t g = *srcptr++;
  693. grub_uint8_t b = *srcptr++;
  694. #ifndef GRUB_CPU_WORDS_BIGENDIAN
  695. grub_uint8_t a = *srcptr++;
  696. #endif
  697. #ifdef GRUB_CPU_WORDS_BIGENDIAN
  698. *dstptr++ = a;
  699. #endif
  700. *dstptr++ = b;
  701. *dstptr++ = g;
  702. *dstptr++ = r;
  703. #ifndef GRUB_CPU_WORDS_BIGENDIAN
  704. *dstptr++ = a;
  705. #endif
  706. }
  707. srcptr += srcrowskip;
  708. dstptr += dstrowskip;
  709. }
  710. }
  711. /* Optimized replacing blitter for RGB888 to BGRX8888. */
  712. static void
  713. grub_video_fbblit_replace_BGRX8888_RGB888 (struct grub_video_fbblit_info *dst,
  714. struct grub_video_fbblit_info *src,
  715. int x, int y,
  716. int width, int height,
  717. int offset_x, int offset_y)
  718. {
  719. int i;
  720. int j;
  721. grub_uint8_t *srcptr;
  722. grub_uint8_t *dstptr;
  723. unsigned int srcrowskip;
  724. unsigned int dstrowskip;
  725. /* Calculate the number of bytes to advance from the end of one line
  726. to the beginning of the next line. */
  727. srcrowskip = src->mode_info->pitch - src->mode_info->bytes_per_pixel * width;
  728. dstrowskip = dst->mode_info->pitch - dst->mode_info->bytes_per_pixel * width;
  729. srcptr = grub_video_fb_get_video_ptr (src, offset_x, offset_y);
  730. dstptr = grub_video_fb_get_video_ptr (dst, x, y);
  731. for (j = 0; j < height; j++)
  732. {
  733. for (i = 0; i < width; i++)
  734. {
  735. grub_uint8_t r = *srcptr++;
  736. grub_uint8_t g = *srcptr++;
  737. grub_uint8_t b = *srcptr++;
  738. #ifdef GRUB_CPU_WORDS_BIGENDIAN
  739. /* Set alpha component as opaque. */
  740. *dstptr++ = 255;
  741. #endif
  742. *dstptr++ = b;
  743. *dstptr++ = g;
  744. *dstptr++ = r;
  745. #ifndef GRUB_CPU_WORDS_BIGENDIAN
  746. /* Set alpha component as opaque. */
  747. *dstptr++ = 255;
  748. #endif
  749. }
  750. srcptr += srcrowskip;
  751. dstptr += dstrowskip;
  752. }
  753. }
  754. /* Optimized replacing blitter for RGBX8888 to BGR888. */
  755. static void
  756. grub_video_fbblit_replace_BGR888_RGBX8888 (struct grub_video_fbblit_info *dst,
  757. struct grub_video_fbblit_info *src,
  758. int x, int y,
  759. int width, int height,
  760. int offset_x, int offset_y)
  761. {
  762. grub_uint32_t *srcptr;
  763. grub_uint8_t *dstptr;
  764. unsigned int srcrowskip;
  765. unsigned int dstrowskip;
  766. int i;
  767. int j;
  768. /* Calculate the number of bytes to advance from the end of one line
  769. to the beginning of the next line. */
  770. srcrowskip = src->mode_info->pitch - src->mode_info->bytes_per_pixel * width;
  771. dstrowskip = dst->mode_info->pitch - dst->mode_info->bytes_per_pixel * width;
  772. srcptr = grub_video_fb_get_video_ptr (src, offset_x, offset_y);
  773. dstptr = grub_video_fb_get_video_ptr (dst, x, y);
  774. for (j = 0; j < height; j++)
  775. {
  776. for (i = 0; i < width; i++)
  777. {
  778. grub_uint32_t color;
  779. grub_uint8_t sr;
  780. grub_uint8_t sg;
  781. grub_uint8_t sb;
  782. color = *srcptr++;
  783. sr = (color >> 0) & 0xFF;
  784. sg = (color >> 8) & 0xFF;
  785. sb = (color >> 16) & 0xFF;
  786. #ifdef GRUB_CPU_WORDS_BIGENDIAN
  787. *dstptr++ = sr;
  788. *dstptr++ = sg;
  789. *dstptr++ = sb;
  790. #else
  791. *dstptr++ = sb;
  792. *dstptr++ = sg;
  793. *dstptr++ = sr;
  794. #endif
  795. }
  796. GRUB_VIDEO_FB_ADVANCE_POINTER (srcptr, srcrowskip);
  797. dstptr += dstrowskip;
  798. }
  799. }
  800. /* Optimized replacing blitter for RGB888 to BGR888. */
  801. static void
  802. grub_video_fbblit_replace_BGR888_RGB888 (struct grub_video_fbblit_info *dst,
  803. struct grub_video_fbblit_info *src,
  804. int x, int y,
  805. int width, int height,
  806. int offset_x, int offset_y)
  807. {
  808. int i;
  809. int j;
  810. grub_uint8_t *srcptr;
  811. grub_uint8_t *dstptr;
  812. unsigned int srcrowskip;
  813. unsigned int dstrowskip;
  814. /* Calculate the number of bytes to advance from the end of one line
  815. to the beginning of the next line. */
  816. srcrowskip = src->mode_info->pitch - src->mode_info->bytes_per_pixel * width;
  817. dstrowskip = dst->mode_info->pitch - dst->mode_info->bytes_per_pixel * width;
  818. srcptr = grub_video_fb_get_video_ptr (src, offset_x, offset_y);
  819. dstptr = grub_video_fb_get_video_ptr (dst, x, y);
  820. for (j = 0; j < height; j++)
  821. {
  822. for (i = 0; i < width; i++)
  823. {
  824. grub_uint8_t r = *srcptr++;
  825. grub_uint8_t g = *srcptr++;
  826. grub_uint8_t b = *srcptr++;
  827. *dstptr++ = b;
  828. *dstptr++ = g;
  829. *dstptr++ = r;
  830. }
  831. srcptr += srcrowskip;
  832. dstptr += dstrowskip;
  833. }
  834. }
  835. /* Optimized replacing blitter for RGB888 to RGBX8888. */
  836. static void
  837. grub_video_fbblit_replace_RGBX8888_RGB888 (struct grub_video_fbblit_info *dst,
  838. struct grub_video_fbblit_info *src,
  839. int x, int y,
  840. int width, int height,
  841. int offset_x, int offset_y)
  842. {
  843. grub_uint32_t color;
  844. int i;
  845. int j;
  846. grub_uint8_t *srcptr;
  847. grub_uint32_t *dstptr;
  848. unsigned int sr;
  849. unsigned int sg;
  850. unsigned int sb;
  851. grub_size_t srcrowskip;
  852. grub_size_t dstrowskip;
  853. srcrowskip = src->mode_info->pitch - 3 * width;
  854. dstrowskip = dst->mode_info->pitch - 4 * width;
  855. srcptr = grub_video_fb_get_video_ptr (src, offset_x, offset_y);
  856. dstptr = grub_video_fb_get_video_ptr (dst, x, y);
  857. for (j = 0; j < height; j++)
  858. {
  859. for (i = 0; i < width; i++)
  860. {
  861. #ifdef GRUB_CPU_WORDS_BIGENDIAN
  862. sb = *srcptr++;
  863. sg = *srcptr++;
  864. sr = *srcptr++;
  865. #else
  866. sr = *srcptr++;
  867. sg = *srcptr++;
  868. sb = *srcptr++;
  869. #endif
  870. /* Set alpha as opaque. */
  871. color = 0xFF000000 | (sb << 16) | (sg << 8) | sr;
  872. *dstptr++ = color;
  873. }
  874. GRUB_VIDEO_FB_ADVANCE_POINTER (srcptr, srcrowskip);
  875. GRUB_VIDEO_FB_ADVANCE_POINTER (dstptr, dstrowskip);
  876. }
  877. }
  878. /* Optimized replacing blitter for RGBX8888 to RGB888. */
  879. static void
  880. grub_video_fbblit_replace_RGB888_RGBX8888 (struct grub_video_fbblit_info *dst,
  881. struct grub_video_fbblit_info *src,
  882. int x, int y,
  883. int width, int height,
  884. int offset_x, int offset_y)
  885. {
  886. grub_uint32_t color;
  887. int i;
  888. int j;
  889. grub_uint32_t *srcptr;
  890. grub_uint8_t *dstptr;
  891. unsigned int sr;
  892. unsigned int sg;
  893. unsigned int sb;
  894. grub_size_t srcrowskip;
  895. grub_size_t dstrowskip;
  896. srcptr = grub_video_fb_get_video_ptr (src, offset_x, offset_y);
  897. dstptr = grub_video_fb_get_video_ptr (dst, x, y);
  898. srcrowskip = src->mode_info->pitch - 4 * width;
  899. dstrowskip = dst->mode_info->pitch - 3 * width;
  900. for (j = 0; j < height; j++)
  901. {
  902. for (i = 0; i < width; i++)
  903. {
  904. color = *srcptr++;
  905. sr = (color >> 0) & 0xFF;
  906. sg = (color >> 8) & 0xFF;
  907. sb = (color >> 16) & 0xFF;
  908. #ifndef GRUB_CPU_WORDS_BIGENDIAN
  909. *dstptr++ = sr;
  910. *dstptr++ = sg;
  911. *dstptr++ = sb;
  912. #else
  913. *dstptr++ = sb;
  914. *dstptr++ = sg;
  915. *dstptr++ = sr;
  916. #endif
  917. }
  918. GRUB_VIDEO_FB_ADVANCE_POINTER (srcptr, srcrowskip);
  919. GRUB_VIDEO_FB_ADVANCE_POINTER (dstptr, dstrowskip);
  920. }
  921. }
  922. /* Optimized replacing blitter for RGBX8888 to indexed color. */
  923. static void
  924. grub_video_fbblit_replace_index_RGBX8888 (struct grub_video_fbblit_info *dst,
  925. struct grub_video_fbblit_info *src,
  926. int x, int y,
  927. int width, int height,
  928. int offset_x, int offset_y)
  929. {
  930. grub_uint32_t color;
  931. int i;
  932. int j;
  933. grub_uint32_t *srcptr;
  934. grub_uint8_t *dstptr;
  935. unsigned int sr;
  936. unsigned int sg;
  937. unsigned int sb;
  938. grub_size_t srcrowskip;
  939. grub_size_t dstrowskip;
  940. srcrowskip = src->mode_info->pitch - 4 * width;
  941. dstrowskip = dst->mode_info->pitch - width;
  942. srcptr = grub_video_fb_get_video_ptr (src, offset_x, offset_y);
  943. dstptr = grub_video_fb_get_video_ptr (dst, x, y);
  944. for (j = 0; j < height; j++)
  945. {
  946. for (i = 0; i < width; i++)
  947. {
  948. color = *srcptr++;
  949. sr = (color >> 0) & 0xFF;
  950. sg = (color >> 8) & 0xFF;
  951. sb = (color >> 16) & 0xFF;
  952. color = grub_video_fb_map_rgb(sr, sg, sb);
  953. *dstptr++ = color & 0xFF;
  954. }
  955. GRUB_VIDEO_FB_ADVANCE_POINTER (srcptr, srcrowskip);
  956. GRUB_VIDEO_FB_ADVANCE_POINTER (dstptr, dstrowskip);
  957. }
  958. }
  959. /* Optimized replacing blitter for RGB888 to indexed color. */
  960. static void
  961. grub_video_fbblit_replace_index_RGB888 (struct grub_video_fbblit_info *dst,
  962. struct grub_video_fbblit_info *src,
  963. int x, int y,
  964. int width, int height,
  965. int offset_x, int offset_y)
  966. {
  967. grub_uint32_t color;
  968. int i;
  969. int j;
  970. grub_uint8_t *srcptr;
  971. grub_uint8_t *dstptr;
  972. unsigned int sr;
  973. unsigned int sg;
  974. unsigned int sb;
  975. grub_size_t srcrowskip;
  976. grub_size_t dstrowskip;
  977. srcrowskip = src->mode_info->pitch - 3 * width;
  978. dstrowskip = dst->mode_info->pitch - width;
  979. srcptr = grub_video_fb_get_video_ptr (src, offset_x, offset_y);
  980. dstptr = grub_video_fb_get_video_ptr (dst, x, y);
  981. for (j = 0; j < height; j++)
  982. {
  983. for (i = 0; i < width; i++)
  984. {
  985. #ifndef GRUB_CPU_WORDS_BIGENDIAN
  986. sr = *srcptr++;
  987. sg = *srcptr++;
  988. sb = *srcptr++;
  989. #else
  990. sb = *srcptr++;
  991. sg = *srcptr++;
  992. sr = *srcptr++;
  993. #endif
  994. color = grub_video_fb_map_rgb(sr, sg, sb);
  995. *dstptr++ = color & 0xFF;
  996. }
  997. GRUB_VIDEO_FB_ADVANCE_POINTER (srcptr, srcrowskip);
  998. GRUB_VIDEO_FB_ADVANCE_POINTER (dstptr, dstrowskip);
  999. }
  1000. }
  1001. static inline grub_uint8_t
  1002. alpha_dilute (grub_uint8_t bg, grub_uint8_t fg, grub_uint8_t alpha)
  1003. {
  1004. grub_uint16_t s;
  1005. grub_uint16_t h, l;
  1006. s = (fg * alpha) + (bg * (255 ^ alpha));
  1007. /* Optimised division by 255. */
  1008. h = s >> 8;
  1009. l = s & 0xff;
  1010. if (h + l >= 255)
  1011. h++;
  1012. return h;
  1013. }
  1014. /* Generic blending blitter. Works for every supported format. */
  1015. static void
  1016. grub_video_fbblit_blend (struct grub_video_fbblit_info *dst,
  1017. struct grub_video_fbblit_info *src,
  1018. int x, int y, int width, int height,
  1019. int offset_x, int offset_y)
  1020. {
  1021. int i;
  1022. int j;
  1023. for (j = 0; j < height; j++)
  1024. {
  1025. for (i = 0; i < width; i++)
  1026. {
  1027. grub_uint8_t src_red;
  1028. grub_uint8_t src_green;
  1029. grub_uint8_t src_blue;
  1030. grub_uint8_t src_alpha;
  1031. grub_uint8_t dst_red;
  1032. grub_uint8_t dst_green;
  1033. grub_uint8_t dst_blue;
  1034. grub_uint8_t dst_alpha;
  1035. grub_video_color_t src_color;
  1036. grub_video_color_t dst_color;
  1037. src_color = get_pixel (src, i + offset_x, j + offset_y);
  1038. grub_video_fb_unmap_color_int (src, src_color, &src_red, &src_green,
  1039. &src_blue, &src_alpha);
  1040. if (src_alpha == 0)
  1041. continue;
  1042. if (src_alpha == 255)
  1043. {
  1044. dst_color = grub_video_fb_map_rgba (src_red, src_green,
  1045. src_blue, src_alpha);
  1046. set_pixel (dst, x + i, y + j, dst_color);
  1047. continue;
  1048. }
  1049. dst_color = get_pixel (dst, x + i, y + j);
  1050. grub_video_fb_unmap_color_int (dst, dst_color, &dst_red,
  1051. &dst_green, &dst_blue, &dst_alpha);
  1052. dst_red = alpha_dilute (dst_red, src_red, src_alpha);
  1053. dst_green = alpha_dilute (dst_green, src_green, src_alpha);
  1054. dst_blue = alpha_dilute (dst_blue, src_blue, src_alpha);
  1055. dst_alpha = src_alpha;
  1056. dst_color = grub_video_fb_map_rgba (dst_red, dst_green, dst_blue,
  1057. dst_alpha);
  1058. set_pixel (dst, x + i, y + j, dst_color);
  1059. }
  1060. }
  1061. }
  1062. /* Optimized blending blitter for RGBA8888 to BGRA8888. */
  1063. static void
  1064. grub_video_fbblit_blend_BGRA8888_RGBA8888 (struct grub_video_fbblit_info *dst,
  1065. struct grub_video_fbblit_info *src,
  1066. int x, int y,
  1067. int width, int height,
  1068. int offset_x, int offset_y)
  1069. {
  1070. grub_uint32_t *srcptr;
  1071. grub_uint32_t *dstptr;
  1072. unsigned int srcrowskip;
  1073. unsigned int dstrowskip;
  1074. int i;
  1075. int j;
  1076. /* Calculate the number of bytes to advance from the end of one line
  1077. to the beginning of the next line. */
  1078. srcrowskip = src->mode_info->pitch - src->mode_info->bytes_per_pixel * width;
  1079. dstrowskip = dst->mode_info->pitch - dst->mode_info->bytes_per_pixel * width;
  1080. srcptr = grub_video_fb_get_video_ptr (src, offset_x, offset_y);
  1081. dstptr = grub_video_fb_get_video_ptr (dst, x, y);
  1082. for (j = 0; j < height; j++)
  1083. {
  1084. for (i = 0; i < width; i++)
  1085. {
  1086. grub_uint32_t color;
  1087. unsigned int sr;
  1088. unsigned int sg;
  1089. unsigned int sb;
  1090. unsigned int a;
  1091. unsigned int dr;
  1092. unsigned int dg;
  1093. unsigned int db;
  1094. color = *srcptr++;
  1095. a = color >> 24;
  1096. if (a == 0)
  1097. {
  1098. /* Skip transparent source pixels. */
  1099. dstptr++;
  1100. continue;
  1101. }
  1102. sr = (color >> 0) & 0xFF;
  1103. sg = (color >> 8) & 0xFF;
  1104. sb = (color >> 16) & 0xFF;
  1105. if (a == 255)
  1106. {
  1107. /* Opaque pixel shortcut. */
  1108. dr = sr;
  1109. dg = sg;
  1110. db = sb;
  1111. }
  1112. else
  1113. {
  1114. /* General pixel color blending. */
  1115. color = *dstptr;
  1116. dr = (color >> 16) & 0xFF;
  1117. dr = alpha_dilute (dr, sr, a);
  1118. dg = (color >> 8) & 0xFF;
  1119. dg = alpha_dilute (dg, sg, a);
  1120. db = (color >> 0) & 0xFF;
  1121. db = alpha_dilute (db, sb, a);
  1122. }
  1123. color = (a << 24) | (dr << 16) | (dg << 8) | db;
  1124. *dstptr++ = color;
  1125. }
  1126. GRUB_VIDEO_FB_ADVANCE_POINTER (srcptr, srcrowskip);
  1127. GRUB_VIDEO_FB_ADVANCE_POINTER (dstptr, dstrowskip);
  1128. }
  1129. }
  1130. /* Optimized blending blitter for RGBA8888 to BGR888. */
  1131. static void
  1132. grub_video_fbblit_blend_BGR888_RGBA8888 (struct grub_video_fbblit_info *dst,
  1133. struct grub_video_fbblit_info *src,
  1134. int x, int y,
  1135. int width, int height,
  1136. int offset_x, int offset_y)
  1137. {
  1138. grub_uint32_t *srcptr;
  1139. grub_uint8_t *dstptr;
  1140. unsigned int srcrowskip;
  1141. unsigned int dstrowskip;
  1142. int i;
  1143. int j;
  1144. /* Calculate the number of bytes to advance from the end of one line
  1145. to the beginning of the next line. */
  1146. srcrowskip = src->mode_info->pitch - src->mode_info->bytes_per_pixel * width;
  1147. dstrowskip = dst->mode_info->pitch - dst->mode_info->bytes_per_pixel * width;
  1148. srcptr = grub_video_fb_get_video_ptr (src, offset_x, offset_y);
  1149. dstptr = grub_video_fb_get_video_ptr (dst, x, y);
  1150. for (j = 0; j < height; j++)
  1151. {
  1152. for (i = 0; i < width; i++)
  1153. {
  1154. grub_uint32_t color;
  1155. unsigned int sr;
  1156. unsigned int sg;
  1157. unsigned int sb;
  1158. unsigned int a;
  1159. unsigned int dr;
  1160. unsigned int dg;
  1161. unsigned int db;
  1162. color = *srcptr++;
  1163. a = color >> 24;
  1164. if (a == 0)
  1165. {
  1166. /* Skip transparent source pixels. */
  1167. dstptr += 3;
  1168. continue;
  1169. }
  1170. sr = (color >> 0) & 0xFF;
  1171. sg = (color >> 8) & 0xFF;
  1172. sb = (color >> 16) & 0xFF;
  1173. if (a == 255)
  1174. {
  1175. /* Opaque pixel shortcut. */
  1176. dr = sr;
  1177. dg = sg;
  1178. db = sb;
  1179. }
  1180. else
  1181. {
  1182. /* General pixel color blending. */
  1183. color = *dstptr;
  1184. #ifndef GRUB_CPU_WORDS_BIGENDIAN
  1185. db = dstptr[0];
  1186. dg = dstptr[1];
  1187. dr = dstptr[2];
  1188. #else
  1189. dr = dstptr[0];
  1190. dg = dstptr[1];
  1191. db = dstptr[2];
  1192. #endif
  1193. db = alpha_dilute (db, sb, a);
  1194. dg = alpha_dilute (dg, sg, a);
  1195. dr = alpha_dilute (dr, sr, a);
  1196. }
  1197. #ifndef GRUB_CPU_WORDS_BIGENDIAN
  1198. *dstptr++ = db;
  1199. *dstptr++ = dg;
  1200. *dstptr++ = dr;
  1201. #else
  1202. *dstptr++ = dr;
  1203. *dstptr++ = dg;
  1204. *dstptr++ = db;
  1205. #endif
  1206. }
  1207. GRUB_VIDEO_FB_ADVANCE_POINTER (srcptr, srcrowskip);
  1208. dstptr += dstrowskip;
  1209. }
  1210. }
  1211. /* Optimized blending blitter for RGBA888 to RGBA8888. */
  1212. static void
  1213. grub_video_fbblit_blend_RGBA8888_RGBA8888 (struct grub_video_fbblit_info *dst,
  1214. struct grub_video_fbblit_info *src,
  1215. int x, int y,
  1216. int width, int height,
  1217. int offset_x, int offset_y)
  1218. {
  1219. grub_uint32_t color;
  1220. int i;
  1221. int j;
  1222. grub_uint32_t *srcptr;
  1223. grub_uint32_t *dstptr;
  1224. unsigned int sr;
  1225. unsigned int sg;
  1226. unsigned int sb;
  1227. unsigned int a;
  1228. unsigned int dr;
  1229. unsigned int dg;
  1230. unsigned int db;
  1231. grub_size_t srcrowskip;
  1232. grub_size_t dstrowskip;
  1233. srcrowskip = src->mode_info->pitch - 4 * width;
  1234. dstrowskip = dst->mode_info->pitch - 4 * width;
  1235. srcptr = grub_video_fb_get_video_ptr (src, offset_x, offset_y);
  1236. dstptr = grub_video_fb_get_video_ptr (dst, x, y);
  1237. for (j = 0; j < height; j++)
  1238. {
  1239. for (i = 0; i < width; i++)
  1240. {
  1241. color = *srcptr++;
  1242. a = color >> 24;
  1243. if (a == 0)
  1244. {
  1245. dstptr++;
  1246. continue;
  1247. }
  1248. if (a == 255)
  1249. {
  1250. *dstptr++ = color;
  1251. continue;
  1252. }
  1253. sr = (color >> 0) & 0xFF;
  1254. sg = (color >> 8) & 0xFF;
  1255. sb = (color >> 16) & 0xFF;
  1256. color = *dstptr;
  1257. dr = (color >> 0) & 0xFF;
  1258. dg = (color >> 8) & 0xFF;
  1259. db = (color >> 16) & 0xFF;
  1260. dr = alpha_dilute (dr, sr, a);
  1261. dg = alpha_dilute (dg, sg, a);
  1262. db = alpha_dilute (db, sb, a);
  1263. color = (a << 24) | (db << 16) | (dg << 8) | dr;
  1264. *dstptr++ = color;
  1265. }
  1266. GRUB_VIDEO_FB_ADVANCE_POINTER (srcptr, srcrowskip);
  1267. GRUB_VIDEO_FB_ADVANCE_POINTER (dstptr, dstrowskip);
  1268. }
  1269. }
  1270. /* Optimized blending blitter for RGBA8888 to RGB888. */
  1271. static void
  1272. grub_video_fbblit_blend_RGB888_RGBA8888 (struct grub_video_fbblit_info *dst,
  1273. struct grub_video_fbblit_info *src,
  1274. int x, int y,
  1275. int width, int height,
  1276. int offset_x, int offset_y)
  1277. {
  1278. grub_uint32_t color;
  1279. int i;
  1280. int j;
  1281. grub_uint32_t *srcptr;
  1282. grub_uint8_t *dstptr;
  1283. unsigned int sr;
  1284. unsigned int sg;
  1285. unsigned int sb;
  1286. unsigned int a;
  1287. unsigned int dr;
  1288. unsigned int dg;
  1289. unsigned int db;
  1290. grub_size_t srcrowskip;
  1291. grub_size_t dstrowskip;
  1292. srcrowskip = src->mode_info->pitch - 4 * width;
  1293. dstrowskip = dst->mode_info->pitch - 3 * width;
  1294. srcptr = grub_video_fb_get_video_ptr (src, offset_x, offset_y);
  1295. dstptr = grub_video_fb_get_video_ptr (dst, x, y);
  1296. for (j = 0; j < height; j++)
  1297. {
  1298. for (i = 0; i < width; i++)
  1299. {
  1300. color = *srcptr++;
  1301. a = color >> 24;
  1302. if (a == 0)
  1303. {
  1304. dstptr += 3;
  1305. continue;
  1306. }
  1307. sr = (color >> 0) & 0xFF;
  1308. sg = (color >> 8) & 0xFF;
  1309. sb = (color >> 16) & 0xFF;
  1310. if (a == 255)
  1311. {
  1312. #ifndef GRUB_CPU_WORDS_BIGENDIAN
  1313. *dstptr++ = sr;
  1314. *dstptr++ = sg;
  1315. *dstptr++ = sb;
  1316. #else
  1317. *dstptr++ = sb;
  1318. *dstptr++ = sg;
  1319. *dstptr++ = sr;
  1320. #endif
  1321. continue;
  1322. }
  1323. #ifndef GRUB_CPU_WORDS_BIGENDIAN
  1324. dr = dstptr[0];
  1325. dg = dstptr[1];
  1326. db = dstptr[2];
  1327. #else
  1328. db = dstptr[0];
  1329. dg = dstptr[1];
  1330. dr = dstptr[2];
  1331. #endif
  1332. dr = alpha_dilute (dr, sr, a);
  1333. dg = alpha_dilute (dg, sg, a);
  1334. db = alpha_dilute (db, sb, a);
  1335. #ifndef GRUB_CPU_WORDS_BIGENDIAN
  1336. *dstptr++ = dr;
  1337. *dstptr++ = dg;
  1338. *dstptr++ = db;
  1339. #else
  1340. *dstptr++ = db;
  1341. *dstptr++ = dg;
  1342. *dstptr++ = dr;
  1343. #endif
  1344. }
  1345. GRUB_VIDEO_FB_ADVANCE_POINTER (srcptr, srcrowskip);
  1346. GRUB_VIDEO_FB_ADVANCE_POINTER (dstptr, dstrowskip);
  1347. }
  1348. }
  1349. /* Optimized blending blitter for RGBA8888 to indexed color. */
  1350. static void
  1351. grub_video_fbblit_blend_index_RGBA8888 (struct grub_video_fbblit_info *dst,
  1352. struct grub_video_fbblit_info *src,
  1353. int x, int y,
  1354. int width, int height,
  1355. int offset_x, int offset_y)
  1356. {
  1357. grub_uint32_t color;
  1358. int i;
  1359. int j;
  1360. grub_uint32_t *srcptr;
  1361. grub_uint8_t *dstptr;
  1362. unsigned int sr;
  1363. unsigned int sg;
  1364. unsigned int sb;
  1365. unsigned int a;
  1366. unsigned char dr;
  1367. unsigned char dg;
  1368. unsigned char db;
  1369. unsigned char da;
  1370. grub_size_t srcrowskip;
  1371. grub_size_t dstrowskip;
  1372. srcrowskip = src->mode_info->pitch - 4 * width;
  1373. dstrowskip = dst->mode_info->pitch - width;
  1374. srcptr = grub_video_fb_get_video_ptr (src, offset_x, offset_y);
  1375. dstptr = grub_video_fb_get_video_ptr (dst, x, y);
  1376. for (j = 0; j < height; j++)
  1377. {
  1378. for (i = 0; i < width; i++)
  1379. {
  1380. color = *srcptr++;
  1381. a = color >> 24;
  1382. if (a == 0)
  1383. {
  1384. dstptr++;
  1385. continue;
  1386. }
  1387. sr = (color >> 0) & 0xFF;
  1388. sg = (color >> 8) & 0xFF;
  1389. sb = (color >> 16) & 0xFF;
  1390. if (a == 255)
  1391. {
  1392. color = grub_video_fb_map_rgb(sr, sg, sb);
  1393. *dstptr++ = color & 0xFF;
  1394. continue;
  1395. }
  1396. grub_video_fb_unmap_color_int (dst, *dstptr, &dr, &dg, &db, &da);
  1397. dr = alpha_dilute (dr, sr, a);
  1398. dg = alpha_dilute (dg, sg, a);
  1399. db = alpha_dilute (db, sb, a);
  1400. color = grub_video_fb_map_rgb(dr, dg, db);
  1401. *dstptr++ = color & 0xFF;
  1402. }
  1403. GRUB_VIDEO_FB_ADVANCE_POINTER (srcptr, srcrowskip);
  1404. GRUB_VIDEO_FB_ADVANCE_POINTER (dstptr, dstrowskip);
  1405. }
  1406. }
  1407. /* Optimized blending blitter for 1-bit to XXXA8888. */
  1408. static void
  1409. grub_video_fbblit_blend_XXXA8888_1bit (struct grub_video_fbblit_info *dst,
  1410. struct grub_video_fbblit_info *src,
  1411. int x, int y,
  1412. int width, int height,
  1413. int offset_x, int offset_y)
  1414. {
  1415. int i;
  1416. int j;
  1417. grub_uint8_t *srcptr;
  1418. grub_uint32_t *dstptr;
  1419. grub_uint8_t srcmask;
  1420. unsigned int dstrowskip;
  1421. unsigned int srcrowskipbyte, srcrowskipbit;
  1422. grub_uint32_t fgcolor, bgcolor;
  1423. int bit_index;
  1424. /* Calculate the number of bytes to advance from the end of one line
  1425. to the beginning of the next line. */
  1426. dstrowskip = dst->mode_info->pitch - dst->mode_info->bytes_per_pixel * width;
  1427. srcrowskipbyte = (src->mode_info->width - width) >> 3;
  1428. srcrowskipbit = (src->mode_info->width - width) & 7;
  1429. bit_index = offset_y * src->mode_info->width + offset_x;
  1430. srcptr = (grub_uint8_t *) src->data + (bit_index >> 3);
  1431. srcmask = 1 << (~bit_index & 7);
  1432. dstptr = grub_video_fb_get_video_ptr (dst, x, y);
  1433. fgcolor = grub_video_fb_map_rgba (src->mode_info->fg_red,
  1434. src->mode_info->fg_green,
  1435. src->mode_info->fg_blue,
  1436. src->mode_info->fg_alpha);
  1437. bgcolor = grub_video_fb_map_rgba (src->mode_info->bg_red,
  1438. src->mode_info->bg_green,
  1439. src->mode_info->bg_blue,
  1440. src->mode_info->bg_alpha);
  1441. for (j = 0; j < height; j++)
  1442. {
  1443. for (i = 0; i < width; i++)
  1444. {
  1445. grub_uint32_t color;
  1446. grub_uint8_t a;
  1447. if (*srcptr & srcmask)
  1448. {
  1449. color = fgcolor;
  1450. a = src->mode_info->fg_alpha;
  1451. }
  1452. else
  1453. {
  1454. color = bgcolor;
  1455. a = src->mode_info->bg_alpha;
  1456. }
  1457. if (a == 255)
  1458. *dstptr = color;
  1459. else if (a != 0)
  1460. {
  1461. grub_uint8_t s1 = (color >> 0) & 0xFF;
  1462. grub_uint8_t s2 = (color >> 8) & 0xFF;
  1463. grub_uint8_t s3 = (color >> 16) & 0xFF;
  1464. grub_uint8_t d1 = (*dstptr >> 0) & 0xFF;
  1465. grub_uint8_t d2 = (*dstptr >> 8) & 0xFF;
  1466. grub_uint8_t d3 = (*dstptr >> 16) & 0xFF;
  1467. d1 = alpha_dilute (d1, s1, a);
  1468. d2 = alpha_dilute (d2, s2, a);
  1469. d3 = alpha_dilute (d3, s3, a);
  1470. *dstptr = (a << 24) | (d3 << 16) | (d2 << 8) | d1;
  1471. }
  1472. srcmask >>= 1;
  1473. if (!srcmask)
  1474. {
  1475. srcptr++;
  1476. srcmask = 0x80;
  1477. }
  1478. dstptr++;
  1479. }
  1480. srcptr += srcrowskipbyte;
  1481. if (srcmask >> srcrowskipbit)
  1482. srcmask >>= srcrowskipbit;
  1483. else
  1484. {
  1485. srcptr++;
  1486. srcmask <<= 8 - srcrowskipbit;
  1487. }
  1488. GRUB_VIDEO_FB_ADVANCE_POINTER (dstptr, dstrowskip);
  1489. }
  1490. }
  1491. /* Optimized blending blitter for 1-bit to XXX888. */
  1492. #ifdef GRUB_HAVE_UNALIGNED_ACCESS
  1493. static void
  1494. grub_video_fbblit_blend_XXX888_1bit (struct grub_video_fbblit_info *dst,
  1495. struct grub_video_fbblit_info *src,
  1496. int x, int y,
  1497. int width, int height,
  1498. int offset_x, int offset_y)
  1499. {
  1500. int i;
  1501. int j;
  1502. grub_uint8_t *srcptr;
  1503. grub_uint8_t *dstptr;
  1504. grub_uint8_t srcmask;
  1505. unsigned int dstrowskip;
  1506. unsigned int srcrowskipbyte, srcrowskipbit;
  1507. grub_uint32_t fgcolor, bgcolor;
  1508. int bit_index;
  1509. /* Calculate the number of bytes to advance from the end of one line
  1510. to the beginning of the next line. */
  1511. dstrowskip = dst->mode_info->pitch - dst->mode_info->bytes_per_pixel * width;
  1512. srcrowskipbyte = (src->mode_info->width - width) >> 3;
  1513. srcrowskipbit = (src->mode_info->width - width) & 7;
  1514. bit_index = offset_y * src->mode_info->width + offset_x;
  1515. srcptr = (grub_uint8_t *) src->data + (bit_index >> 3);
  1516. srcmask = 1 << (~bit_index & 7);
  1517. dstptr = grub_video_fb_get_video_ptr (dst, x, y);
  1518. fgcolor = grub_video_fb_map_rgba (src->mode_info->fg_red,
  1519. src->mode_info->fg_green,
  1520. src->mode_info->fg_blue,
  1521. src->mode_info->fg_alpha);
  1522. bgcolor = grub_video_fb_map_rgba (src->mode_info->bg_red,
  1523. src->mode_info->bg_green,
  1524. src->mode_info->bg_blue,
  1525. src->mode_info->bg_alpha);
  1526. for (j = 0; j < height; j++)
  1527. {
  1528. for (i = 0; i < width; i++)
  1529. {
  1530. grub_uint32_t color;
  1531. grub_uint8_t a;
  1532. if (*srcptr & srcmask)
  1533. {
  1534. color = fgcolor;
  1535. a = src->mode_info->fg_alpha;
  1536. }
  1537. else
  1538. {
  1539. color = bgcolor;
  1540. a = src->mode_info->bg_alpha;
  1541. }
  1542. if (a == 255)
  1543. {
  1544. #ifndef GRUB_CPU_WORDS_BIGENDIAN
  1545. ((grub_uint8_t *) dstptr)[0] = color & 0xff;
  1546. ((grub_uint8_t *) dstptr)[1] = (color & 0xff00) >> 8;
  1547. ((grub_uint8_t *) dstptr)[2] = (color & 0xff0000) >> 16;
  1548. #else
  1549. ((grub_uint8_t *) dstptr)[2] = color & 0xff;
  1550. ((grub_uint8_t *) dstptr)[1] = (color & 0xff00) >> 8;
  1551. ((grub_uint8_t *) dstptr)[0] = (color & 0xff0000) >> 16;
  1552. #endif
  1553. }
  1554. else if (a != 0)
  1555. {
  1556. grub_uint8_t s1 = (color >> 0) & 0xFF;
  1557. grub_uint8_t s2 = (color >> 8) & 0xFF;
  1558. grub_uint8_t s3 = (color >> 16) & 0xFF;
  1559. grub_uint8_t d1 = (*(grub_uint32_t *) dstptr >> 0) & 0xFF;
  1560. grub_uint8_t d2 = (*(grub_uint32_t *) dstptr >> 8) & 0xFF;
  1561. grub_uint8_t d3 = (*(grub_uint32_t *) dstptr >> 16) & 0xFF;
  1562. ((grub_uint8_t *) dstptr)[0] = alpha_dilute (d1, s1, a);
  1563. ((grub_uint8_t *) dstptr)[1] = alpha_dilute (d2, s2, a);
  1564. ((grub_uint8_t *) dstptr)[2] = alpha_dilute (d3, s3, a);
  1565. }
  1566. srcmask >>= 1;
  1567. if (!srcmask)
  1568. {
  1569. srcptr++;
  1570. srcmask = 0x80;
  1571. }
  1572. dstptr += 3;
  1573. }
  1574. srcptr += srcrowskipbyte;
  1575. if (srcmask >> srcrowskipbit)
  1576. srcmask >>= srcrowskipbit;
  1577. else
  1578. {
  1579. srcptr++;
  1580. srcmask <<= 8 - srcrowskipbit;
  1581. }
  1582. dstptr += dstrowskip;
  1583. }
  1584. }
  1585. #endif
  1586. /* Optimized blending blitter for 1-bit to XXX888. */
  1587. static void
  1588. grub_video_fbblit_blend_XXX565_1bit (struct grub_video_fbblit_info *dst,
  1589. struct grub_video_fbblit_info *src,
  1590. int x, int y,
  1591. int width, int height,
  1592. int offset_x, int offset_y)
  1593. {
  1594. int i;
  1595. int j;
  1596. grub_uint8_t *srcptr;
  1597. grub_uint16_t *dstptr;
  1598. grub_uint8_t srcmask;
  1599. unsigned int dstrowskip;
  1600. unsigned int srcrowskipbyte, srcrowskipbit;
  1601. grub_uint16_t fgcolor, bgcolor;
  1602. int bit_index;
  1603. /* Calculate the number of bytes to advance from the end of one line
  1604. to the beginning of the next line. */
  1605. dstrowskip = dst->mode_info->pitch - dst->mode_info->bytes_per_pixel * width;
  1606. srcrowskipbyte = (src->mode_info->width - width) >> 3;
  1607. srcrowskipbit = (src->mode_info->width - width) & 7;
  1608. bit_index = offset_y * src->mode_info->width + offset_x;
  1609. srcptr = (grub_uint8_t *) src->data + (bit_index >> 3);
  1610. srcmask = 1 << (~bit_index & 7);
  1611. dstptr = grub_video_fb_get_video_ptr (dst, x, y);
  1612. fgcolor = grub_video_fb_map_rgba (src->mode_info->fg_red,
  1613. src->mode_info->fg_green,
  1614. src->mode_info->fg_blue,
  1615. src->mode_info->fg_alpha);
  1616. bgcolor = grub_video_fb_map_rgba (src->mode_info->bg_red,
  1617. src->mode_info->bg_green,
  1618. src->mode_info->bg_blue,
  1619. src->mode_info->bg_alpha);
  1620. for (j = 0; j < height; j++)
  1621. {
  1622. for (i = 0; i < width; i++)
  1623. {
  1624. grub_uint32_t color;
  1625. grub_uint8_t a;
  1626. if (*srcptr & srcmask)
  1627. {
  1628. color = fgcolor;
  1629. a = src->mode_info->fg_alpha;
  1630. }
  1631. else
  1632. {
  1633. color = bgcolor;
  1634. a = src->mode_info->bg_alpha;
  1635. }
  1636. if (a == 255)
  1637. *dstptr = color;
  1638. else if (a != 0)
  1639. {
  1640. grub_uint8_t s1 = (color >> 0) & 0x1F;
  1641. grub_uint8_t s2 = (color >> 5) & 0x3F;
  1642. grub_uint8_t s3 = (color >> 11) & 0x1F;
  1643. grub_uint8_t d1 = (*dstptr >> 0) & 0x1F;
  1644. grub_uint8_t d2 = (*dstptr >> 5) & 0x3F;
  1645. grub_uint8_t d3 = (*dstptr >> 11) & 0x1F;
  1646. d1 = alpha_dilute (d1, s1, a);
  1647. d2 = alpha_dilute (d2, s2, a);
  1648. d3 = alpha_dilute (d3, s3, a);
  1649. *dstptr = (d1 & 0x1f) | ((d2 & 0x3f) << 5) | ((d3 & 0x1f) << 11);
  1650. }
  1651. srcmask >>= 1;
  1652. if (!srcmask)
  1653. {
  1654. srcptr++;
  1655. srcmask = 0x80;
  1656. }
  1657. dstptr++;
  1658. }
  1659. srcptr += srcrowskipbyte;
  1660. if (srcmask >> srcrowskipbit)
  1661. srcmask >>= srcrowskipbit;
  1662. else
  1663. {
  1664. srcptr++;
  1665. srcmask <<= 8 - srcrowskipbit;
  1666. }
  1667. GRUB_VIDEO_FB_ADVANCE_POINTER (dstptr, dstrowskip);
  1668. }
  1669. }
  1670. /* NOTE: This function assumes that given coordinates are within bounds of
  1671. handled data. */
  1672. void
  1673. grub_video_fb_dispatch_blit (struct grub_video_fbblit_info *target,
  1674. struct grub_video_fbblit_info *source,
  1675. enum grub_video_blit_operators oper, int x, int y,
  1676. unsigned int width, unsigned int height,
  1677. int offset_x, int offset_y)
  1678. {
  1679. if (oper == GRUB_VIDEO_BLIT_REPLACE)
  1680. {
  1681. /* Try to figure out more optimized version for replace operator. */
  1682. switch (source->mode_info->blit_format)
  1683. {
  1684. case GRUB_VIDEO_BLIT_FORMAT_RGBA_8888:
  1685. switch (target->mode_info->blit_format)
  1686. {
  1687. case GRUB_VIDEO_BLIT_FORMAT_RGBA_8888:
  1688. grub_video_fbblit_replace_directN (target, source,
  1689. x, y, width, height,
  1690. offset_x, offset_y);
  1691. return;
  1692. case GRUB_VIDEO_BLIT_FORMAT_BGRA_8888:
  1693. grub_video_fbblit_replace_BGRX8888_RGBX8888 (target, source,
  1694. x, y, width, height,
  1695. offset_x, offset_y);
  1696. return;
  1697. case GRUB_VIDEO_BLIT_FORMAT_BGR_888:
  1698. grub_video_fbblit_replace_BGR888_RGBX8888 (target, source,
  1699. x, y, width, height,
  1700. offset_x, offset_y);
  1701. return;
  1702. case GRUB_VIDEO_BLIT_FORMAT_RGB_888:
  1703. grub_video_fbblit_replace_RGB888_RGBX8888 (target, source,
  1704. x, y, width, height,
  1705. offset_x, offset_y);
  1706. return;
  1707. case GRUB_VIDEO_BLIT_FORMAT_INDEXCOLOR:
  1708. grub_video_fbblit_replace_index_RGBX8888 (target, source,
  1709. x, y, width, height,
  1710. offset_x, offset_y);
  1711. return;
  1712. default:
  1713. break;
  1714. }
  1715. break;
  1716. case GRUB_VIDEO_BLIT_FORMAT_RGB_888:
  1717. switch (target->mode_info->blit_format)
  1718. {
  1719. case GRUB_VIDEO_BLIT_FORMAT_BGRA_8888:
  1720. grub_video_fbblit_replace_BGRX8888_RGB888 (target, source,
  1721. x, y, width, height,
  1722. offset_x, offset_y);
  1723. return;
  1724. case GRUB_VIDEO_BLIT_FORMAT_RGBA_8888:
  1725. grub_video_fbblit_replace_RGBX8888_RGB888 (target, source,
  1726. x, y, width, height,
  1727. offset_x, offset_y);
  1728. return;
  1729. case GRUB_VIDEO_BLIT_FORMAT_BGR_888:
  1730. grub_video_fbblit_replace_BGR888_RGB888 (target, source,
  1731. x, y, width, height,
  1732. offset_x, offset_y);
  1733. return;
  1734. case GRUB_VIDEO_BLIT_FORMAT_RGB_888:
  1735. grub_video_fbblit_replace_directN (target, source,
  1736. x, y, width, height,
  1737. offset_x, offset_y);
  1738. return;
  1739. case GRUB_VIDEO_BLIT_FORMAT_INDEXCOLOR:
  1740. grub_video_fbblit_replace_index_RGB888 (target, source,
  1741. x, y, width, height,
  1742. offset_x, offset_y);
  1743. return;
  1744. default:
  1745. break;
  1746. }
  1747. break;
  1748. case GRUB_VIDEO_BLIT_FORMAT_BGRA_8888:
  1749. switch (target->mode_info->blit_format)
  1750. {
  1751. case GRUB_VIDEO_BLIT_FORMAT_BGRA_8888:
  1752. grub_video_fbblit_replace_directN (target, source,
  1753. x, y, width, height,
  1754. offset_x, offset_y);
  1755. return;
  1756. default:
  1757. break;
  1758. }
  1759. break;
  1760. case GRUB_VIDEO_BLIT_FORMAT_INDEXCOLOR:
  1761. switch (target->mode_info->blit_format)
  1762. {
  1763. case GRUB_VIDEO_BLIT_FORMAT_INDEXCOLOR:
  1764. case GRUB_VIDEO_BLIT_FORMAT_INDEXCOLOR_ALPHA:
  1765. grub_video_fbblit_replace_directN (target, source,
  1766. x, y, width, height,
  1767. offset_x, offset_y);
  1768. return;
  1769. default:
  1770. break;
  1771. }
  1772. break;
  1773. case GRUB_VIDEO_BLIT_FORMAT_INDEXCOLOR_ALPHA:
  1774. switch (target->mode_info->bytes_per_pixel)
  1775. {
  1776. case 4:
  1777. grub_video_fbblit_replace_32bit_indexa (target, source,
  1778. x, y, width, height,
  1779. offset_x, offset_y);
  1780. return;
  1781. case 3:
  1782. grub_video_fbblit_replace_24bit_indexa (target, source,
  1783. x, y, width, height,
  1784. offset_x, offset_y);
  1785. return;
  1786. case 2:
  1787. grub_video_fbblit_replace_16bit_indexa (target, source,
  1788. x, y, width, height,
  1789. offset_x, offset_y);
  1790. return;
  1791. case 1:
  1792. grub_video_fbblit_replace_8bit_indexa (target, source,
  1793. x, y, width, height,
  1794. offset_x, offset_y);
  1795. return;
  1796. default:
  1797. break;
  1798. }
  1799. break;
  1800. case GRUB_VIDEO_BLIT_FORMAT_1BIT_PACKED:
  1801. switch (target->mode_info->bytes_per_pixel)
  1802. {
  1803. case 4:
  1804. grub_video_fbblit_replace_32bit_1bit (target, source,
  1805. x, y, width, height,
  1806. offset_x, offset_y);
  1807. return;
  1808. #ifdef GRUB_HAVE_UNALIGNED_ACCESS
  1809. case 3:
  1810. grub_video_fbblit_replace_24bit_1bit (target, source,
  1811. x, y, width, height,
  1812. offset_x, offset_y);
  1813. return;
  1814. #endif
  1815. case 2:
  1816. grub_video_fbblit_replace_16bit_1bit (target, source,
  1817. x, y, width, height,
  1818. offset_x, offset_y);
  1819. return;
  1820. case 1:
  1821. grub_video_fbblit_replace_8bit_1bit (target, source,
  1822. x, y, width, height,
  1823. offset_x, offset_y);
  1824. return;
  1825. }
  1826. break;
  1827. default:
  1828. break;
  1829. }
  1830. /* No optimized replace operator found, use default (slow) blitter. */
  1831. grub_video_fbblit_replace (target, source, x, y, width, height,
  1832. offset_x, offset_y);
  1833. }
  1834. else
  1835. {
  1836. /* Try to figure out more optimized blend operator. */
  1837. switch (source->mode_info->blit_format)
  1838. {
  1839. case GRUB_VIDEO_BLIT_FORMAT_RGBA_8888:
  1840. switch (target->mode_info->blit_format)
  1841. {
  1842. case GRUB_VIDEO_BLIT_FORMAT_BGRA_8888:
  1843. grub_video_fbblit_blend_BGRA8888_RGBA8888 (target, source,
  1844. x, y, width, height,
  1845. offset_x, offset_y);
  1846. return;
  1847. case GRUB_VIDEO_BLIT_FORMAT_RGBA_8888:
  1848. grub_video_fbblit_blend_RGBA8888_RGBA8888 (target, source,
  1849. x, y, width, height,
  1850. offset_x, offset_y);
  1851. return;
  1852. case GRUB_VIDEO_BLIT_FORMAT_BGR_888:
  1853. grub_video_fbblit_blend_BGR888_RGBA8888 (target, source,
  1854. x, y, width, height,
  1855. offset_x, offset_y);
  1856. return;
  1857. case GRUB_VIDEO_BLIT_FORMAT_RGB_888:
  1858. grub_video_fbblit_blend_RGB888_RGBA8888 (target, source,
  1859. x, y, width, height,
  1860. offset_x, offset_y);
  1861. return;
  1862. case GRUB_VIDEO_BLIT_FORMAT_INDEXCOLOR:
  1863. grub_video_fbblit_blend_index_RGBA8888 (target, source,
  1864. x, y, width, height,
  1865. offset_x, offset_y);
  1866. return;
  1867. default:
  1868. break;
  1869. }
  1870. break;
  1871. case GRUB_VIDEO_BLIT_FORMAT_RGB_888:
  1872. /* Note: There is really no alpha information here, so blend is
  1873. changed to replace. */
  1874. switch (target->mode_info->blit_format)
  1875. {
  1876. case GRUB_VIDEO_BLIT_FORMAT_BGRA_8888:
  1877. grub_video_fbblit_replace_BGRX8888_RGB888 (target, source,
  1878. x, y, width, height,
  1879. offset_x, offset_y);
  1880. return;
  1881. case GRUB_VIDEO_BLIT_FORMAT_RGBA_8888:
  1882. grub_video_fbblit_replace_RGBX8888_RGB888 (target, source,
  1883. x, y, width, height,
  1884. offset_x, offset_y);
  1885. return;
  1886. case GRUB_VIDEO_BLIT_FORMAT_BGR_888:
  1887. grub_video_fbblit_replace_BGR888_RGB888 (target, source,
  1888. x, y, width, height,
  1889. offset_x, offset_y);
  1890. return;
  1891. case GRUB_VIDEO_BLIT_FORMAT_RGB_888:
  1892. grub_video_fbblit_replace_directN (target, source,
  1893. x, y, width, height,
  1894. offset_x, offset_y);
  1895. return;
  1896. case GRUB_VIDEO_BLIT_FORMAT_INDEXCOLOR:
  1897. grub_video_fbblit_replace_index_RGB888 (target, source,
  1898. x, y, width, height,
  1899. offset_x, offset_y);
  1900. return;
  1901. default:
  1902. break;
  1903. }
  1904. break;
  1905. case GRUB_VIDEO_BLIT_FORMAT_1BIT_PACKED:
  1906. switch (target->mode_info->blit_format)
  1907. {
  1908. case GRUB_VIDEO_BLIT_FORMAT_BGRA_8888:
  1909. case GRUB_VIDEO_BLIT_FORMAT_RGBA_8888:
  1910. grub_video_fbblit_blend_XXXA8888_1bit (target, source,
  1911. x, y, width, height,
  1912. offset_x, offset_y);
  1913. return;
  1914. #ifdef GRUB_HAVE_UNALIGNED_ACCESS
  1915. case GRUB_VIDEO_BLIT_FORMAT_BGR_888:
  1916. case GRUB_VIDEO_BLIT_FORMAT_RGB_888:
  1917. grub_video_fbblit_blend_XXX888_1bit (target, source,
  1918. x, y, width, height,
  1919. offset_x, offset_y);
  1920. return;
  1921. #endif
  1922. case GRUB_VIDEO_BLIT_FORMAT_BGR_565:
  1923. case GRUB_VIDEO_BLIT_FORMAT_RGB_565:
  1924. grub_video_fbblit_blend_XXX565_1bit (target, source,
  1925. x, y, width, height,
  1926. offset_x, offset_y);
  1927. return;
  1928. default:
  1929. break;
  1930. }
  1931. break;
  1932. case GRUB_VIDEO_BLIT_FORMAT_INDEXCOLOR_ALPHA:
  1933. switch (target->mode_info->bytes_per_pixel)
  1934. {
  1935. case 4:
  1936. grub_video_fbblit_blend_32bit_indexa (target, source,
  1937. x, y, width, height,
  1938. offset_x, offset_y);
  1939. return;
  1940. case 3:
  1941. grub_video_fbblit_blend_24bit_indexa (target, source,
  1942. x, y, width, height,
  1943. offset_x, offset_y);
  1944. return;
  1945. case 2:
  1946. grub_video_fbblit_blend_16bit_indexa (target, source,
  1947. x, y, width, height,
  1948. offset_x, offset_y);
  1949. return;
  1950. case 1:
  1951. grub_video_fbblit_blend_8bit_indexa (target, source,
  1952. x, y, width, height,
  1953. offset_x, offset_y);
  1954. return;
  1955. }
  1956. break;
  1957. default:
  1958. break;
  1959. }
  1960. /* No optimized blend operation found, use default (slow) blitter. */
  1961. grub_video_fbblit_blend (target, source, x, y, width, height,
  1962. offset_x, offset_y);
  1963. }
  1964. }