5 * Copyright (C) 2007 Hiroshi Morii All Rights Reserved.
6 * Email koolsmoky(at)users.sourceforge.net
7 * Web http://www.3dfxzone.it/koolsmoky
9 * this is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2, or (at your option)
14 * this is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with GNU Make; see the file COPYING. If not, write to
21 * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
25 #pragma warning(disable: 4786)
31 /* NOTE: The codes are not optimized. They can be made faster. */
33 #include "TxQuantize.h"
35 TxQuantize::TxQuantize()
37 _txUtil = new TxUtil();
39 /* get number of CPU cores. */
40 _numcore = _txUtil->getNumberofProcessors();
42 /* get dxtn extensions */
43 _tx_compress_fxt1 = TxLoadLib::getInstance()->getfxtCompressTexFuncExt();
44 _tx_compress_dxtn = TxLoadLib::getInstance()->getdxtCompressTexFuncExt();
48 TxQuantize::~TxQuantize()
54 TxQuantize::ARGB1555_ARGB8888(uint32* src, uint32* dest, int width, int height)
57 int siz = (width * height) >> 1;
59 for (i = 0; i < siz; i++) {
60 *dest = (((*src & 0x00008000) ? 0xff000000 : 0x00000000) |
61 ((*src & 0x00007c00) << 9) | ((*src & 0x00007000) << 4) |
62 ((*src & 0x000003e0) << 6) | ((*src & 0x00000380) << 1) |
63 ((*src & 0x0000001f) << 3) | ((*src & 0x0000001c) >> 2));
65 *dest = (((*src & 0x80000000) ? 0xff000000 : 0x00000000) |
66 ((*src & 0x7c000000) >> 7) | ((*src & 0x70000000) >> 12) |
67 ((*src & 0x03e00000) >> 10) | ((*src & 0x03800000) >> 15) |
68 ((*src & 0x001f0000) >> 13) | ((*src & 0x001c0000) >> 18));
73 int siz = (width * height) >> 1;
80 mov esi, dword ptr [src];
81 mov edi, dword ptr [dest];
82 mov ecx, dword ptr [siz];
85 mov eax, dword ptr [esi];
88 // arrr rrgg gggb bbbb
89 // aaaaaaaa rrrrrrrr gggggggg bbbbbbbb
90 mov edx, eax; // edx = arrrrrgg gggbbbbb arrrrrgg gggbbbbb
92 and eax, 0x00008000; // eax = 00000000 00000000 a0000000 00000000
94 mov ebx, 0xff000000; // ebx = aaaaaaaa 00000000 00000000 00000000
97 mov eax, edx; // eax = arrrrrgg gggbbbbb arrrrrgg gggbbbbb
98 and edx, 0x00007c00; // edx = 00000000 00000000 0rrrrr00 00000000
99 shl edx, 4; // edx = 00000000 00000rrr rr000000 00000000
100 or ebx, edx; // ebx = aaaaaaaa 00000rrr rr000000 00000000
101 shl edx, 5; // edx = 00000000 rrrrr000 00000000 00000000
102 or ebx, edx; // ebx = aaaaaaaa rrrrrrrr rr000000 00000000
103 and ebx, 0xffff0000; // ebx = aaaaaaaa rrrrrrrr 00000000 00000000
105 and edx, 0x000003e0; // edx = 00000000 00000000 000000gg ggg00000
106 shl edx, 1; // edx = 00000000 00000000 00000ggg gg000000
107 or ebx, edx; // ebx = aaaaaaaa rrrrrrrr 00000ggg gg000000
108 shl edx, 5; // edx = 00000000 00000000 ggggg000 00000000
109 or ebx, edx; // ebx = aaaaaaaa rrrrrrrr gggggggg gg000000
110 and ebx, 0xffffff00; // ebx = aaaaaaaa rrrrrrrr gggggggg 00000000
112 and edx, 0x0000001f; // edx = 00000000 00000000 00000000 000bbbbb
113 shl edx, 3; // edx = 00000000 00000000 00000000 bbbbb000
114 or ebx, edx; // ebx = aaaaaaaa rrrrrrrr gggggggg bbbbb000
115 shr edx, 5; // edx = 00000000 00000000 00000000 00000bbb
116 or ebx, edx; // ebx = aaaaaaaa rrrrrrrr gggggggg bbbbbbbb
118 mov dword ptr [edi], ebx;
121 shr eax, 16; // eax = 00000000 00000000 arrrrrgg gggbbbbb
122 mov edx, eax; // edx = 00000000 00000000 arrrrrgg gggbbbbb
124 and eax, 0x00008000; // eax = 00000000 00000000 a0000000 00000000
126 mov ebx, 0xff000000; // ebx = aaaaaaaa 00000000 00000000 00000000
129 mov eax, edx; // eax = 00000000 00000000 arrrrrgg gggbbbbb
130 and edx, 0x00007c00; // edx = 00000000 00000000 0rrrrr00 00000000
131 shl edx, 4; // edx = 00000000 00000rrr rr000000 00000000
132 or ebx, edx; // ebx = aaaaaaaa 00000rrr rr000000 00000000
133 shl edx, 5; // edx = 00000000 rrrrr000 00000000 00000000
134 or ebx, edx; // ebx = aaaaaaaa rrrrrrrr rr000000 00000000
135 and ebx, 0xffff0000; // ebx = aaaaaaaa rrrrrrrr 00000000 00000000
137 and edx, 0x000003e0; // edx = 00000000 00000000 000000gg ggg00000
138 shl edx, 1; // edx = 00000000 00000000 00000ggg gg000000
139 or ebx, edx; // ebx = aaaaaaaa rrrrrrrr 00000ggg gg000000
140 shl edx, 5; // edx = 00000000 00000000 ggggg000 00000000
141 or ebx, edx; // ebx = aaaaaaaa rrrrrrrr gggggggg gg000000
142 and ebx, 0xffffff00; // ebx = aaaaaaaa rrrrrrrr gggggggg 00000000
144 and edx, 0x0000001f; // edx = 00000000 00000000 00000000 000bbbbb
145 shl edx, 3; // edx = 00000000 00000000 00000000 bbbbb000
146 or ebx, edx; // ebx = aaaaaaaa rrrrrrrr gggggggg bbbbb000
147 shr edx, 5; // edx = 00000000 00000000 00000000 00000bbb
148 or ebx, edx; // ebx = aaaaaaaa rrrrrrrr gggggggg bbbbbbbb
150 mov dword ptr [edi], ebx;
164 TxQuantize::ARGB4444_ARGB8888(uint32* src, uint32* dest, int width, int height)
167 int siz = (width * height) >> 1;
169 for (i = 0; i < siz; i++) {
170 *dest = ((*src & 0x0000f000) << 12) |
171 ((*src & 0x00000f00) << 8) |
172 ((*src & 0x000000f0) << 4) |
174 *dest |= (*dest << 4);
176 *dest = ((*src & 0xf0000000) |
177 ((*src & 0x0f000000) >> 4) |
178 ((*src & 0x00f00000) >> 8) |
179 ((*src & 0x000f0000) >> 12));
180 *dest |= (*dest >> 4);
185 int siz = (width * height) >> 1;
192 mov esi, dword ptr [src];
193 mov edi, dword ptr [dest];
194 mov ecx, dword ptr [siz];
197 mov eax, dword ptr [esi];
200 // aaaa rrrr gggg bbbb
201 // aaaaaaaa rrrrrrrr gggggggg bbbbbbbb
204 mov ebx, eax; // 00000000 00000000 aaaarrrr ggggbbbb
205 and ebx, 0x0000f000; // 00000000 00000000 aaaa0000 00000000
206 shl ebx, 12; // 0000aaaa 00000000 00000000 00000000
207 or eax, ebx; // 0000aaaa 00000000 aaaarrrr ggggbbbb
209 and ebx, 0x00000f00; // 00000000 00000000 0000rrrr 00000000
210 shl ebx, 8; // 00000000 0000rrrr 00000000 00000000
211 or eax, ebx; // 0000aaaa 0000rrrr aaaarrrr ggggbbbb
213 and ebx, 0x000000f0; // 00000000 00000000 00000000 gggg0000
214 shl ebx, 4; // 00000000 00000000 0000gggg 00000000
215 and eax, 0x0f0f000f; // 0000aaaa 0000rrrr 00000000 0000bbbb
216 or eax, ebx; // 0000aaaa 0000rrrr 0000gggg 0000bbbb
218 shl ebx, 4; // aaaa0000 rrrr0000 gggg0000 bbbb0000
219 or eax, ebx; // aaaaaaaa rrrrrrrr gggggggg bbbbbbbb
221 mov dword ptr [edi], eax;
225 mov ebx, edx; // 00000000 00000000 aaaarrrr ggggbbbb
226 and ebx, 0x0000f000; // 00000000 00000000 aaaa0000 00000000
227 shl ebx, 12; // 0000aaaa 00000000 00000000 00000000
228 or edx, ebx; // 0000aaaa 00000000 aaaarrrr ggggbbbb
230 and ebx, 0x00000f00; // 00000000 00000000 0000rrrr 00000000
231 shl ebx, 8; // 00000000 0000rrrr 00000000 00000000
232 or edx, ebx; // 0000aaaa 0000rrrr aaaarrrr ggggbbbb
234 and ebx, 0x000000f0; // 00000000 00000000 00000000 gggg0000
235 shl ebx, 4; // 00000000 00000000 0000gggg 00000000
236 and edx, 0x0f0f000f; // 0000aaaa 0000rrrr 00000000 0000bbbb
237 or edx, ebx; // 0000aaaa 0000rrrr 0000gggg 0000bbbb
239 shl ebx, 4; // aaaa0000 rrrr0000 gggg0000 bbbb0000
240 or edx, ebx; // aaaaaaaa rrrrrrrr gggggggg bbbbbbbb
242 mov dword ptr [edi], edx;
256 TxQuantize::RGB565_ARGB8888(uint32* src, uint32* dest, int width, int height)
259 int siz = (width * height) >> 1;
261 for (i = 0; i < siz; i++) {
262 *dest = (0xff000000 |
263 ((*src & 0x0000f800) << 8) | ((*src & 0x0000e000) << 3) |
264 ((*src & 0x000007e0) << 5) | ((*src & 0x00000600) >> 1) |
265 ((*src & 0x0000001f) << 3) | ((*src & 0x0000001c) >> 2));
267 *dest = (0xff000000 |
268 ((*src & 0xf8000000) >> 8) | ((*src & 0xe0000000) >> 13) |
269 ((*src & 0x07e00000) >> 11) | ((*src & 0x06000000) >> 17) |
270 ((*src & 0x001f0000) >> 13) | ((*src & 0x001c0000) >> 18));
275 int siz = (width * height) >> 1;
282 mov esi, dword ptr [src];
283 mov edi, dword ptr [dest];
284 mov ecx, dword ptr [siz];
287 mov eax, dword ptr [esi];
290 // rrrr rggg gggb bbbb
291 // 11111111 rrrrrrrr gggggggg bbbbbbbb
294 mov ebx, eax; // 00000000 00000000 rrrrrggg gggbbbbb
295 and ebx, 0x0000f800; // 00000000 00000000 rrrrr000 00000000
296 shl ebx, 5; // 00000000 000rrrrr 00000000 00000000
297 or eax, ebx; // 00000000 000rrrrr rrrrrggg gggbbbbb
299 and ebx, 0x000007e0; // 00000000 00000000 00000ggg ggg00000
300 shl ebx, 5; // 00000000 00000000 gggggg00 00000000
301 and eax, 0x001F001F; // 00000000 000rrrrr 00000000 000bbbbb
302 shl eax, 3; // 00000000 rrrrr000 00000000 bbbbb000
303 or eax, ebx; // 00000000 rrrrr000 gggggg00 bbbbb000
305 shr ebx, 5; // 00000000 00000rrr rr000ggg ggg00bbb
306 and ebx, 0x00070007; // 00000000 00000rrr 00000000 00000bbb
307 or eax, ebx; // 00000000 rrrrrrrr gggggg00 bbbbbbbb
310 and ebx, 0x00000300; // 00000000 00000000 000000gg 00000000
311 or eax, ebx // 00000000 rrrrrrrr gggggggg bbbbbbbb
312 or eax, 0xff000000; // 11111111 rrrrrrrr gggggggg bbbbbbbb
314 mov dword ptr [edi], eax;
318 mov eax, edx; // 00000000 00000000 rrrrrggg gggbbbbb
320 mov ebx, eax; // 00000000 00000000 rrrrrggg gggbbbbb
321 and ebx, 0x0000f800; // 00000000 00000000 rrrrr000 00000000
322 shl ebx, 5; // 00000000 000rrrrr 00000000 00000000
323 or eax, ebx; // 00000000 000rrrrr rrrrrggg gggbbbbb
325 and ebx, 0x000007e0; // 00000000 00000000 00000ggg ggg00000
326 shl ebx, 5; // 00000000 00000000 gggggg00 00000000
327 and eax, 0x001F001F; // 00000000 000rrrrr 00000000 000bbbbb
328 shl eax, 3; // 00000000 rrrrr000 00000000 bbbbb000
329 or eax, ebx; // 00000000 rrrrr000 gggggg00 bbbbb000
331 shr ebx, 5; // 00000000 00000rrr rr000ggg ggg00bbb
332 and ebx, 0x00070007; // 00000000 00000rrr 00000000 00000bbb
333 or eax, ebx; // 00000000 rrrrrrrr gggggg00 bbbbbbbb
336 and ebx, 0x00000300; // 00000000 00000000 000000gg 00000000
337 or eax, ebx // 00000000 rrrrrrrr gggggggg bbbbbbbb
338 or eax, 0xff000000; // 11111111 rrrrrrrr gggggggg bbbbbbbb
340 mov dword ptr [edi], eax;
354 TxQuantize::A8_ARGB8888(uint32* src, uint32* dest, int width, int height)
357 int siz = (width * height) >> 2;
359 for (i = 0; i < siz; i++) {
360 *dest = (*src & 0x000000ff);
361 *dest |= (*dest << 8);
362 *dest |= (*dest << 16);
364 *dest = (*src & 0x0000ff00);
365 *dest |= (*dest >> 8);
366 *dest |= (*dest << 16);
368 *dest = (*src & 0x00ff0000);
369 *dest |= (*dest << 8);
370 *dest |= (*dest >> 16);
372 *dest = (*src & 0xff000000);
373 *dest |= (*dest >> 8);
374 *dest |= (*dest >> 16);
379 int siz = (width * height) >> 2;
386 mov esi, dword ptr [src];
387 mov edi, dword ptr [dest];
388 mov ecx, dword ptr [siz];
391 mov eax, dword ptr [esi];
395 // aaaaaaaa rrrrrrrr gggggggg bbbbbbbb
398 mov ebx, eax; // 00000000 00000000 00000000 aaaaaaaa
399 shl ebx, 8; // 00000000 00000000 aaaaaaaa 00000000
400 or eax, ebx; // 00000000 00000000 aaaaaaaa aaaaaaaa
402 shl ebx, 16; // aaaaaaaa aaaaaaaa 00000000 00000000
403 or eax, ebx; // aaaaaaaa rrrrrrrr gggggggg bbbbbbbb
405 mov dword ptr [edi], eax;
410 mov ebx, eax; // 00000000 00000000 aaaaaaaa 00000000
411 shr ebx, 8; // 00000000 00000000 00000000 aaaaaaaa
412 or eax, ebx; // 00000000 00000000 aaaaaaaa aaaaaaaa
414 shl ebx, 16; // aaaaaaaa aaaaaaaa 00000000 00000000
415 or eax, ebx; // aaaaaaaa rrrrrrrr gggggggg bbbbbbbb
417 mov dword ptr [edi], eax;
422 mov ebx, eax; // 00000000 aaaaaaaa 00000000 00000000
423 shl ebx, 8; // aaaaaaaa 00000000 00000000 00000000
424 or eax, ebx; // aaaaaaaa aaaaaaaa 00000000 00000000
426 shr ebx, 16; // 00000000 00000000 aaaaaaaa aaaaaaaa
427 or eax, ebx; // aaaaaaaa rrrrrrrr gggggggg bbbbbbbb
429 mov dword ptr [edi], eax;
434 mov ebx, eax; // aaaaaaaa 00000000 00000000 00000000
435 shr ebx, 8; // 00000000 aaaaaaaa 00000000 00000000
436 or eax, ebx; // aaaaaaaa aaaaaaaa 00000000 00000000
438 shr ebx, 16; // 00000000 00000000 aaaaaaaa aaaaaaaa
439 or eax, ebx; // aaaaaaaa rrrrrrrr gggggggg bbbbbbbb
441 mov dword ptr [edi], eax;
455 TxQuantize::AI44_ARGB8888(uint32* src, uint32* dest, int width, int height)
458 int siz = (width * height) >> 2;
460 for (i = 0; i < siz; i++) {
461 *dest = (*src & 0x0000000f);
462 *dest |= ((*dest << 8) | (*dest << 16));
463 *dest |= ((*src & 0x000000f0) << 20);
464 *dest |= (*dest << 4);
466 *dest = (*src & 0x00000f00);
467 *dest |= ((*dest << 8) | (*dest >> 8));
468 *dest |= ((*src & 0x0000f000) << 12);
469 *dest |= (*dest << 4);
471 *dest = (*src & 0x000f0000);
472 *dest |= ((*dest >> 8) | (*dest >> 16));
473 *dest |= ((*src & 0x00f00000) << 4);
474 *dest |= (*dest << 4);
476 *dest = ((*src & 0x0f000000) >> 4);
477 *dest |= ((*dest >> 8) | (*dest >> 16));
478 *dest |= (*src & 0xf0000000);
479 *dest |= (*dest >> 4);
484 int siz = (width * height) >> 2;
491 mov esi, dword ptr [src];
492 mov edi, dword ptr [dest];
493 mov ecx, dword ptr [siz];
496 mov eax, dword ptr [esi];
500 // aaaaaaaa iiiiiiii iiiiiiii iiiiiiii
502 and eax, 0x000000f0; // 00000000 00000000 00000000 aaaa0000
504 shl eax, 20; // 0000aaaa 00000000 00000000 00000000
505 and ebx, 0x0000000f; // 00000000 00000000 00000000 0000iiii
506 or eax, ebx; // 0000aaaa 00000000 00000000 0000iiii
507 shl ebx, 8; // 00000000 00000000 0000iiii 00000000
508 or eax, ebx; // 0000aaaa 00000000 0000iiii 0000iiii
509 shl ebx, 8; // 00000000 0000iiii 00000000 00000000
510 or eax, ebx; // 0000aaaa 0000iiii 0000iiii 0000iiii
512 shl ebx, 4; // aaaa0000 iiii0000 iiii0000 iiii0000
513 or eax, ebx; // aaaaaaaa iiiiiiii iiiiiiii iiiiiiii
515 mov dword ptr [edi], eax;
519 and eax, 0x0000f000; // 00000000 00000000 aaaa0000 00000000
521 shl eax, 12; // 0000aaaa 00000000 00000000 00000000
522 and ebx, 0x00000f00; // 00000000 00000000 0000iiii 00000000
523 or eax, ebx; // 0000aaaa 00000000 0000iiii 00000000
524 shr ebx, 8; // 00000000 00000000 00000000 0000iiii
525 or eax, ebx; // 0000aaaa 00000000 0000iiii 0000iiii
526 shl ebx, 16; // 00000000 0000iiii 00000000 00000000
527 or eax, ebx; // 0000aaaa 0000iiii 0000iiii 0000iiii
529 shl ebx, 4; // aaaa0000 iiii0000 iiii0000 iiii0000
530 or eax, ebx; // aaaaaaaa iiiiiiii iiiiiiii iiiiiiii
532 mov dword ptr [edi], eax;
536 and eax, 0x00f00000; // 00000000 aaaa0000 00000000 00000000
538 shl eax, 4; // 0000aaaa 00000000 00000000 00000000
539 and ebx, 0x000f0000; // 00000000 0000iiii 00000000 00000000
540 or eax, ebx; // 0000aaaa 0000iiii 00000000 00000000
541 shr ebx, 8; // 00000000 00000000 0000iiii 00000000
542 or eax, ebx; // 0000aaaa 0000iiii 0000iiii 00000000
543 shr ebx, 8; // 00000000 00000000 00000000 0000iiii
544 or eax, ebx; // 0000aaaa 0000iiii 0000iiii 0000iiii
546 shl ebx, 4; // aaaa0000 iiii0000 iiii0000 iiii0000
547 or eax, ebx; // aaaaaaaa iiiiiiii iiiiiiii iiiiiiii
549 mov dword ptr [edi], eax;
553 and eax, 0xf0000000; // aaaa0000 00000000 00000000 00000000
555 and ebx, 0x0f000000; // 0000iiii 00000000 00000000 00000000
556 shr ebx, 4; // 00000000 iiii0000 00000000 00000000
557 or eax, ebx; // aaaa0000 iiii0000 00000000 00000000
558 shr ebx, 8; // 00000000 00000000 iiii0000 00000000
559 or eax, ebx; // aaaa0000 iiii0000 iiii0000 00000000
560 shr ebx, 8; // 00000000 00000000 00000000 iiii0000
561 or eax, ebx; // aaaa0000 iiii0000 iiii0000 iiii0000
563 shr ebx, 4; // 0000aaaa 0000iiii 0000iiii 0000iiii
564 or eax, ebx; // aaaaaaaa iiiiiiii iiiiiiii iiiiiiii
566 mov dword ptr [edi], eax;
580 TxQuantize::AI88_ARGB8888(uint32* src, uint32* dest, int width, int height)
583 int siz = (width * height) >> 1;
585 for (i = 0; i < siz; i++) {
586 *dest = (*src & 0x000000ff);
587 *dest |= ((*dest << 8) | (*dest << 16));
588 *dest |= ((*src & 0x0000ff00) << 16);
590 *dest = (*src & 0x00ff0000);
591 *dest |= ((*dest >> 8) | (*dest >> 16));
592 *dest |= (*src & 0xff000000);
597 int siz = (width * height) >> 1;
604 mov esi, dword ptr [src];
605 mov edi, dword ptr [dest];
606 mov ecx, dword ptr [siz];
609 mov eax, dword ptr [esi];
613 // aaaaaaaa iiiiiiii iiiiiiii iiiiiiii
615 and eax, 0x0000ffff; // 00000000 00000000 aaaaaaaa iiiiiiii
616 mov ebx, eax; // 00000000 00000000 aaaaaaaa iiiiiiii
617 shl eax, 16; // aaaaaaaa iiiiiiii 00000000 00000000
618 and ebx, 0x000000ff; // 00000000 00000000 00000000 iiiiiiii
619 or eax, ebx; // aaaaaaaa iiiiiiii 00000000 iiiiiiii
620 shl ebx, 8; // 00000000 00000000 iiiiiiii 00000000
621 or eax, ebx; // aaaaaaaa iiiiiiii iiiiiiii iiiiiiii
623 mov dword ptr [edi], eax;
627 and eax, 0xffff0000; // aaaaaaaa iiiiiiii 00000000 00000000
628 mov ebx, eax; // aaaaaaaa iiiiiiii 00000000 00000000
629 and ebx, 0x00ff0000; // 00000000 iiiiiiii 00000000 00000000
630 shr ebx, 8; // 00000000 00000000 iiiiiiii 00000000
631 or eax, ebx; // aaaaaaaa iiiiiiii iiiiiiii 00000000
632 shr ebx, 8; // 00000000 00000000 00000000 iiiiiiii
633 or eax, ebx; // aaaaaaaa iiiiiiii iiiiiiii iiiiiiii
635 mov dword ptr [edi], eax;
649 TxQuantize::ARGB8888_ARGB1555(uint32* src, uint32* dest, int width, int height)
652 int siz = (width * height) >> 1;
654 for (i = 0; i < siz; i++) {
655 *dest = ((*src & 0xff000000) ? 0x00008000 : 0x00000000);
656 *dest |= (((*src & 0x00f80000) >> 9) |
657 ((*src & 0x0000f800) >> 6) |
658 ((*src & 0x000000f8) >> 3));
660 *dest |= ((*src & 0xff000000) ? 0x80000000 : 0x00000000);
661 *dest |= (((*src & 0x00f80000) << 7) |
662 ((*src & 0x0000f800) << 10) |
663 ((*src & 0x000000f8) << 13));
668 int siz = (width * height) >> 1;
675 mov esi, dword ptr [src];
676 mov edi, dword ptr [dest];
677 mov ecx, dword ptr [siz];
680 mov eax, dword ptr [esi];
685 and eax, 0xff000000; // aaaa0000 00000000 00000000 00000000
687 mov eax, 0x00008000; // 00000000 00000000 a0000000 00000000
691 and ebx, 0x00f80000; // 00000000 rrrrr000 00000000 00000000
692 shr ebx, 9; // 00000000 00000000 0rrrrr00 00000000
693 or eax, ebx; // 00000000 00000000 arrrrr00 00000000
695 and ebx, 0x0000f800; // 00000000 00000000 ggggg000 00000000
696 shr ebx, 6; // 00000000 00000000 000000gg ggg00000
697 or eax, ebx; // 00000000 00000000 arrrrrgg ggg00000
698 and edx, 0x000000f8; // 00000000 00000000 00000000 bbbbb000
699 shr edx, 3; // 00000000 00000000 00000000 000bbbbb
700 or edx, eax; // 00000000 00000000 arrrrrgg gggbbbbb
702 mov eax, dword ptr [esi];
706 and eax, 0xff000000; // aaaa0000 00000000 00000000 00000000
708 or edx, 0x80000000; // a0000000 00000000 arrrrrgg gggbbbbb
712 and ebx, 0x00f80000; // 00000000 rrrrr000 00000000 00000000
713 shl ebx, 7; // 0rrrrr00 00000000 00000000 00000000
714 or edx, ebx; // arrrrr00 00000000 arrrrrgg gggbbbbb
716 and ebx, 0x0000f800; // 00000000 00000000 ggggg000 00000000
717 shl ebx, 10; // 000000gg ggg00000 00000000 00000000
718 or edx, ebx; // arrrrrgg ggg00000 arrrrrgg gggbbbbb
719 and eax, 0x000000f8; // 00000000 00000000 00000000 bbbbb000
720 shl eax, 13; // 00000000 000bbbbb 00000000 00000000
721 or edx, eax; // arrrrrgg gggbbbbb arrrrrgg gggbbbbb
723 mov dword ptr [edi], edx;
727 and edx, 0x01000000; // 0000000a 00000000 00000000 00000000
728 shr edx, 9; // 00000000 00000000 a0000000 00000000
730 and ebx, 0x00f80000; // 00000000 rrrrr000 00000000 00000000
731 shr ebx, 9; // 00000000 00000000 0rrrrr00 00000000
732 or edx, ebx; // 00000000 00000000 arrrrr00 00000000
734 and ebx, 0x0000f800; // 00000000 00000000 ggggg000 00000000
735 shr ebx, 6; // 00000000 00000000 000000gg ggg00000
736 or edx, ebx; // 00000000 00000000 arrrrrgg ggg00000
737 and eax, 0x000000f8; // 00000000 00000000 00000000 bbbbb000
738 shr eax, 3; // 00000000 00000000 00000000 000bbbbb
739 or edx, eax; // 00000000 00000000 arrrrrgg gggbbbbb
741 mov eax, dword ptr [esi];
745 and ebx, 0x80000000; // a0000000 00000000 00000000 00000000
746 or edx, ebx; // a0000000 00000000 arrrrrgg gggbbbbb
748 and ebx, 0x00f80000; // 00000000 rrrrr000 00000000 00000000
749 shl ebx, 7; // 0rrrrr00 00000000 00000000 00000000
750 or edx, ebx; // arrrrr00 00000000 arrrrrgg gggbbbbb
752 and ebx, 0x0000f800; // 00000000 00000000 ggggg000 00000000
753 shl ebx, 10; // 000000gg ggg00000 00000000 00000000
754 or edx, ebx; // arrrrrgg ggg00000 arrrrrgg gggbbbbb
755 and eax, 0x000000f8; // 00000000 00000000 00000000 bbbbb000
756 shl eax, 13; // 00000000 000bbbbb 00000000 00000000
757 or edx, eax; // arrrrrgg gggbbbbb arrrrrgg gggbbbbb
759 mov dword ptr [edi], edx;
773 TxQuantize::ARGB8888_ARGB4444(uint32* src, uint32* dest, int width, int height)
776 int siz = (width * height) >> 1;
778 for (i = 0; i < siz; i++) {
779 *dest = (((*src & 0xf0000000) >> 16) |
780 ((*src & 0x00f00000) >> 12) |
781 ((*src & 0x0000f000) >> 8) |
782 ((*src & 0x000000f0) >> 4));
784 *dest |= ((*src & 0xf0000000) |
785 ((*src & 0x00f00000) << 4) |
786 ((*src & 0x0000f000) << 8) |
787 ((*src & 0x000000f0) << 12));
792 int siz = (width * height) >> 1;
799 mov esi, dword ptr [src];
800 mov edi, dword ptr [dest];
801 mov ecx, dword ptr [siz];
804 mov eax, dword ptr [esi];
808 and edx, 0xf0000000; // aaaa0000 00000000 00000000 00000000
809 shr edx, 16; // 00000000 00000000 aaaa0000 00000000
811 and ebx, 0x00f00000; // 00000000 rrrr0000 00000000 00000000
812 shr ebx, 12; // 00000000 00000000 0000rrrr 00000000
813 or edx, ebx; // 00000000 00000000 aaaarrrr 00000000
815 and ebx, 0x0000f000; // 00000000 00000000 gggg0000 00000000
816 shr ebx, 8; // 00000000 00000000 00000000 gggg0000
817 or edx, ebx; // 00000000 00000000 aaaarrrr gggg0000
818 and eax, 0x000000f0; // 00000000 00000000 00000000 bbbb0000
819 shr eax, 4; // 00000000 00000000 00000000 0000bbbb
820 or edx, eax; // 00000000 00000000 aaaarrrr ggggbbbb
822 mov eax, dword ptr [esi];
826 and ebx, 0xf0000000; // aaaa0000 00000000 00000000 00000000
827 or edx, ebx; // aaaa0000 00000000 aaaarrrr ggggbbbb
829 and ebx, 0x00f00000; // 00000000 rrrr0000 00000000 00000000
830 shl ebx, 4; // 0000rrrr 00000000 00000000 00000000
831 or edx, ebx; // aaaarrrr 00000000 aaaarrrr ggggbbbb
833 and ebx, 0x0000f000; // 00000000 00000000 gggg0000 00000000
834 shl ebx, 8; // 00000000 gggg0000 00000000 00000000
835 or edx, ebx; // aaaarrrr gggg0000 aaaarrrr ggggbbbb
836 and eax, 0x000000f0; // 00000000 00000000 00000000 bbbb0000
837 shl eax, 12; // 00000000 0000bbbb 00000000 00000000
838 or edx, eax; // arrrrrgg ggggbbbb aaaarrrr ggggbbbb
840 mov dword ptr [edi], edx;
854 TxQuantize::ARGB8888_RGB565(uint32* src, uint32* dest, int width, int height)
857 int siz = (width * height) >> 1;
859 for (i = 0; i < siz; i++) {
860 *dest = (((*src & 0x000000f8) >> 3) |
861 ((*src & 0x0000fc00) >> 5) |
862 ((*src & 0x00f80000) >> 8));
864 *dest |= (((*src & 0x000000f8) << 13) |
865 ((*src & 0x0000fc00) << 11) |
866 ((*src & 0x00f80000) << 8));
871 int siz = (width * height) >> 1;
878 mov esi, dword ptr [src];
879 mov edi, dword ptr [dest];
880 mov ecx, dword ptr [siz];
883 mov eax, dword ptr [esi];
887 and edx, 0x000000F8; // 00000000 00000000 00000000 bbbbb000
888 shr edx, 3; // 00000000 00000000 00000000 000bbbbb
890 and ebx, 0x0000FC00; // 00000000 00000000 gggggg00 00000000
891 shr ebx, 5; // 00000000 00000000 00000ggg ggg00000
892 or edx, ebx; // 00000000 00000000 00000ggg gggbbbbb
894 and ebx, 0x00F80000; // 00000000 rrrrr000 00000000 00000000
895 shr ebx, 8; // 00000000 00000000 rrrrr000 00000000
896 or edx, ebx; // 00000000 00000000 rrrrrggg gggbbbbb
898 mov eax, dword ptr [esi];
902 and ebx, 0x000000F8; // 00000000 00000000 00000000 bbbbb000
903 shl ebx, 13; // 00000000 000bbbbb 00000000 00000000
904 or edx, ebx; // 00000000 000bbbbb rrrrrggg gggbbbbb
906 and ebx, 0x0000FC00; // 00000000 00000000 gggggg00 00000000
907 shl ebx, 11; // 00000ggg ggg00000 00000000 00000000
908 or edx, ebx; // 00000ggg gggbbbbb rrrrrggg gggbbbbb
910 and ebx, 0x00F80000; // 00000000 rrrrr000 00000000 00000000
911 shl ebx, 8; // rrrrr000 00000000 00000000 00000000
912 or edx, ebx; // rrrrrggg gggbbbbb rrrrrggg gggbbbbb
914 mov dword ptr [edi], edx;
928 TxQuantize::ARGB8888_A8(uint32* src, uint32* dest, int width, int height)
931 int siz = (width * height) >> 2;
933 for (i = 0; i < siz; i++) {
934 *dest = (*src & 0x0000ff00) >> 8;
936 *dest |= (*src & 0x0000ff00);
938 *dest |= ((*src & 0x0000ff00) << 8);
940 *dest |= ((*src & 0x0000ff00) << 16);
945 int siz = (width * height) >> 2;
952 mov esi, dword ptr [src];
953 mov edi, dword ptr [dest];
954 mov ecx, dword ptr [siz];
957 mov eax, dword ptr [esi];
961 mov edx, eax; // we'll use A comp for every pixel
962 and edx, 0xFF000000; // aaaaaaaa 00000000 00000000 00000000
963 shr edx, 24; // 00000000 00000000 00000000 aaaaaaaa
965 mov eax, dword ptr [esi];
968 and eax, 0xFF000000; // aaaaaaaa 00000000 00000000 00000000
969 shr eax, 16; // 00000000 00000000 aaaaaaaa 00000000
970 or edx, eax; // 00000000 00000000 aaaaaaaa aaaaaaaa
972 mov eax, dword ptr [esi];
975 and eax, 0xFF000000; // aaaaaaaa 00000000 00000000 00000000
976 shr eax, 8; // 00000000 aaaaaaaa 00000000 00000000
977 or edx, eax; // 00000000 aaaaaaaa aaaaaaaa aaaaaaaa
979 mov eax, dword ptr [esi];
982 and eax, 0xFF000000; // aaaaaaaa 00000000 00000000 00000000
983 or edx, eax; // aaaaaaaa aaaaaaaa aaaaaaaa aaaaaaaa
987 mov edx, eax; // we'll use G comp for every pixel
988 and edx, 0x0000FF00; // 00000000 00000000 aaaaaaaa 00000000
989 shr edx, 8; // 00000000 00000000 00000000 aaaaaaaa
991 mov eax, dword ptr [esi];
994 and eax, 0x0000FF00; // 00000000 00000000 aaaaaaaa 00000000
995 or edx, eax; // 00000000 00000000 aaaaaaaa aaaaaaaa
997 mov eax, dword ptr [esi];
1000 and eax, 0x0000FF00; // 00000000 00000000 aaaaaaaa 00000000
1001 shl eax, 8; // 00000000 aaaaaaaa 00000000 00000000
1002 or edx, eax; // 00000000 aaaaaaaa aaaaaaaa aaaaaaaa
1004 mov eax, dword ptr [esi];
1007 and eax, 0x0000FF00; // 00000000 00000000 aaaaaaaa 00000000
1008 shl eax, 16; // aaaaaaaa 00000000 00000000 00000000
1009 or edx, eax; // aaaaaaaa aaaaaaaa aaaaaaaa aaaaaaaa
1014 and edx, 0x000000FF; // 00000000 00000000 00000000 aaaaaaaa
1016 mov eax, dword ptr [esi];
1019 and eax, 0x0000FF00; // 00000000 00000000 aaaaaaaa 00000000
1020 or edx, eax; // 00000000 00000000 aaaaaaaa aaaaaaaa
1022 mov eax, dword ptr [esi];
1025 and eax, 0x00FF0000; // 00000000 aaaaaaaa 00000000 00000000
1026 or edx, eax; // 00000000 aaaaaaaa aaaaaaaa aaaaaaaa
1028 mov eax, dword ptr [esi];
1031 and eax, 0xFF000000; // aaaaaaaa 00000000 00000000 00000000
1032 or edx, eax; // aaaaaaaa aaaaaaaa aaaaaaaa aaaaaaaa
1034 mov dword ptr [edi], edx;
1048 TxQuantize::ARGB8888_AI44(uint32* src, uint32* dest, int width, int height)
1051 int siz = (width * height) >> 2;
1053 for (i = 0; i < siz; i++) {
1054 *dest = (((*src & 0xf0000000) >> 24) | ((*src & 0x0000f000) >> 12));
1056 *dest |= (((*src & 0xf0000000) >> 16) | ((*src & 0x0000f000) >> 4));
1058 *dest |= (((*src & 0xf0000000) >> 8) | ((*src & 0x0000f000) << 4));
1060 *dest |= ((*src & 0xf0000000) | ((*src & 0x0000f000) << 12));
1065 int siz = (width * height) >> 2;
1072 mov esi, dword ptr [src];
1073 mov edi, dword ptr [dest];
1074 mov ecx, dword ptr [siz];
1077 mov eax, dword ptr [esi];
1080 mov edx, eax; // use A and G comps MSB
1081 and edx, 0xF0000000; // aaaa0000 00000000 00000000 00000000
1083 shr edx, 24; // 00000000 00000000 00000000 aaaa0000
1084 and ebx, 0x0000F000; // 00000000 00000000 iiii0000 00000000
1085 shr ebx, 12; // 00000000 00000000 00000000 0000iiii
1086 or edx, ebx; // 00000000 00000000 00000000 aaaaiiii
1088 mov eax, dword ptr [esi];
1092 and eax, 0xF0000000; // aaaa0000 00000000 00000000 00000000
1093 shr eax, 16; // 00000000 00000000 aaaa0000 00000000
1094 and ebx, 0x0000F000; // 00000000 00000000 iiii0000 00000000
1095 shr ebx, 4; // 00000000 00000000 0000iiii 00000000
1096 or eax, ebx; // 00000000 00000000 aaaaiiii 00000000
1097 or edx, eax; // 00000000 00000000 aaaaiiii aaaaiiii
1099 mov eax, dword ptr [esi];
1103 and eax, 0xF0000000; // aaaa0000 00000000 00000000 00000000
1104 shr eax, 8; // 00000000 aaaa0000 00000000 00000000
1105 and ebx, 0x0000F000; // 00000000 00000000 iiii0000 00000000
1106 shl ebx, 4; // 00000000 0000iiii 00000000 00000000
1107 or eax, ebx; // 00000000 aaaaiiii 00000000 00000000
1108 or edx, eax; // 00000000 aaaaiiii aaaaiiii aaaaiiii
1110 mov eax, dword ptr [esi];
1114 and eax, 0xF0000000; // aaaa0000 00000000 00000000 00000000
1115 and ebx, 0x0000F000; // 00000000 00000000 iiii0000 00000000
1116 shl ebx, 12; // 0000iiii 00000000 00000000 00000000
1117 or eax, ebx; // aaaaiiii 00000000 00000000 00000000
1118 or edx, eax; // aaaaiiii aaaaiiii aaaaiiii aaaaiiii
1120 mov dword ptr [edi], edx;
1134 TxQuantize::ARGB8888_AI88(uint32* src, uint32* dest, int width, int height)
1137 int siz = (width * height) >> 1;
1139 for (i = 0; i < siz; i++) {
1140 *dest = (((*src & 0xff000000) >> 16) | ((*src & 0x0000ff00) >> 8));
1142 *dest |= ((*src & 0xff000000) | ((*src & 0x0000ff00) << 8));
1147 int siz = (width * height) >> 1;
1154 mov esi, dword ptr [src];
1155 mov edi, dword ptr [dest];
1156 mov ecx, dword ptr [siz];
1159 mov eax, dword ptr [esi];
1163 and edx, 0xFF000000; // aaaaaaaa 00000000 00000000 00000000
1165 shr edx, 16; // 00000000 00000000 aaaaaaaa 00000000
1166 and ebx, 0x0000FF00; // 00000000 00000000 iiiiiiii 00000000
1167 shr ebx, 8; // 00000000 00000000 00000000 iiiiiiii
1168 or edx, ebx; // 00000000 00000000 aaaaaaaa iiiiiiii
1170 mov eax, dword ptr [esi];
1174 and eax, 0xFF000000; // aaaaaaaa 00000000 00000000 00000000
1175 and ebx, 0x0000FF00; // 00000000 00000000 iiiiiiii 00000000
1176 shl ebx, 8; // 00000000 iiiiiiii 00000000 00000000
1177 or eax, ebx; // aaaaaaaa iiiiiiii 00000000 00000000
1178 or edx, eax; // aaaaaaaa iiiiiiii aaaaaaaa iiiiiiii
1180 mov dword ptr [edi], edx;
1193 /* R.W. Floyd and L. Steinberg, An adaptive algorithm
1194 * for spatial grey scale, Proceedings of the Society
1195 * of Information Display 17, pp75-77, 1976
1198 TxQuantize::ARGB8888_RGB565_ErrD(uint32* src, uint32* dst, int width, int height)
1200 /* Floyd-Steinberg error-diffusion halftoning */
1203 int qr, qg, qb; /* quantized incoming values */
1204 int ir, ig, ib; /* incoming values */
1206 int *errR = new int[width];
1207 int *errG = new int[width];
1208 int *errB = new int[width];
1210 uint16 *dest = (uint16 *)dst;
1212 for (i = 0; i < width; i++) errR[i] = errG[i] = errB[i] = 0;
1214 for (y = 0; y < height; y++) {
1216 for (x = 0; x < width; x++) {
1217 /* incoming pixel values */
1218 ir = ((*src >> 16) & 0xFF) * 10000;
1219 ig = ((*src >> 8) & 0xFF) * 10000;
1220 ib = ((*src ) & 0xFF) * 10000;
1222 /* quantize pixel values.
1223 * qr * 0.4375 is the error from the pixel to the left,
1224 * errR is the error from the pixel to the top, top left, and top right */
1225 /* qr * 0.4375 is the error distribution to the EAST in
1226 * the previous loop */
1227 ir += errR[x] + qr * 4375 / 10000;
1228 ig += errG[x] + qg * 4375 / 10000;
1229 ib += errB[x] + qb * 4375 / 10000;
1231 /* error distribution to the SOUTH-EAST in the previous loop
1232 * can't calculate in the previous loop because it steps on
1233 * the above quantization */
1234 errR[x] = qr * 625 / 10000;
1235 errG[x] = qg * 625 / 10000;
1236 errB[x] = qb * 625 / 10000;
1243 if (qr < 0) qr = 0; else if (qr > 2550000) qr = 2550000;
1244 if (qg < 0) qg = 0; else if (qg > 2550000) qg = 2550000;
1245 if (qb < 0) qb = 0; else if (qb > 2550000) qb = 2550000;
1247 /* convert to RGB565 */
1248 qr = qr * 0x1F / 2550000;
1249 qg = qg * 0x3F / 2550000;
1250 qb = qb * 0x1F / 2550000;
1252 /* this is the dithered pixel */
1253 t = (qr << 11) | (qg << 5) | qb;
1255 /* compute the errors */
1256 qr = ((qr << 3) | (qr >> 2)) * 10000;
1257 qg = ((qg << 2) | (qg >> 4)) * 10000;
1258 qb = ((qb << 3) | (qb >> 2)) * 10000;
1263 /* compute the error distributions */
1264 /* Floyd-Steinberg filter
1265 * 7/16 (=0.4375) to the EAST
1266 * 5/16 (=0.3125) to the SOUTH
1267 * 1/16 (=0.0625) to the SOUTH-EAST
1268 * 3/16 (=0.1875) to the SOUTH-WEST
1275 errR[x - 1] += qr * 1875 / 10000;
1276 errG[x - 1] += qg * 1875 / 10000;
1277 errB[x - 1] += qb * 1875 / 10000;
1281 errR[x] += qr * 3125 / 10000;
1282 errG[x] += qg * 3125 / 10000;
1283 errB[x] += qb * 3125 / 10000;
1285 *dest = (t & 0xFFFF);
1299 TxQuantize::ARGB8888_ARGB1555_ErrD(uint32* src, uint32* dst, int width, int height)
1301 /* Floyd-Steinberg error-diffusion halftoning */
1304 int qr, qg, qb; /* quantized incoming values */
1305 int ir, ig, ib; /* incoming values */
1307 int *errR = new int[width];
1308 int *errG = new int[width];
1309 int *errB = new int[width];
1311 uint16 *dest = (uint16 *)dst;
1313 for (i = 0; i < width; i++) errR[i] = errG[i] = errB[i] = 0;
1315 for (y = 0; y < height; y++) {
1317 for (x = 0; x < width; x++) {
1318 /* incoming pixel values */
1319 ir = ((*src >> 16) & 0xFF) * 10000;
1320 ig = ((*src >> 8) & 0xFF) * 10000;
1321 ib = ((*src ) & 0xFF) * 10000;
1323 /* quantize pixel values.
1324 * qr * 0.4375 is the error from the pixel to the left,
1325 * errR is the error from the pixel to the top, top left, and top right */
1326 /* qr * 0.4375 is the error distribution to the EAST in
1327 * the previous loop */
1328 ir += errR[x] + qr * 4375 / 10000;
1329 ig += errG[x] + qg * 4375 / 10000;
1330 ib += errB[x] + qb * 4375 / 10000;
1332 /* error distribution to the SOUTH-EAST of the previous loop.
1333 * cannot calculate in the previous loop because it steps on
1334 * the above quantization */
1335 errR[x] = qr * 625 / 10000;
1336 errG[x] = qg * 625 / 10000;
1337 errB[x] = qb * 625 / 10000;
1344 if (qr < 0) qr = 0; else if (qr > 2550000) qr = 2550000;
1345 if (qg < 0) qg = 0; else if (qg > 2550000) qg = 2550000;
1346 if (qb < 0) qb = 0; else if (qb > 2550000) qb = 2550000;
1348 /* convert to RGB555 */
1349 qr = qr * 0x1F / 2550000;
1350 qg = qg * 0x1F / 2550000;
1351 qb = qb * 0x1F / 2550000;
1353 /* this is the dithered pixel */
1354 t = (qr << 10) | (qg << 5) | qb;
1355 t |= ((*src >> 24) ? 0x8000 : 0);
1357 /* compute the errors */
1358 qr = ((qr << 3) | (qr >> 2)) * 10000;
1359 qg = ((qg << 3) | (qg >> 2)) * 10000;
1360 qb = ((qb << 3) | (qb >> 2)) * 10000;
1365 /* compute the error distributions */
1366 /* Floyd-Steinberg filter
1367 * 7/16 (=0.4375) to the EAST
1368 * 5/16 (=0.3125) to the SOUTH
1369 * 1/16 (=0.0625) to the SOUTH-EAST
1370 * 3/16 (=0.1875) to the SOUTH-WEST
1377 errR[x - 1] += qr * 1875 / 10000;
1378 errG[x - 1] += qg * 1875 / 10000;
1379 errB[x - 1] += qb * 1875 / 10000;
1383 errR[x] += qr * 3125 / 10000;
1384 errG[x] += qg * 3125 / 10000;
1385 errB[x] += qb * 3125 / 10000;
1387 *dest = (t & 0xFFFF);
1400 TxQuantize::ARGB8888_ARGB4444_ErrD(uint32* src, uint32* dst, int width, int height)
1402 /* Floyd-Steinberg error-diffusion halftoning */
1404 /* NOTE: alpha dithering looks better for alpha gradients, but are prone
1405 * to producing noisy speckles for constant or step level alpha. Output
1406 * results should always be checked.
1408 boolean ditherAlpha = 0;
1411 int qr, qg, qb, qa; /* quantized incoming values */
1412 int ir, ig, ib, ia; /* incoming values */
1414 int *errR = new int[width];
1415 int *errG = new int[width];
1416 int *errB = new int[width];
1417 int *errA = new int[width];
1419 uint16 *dest = (uint16 *)dst;
1421 for (i = 0; i < width; i++) errR[i] = errG[i] = errB[i] = errA[i] = 0;
1423 for (y = 0; y < height; y++) {
1424 qr = qg = qb = qa = 0;
1425 for (x = 0; x < width; x++) {
1426 /* incoming pixel values */
1427 ir = ((*src >> 16) & 0xFF) * 10000;
1428 ig = ((*src >> 8) & 0xFF) * 10000;
1429 ib = ((*src ) & 0xFF) * 10000;
1430 ia = ((*src >> 24) & 0xFF) * 10000;
1432 /* quantize pixel values.
1433 * qr * 0.4375 is the error from the pixel to the left,
1434 * errR is the error from the pixel to the top, top left, and top right */
1435 /* qr * 0.4375 is the error distribution to the EAST in
1436 * the previous loop */
1437 ir += errR[x] + qr * 4375 / 10000;
1438 ig += errG[x] + qg * 4375 / 10000;
1439 ib += errB[x] + qb * 4375 / 10000;
1440 ia += errA[x] + qa * 4375 / 10000;
1442 /* error distribution to the SOUTH-EAST of the previous loop.
1443 * cannot calculate in the previous loop because it steps on
1444 * the above quantization */
1445 errR[x] = qr * 625 / 10000;
1446 errG[x] = qg * 625 / 10000;
1447 errB[x] = qb * 625 / 10000;
1448 errA[x] = qa * 625 / 10000;
1456 if (qr < 0) qr = 0; else if (qr > 2550000) qr = 2550000;
1457 if (qg < 0) qg = 0; else if (qg > 2550000) qg = 2550000;
1458 if (qb < 0) qb = 0; else if (qb > 2550000) qb = 2550000;
1459 if (qa < 0) qa = 0; else if (qa > 2550000) qa = 2550000;
1461 /* convert to RGB444 */
1462 qr = qr * 0xF / 2550000;
1463 qg = qg * 0xF / 2550000;
1464 qb = qb * 0xF / 2550000;
1465 qa = qa * 0xF / 2550000;
1467 /* this is the value to be returned */
1469 t = (qa << 12) | (qr << 8) | (qg << 4) | qb;
1471 t = (qr << 8) | (qg << 4) | qb;
1472 t |= (*src >> 16) & 0xF000;
1475 /* compute the errors */
1476 qr = ((qr << 4) | qr) * 10000;
1477 qg = ((qg << 4) | qg) * 10000;
1478 qb = ((qb << 4) | qb) * 10000;
1479 qa = ((qa << 4) | qa) * 10000;
1485 /* compute the error distributions */
1486 /* Floyd-Steinberg filter
1487 * 7/16 (=0.4375) to the EAST
1488 * 5/16 (=0.3125) to the SOUTH
1489 * 1/16 (=0.0625) to the SOUTH-EAST
1490 * 3/16 (=0.1875) to the SOUTH-WEST
1497 errR[x - 1] += qr * 1875 / 10000;
1498 errG[x - 1] += qg * 1875 / 10000;
1499 errB[x - 1] += qb * 1875 / 10000;
1500 errA[x - 1] += qa * 1875 / 10000;
1504 errR[x] += qr * 3125 / 10000;
1505 errG[x] += qg * 3125 / 10000;
1506 errB[x] += qb * 3125 / 10000;
1507 errA[x] += qa * 3125 / 10000;
1509 *dest = (t & 0xFFFF);
1523 TxQuantize::ARGB8888_AI44_ErrD(uint32* src, uint32* dst, int width, int height)
1525 /* Floyd-Steinberg error-diffusion halftoning */
1527 /* NOTE: alpha dithering looks better for alpha gradients, but are prone
1528 * to producing noisy speckles for constant or step level alpha. Output
1529 * results should always be checked.
1531 boolean ditherAlpha = 0;
1534 int qi, qa; /* quantized incoming values */
1535 int ii, ia; /* incoming values */
1537 int *errI = new int[width];
1538 int *errA = new int[width];
1540 uint8 *dest = (uint8 *)dst;
1542 for (i = 0; i < width; i++) errI[i] = errA[i] = 0;
1544 for (y = 0; y < height; y++) {
1546 for (x = 0; x < width; x++) {
1547 /* 3dfx style Intensity = R * 0.299 + G * 0.587 + B * 0.114 */
1548 ii = ((*src >> 16) & 0xFF) * 2990 +
1549 ((*src >> 8) & 0xFF) * 5870 +
1550 ((*src ) & 0xFF) * 1140;
1551 ia = ((*src >> 24) & 0xFF) * 10000;
1553 /* quantize pixel values.
1554 * qi * 0.4375 is the error from the pixel to the left,
1555 * errI is the error from the pixel to the top, top left, and top right */
1556 /* qi * 0.4375 is the error distrtibution to the EAST in
1557 * the previous loop */
1558 ii += errI[x] + qi * 4375 / 10000;
1559 ia += errA[x] + qa * 4375 / 10000;
1561 /* error distribution to the SOUTH-EAST in the previous loop.
1562 * cannot calculate in the previous loop because it steps on
1563 * the above quantization */
1564 errI[x] = qi * 625 / 10000;
1565 errA[x] = qa * 625 / 10000;
1571 if (qi < 0) qi = 0; else if (qi > 2550000) qi = 2550000;
1572 if (qa < 0) qa = 0; else if (qa > 2550000) qa = 2550000;
1575 qi = qi * 0xF / 2550000;
1576 qa = qa * 0xF / 2550000;
1578 /* this is the value to be returned */
1583 t |= ((*src >> 24) & 0xF0);
1586 /* compute the errors */
1587 qi = ((qi << 4) | qi) * 10000;
1588 qa = ((qa << 4) | qa) * 10000;
1592 /* compute the error distributions */
1593 /* Floyd-Steinberg filter
1594 * 7/16 (=0.4375) to the EAST
1595 * 5/16 (=0.3125) to the SOUTH
1596 * 1/16 (=0.0625) to the SOUTH-EAST
1597 * 3/16 (=0.1875) to the SOUTH-WEST
1604 errI[x - 1] += qi * 1875 / 10000;
1605 errA[x - 1] += qa * 1875 / 10000;
1609 errI[x] += qi * 3125 / 10000;
1610 errA[x] += qa * 3125 / 10000;
1624 TxQuantize::ARGB8888_AI88_Slow(uint32* src, uint32* dst, int width, int height)
1627 uint16 *dest = (uint16 *)dst;
1628 for (y = 0; y < height; y++) {
1629 for (x = 0; x < width; x++) {
1631 /* libpng style grayscale conversion.
1632 * Reduce RGB files to grayscale with or without alpha
1633 * using the equation given in Poynton's ColorFAQ at
1634 * <http://www.inforamp.net/~poynton/>
1635 * Copyright (c) 1998-01-04 Charles Poynton poynton at inforamp.net
1637 * Y = 0.212671 * R + 0.715160 * G + 0.072169 * B
1639 * We approximate this with
1641 * Y = 0.21268 * R + 0.7151 * G + 0.07217 * B
1643 * which can be expressed with integers as
1645 * Y = (6969 * R + 23434 * G + 2365 * B)/32768
1647 * The calculation is to be done in a linear colorspace.
1649 *dest = (((int)((((*src >> 16) & 0xFF) * 6969 +
1650 ((*src >> 8) & 0xFF) * 23434 +
1651 ((*src ) & 0xFF) * 2365) / 32768) & 0xFF) |
1652 (uint16)((*src >> 16) & 0xFF00));
1654 /* 3dfx style Intensity = R * 0.299 + G * 0.587 + B * 0.114
1655 * this is same as the standard NTSC gray scale conversion. */
1656 *dest = (((int)((((*src >> 16) & 0xFF) * 299 +
1657 ((*src >> 8) & 0xFF) * 587 +
1658 ((*src ) & 0xFF) * 114) / 1000) & 0xFF) |
1659 (uint16)((*src >> 16) & 0xFF00));
1668 TxQuantize::ARGB8888_I8_Slow(uint32* src, uint32* dst, int width, int height)
1671 uint8 *dest = (uint8 *)dst;
1672 for (y = 0; y < height; y++) {
1673 for (x = 0; x < width; x++) {
1675 /* libpng style Intensity = (6969 * R + 23434 * G + 2365 * B)/32768 */
1676 *dest = (int)((((*src >> 16) & 0xFF) * 6969 +
1677 ((*src >> 8) & 0xFF) * 23434 +
1678 ((*src ) & 0xFF) * 2365) / 32768) & 0xFF;
1680 /* 3dfx style Intensity = R * 0.299 + G * 0.587 + B * 0.114
1681 * this is same as the standard NTSC gray scale conversion. */
1682 *dest = (int)((((*src >>16) & 0xFF) * 299 +
1683 ((*src >> 8) & 0xFF) * 587 +
1684 ((*src ) & 0xFF) * 114) / 1000) & 0xFF;
1693 TxQuantize::P8_16BPP(uint32* src, uint32* dest, int width, int height, uint32* palette)
1695 /* passed in palette is RGBA5551 format */
1698 int size = width * height;
1699 for (i = 0; i < size; i++) {
1700 ((uint16*)dest)[i] = ((uint16*)palette)[(int)(((uint8*)src)[i])];
1701 ((uint16*)dest)[i] = ((((uint16*)dest)[i] << 15) | (((uint16*)dest)[i] >> 1));
1705 /* not finished yet... */
1707 int siz = (width * height) >> 2;
1714 mov esi, dword ptr [src];
1715 mov edi, dword ptr [dest];
1716 mov ecx, dword ptr [siz];
1717 mov edx, dword ptr [palette];
1720 mov eax, dword ptr [esi];
1734 TxQuantize::quantize(uint8* src, uint8* dest, int width, int height, uint16 srcformat, uint16 destformat, boolean fastQuantizer)
1736 typedef void (TxQuantize::*quantizerFunc)(uint32* src, uint32* dest, int width, int height);
1737 quantizerFunc quantizer;
1740 if (destformat == GR_TEXFMT_ARGB_8888) {
1741 switch (srcformat) {
1742 case GR_TEXFMT_ARGB_1555:
1743 quantizer = &TxQuantize::ARGB1555_ARGB8888;
1746 case GR_TEXFMT_ARGB_4444:
1747 quantizer = &TxQuantize::ARGB4444_ARGB8888;
1750 case GR_TEXFMT_RGB_565:
1751 quantizer = &TxQuantize::RGB565_ARGB8888;
1754 case GR_TEXFMT_ALPHA_8:
1755 quantizer = &TxQuantize::A8_ARGB8888;
1758 case GR_TEXFMT_ALPHA_INTENSITY_44:
1759 quantizer = &TxQuantize::AI44_ARGB8888;
1762 case GR_TEXFMT_ALPHA_INTENSITY_88:
1763 quantizer = &TxQuantize::AI88_ARGB8888;
1770 #if !defined(NO_FILTER_THREAD)
1771 unsigned int numcore = _numcore;
1772 unsigned int blkrow = 0;
1773 while (numcore > 1 && blkrow == 0) {
1774 blkrow = (height >> 2) / numcore;
1777 if (blkrow > 0 && numcore > 1) {
1778 std::thread *thrd[MAX_NUMCORE];
1780 int blkheight = blkrow << 2;
1781 unsigned int srcStride = (width * blkheight) << (2 - bpp_shift);
1782 unsigned int destStride = srcStride << bpp_shift;
1783 for (i = 0; i < numcore - 1; i++) {
1784 thrd[i] = new std::thread(std::bind(quantizer,
1793 thrd[i] = new std::thread(std::bind(quantizer,
1798 height - blkheight * i));
1799 for (i = 0; i < numcore; i++) {
1804 (*this.*quantizer)((uint32*)src, (uint32*)dest, width, height);
1807 (*this.*quantizer)((uint32*)src, (uint32*)dest, width, height);
1810 } else if (srcformat == GR_TEXFMT_ARGB_8888) {
1811 switch (destformat) {
1812 case GR_TEXFMT_ARGB_1555:
1813 quantizer = fastQuantizer ? &TxQuantize::ARGB8888_ARGB1555 : &TxQuantize::ARGB8888_ARGB1555_ErrD;
1816 case GR_TEXFMT_ARGB_4444:
1817 quantizer = fastQuantizer ? &TxQuantize::ARGB8888_ARGB4444 : &TxQuantize::ARGB8888_ARGB4444_ErrD;
1820 case GR_TEXFMT_RGB_565:
1821 quantizer = fastQuantizer ? &TxQuantize::ARGB8888_RGB565 : &TxQuantize::ARGB8888_RGB565_ErrD;
1824 case GR_TEXFMT_ALPHA_8:
1825 case GR_TEXFMT_INTENSITY_8:
1826 quantizer = fastQuantizer ? &TxQuantize::ARGB8888_A8 : &TxQuantize::ARGB8888_I8_Slow;
1829 case GR_TEXFMT_ALPHA_INTENSITY_44:
1830 quantizer = fastQuantizer ? &TxQuantize::ARGB8888_AI44 : &TxQuantize::ARGB8888_AI44_ErrD;
1833 case GR_TEXFMT_ALPHA_INTENSITY_88:
1834 quantizer = fastQuantizer ? &TxQuantize::ARGB8888_AI88 : &TxQuantize::ARGB8888_AI88_Slow;
1841 #if !defined(NO_FILTER_THREAD)
1842 unsigned int numcore = _numcore;
1843 unsigned int blkrow = 0;
1844 while (numcore > 1 && blkrow == 0) {
1845 blkrow = (height >> 2) / numcore;
1848 if (blkrow > 0 && numcore > 1) {
1849 std::thread *thrd[MAX_NUMCORE];
1851 int blkheight = blkrow << 2;
1852 unsigned int srcStride = (width * blkheight) << 2;
1853 unsigned int destStride = srcStride >> bpp_shift;
1854 for (i = 0; i < numcore - 1; i++) {
1855 thrd[i] = new std::thread(std::bind(quantizer,
1864 thrd[i] = new std::thread(std::bind(quantizer,
1869 height - blkheight * i));
1870 for (i = 0; i < numcore; i++) {
1875 (*this.*quantizer)((uint32*)src, (uint32*)dest, width, height);
1878 (*this.*quantizer)((uint32*)src, (uint32*)dest, width, height);
1889 TxQuantize::FXT1(uint8 *src, uint8 *dest,
1890 int srcwidth, int srcheight, uint16 srcformat,
1891 int *destwidth, int *destheight, uint16 *destformat)
1894 * NOTE: src must be in ARGB8888 format, srcformat describes
1895 * the closest 16bbp representation of src.
1897 * NOTE: I have modified the dxtn library to use ARGB format
1898 * which originaly was ABGR format.
1903 if (_tx_compress_fxt1 &&
1904 srcwidth >= 8 && srcheight >= 4) {
1906 * width and height must be larger than 8 and 4 respectively
1908 int dstRowStride = ((srcwidth + 7) & ~7) << 1;
1909 int srcRowStride = (srcwidth << 2);
1911 #if !defined(NO_FILTER_THREAD)
1912 unsigned int numcore = _numcore;
1913 unsigned int blkrow = 0;
1914 while (numcore > 1 && blkrow == 0) {
1915 blkrow = (srcheight >> 2) / numcore;
1918 if (blkrow > 0 && numcore > 1) {
1919 std::thread *thrd[MAX_NUMCORE];
1921 int blkheight = blkrow << 2;
1922 unsigned int srcStride = (srcwidth * blkheight) << 2;
1923 unsigned int destStride = dstRowStride * blkrow;
1924 for (i = 0; i < numcore - 1; i++) {
1925 thrd[i] = new std::thread(std::bind(_tx_compress_fxt1,
1936 thrd[i] = new std::thread(std::bind(_tx_compress_fxt1,
1938 srcheight - blkheight * i,
1944 for (i = 0; i < numcore; i++) {
1949 (*_tx_compress_fxt1)(srcwidth, /* width */
1950 srcheight, /* height */
1951 4, /* comps: ARGB8888=4, RGB888=3 */
1953 srcRowStride, /* width*comps */
1954 dest, /* destination */
1955 dstRowStride); /* 16 bytes per 8x4 texel */
1958 (*_tx_compress_fxt1)(srcwidth, /* width */
1959 srcheight, /* height */
1960 4, /* comps: ARGB8888=4, RGB888=3 */
1962 srcRowStride, /* width*comps */
1963 dest, /* destination */
1964 dstRowStride); /* 16 bytes per 8x4 texel */
1967 /* dxtn adjusts width and height to M8 and M4 respectively by replication */
1968 *destwidth = (srcwidth + 7) & ~7;
1969 *destheight = (srcheight + 3) & ~3;
1970 *destformat = GR_TEXFMT_ARGB_CMP_FXT1;
1979 TxQuantize::DXTn(uint8 *src, uint8 *dest,
1980 int srcwidth, int srcheight, uint16 srcformat,
1981 int *destwidth, int *destheight, uint16 *destformat)
1984 * NOTE: src must be in ARGB8888 format, srcformat describes
1985 * the closest 16bbp representation of src.
1987 * NOTE: I have modified the dxtn library to use ARGB format
1988 * which originaly was ABGR format.
1993 if (_tx_compress_dxtn &&
1994 srcwidth >= 4 && srcheight >= 4) {
1996 * width and height must be larger than 4
1999 /* skip formats that DXTn won't help in size. */
2000 if (srcformat == GR_TEXFMT_ALPHA_8 ||
2001 srcformat == GR_TEXFMT_ALPHA_INTENSITY_44) {
2002 ; /* shutup compiler */
2004 int dstRowStride = ((srcwidth + 3) & ~3) << 2;
2005 int compression = GL_COMPRESSED_RGBA_S3TC_DXT5_EXT;
2007 *destformat = GR_TEXFMT_ARGB_CMP_DXT5;
2010 /* okay... we are going to disable DXT1 with 1bit alpha
2011 * for Glide64. some textures have all 0 alpha values.
2012 * see "N64 Kobe Bryant in NBA Courtside"
2014 if (srcformat == GR_TEXFMT_ARGB_1555) {
2016 compression = GL_COMPRESSED_RGBA_S3TC_DXT1_EXT;
2017 *destformat = GR_TEXFMT_ARGB_CMP_DXT1;
2020 if (srcformat == GR_TEXFMT_RGB_565 ||
2021 srcformat == GR_TEXFMT_INTENSITY_8) {
2023 compression = GL_COMPRESSED_RGB_S3TC_DXT1_EXT;
2024 *destformat = GR_TEXFMT_ARGB_CMP_DXT1;
2027 #if !defined(NO_FILTER_THREAD)
2028 unsigned int numcore = _numcore;
2029 unsigned int blkrow = 0;
2030 while (numcore > 1 && blkrow == 0) {
2031 blkrow = (srcheight >> 2) / numcore;
2034 if (blkrow > 0 && numcore > 1) {
2035 std::thread *thrd[MAX_NUMCORE];
2037 int blkheight = blkrow << 2;
2038 unsigned int srcStride = (srcwidth * blkheight) << 2;
2039 unsigned int destStride = dstRowStride * blkrow;
2040 for (i = 0; i < numcore - 1; i++) {
2041 thrd[i] = new std::thread(std::bind(_tx_compress_dxtn,
2052 thrd[i] = new std::thread(std::bind(_tx_compress_dxtn,
2055 srcheight - blkheight * i,
2060 for (i = 0; i < numcore; i++) {
2065 (*_tx_compress_dxtn)(4, /* comps: ARGB8888=4, RGB888=3 */
2066 srcwidth, /* width */
2067 srcheight, /* height */
2069 compression, /* format */
2070 dest, /* destination */
2071 dstRowStride); /* DXT1 = 8 bytes per 4x4 texel
2072 * others = 16 bytes per 4x4 texel */
2075 (*_tx_compress_dxtn)(4, /* comps: ARGB8888=4, RGB888=3 */
2076 srcwidth, /* width */
2077 srcheight, /* height */
2079 compression, /* format */
2080 dest, /* destination */
2081 dstRowStride); /* DXT1 = 8 bytes per 4x4 texel
2082 * others = 16 bytes per 4x4 texel */
2085 /* dxtn adjusts width and height to M4 by replication */
2086 *destwidth = (srcwidth + 3) & ~3;
2087 *destheight = (srcheight + 3) & ~3;
2097 TxQuantize::compress(uint8 *src, uint8 *dest,
2098 int srcwidth, int srcheight, uint16 srcformat,
2099 int *destwidth, int *destheight, uint16 *destformat,
2100 int compressionType)
2104 switch (compressionType) {
2105 case FXT1_COMPRESSION:
2106 bRet = FXT1(src, dest,
2107 srcwidth, srcheight, srcformat,
2108 destwidth, destheight, destformat);
2110 case S3TC_COMPRESSION:
2111 bRet = DXTn(src, dest,
2112 srcwidth, srcheight, srcformat,
2113 destwidth, destheight, destformat);
2115 case NCC_COMPRESSION:
2116 /* TODO: narrow channel compression */
2125 TxQuantize::I8_ARGB8888(uint32* src, uint32* dest, int width, int height)
2127 int siz = (width * height) >> 2;
2134 mov esi, dword ptr [src];
2135 mov edi, dword ptr [dest];
2136 mov ecx, dword ptr [siz];
2139 mov eax, dword ptr [esi];
2143 // 11111111 aaaaaaaa aaaaaaaa aaaaaaaa
2145 and eax, 0x000000ff;
2146 mov ebx, eax; // 00000000 00000000 00000000 aaaaaaaa
2147 shl ebx, 8; // 00000000 00000000 aaaaaaaa 00000000
2148 or eax, ebx; // 00000000 00000000 aaaaaaaa aaaaaaaa
2149 shl ebx, 8; // 00000000 aaaaaaaa 00000000 00000000
2150 or eax, ebx; // 00000000 aaaaaaaa aaaaaaaa aaaaaaaa
2151 or eax, 0xff000000; // 11111111 aaaaaaaa aaaaaaaa aaaaaaaa
2153 mov dword ptr [edi], eax;
2157 and eax, 0x0000ff00;
2158 mov ebx, eax; // 00000000 00000000 aaaaaaaa 00000000
2159 shr ebx, 8; // 00000000 00000000 00000000 aaaaaaaa
2160 or eax, ebx; // 00000000 00000000 aaaaaaaa aaaaaaaa
2161 shl ebx, 16; // 00000000 aaaaaaaa 00000000 00000000
2162 or eax, ebx; // 00000000 aaaaaaaa aaaaaaaa aaaaaaaa
2163 or eax, 0xff000000; // 11111111 aaaaaaaa aaaaaaaa aaaaaaaa
2165 mov dword ptr [edi], eax;
2169 and eax, 0x00ff0000;
2170 mov ebx, eax; // 00000000 aaaaaaaa 00000000 00000000
2171 shr ebx, 8; // 00000000 00000000 aaaaaaaa 00000000
2172 or eax, ebx; // 00000000 aaaaaaaa aaaaaaaa 00000000
2173 shr ebx, 8; // 00000000 00000000 00000000 aaaaaaaa
2174 or eax, ebx; // 00000000 aaaaaaaa aaaaaaaa aaaaaaaa
2175 or eax, 0xff000000; // 11111111 aaaaaaaa aaaaaaaa aaaaaaaa
2177 mov dword ptr [edi], eax;
2181 and eax, 0xff000000;
2182 mov ebx, eax; // aaaaaaaa 00000000 00000000 00000000
2183 shr ebx, 8; // 00000000 aaaaaaaa 00000000 00000000
2184 or eax, ebx; // aaaaaaaa aaaaaaaa 00000000 00000000
2185 shr ebx, 8; // 00000000 00000000 aaaaaaaa 00000000
2186 or eax, ebx; // aaaaaaaa aaaaaaaa aaaaaaaa 00000000
2187 shr eax, 8; // 00000000 aaaaaaaa aaaaaaaa aaaaaaaa
2188 or eax, 0xff000000; // 11111111 aaaaaaaa aaaaaaaa aaaaaaaa
2190 mov dword ptr [edi], eax;
2203 TxQuantize::ARGB8888_I8(uint32* src, uint32* dest, int width, int height)
2205 ARGB8888_A8(src, dest, width, height);
2209 TxQuantize::ARGB1555_ABGR8888(uint32* src, uint32* dest, int width, int height)
2211 int siz = (width * height) >> 1;
2218 mov esi, dword ptr [src];
2219 mov edi, dword ptr [dest];
2220 mov ecx, dword ptr [siz];
2223 mov eax, dword ptr [esi];
2226 // arrr rrgg gggb bbbb
2227 // aaaaaaaa bbbbbbbb gggggggg rrrrrrrr
2228 mov edx, eax; // edx = arrrrrgg gggbbbbb arrrrrgg gggbbbbb
2229 and ebx, 0x00000000;
2230 and eax, 0x00008000; // eax = 00000000 00000000 a0000000 00000000
2232 or ebx, 0xff000000; // ebx = aaaaaaaa 00000000 00000000 00000000
2235 mov eax, edx; // eax = arrrrrgg gggbbbbb arrrrrgg gggbbbbb
2236 and edx, 0x0000001f; // edx = 00000000 00000000 00000000 000bbbbb
2237 shl edx, 14; // edx = 00000000 00000bbb bb000000 00000000
2238 or ebx, edx; // ebx = aaaaaaaa 00000bbb bb000000 00000000
2239 shl edx, 5; // edx = 00000000 bbbbb000 00000000 00000000
2240 or ebx, edx; // ebx = aaaaaaaa bbbbbbbb bb000000 00000000
2241 and ebx, 0xffff0000; // ebx = aaaaaaaa bbbbbbbb 00000000 00000000
2243 and edx, 0x000003e0; // edx = 00000000 00000000 000000gg ggg00000
2244 shl edx, 1; // edx = 00000000 00000000 00000ggg gg000000
2245 or ebx, edx; // ebx = aaaaaaaa bbbbbbbb 00000ggg gg000000
2246 shl edx, 5; // edx = 00000000 00000000 ggggg000 00000000
2247 or ebx, edx; // ebx = aaaaaaaa bbbbbbbb gggggggg gg000000
2248 and ebx, 0xffffff00; // ebx = aaaaaaaa bbbbbbbb gggggggg 00000000
2250 and edx, 0x00007c00; // edx = 00000000 00000000 0rrrrr00 00000000
2251 shr edx, 7; // edx = 00000000 00000000 00000000 rrrrr000
2252 or ebx, edx; // ebx = aaaaaaaa bbbbbbbb gggggggg rrrrr000
2253 shr edx, 5; // edx = 00000000 00000000 00000000 00000rrr
2254 or ebx, edx; // ebx = aaaaaaaa bbbbbbbb gggggggg rrrrrrrr
2256 mov dword ptr [edi], ebx;
2259 shr eax, 16; // eax = 00000000 00000000 arrrrrgg gggbbbbb
2260 mov edx, eax; // edx = 00000000 00000000 arrrrrgg gggbbbbb
2261 and ebx, 0x00000000;
2262 and eax, 0x00008000; // eax = 00000000 00000000 a0000000 00000000
2264 or ebx, 0xff000000; // ebx = aaaaaaaa 00000000 00000000 00000000
2267 mov eax, edx; // eax = arrrrrgg gggbbbbb arrrrrgg gggbbbbb
2268 and edx, 0x0000001f; // edx = 00000000 00000000 00000000 000bbbbb
2269 shl edx, 14; // edx = 00000000 00000bbb bb000000 00000000
2270 or ebx, edx; // ebx = aaaaaaaa 00000bbb bb000000 00000000
2271 shl edx, 5; // edx = 00000000 bbbbb000 00000000 00000000
2272 or ebx, edx; // ebx = aaaaaaaa bbbbbbbb bb000000 00000000
2273 and ebx, 0xffff0000; // ebx = aaaaaaaa bbbbbbbb 00000000 00000000
2275 and edx, 0x000003e0; // edx = 00000000 00000000 000000gg ggg00000
2276 shl edx, 1; // edx = 00000000 00000000 00000ggg gg000000
2277 or ebx, edx; // ebx = aaaaaaaa bbbbbbbb 00000ggg gg000000
2278 shl edx, 5; // edx = 00000000 00000000 ggggg000 00000000
2279 or ebx, edx; // ebx = aaaaaaaa bbbbbbbb gggggggg gg000000
2280 and ebx, 0xffffff00; // ebx = aaaaaaaa bbbbbbbb gggggggg 00000000
2282 and edx, 0x00007c00; // edx = 00000000 00000000 0rrrrr00 00000000
2283 shr edx, 7; // edx = 00000000 00000000 00000000 rrrrr000
2284 or ebx, edx; // ebx = aaaaaaaa bbbbbbbb gggggggg rrrrr000
2285 shr edx, 5; // edx = 00000000 00000000 00000000 00000rrr
2286 or ebx, edx; // ebx = aaaaaaaa bbbbbbbb gggggggg rrrrrrrr
2288 mov dword ptr [edi], ebx;
2301 TxQuantize::ARGB4444_ABGR8888(uint32* src, uint32* dest, int width, int height)
2303 int siz = (width * height) >> 1;
2310 mov esi, dword ptr [src];
2311 mov edi, dword ptr [dest];
2312 mov ecx, dword ptr [siz];
2315 mov eax, dword ptr [esi];
2318 // aaaa rrrr gggg bbbb
2319 // aaaaaaaa bbbbbbbb gggggggg rrrrrrrr
2321 and eax, 0x0000ffff;
2322 mov ebx, eax; // 00000000 00000000 aaaarrrr ggggbbbb
2323 and ebx, 0x0000f000; // 00000000 00000000 aaaa0000 00000000
2324 shl ebx, 12; // 0000aaaa 00000000 00000000 00000000
2325 or eax, ebx; // 0000aaaa 00000000 aaaarrrr ggggbbbb
2327 and ebx, 0x0000000f; // 00000000 00000000 00000000 0000bbbb
2328 shl ebx, 16; // 00000000 0000bbbb 00000000 00000000
2329 or eax, ebx; // 0000aaaa 0000bbbb aaaarrrr ggggbbbb
2331 and ebx, 0x00000f00; // 00000000 00000000 0000rrrr 00000000
2332 shr ebx, 8; // 00000000 00000000 00000000 0000rrrr
2333 and eax, 0xfffffff0;
2334 or eax, ebx; // 0000aaaa 0000bbbb aaaarrrr ggggrrrr
2336 and ebx, 0x000000f0; // 00000000 00000000 00000000 gggg0000
2337 shl ebx, 4; // 00000000 00000000 0000gggg 00000000
2338 and eax, 0x0f0f000f; // 0000aaaa 0000bbbb 00000000 0000rrrr
2339 or eax, ebx; // 0000aaaa 0000bbbb 0000gggg 0000rrrr
2341 shl ebx, 4; // aaaa0000 bbbb0000 gggg0000 rrrr0000
2342 or eax, ebx; // aaaaaaaa bbbbbbbb gggggggg rrrrrrrr
2344 mov dword ptr [edi], eax;
2349 mov ebx, edx; // 00000000 00000000 aaaarrrr ggggbbbb
2350 and ebx, 0x0000f000; // 00000000 00000000 aaaa0000 00000000
2351 shl ebx, 12; // 0000aaaa 00000000 00000000 00000000
2352 or edx, ebx; // 0000aaaa 00000000 aaaarrrr ggggbbbb
2354 and ebx, 0x0000000f; // 00000000 00000000 00000000 0000bbbb
2355 shl ebx, 16; // 00000000 0000bbbb 00000000 00000000
2356 or edx, ebx; // 0000aaaa 0000bbbb aaaarrrr ggggbbbb
2358 and ebx, 0x00000f00; // 00000000 00000000 0000rrrr 00000000
2359 shr ebx, 8; // 00000000 00000000 00000000 0000rrrr
2360 and edx, 0xfffffff0;
2361 or edx, ebx; // 0000aaaa 0000bbbb aaaarrrr ggggrrrr
2363 and ebx, 0x000000f0; // 00000000 00000000 00000000 gggg0000
2364 shl ebx, 4; // 00000000 00000000 0000gggg 00000000
2365 and edx, 0x0f0f000f; // 0000aaaa 0000bbbb 00000000 0000rrrr
2366 or edx, ebx; // 0000aaaa 0000bbbb 0000gggg 0000rrrr
2368 shl ebx, 4; // aaaa0000 bbbb0000 gggg0000 rrrr0000
2369 or edx, ebx; // aaaaaaaa bbbbbbbb gggggggg rrrrrrrr
2371 mov dword ptr [edi], edx;
2384 TxQuantize::ARGB8888_ABGR8888(uint32* src, uint32* dest, int width, int height)
2386 int siz = width * height;
2393 mov esi, dword ptr [src];
2394 mov edi, dword ptr [dest];
2395 mov ecx, dword ptr [siz];
2398 mov eax, dword ptr [esi];
2401 // aaaaaaaa bbbbbbbb gggggggg rrrrrrrr
2405 and eax, 0xff000000;
2409 mov dword ptr [edi], eax;