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)
28 #ifndef NO_FILTER_THREAD
33 /* NOTE: The codes are not optimized. They can be made faster. */
35 #include "TxQuantize.h"
37 TxQuantize::TxQuantize()
39 _txUtil = new TxUtil();
41 /* get number of CPU cores. */
42 _numcore = _txUtil->getNumberofProcessors();
44 /* get dxtn extensions */
45 _tx_compress_fxt1 = TxLoadLib::getInstance()->getfxtCompressTexFuncExt();
46 _tx_compress_dxtn_rgba = TxLoadLib::getInstance()->getdxtCompressTexFuncExt();
50 TxQuantize::~TxQuantize()
56 TxQuantize::ARGB1555_ARGB8888(uint32* src, uint32* dest, int width, int height)
59 int siz = (width * height) >> 1;
61 for (i = 0; i < siz; i++) {
62 *dest = (((*src & 0x00008000) ? 0xff000000 : 0x00000000) |
63 ((*src & 0x00007c00) << 9) | ((*src & 0x00007000) << 4) |
64 ((*src & 0x000003e0) << 6) | ((*src & 0x00000380) << 1) |
65 ((*src & 0x0000001f) << 3) | ((*src & 0x0000001c) >> 2));
67 *dest = (((*src & 0x80000000) ? 0xff000000 : 0x00000000) |
68 ((*src & 0x7c000000) >> 7) | ((*src & 0x70000000) >> 12) |
69 ((*src & 0x03e00000) >> 10) | ((*src & 0x03800000) >> 15) |
70 ((*src & 0x001f0000) >> 13) | ((*src & 0x001c0000) >> 18));
75 int siz = (width * height) >> 1;
82 mov esi, dword ptr [src];
83 mov edi, dword ptr [dest];
84 mov ecx, dword ptr [siz];
87 mov eax, dword ptr [esi];
90 // arrr rrgg gggb bbbb
91 // aaaaaaaa rrrrrrrr gggggggg bbbbbbbb
92 mov edx, eax; // edx = arrrrrgg gggbbbbb arrrrrgg gggbbbbb
94 and eax, 0x00008000; // eax = 00000000 00000000 a0000000 00000000
96 mov ebx, 0xff000000; // ebx = aaaaaaaa 00000000 00000000 00000000
99 mov eax, edx; // eax = arrrrrgg gggbbbbb arrrrrgg gggbbbbb
100 and edx, 0x00007c00; // edx = 00000000 00000000 0rrrrr00 00000000
101 shl edx, 4; // edx = 00000000 00000rrr rr000000 00000000
102 or ebx, edx; // ebx = aaaaaaaa 00000rrr rr000000 00000000
103 shl edx, 5; // edx = 00000000 rrrrr000 00000000 00000000
104 or ebx, edx; // ebx = aaaaaaaa rrrrrrrr rr000000 00000000
105 and ebx, 0xffff0000; // ebx = aaaaaaaa rrrrrrrr 00000000 00000000
107 and edx, 0x000003e0; // edx = 00000000 00000000 000000gg ggg00000
108 shl edx, 1; // edx = 00000000 00000000 00000ggg gg000000
109 or ebx, edx; // ebx = aaaaaaaa rrrrrrrr 00000ggg gg000000
110 shl edx, 5; // edx = 00000000 00000000 ggggg000 00000000
111 or ebx, edx; // ebx = aaaaaaaa rrrrrrrr gggggggg gg000000
112 and ebx, 0xffffff00; // ebx = aaaaaaaa rrrrrrrr gggggggg 00000000
114 and edx, 0x0000001f; // edx = 00000000 00000000 00000000 000bbbbb
115 shl edx, 3; // edx = 00000000 00000000 00000000 bbbbb000
116 or ebx, edx; // ebx = aaaaaaaa rrrrrrrr gggggggg bbbbb000
117 shr edx, 5; // edx = 00000000 00000000 00000000 00000bbb
118 or ebx, edx; // ebx = aaaaaaaa rrrrrrrr gggggggg bbbbbbbb
120 mov dword ptr [edi], ebx;
123 shr eax, 16; // eax = 00000000 00000000 arrrrrgg gggbbbbb
124 mov edx, eax; // edx = 00000000 00000000 arrrrrgg gggbbbbb
126 and eax, 0x00008000; // eax = 00000000 00000000 a0000000 00000000
128 mov ebx, 0xff000000; // ebx = aaaaaaaa 00000000 00000000 00000000
131 mov eax, edx; // eax = 00000000 00000000 arrrrrgg gggbbbbb
132 and edx, 0x00007c00; // edx = 00000000 00000000 0rrrrr00 00000000
133 shl edx, 4; // edx = 00000000 00000rrr rr000000 00000000
134 or ebx, edx; // ebx = aaaaaaaa 00000rrr rr000000 00000000
135 shl edx, 5; // edx = 00000000 rrrrr000 00000000 00000000
136 or ebx, edx; // ebx = aaaaaaaa rrrrrrrr rr000000 00000000
137 and ebx, 0xffff0000; // ebx = aaaaaaaa rrrrrrrr 00000000 00000000
139 and edx, 0x000003e0; // edx = 00000000 00000000 000000gg ggg00000
140 shl edx, 1; // edx = 00000000 00000000 00000ggg gg000000
141 or ebx, edx; // ebx = aaaaaaaa rrrrrrrr 00000ggg gg000000
142 shl edx, 5; // edx = 00000000 00000000 ggggg000 00000000
143 or ebx, edx; // ebx = aaaaaaaa rrrrrrrr gggggggg gg000000
144 and ebx, 0xffffff00; // ebx = aaaaaaaa rrrrrrrr gggggggg 00000000
146 and edx, 0x0000001f; // edx = 00000000 00000000 00000000 000bbbbb
147 shl edx, 3; // edx = 00000000 00000000 00000000 bbbbb000
148 or ebx, edx; // ebx = aaaaaaaa rrrrrrrr gggggggg bbbbb000
149 shr edx, 5; // edx = 00000000 00000000 00000000 00000bbb
150 or ebx, edx; // ebx = aaaaaaaa rrrrrrrr gggggggg bbbbbbbb
152 mov dword ptr [edi], ebx;
166 TxQuantize::ARGB4444_ARGB8888(uint32* src, uint32* dest, int width, int height)
169 int siz = (width * height) >> 1;
171 for (i = 0; i < siz; i++) {
172 *dest = ((*src & 0x0000f000) << 12) |
173 ((*src & 0x00000f00) << 8) |
174 ((*src & 0x000000f0) << 4) |
176 *dest |= (*dest << 4);
178 *dest = ((*src & 0xf0000000) |
179 ((*src & 0x0f000000) >> 4) |
180 ((*src & 0x00f00000) >> 8) |
181 ((*src & 0x000f0000) >> 12));
182 *dest |= (*dest >> 4);
187 int siz = (width * height) >> 1;
194 mov esi, dword ptr [src];
195 mov edi, dword ptr [dest];
196 mov ecx, dword ptr [siz];
199 mov eax, dword ptr [esi];
202 // aaaa rrrr gggg bbbb
203 // aaaaaaaa rrrrrrrr gggggggg bbbbbbbb
206 mov ebx, eax; // 00000000 00000000 aaaarrrr ggggbbbb
207 and ebx, 0x0000f000; // 00000000 00000000 aaaa0000 00000000
208 shl ebx, 12; // 0000aaaa 00000000 00000000 00000000
209 or eax, ebx; // 0000aaaa 00000000 aaaarrrr ggggbbbb
211 and ebx, 0x00000f00; // 00000000 00000000 0000rrrr 00000000
212 shl ebx, 8; // 00000000 0000rrrr 00000000 00000000
213 or eax, ebx; // 0000aaaa 0000rrrr aaaarrrr ggggbbbb
215 and ebx, 0x000000f0; // 00000000 00000000 00000000 gggg0000
216 shl ebx, 4; // 00000000 00000000 0000gggg 00000000
217 and eax, 0x0f0f000f; // 0000aaaa 0000rrrr 00000000 0000bbbb
218 or eax, ebx; // 0000aaaa 0000rrrr 0000gggg 0000bbbb
220 shl ebx, 4; // aaaa0000 rrrr0000 gggg0000 bbbb0000
221 or eax, ebx; // aaaaaaaa rrrrrrrr gggggggg bbbbbbbb
223 mov dword ptr [edi], eax;
227 mov ebx, edx; // 00000000 00000000 aaaarrrr ggggbbbb
228 and ebx, 0x0000f000; // 00000000 00000000 aaaa0000 00000000
229 shl ebx, 12; // 0000aaaa 00000000 00000000 00000000
230 or edx, ebx; // 0000aaaa 00000000 aaaarrrr ggggbbbb
232 and ebx, 0x00000f00; // 00000000 00000000 0000rrrr 00000000
233 shl ebx, 8; // 00000000 0000rrrr 00000000 00000000
234 or edx, ebx; // 0000aaaa 0000rrrr aaaarrrr ggggbbbb
236 and ebx, 0x000000f0; // 00000000 00000000 00000000 gggg0000
237 shl ebx, 4; // 00000000 00000000 0000gggg 00000000
238 and edx, 0x0f0f000f; // 0000aaaa 0000rrrr 00000000 0000bbbb
239 or edx, ebx; // 0000aaaa 0000rrrr 0000gggg 0000bbbb
241 shl ebx, 4; // aaaa0000 rrrr0000 gggg0000 bbbb0000
242 or edx, ebx; // aaaaaaaa rrrrrrrr gggggggg bbbbbbbb
244 mov dword ptr [edi], edx;
258 TxQuantize::RGB565_ARGB8888(uint32* src, uint32* dest, int width, int height)
261 int siz = (width * height) >> 1;
263 for (i = 0; i < siz; i++) {
264 *dest = (0xff000000 |
265 ((*src & 0x0000f800) << 8) | ((*src & 0x0000e000) << 3) |
266 ((*src & 0x000007e0) << 5) | ((*src & 0x00000600) >> 1) |
267 ((*src & 0x0000001f) << 3) | ((*src & 0x0000001c) >> 2));
269 *dest = (0xff000000 |
270 ((*src & 0xf8000000) >> 8) | ((*src & 0xe0000000) >> 13) |
271 ((*src & 0x07e00000) >> 11) | ((*src & 0x06000000) >> 17) |
272 ((*src & 0x001f0000) >> 13) | ((*src & 0x001c0000) >> 18));
277 int siz = (width * height) >> 1;
284 mov esi, dword ptr [src];
285 mov edi, dword ptr [dest];
286 mov ecx, dword ptr [siz];
289 mov eax, dword ptr [esi];
292 // rrrr rggg gggb bbbb
293 // 11111111 rrrrrrrr gggggggg bbbbbbbb
296 mov ebx, eax; // 00000000 00000000 rrrrrggg gggbbbbb
297 and ebx, 0x0000f800; // 00000000 00000000 rrrrr000 00000000
298 shl ebx, 5; // 00000000 000rrrrr 00000000 00000000
299 or eax, ebx; // 00000000 000rrrrr rrrrrggg gggbbbbb
301 and ebx, 0x000007e0; // 00000000 00000000 00000ggg ggg00000
302 shl ebx, 5; // 00000000 00000000 gggggg00 00000000
303 and eax, 0x001F001F; // 00000000 000rrrrr 00000000 000bbbbb
304 shl eax, 3; // 00000000 rrrrr000 00000000 bbbbb000
305 or eax, ebx; // 00000000 rrrrr000 gggggg00 bbbbb000
307 shr ebx, 5; // 00000000 00000rrr rr000ggg ggg00bbb
308 and ebx, 0x00070007; // 00000000 00000rrr 00000000 00000bbb
309 or eax, ebx; // 00000000 rrrrrrrr gggggg00 bbbbbbbb
312 and ebx, 0x00000300; // 00000000 00000000 000000gg 00000000
313 or eax, ebx // 00000000 rrrrrrrr gggggggg bbbbbbbb
314 or eax, 0xff000000; // 11111111 rrrrrrrr gggggggg bbbbbbbb
316 mov dword ptr [edi], eax;
320 mov eax, edx; // 00000000 00000000 rrrrrggg gggbbbbb
322 mov ebx, eax; // 00000000 00000000 rrrrrggg gggbbbbb
323 and ebx, 0x0000f800; // 00000000 00000000 rrrrr000 00000000
324 shl ebx, 5; // 00000000 000rrrrr 00000000 00000000
325 or eax, ebx; // 00000000 000rrrrr rrrrrggg gggbbbbb
327 and ebx, 0x000007e0; // 00000000 00000000 00000ggg ggg00000
328 shl ebx, 5; // 00000000 00000000 gggggg00 00000000
329 and eax, 0x001F001F; // 00000000 000rrrrr 00000000 000bbbbb
330 shl eax, 3; // 00000000 rrrrr000 00000000 bbbbb000
331 or eax, ebx; // 00000000 rrrrr000 gggggg00 bbbbb000
333 shr ebx, 5; // 00000000 00000rrr rr000ggg ggg00bbb
334 and ebx, 0x00070007; // 00000000 00000rrr 00000000 00000bbb
335 or eax, ebx; // 00000000 rrrrrrrr gggggg00 bbbbbbbb
338 and ebx, 0x00000300; // 00000000 00000000 000000gg 00000000
339 or eax, ebx // 00000000 rrrrrrrr gggggggg bbbbbbbb
340 or eax, 0xff000000; // 11111111 rrrrrrrr gggggggg bbbbbbbb
342 mov dword ptr [edi], eax;
356 TxQuantize::A8_ARGB8888(uint32* src, uint32* dest, int width, int height)
359 int siz = (width * height) >> 2;
361 for (i = 0; i < siz; i++) {
362 *dest = (*src & 0x000000ff);
363 *dest |= (*dest << 8);
364 *dest |= (*dest << 16);
366 *dest = (*src & 0x0000ff00);
367 *dest |= (*dest >> 8);
368 *dest |= (*dest << 16);
370 *dest = (*src & 0x00ff0000);
371 *dest |= (*dest << 8);
372 *dest |= (*dest >> 16);
374 *dest = (*src & 0xff000000);
375 *dest |= (*dest >> 8);
376 *dest |= (*dest >> 16);
381 int siz = (width * height) >> 2;
388 mov esi, dword ptr [src];
389 mov edi, dword ptr [dest];
390 mov ecx, dword ptr [siz];
393 mov eax, dword ptr [esi];
397 // aaaaaaaa rrrrrrrr gggggggg bbbbbbbb
400 mov ebx, eax; // 00000000 00000000 00000000 aaaaaaaa
401 shl ebx, 8; // 00000000 00000000 aaaaaaaa 00000000
402 or eax, ebx; // 00000000 00000000 aaaaaaaa aaaaaaaa
404 shl ebx, 16; // aaaaaaaa aaaaaaaa 00000000 00000000
405 or eax, ebx; // aaaaaaaa rrrrrrrr gggggggg bbbbbbbb
407 mov dword ptr [edi], eax;
412 mov ebx, eax; // 00000000 00000000 aaaaaaaa 00000000
413 shr ebx, 8; // 00000000 00000000 00000000 aaaaaaaa
414 or eax, ebx; // 00000000 00000000 aaaaaaaa aaaaaaaa
416 shl ebx, 16; // aaaaaaaa aaaaaaaa 00000000 00000000
417 or eax, ebx; // aaaaaaaa rrrrrrrr gggggggg bbbbbbbb
419 mov dword ptr [edi], eax;
424 mov ebx, eax; // 00000000 aaaaaaaa 00000000 00000000
425 shl ebx, 8; // aaaaaaaa 00000000 00000000 00000000
426 or eax, ebx; // aaaaaaaa aaaaaaaa 00000000 00000000
428 shr ebx, 16; // 00000000 00000000 aaaaaaaa aaaaaaaa
429 or eax, ebx; // aaaaaaaa rrrrrrrr gggggggg bbbbbbbb
431 mov dword ptr [edi], eax;
436 mov ebx, eax; // aaaaaaaa 00000000 00000000 00000000
437 shr ebx, 8; // 00000000 aaaaaaaa 00000000 00000000
438 or eax, ebx; // aaaaaaaa aaaaaaaa 00000000 00000000
440 shr ebx, 16; // 00000000 00000000 aaaaaaaa aaaaaaaa
441 or eax, ebx; // aaaaaaaa rrrrrrrr gggggggg bbbbbbbb
443 mov dword ptr [edi], eax;
457 TxQuantize::AI44_ARGB8888(uint32* src, uint32* dest, int width, int height)
460 int siz = (width * height) >> 2;
462 for (i = 0; i < siz; i++) {
463 *dest = (*src & 0x0000000f);
464 *dest |= ((*dest << 8) | (*dest << 16));
465 *dest |= ((*src & 0x000000f0) << 20);
466 *dest |= (*dest << 4);
468 *dest = (*src & 0x00000f00);
469 *dest |= ((*dest << 8) | (*dest >> 8));
470 *dest |= ((*src & 0x0000f000) << 12);
471 *dest |= (*dest << 4);
473 *dest = (*src & 0x000f0000);
474 *dest |= ((*dest >> 8) | (*dest >> 16));
475 *dest |= ((*src & 0x00f00000) << 4);
476 *dest |= (*dest << 4);
478 *dest = ((*src & 0x0f000000) >> 4);
479 *dest |= ((*dest >> 8) | (*dest >> 16));
480 *dest |= (*src & 0xf0000000);
481 *dest |= (*dest >> 4);
486 int siz = (width * height) >> 2;
493 mov esi, dword ptr [src];
494 mov edi, dword ptr [dest];
495 mov ecx, dword ptr [siz];
498 mov eax, dword ptr [esi];
502 // aaaaaaaa iiiiiiii iiiiiiii iiiiiiii
504 and eax, 0x000000f0; // 00000000 00000000 00000000 aaaa0000
506 shl eax, 20; // 0000aaaa 00000000 00000000 00000000
507 and ebx, 0x0000000f; // 00000000 00000000 00000000 0000iiii
508 or eax, ebx; // 0000aaaa 00000000 00000000 0000iiii
509 shl ebx, 8; // 00000000 00000000 0000iiii 00000000
510 or eax, ebx; // 0000aaaa 00000000 0000iiii 0000iiii
511 shl ebx, 8; // 00000000 0000iiii 00000000 00000000
512 or eax, ebx; // 0000aaaa 0000iiii 0000iiii 0000iiii
514 shl ebx, 4; // aaaa0000 iiii0000 iiii0000 iiii0000
515 or eax, ebx; // aaaaaaaa iiiiiiii iiiiiiii iiiiiiii
517 mov dword ptr [edi], eax;
521 and eax, 0x0000f000; // 00000000 00000000 aaaa0000 00000000
523 shl eax, 12; // 0000aaaa 00000000 00000000 00000000
524 and ebx, 0x00000f00; // 00000000 00000000 0000iiii 00000000
525 or eax, ebx; // 0000aaaa 00000000 0000iiii 00000000
526 shr ebx, 8; // 00000000 00000000 00000000 0000iiii
527 or eax, ebx; // 0000aaaa 00000000 0000iiii 0000iiii
528 shl ebx, 16; // 00000000 0000iiii 00000000 00000000
529 or eax, ebx; // 0000aaaa 0000iiii 0000iiii 0000iiii
531 shl ebx, 4; // aaaa0000 iiii0000 iiii0000 iiii0000
532 or eax, ebx; // aaaaaaaa iiiiiiii iiiiiiii iiiiiiii
534 mov dword ptr [edi], eax;
538 and eax, 0x00f00000; // 00000000 aaaa0000 00000000 00000000
540 shl eax, 4; // 0000aaaa 00000000 00000000 00000000
541 and ebx, 0x000f0000; // 00000000 0000iiii 00000000 00000000
542 or eax, ebx; // 0000aaaa 0000iiii 00000000 00000000
543 shr ebx, 8; // 00000000 00000000 0000iiii 00000000
544 or eax, ebx; // 0000aaaa 0000iiii 0000iiii 00000000
545 shr ebx, 8; // 00000000 00000000 00000000 0000iiii
546 or eax, ebx; // 0000aaaa 0000iiii 0000iiii 0000iiii
548 shl ebx, 4; // aaaa0000 iiii0000 iiii0000 iiii0000
549 or eax, ebx; // aaaaaaaa iiiiiiii iiiiiiii iiiiiiii
551 mov dword ptr [edi], eax;
555 and eax, 0xf0000000; // aaaa0000 00000000 00000000 00000000
557 and ebx, 0x0f000000; // 0000iiii 00000000 00000000 00000000
558 shr ebx, 4; // 00000000 iiii0000 00000000 00000000
559 or eax, ebx; // aaaa0000 iiii0000 00000000 00000000
560 shr ebx, 8; // 00000000 00000000 iiii0000 00000000
561 or eax, ebx; // aaaa0000 iiii0000 iiii0000 00000000
562 shr ebx, 8; // 00000000 00000000 00000000 iiii0000
563 or eax, ebx; // aaaa0000 iiii0000 iiii0000 iiii0000
565 shr ebx, 4; // 0000aaaa 0000iiii 0000iiii 0000iiii
566 or eax, ebx; // aaaaaaaa iiiiiiii iiiiiiii iiiiiiii
568 mov dword ptr [edi], eax;
582 TxQuantize::AI88_ARGB8888(uint32* src, uint32* dest, int width, int height)
585 int siz = (width * height) >> 1;
587 for (i = 0; i < siz; i++) {
588 *dest = (*src & 0x000000ff);
589 *dest |= ((*dest << 8) | (*dest << 16));
590 *dest |= ((*src & 0x0000ff00) << 16);
592 *dest = (*src & 0x00ff0000);
593 *dest |= ((*dest >> 8) | (*dest >> 16));
594 *dest |= (*src & 0xff000000);
599 int siz = (width * height) >> 1;
606 mov esi, dword ptr [src];
607 mov edi, dword ptr [dest];
608 mov ecx, dword ptr [siz];
611 mov eax, dword ptr [esi];
615 // aaaaaaaa iiiiiiii iiiiiiii iiiiiiii
617 and eax, 0x0000ffff; // 00000000 00000000 aaaaaaaa iiiiiiii
618 mov ebx, eax; // 00000000 00000000 aaaaaaaa iiiiiiii
619 shl eax, 16; // aaaaaaaa iiiiiiii 00000000 00000000
620 and ebx, 0x000000ff; // 00000000 00000000 00000000 iiiiiiii
621 or eax, ebx; // aaaaaaaa iiiiiiii 00000000 iiiiiiii
622 shl ebx, 8; // 00000000 00000000 iiiiiiii 00000000
623 or eax, ebx; // aaaaaaaa iiiiiiii iiiiiiii iiiiiiii
625 mov dword ptr [edi], eax;
629 and eax, 0xffff0000; // aaaaaaaa iiiiiiii 00000000 00000000
630 mov ebx, eax; // aaaaaaaa iiiiiiii 00000000 00000000
631 and ebx, 0x00ff0000; // 00000000 iiiiiiii 00000000 00000000
632 shr ebx, 8; // 00000000 00000000 iiiiiiii 00000000
633 or eax, ebx; // aaaaaaaa iiiiiiii iiiiiiii 00000000
634 shr ebx, 8; // 00000000 00000000 00000000 iiiiiiii
635 or eax, ebx; // aaaaaaaa iiiiiiii iiiiiiii iiiiiiii
637 mov dword ptr [edi], eax;
651 TxQuantize::ARGB8888_ARGB1555(uint32* src, uint32* dest, int width, int height)
654 int siz = (width * height) >> 1;
656 for (i = 0; i < siz; i++) {
657 *dest = ((*src & 0xff000000) ? 0x00008000 : 0x00000000);
658 *dest |= (((*src & 0x00f80000) >> 9) |
659 ((*src & 0x0000f800) >> 6) |
660 ((*src & 0x000000f8) >> 3));
662 *dest |= ((*src & 0xff000000) ? 0x80000000 : 0x00000000);
663 *dest |= (((*src & 0x00f80000) << 7) |
664 ((*src & 0x0000f800) << 10) |
665 ((*src & 0x000000f8) << 13));
670 int siz = (width * height) >> 1;
677 mov esi, dword ptr [src];
678 mov edi, dword ptr [dest];
679 mov ecx, dword ptr [siz];
682 mov eax, dword ptr [esi];
687 and eax, 0xff000000; // aaaa0000 00000000 00000000 00000000
689 mov eax, 0x00008000; // 00000000 00000000 a0000000 00000000
693 and ebx, 0x00f80000; // 00000000 rrrrr000 00000000 00000000
694 shr ebx, 9; // 00000000 00000000 0rrrrr00 00000000
695 or eax, ebx; // 00000000 00000000 arrrrr00 00000000
697 and ebx, 0x0000f800; // 00000000 00000000 ggggg000 00000000
698 shr ebx, 6; // 00000000 00000000 000000gg ggg00000
699 or eax, ebx; // 00000000 00000000 arrrrrgg ggg00000
700 and edx, 0x000000f8; // 00000000 00000000 00000000 bbbbb000
701 shr edx, 3; // 00000000 00000000 00000000 000bbbbb
702 or edx, eax; // 00000000 00000000 arrrrrgg gggbbbbb
704 mov eax, dword ptr [esi];
708 and eax, 0xff000000; // aaaa0000 00000000 00000000 00000000
710 or edx, 0x80000000; // a0000000 00000000 arrrrrgg gggbbbbb
714 and ebx, 0x00f80000; // 00000000 rrrrr000 00000000 00000000
715 shl ebx, 7; // 0rrrrr00 00000000 00000000 00000000
716 or edx, ebx; // arrrrr00 00000000 arrrrrgg gggbbbbb
718 and ebx, 0x0000f800; // 00000000 00000000 ggggg000 00000000
719 shl ebx, 10; // 000000gg ggg00000 00000000 00000000
720 or edx, ebx; // arrrrrgg ggg00000 arrrrrgg gggbbbbb
721 and eax, 0x000000f8; // 00000000 00000000 00000000 bbbbb000
722 shl eax, 13; // 00000000 000bbbbb 00000000 00000000
723 or edx, eax; // arrrrrgg gggbbbbb arrrrrgg gggbbbbb
725 mov dword ptr [edi], edx;
729 and edx, 0x01000000; // 0000000a 00000000 00000000 00000000
730 shr edx, 9; // 00000000 00000000 a0000000 00000000
732 and ebx, 0x00f80000; // 00000000 rrrrr000 00000000 00000000
733 shr ebx, 9; // 00000000 00000000 0rrrrr00 00000000
734 or edx, ebx; // 00000000 00000000 arrrrr00 00000000
736 and ebx, 0x0000f800; // 00000000 00000000 ggggg000 00000000
737 shr ebx, 6; // 00000000 00000000 000000gg ggg00000
738 or edx, ebx; // 00000000 00000000 arrrrrgg ggg00000
739 and eax, 0x000000f8; // 00000000 00000000 00000000 bbbbb000
740 shr eax, 3; // 00000000 00000000 00000000 000bbbbb
741 or edx, eax; // 00000000 00000000 arrrrrgg gggbbbbb
743 mov eax, dword ptr [esi];
747 and ebx, 0x80000000; // a0000000 00000000 00000000 00000000
748 or edx, ebx; // a0000000 00000000 arrrrrgg gggbbbbb
750 and ebx, 0x00f80000; // 00000000 rrrrr000 00000000 00000000
751 shl ebx, 7; // 0rrrrr00 00000000 00000000 00000000
752 or edx, ebx; // arrrrr00 00000000 arrrrrgg gggbbbbb
754 and ebx, 0x0000f800; // 00000000 00000000 ggggg000 00000000
755 shl ebx, 10; // 000000gg ggg00000 00000000 00000000
756 or edx, ebx; // arrrrrgg ggg00000 arrrrrgg gggbbbbb
757 and eax, 0x000000f8; // 00000000 00000000 00000000 bbbbb000
758 shl eax, 13; // 00000000 000bbbbb 00000000 00000000
759 or edx, eax; // arrrrrgg gggbbbbb arrrrrgg gggbbbbb
761 mov dword ptr [edi], edx;
775 TxQuantize::ARGB8888_ARGB4444(uint32* src, uint32* dest, int width, int height)
778 int siz = (width * height) >> 1;
780 for (i = 0; i < siz; i++) {
781 *dest = (((*src & 0xf0000000) >> 16) |
782 ((*src & 0x00f00000) >> 12) |
783 ((*src & 0x0000f000) >> 8) |
784 ((*src & 0x000000f0) >> 4));
786 *dest |= ((*src & 0xf0000000) |
787 ((*src & 0x00f00000) << 4) |
788 ((*src & 0x0000f000) << 8) |
789 ((*src & 0x000000f0) << 12));
794 int siz = (width * height) >> 1;
801 mov esi, dword ptr [src];
802 mov edi, dword ptr [dest];
803 mov ecx, dword ptr [siz];
806 mov eax, dword ptr [esi];
810 and edx, 0xf0000000; // aaaa0000 00000000 00000000 00000000
811 shr edx, 16; // 00000000 00000000 aaaa0000 00000000
813 and ebx, 0x00f00000; // 00000000 rrrr0000 00000000 00000000
814 shr ebx, 12; // 00000000 00000000 0000rrrr 00000000
815 or edx, ebx; // 00000000 00000000 aaaarrrr 00000000
817 and ebx, 0x0000f000; // 00000000 00000000 gggg0000 00000000
818 shr ebx, 8; // 00000000 00000000 00000000 gggg0000
819 or edx, ebx; // 00000000 00000000 aaaarrrr gggg0000
820 and eax, 0x000000f0; // 00000000 00000000 00000000 bbbb0000
821 shr eax, 4; // 00000000 00000000 00000000 0000bbbb
822 or edx, eax; // 00000000 00000000 aaaarrrr ggggbbbb
824 mov eax, dword ptr [esi];
828 and ebx, 0xf0000000; // aaaa0000 00000000 00000000 00000000
829 or edx, ebx; // aaaa0000 00000000 aaaarrrr ggggbbbb
831 and ebx, 0x00f00000; // 00000000 rrrr0000 00000000 00000000
832 shl ebx, 4; // 0000rrrr 00000000 00000000 00000000
833 or edx, ebx; // aaaarrrr 00000000 aaaarrrr ggggbbbb
835 and ebx, 0x0000f000; // 00000000 00000000 gggg0000 00000000
836 shl ebx, 8; // 00000000 gggg0000 00000000 00000000
837 or edx, ebx; // aaaarrrr gggg0000 aaaarrrr ggggbbbb
838 and eax, 0x000000f0; // 00000000 00000000 00000000 bbbb0000
839 shl eax, 12; // 00000000 0000bbbb 00000000 00000000
840 or edx, eax; // arrrrrgg ggggbbbb aaaarrrr ggggbbbb
842 mov dword ptr [edi], edx;
856 TxQuantize::ARGB8888_RGB565(uint32* src, uint32* dest, int width, int height)
859 int siz = (width * height) >> 1;
861 for (i = 0; i < siz; i++) {
862 *dest = (((*src & 0x000000f8) >> 3) |
863 ((*src & 0x0000fc00) >> 5) |
864 ((*src & 0x00f80000) >> 8));
866 *dest |= (((*src & 0x000000f8) << 13) |
867 ((*src & 0x0000fc00) << 11) |
868 ((*src & 0x00f80000) << 8));
873 int siz = (width * height) >> 1;
880 mov esi, dword ptr [src];
881 mov edi, dword ptr [dest];
882 mov ecx, dword ptr [siz];
885 mov eax, dword ptr [esi];
889 and edx, 0x000000F8; // 00000000 00000000 00000000 bbbbb000
890 shr edx, 3; // 00000000 00000000 00000000 000bbbbb
892 and ebx, 0x0000FC00; // 00000000 00000000 gggggg00 00000000
893 shr ebx, 5; // 00000000 00000000 00000ggg ggg00000
894 or edx, ebx; // 00000000 00000000 00000ggg gggbbbbb
896 and ebx, 0x00F80000; // 00000000 rrrrr000 00000000 00000000
897 shr ebx, 8; // 00000000 00000000 rrrrr000 00000000
898 or edx, ebx; // 00000000 00000000 rrrrrggg gggbbbbb
900 mov eax, dword ptr [esi];
904 and ebx, 0x000000F8; // 00000000 00000000 00000000 bbbbb000
905 shl ebx, 13; // 00000000 000bbbbb 00000000 00000000
906 or edx, ebx; // 00000000 000bbbbb rrrrrggg gggbbbbb
908 and ebx, 0x0000FC00; // 00000000 00000000 gggggg00 00000000
909 shl ebx, 11; // 00000ggg ggg00000 00000000 00000000
910 or edx, ebx; // 00000ggg gggbbbbb rrrrrggg gggbbbbb
912 and ebx, 0x00F80000; // 00000000 rrrrr000 00000000 00000000
913 shl ebx, 8; // rrrrr000 00000000 00000000 00000000
914 or edx, ebx; // rrrrrggg gggbbbbb rrrrrggg gggbbbbb
916 mov dword ptr [edi], edx;
930 TxQuantize::ARGB8888_A8(uint32* src, uint32* dest, int width, int height)
933 int siz = (width * height) >> 2;
935 for (i = 0; i < siz; i++) {
936 *dest = (*src & 0x0000ff00) >> 8;
938 *dest |= (*src & 0x0000ff00);
940 *dest |= ((*src & 0x0000ff00) << 8);
942 *dest |= ((*src & 0x0000ff00) << 16);
947 int siz = (width * height) >> 2;
954 mov esi, dword ptr [src];
955 mov edi, dword ptr [dest];
956 mov ecx, dword ptr [siz];
959 mov eax, dword ptr [esi];
963 mov edx, eax; // we'll use A comp for every pixel
964 and edx, 0xFF000000; // aaaaaaaa 00000000 00000000 00000000
965 shr edx, 24; // 00000000 00000000 00000000 aaaaaaaa
967 mov eax, dword ptr [esi];
970 and eax, 0xFF000000; // aaaaaaaa 00000000 00000000 00000000
971 shr eax, 16; // 00000000 00000000 aaaaaaaa 00000000
972 or edx, eax; // 00000000 00000000 aaaaaaaa aaaaaaaa
974 mov eax, dword ptr [esi];
977 and eax, 0xFF000000; // aaaaaaaa 00000000 00000000 00000000
978 shr eax, 8; // 00000000 aaaaaaaa 00000000 00000000
979 or edx, eax; // 00000000 aaaaaaaa aaaaaaaa aaaaaaaa
981 mov eax, dword ptr [esi];
984 and eax, 0xFF000000; // aaaaaaaa 00000000 00000000 00000000
985 or edx, eax; // aaaaaaaa aaaaaaaa aaaaaaaa aaaaaaaa
989 mov edx, eax; // we'll use G comp for every pixel
990 and edx, 0x0000FF00; // 00000000 00000000 aaaaaaaa 00000000
991 shr edx, 8; // 00000000 00000000 00000000 aaaaaaaa
993 mov eax, dword ptr [esi];
996 and eax, 0x0000FF00; // 00000000 00000000 aaaaaaaa 00000000
997 or edx, eax; // 00000000 00000000 aaaaaaaa aaaaaaaa
999 mov eax, dword ptr [esi];
1002 and eax, 0x0000FF00; // 00000000 00000000 aaaaaaaa 00000000
1003 shl eax, 8; // 00000000 aaaaaaaa 00000000 00000000
1004 or edx, eax; // 00000000 aaaaaaaa aaaaaaaa aaaaaaaa
1006 mov eax, dword ptr [esi];
1009 and eax, 0x0000FF00; // 00000000 00000000 aaaaaaaa 00000000
1010 shl eax, 16; // aaaaaaaa 00000000 00000000 00000000
1011 or edx, eax; // aaaaaaaa aaaaaaaa aaaaaaaa aaaaaaaa
1016 and edx, 0x000000FF; // 00000000 00000000 00000000 aaaaaaaa
1018 mov eax, dword ptr [esi];
1021 and eax, 0x0000FF00; // 00000000 00000000 aaaaaaaa 00000000
1022 or edx, eax; // 00000000 00000000 aaaaaaaa aaaaaaaa
1024 mov eax, dword ptr [esi];
1027 and eax, 0x00FF0000; // 00000000 aaaaaaaa 00000000 00000000
1028 or edx, eax; // 00000000 aaaaaaaa aaaaaaaa aaaaaaaa
1030 mov eax, dword ptr [esi];
1033 and eax, 0xFF000000; // aaaaaaaa 00000000 00000000 00000000
1034 or edx, eax; // aaaaaaaa aaaaaaaa aaaaaaaa aaaaaaaa
1036 mov dword ptr [edi], edx;
1050 TxQuantize::ARGB8888_AI44(uint32* src, uint32* dest, int width, int height)
1053 int siz = (width * height) >> 2;
1055 for (i = 0; i < siz; i++) {
1056 *dest = (((*src & 0xf0000000) >> 24) | ((*src & 0x0000f000) >> 12));
1058 *dest |= (((*src & 0xf0000000) >> 16) | ((*src & 0x0000f000) >> 4));
1060 *dest |= (((*src & 0xf0000000) >> 8) | ((*src & 0x0000f000) << 4));
1062 *dest |= ((*src & 0xf0000000) | ((*src & 0x0000f000) << 12));
1067 int siz = (width * height) >> 2;
1074 mov esi, dword ptr [src];
1075 mov edi, dword ptr [dest];
1076 mov ecx, dword ptr [siz];
1079 mov eax, dword ptr [esi];
1082 mov edx, eax; // use A and G comps MSB
1083 and edx, 0xF0000000; // aaaa0000 00000000 00000000 00000000
1085 shr edx, 24; // 00000000 00000000 00000000 aaaa0000
1086 and ebx, 0x0000F000; // 00000000 00000000 iiii0000 00000000
1087 shr ebx, 12; // 00000000 00000000 00000000 0000iiii
1088 or edx, ebx; // 00000000 00000000 00000000 aaaaiiii
1090 mov eax, dword ptr [esi];
1094 and eax, 0xF0000000; // aaaa0000 00000000 00000000 00000000
1095 shr eax, 16; // 00000000 00000000 aaaa0000 00000000
1096 and ebx, 0x0000F000; // 00000000 00000000 iiii0000 00000000
1097 shr ebx, 4; // 00000000 00000000 0000iiii 00000000
1098 or eax, ebx; // 00000000 00000000 aaaaiiii 00000000
1099 or edx, eax; // 00000000 00000000 aaaaiiii aaaaiiii
1101 mov eax, dword ptr [esi];
1105 and eax, 0xF0000000; // aaaa0000 00000000 00000000 00000000
1106 shr eax, 8; // 00000000 aaaa0000 00000000 00000000
1107 and ebx, 0x0000F000; // 00000000 00000000 iiii0000 00000000
1108 shl ebx, 4; // 00000000 0000iiii 00000000 00000000
1109 or eax, ebx; // 00000000 aaaaiiii 00000000 00000000
1110 or edx, eax; // 00000000 aaaaiiii aaaaiiii aaaaiiii
1112 mov eax, dword ptr [esi];
1116 and eax, 0xF0000000; // aaaa0000 00000000 00000000 00000000
1117 and ebx, 0x0000F000; // 00000000 00000000 iiii0000 00000000
1118 shl ebx, 12; // 0000iiii 00000000 00000000 00000000
1119 or eax, ebx; // aaaaiiii 00000000 00000000 00000000
1120 or edx, eax; // aaaaiiii aaaaiiii aaaaiiii aaaaiiii
1122 mov dword ptr [edi], edx;
1136 TxQuantize::ARGB8888_AI88(uint32* src, uint32* dest, int width, int height)
1139 int siz = (width * height) >> 1;
1141 for (i = 0; i < siz; i++) {
1142 *dest = (((*src & 0xff000000) >> 16) | ((*src & 0x0000ff00) >> 8));
1144 *dest |= ((*src & 0xff000000) | ((*src & 0x0000ff00) << 8));
1149 int siz = (width * height) >> 1;
1156 mov esi, dword ptr [src];
1157 mov edi, dword ptr [dest];
1158 mov ecx, dword ptr [siz];
1161 mov eax, dword ptr [esi];
1165 and edx, 0xFF000000; // aaaaaaaa 00000000 00000000 00000000
1167 shr edx, 16; // 00000000 00000000 aaaaaaaa 00000000
1168 and ebx, 0x0000FF00; // 00000000 00000000 iiiiiiii 00000000
1169 shr ebx, 8; // 00000000 00000000 00000000 iiiiiiii
1170 or edx, ebx; // 00000000 00000000 aaaaaaaa iiiiiiii
1172 mov eax, dword ptr [esi];
1176 and eax, 0xFF000000; // aaaaaaaa 00000000 00000000 00000000
1177 and ebx, 0x0000FF00; // 00000000 00000000 iiiiiiii 00000000
1178 shl ebx, 8; // 00000000 iiiiiiii 00000000 00000000
1179 or eax, ebx; // aaaaaaaa iiiiiiii 00000000 00000000
1180 or edx, eax; // aaaaaaaa iiiiiiii aaaaaaaa iiiiiiii
1182 mov dword ptr [edi], edx;
1195 /* R.W. Floyd and L. Steinberg, An adaptive algorithm
1196 * for spatial grey scale, Proceedings of the Society
1197 * of Information Display 17, pp75-77, 1976
1200 TxQuantize::ARGB8888_RGB565_ErrD(uint32* src, uint32* dst, int width, int height)
1202 /* Floyd-Steinberg error-diffusion halftoning */
1205 int qr, qg, qb; /* quantized incoming values */
1206 int ir, ig, ib; /* incoming values */
1208 int *errR = new int[width];
1209 int *errG = new int[width];
1210 int *errB = new int[width];
1212 uint16 *dest = (uint16 *)dst;
1214 for (i = 0; i < width; i++) errR[i] = errG[i] = errB[i] = 0;
1216 for (y = 0; y < height; y++) {
1218 for (x = 0; x < width; x++) {
1219 /* incoming pixel values */
1220 ir = ((*src >> 16) & 0xFF) * 10000;
1221 ig = ((*src >> 8) & 0xFF) * 10000;
1222 ib = ((*src ) & 0xFF) * 10000;
1224 /* quantize pixel values.
1225 * qr * 0.4375 is the error from the pixel to the left,
1226 * errR is the error from the pixel to the top, top left, and top right */
1227 /* qr * 0.4375 is the error distribution to the EAST in
1228 * the previous loop */
1229 ir += errR[x] + qr * 4375 / 10000;
1230 ig += errG[x] + qg * 4375 / 10000;
1231 ib += errB[x] + qb * 4375 / 10000;
1233 /* error distribution to the SOUTH-EAST in the previous loop
1234 * can't calculate in the previous loop because it steps on
1235 * the above quantization */
1236 errR[x] = qr * 625 / 10000;
1237 errG[x] = qg * 625 / 10000;
1238 errB[x] = qb * 625 / 10000;
1245 if (qr < 0) qr = 0; else if (qr > 2550000) qr = 2550000;
1246 if (qg < 0) qg = 0; else if (qg > 2550000) qg = 2550000;
1247 if (qb < 0) qb = 0; else if (qb > 2550000) qb = 2550000;
1249 /* convert to RGB565 */
1250 qr = qr * 0x1F / 2550000;
1251 qg = qg * 0x3F / 2550000;
1252 qb = qb * 0x1F / 2550000;
1254 /* this is the dithered pixel */
1255 t = (qr << 11) | (qg << 5) | qb;
1257 /* compute the errors */
1258 qr = ((qr << 3) | (qr >> 2)) * 10000;
1259 qg = ((qg << 2) | (qg >> 4)) * 10000;
1260 qb = ((qb << 3) | (qb >> 2)) * 10000;
1265 /* compute the error distributions */
1266 /* Floyd-Steinberg filter
1267 * 7/16 (=0.4375) to the EAST
1268 * 5/16 (=0.3125) to the SOUTH
1269 * 1/16 (=0.0625) to the SOUTH-EAST
1270 * 3/16 (=0.1875) to the SOUTH-WEST
1277 errR[x - 1] += qr * 1875 / 10000;
1278 errG[x - 1] += qg * 1875 / 10000;
1279 errB[x - 1] += qb * 1875 / 10000;
1283 errR[x] += qr * 3125 / 10000;
1284 errG[x] += qg * 3125 / 10000;
1285 errB[x] += qb * 3125 / 10000;
1287 *dest = (t & 0xFFFF);
1301 TxQuantize::ARGB8888_ARGB1555_ErrD(uint32* src, uint32* dst, int width, int height)
1303 /* Floyd-Steinberg error-diffusion halftoning */
1306 int qr, qg, qb; /* quantized incoming values */
1307 int ir, ig, ib; /* incoming values */
1309 int *errR = new int[width];
1310 int *errG = new int[width];
1311 int *errB = new int[width];
1313 uint16 *dest = (uint16 *)dst;
1315 for (i = 0; i < width; i++) errR[i] = errG[i] = errB[i] = 0;
1317 for (y = 0; y < height; y++) {
1319 for (x = 0; x < width; x++) {
1320 /* incoming pixel values */
1321 ir = ((*src >> 16) & 0xFF) * 10000;
1322 ig = ((*src >> 8) & 0xFF) * 10000;
1323 ib = ((*src ) & 0xFF) * 10000;
1325 /* quantize pixel values.
1326 * qr * 0.4375 is the error from the pixel to the left,
1327 * errR is the error from the pixel to the top, top left, and top right */
1328 /* qr * 0.4375 is the error distribution to the EAST in
1329 * the previous loop */
1330 ir += errR[x] + qr * 4375 / 10000;
1331 ig += errG[x] + qg * 4375 / 10000;
1332 ib += errB[x] + qb * 4375 / 10000;
1334 /* error distribution to the SOUTH-EAST of the previous loop.
1335 * cannot calculate in the previous loop because it steps on
1336 * the above quantization */
1337 errR[x] = qr * 625 / 10000;
1338 errG[x] = qg * 625 / 10000;
1339 errB[x] = qb * 625 / 10000;
1346 if (qr < 0) qr = 0; else if (qr > 2550000) qr = 2550000;
1347 if (qg < 0) qg = 0; else if (qg > 2550000) qg = 2550000;
1348 if (qb < 0) qb = 0; else if (qb > 2550000) qb = 2550000;
1350 /* convert to RGB555 */
1351 qr = qr * 0x1F / 2550000;
1352 qg = qg * 0x1F / 2550000;
1353 qb = qb * 0x1F / 2550000;
1355 /* this is the dithered pixel */
1356 t = (qr << 10) | (qg << 5) | qb;
1357 t |= ((*src >> 24) ? 0x8000 : 0);
1359 /* compute the errors */
1360 qr = ((qr << 3) | (qr >> 2)) * 10000;
1361 qg = ((qg << 3) | (qg >> 2)) * 10000;
1362 qb = ((qb << 3) | (qb >> 2)) * 10000;
1367 /* compute the error distributions */
1368 /* Floyd-Steinberg filter
1369 * 7/16 (=0.4375) to the EAST
1370 * 5/16 (=0.3125) to the SOUTH
1371 * 1/16 (=0.0625) to the SOUTH-EAST
1372 * 3/16 (=0.1875) to the SOUTH-WEST
1379 errR[x - 1] += qr * 1875 / 10000;
1380 errG[x - 1] += qg * 1875 / 10000;
1381 errB[x - 1] += qb * 1875 / 10000;
1385 errR[x] += qr * 3125 / 10000;
1386 errG[x] += qg * 3125 / 10000;
1387 errB[x] += qb * 3125 / 10000;
1389 *dest = (t & 0xFFFF);
1402 TxQuantize::ARGB8888_ARGB4444_ErrD(uint32* src, uint32* dst, int width, int height)
1404 /* Floyd-Steinberg error-diffusion halftoning */
1406 /* NOTE: alpha dithering looks better for alpha gradients, but are prone
1407 * to producing noisy speckles for constant or step level alpha. Output
1408 * results should always be checked.
1410 boolean ditherAlpha = 0;
1413 int qr, qg, qb, qa; /* quantized incoming values */
1414 int ir, ig, ib, ia; /* incoming values */
1416 int *errR = new int[width];
1417 int *errG = new int[width];
1418 int *errB = new int[width];
1419 int *errA = new int[width];
1421 uint16 *dest = (uint16 *)dst;
1423 for (i = 0; i < width; i++) errR[i] = errG[i] = errB[i] = errA[i] = 0;
1425 for (y = 0; y < height; y++) {
1426 qr = qg = qb = qa = 0;
1427 for (x = 0; x < width; x++) {
1428 /* incoming pixel values */
1429 ir = ((*src >> 16) & 0xFF) * 10000;
1430 ig = ((*src >> 8) & 0xFF) * 10000;
1431 ib = ((*src ) & 0xFF) * 10000;
1432 ia = ((*src >> 24) & 0xFF) * 10000;
1434 /* quantize pixel values.
1435 * qr * 0.4375 is the error from the pixel to the left,
1436 * errR is the error from the pixel to the top, top left, and top right */
1437 /* qr * 0.4375 is the error distribution to the EAST in
1438 * the previous loop */
1439 ir += errR[x] + qr * 4375 / 10000;
1440 ig += errG[x] + qg * 4375 / 10000;
1441 ib += errB[x] + qb * 4375 / 10000;
1442 ia += errA[x] + qa * 4375 / 10000;
1444 /* error distribution to the SOUTH-EAST of the previous loop.
1445 * cannot calculate in the previous loop because it steps on
1446 * the above quantization */
1447 errR[x] = qr * 625 / 10000;
1448 errG[x] = qg * 625 / 10000;
1449 errB[x] = qb * 625 / 10000;
1450 errA[x] = qa * 625 / 10000;
1458 if (qr < 0) qr = 0; else if (qr > 2550000) qr = 2550000;
1459 if (qg < 0) qg = 0; else if (qg > 2550000) qg = 2550000;
1460 if (qb < 0) qb = 0; else if (qb > 2550000) qb = 2550000;
1461 if (qa < 0) qa = 0; else if (qa > 2550000) qa = 2550000;
1463 /* convert to RGB444 */
1464 qr = qr * 0xF / 2550000;
1465 qg = qg * 0xF / 2550000;
1466 qb = qb * 0xF / 2550000;
1467 qa = qa * 0xF / 2550000;
1469 /* this is the value to be returned */
1471 t = (qa << 12) | (qr << 8) | (qg << 4) | qb;
1473 t = (qr << 8) | (qg << 4) | qb;
1474 t |= (*src >> 16) & 0xF000;
1477 /* compute the errors */
1478 qr = ((qr << 4) | qr) * 10000;
1479 qg = ((qg << 4) | qg) * 10000;
1480 qb = ((qb << 4) | qb) * 10000;
1481 qa = ((qa << 4) | qa) * 10000;
1487 /* compute the error distributions */
1488 /* Floyd-Steinberg filter
1489 * 7/16 (=0.4375) to the EAST
1490 * 5/16 (=0.3125) to the SOUTH
1491 * 1/16 (=0.0625) to the SOUTH-EAST
1492 * 3/16 (=0.1875) to the SOUTH-WEST
1499 errR[x - 1] += qr * 1875 / 10000;
1500 errG[x - 1] += qg * 1875 / 10000;
1501 errB[x - 1] += qb * 1875 / 10000;
1502 errA[x - 1] += qa * 1875 / 10000;
1506 errR[x] += qr * 3125 / 10000;
1507 errG[x] += qg * 3125 / 10000;
1508 errB[x] += qb * 3125 / 10000;
1509 errA[x] += qa * 3125 / 10000;
1511 *dest = (t & 0xFFFF);
1525 TxQuantize::ARGB8888_AI44_ErrD(uint32* src, uint32* dst, int width, int height)
1527 /* Floyd-Steinberg error-diffusion halftoning */
1529 /* NOTE: alpha dithering looks better for alpha gradients, but are prone
1530 * to producing noisy speckles for constant or step level alpha. Output
1531 * results should always be checked.
1533 boolean ditherAlpha = 0;
1536 int qi, qa; /* quantized incoming values */
1537 int ii, ia; /* incoming values */
1539 int *errI = new int[width];
1540 int *errA = new int[width];
1542 uint8 *dest = (uint8 *)dst;
1544 for (i = 0; i < width; i++) errI[i] = errA[i] = 0;
1546 for (y = 0; y < height; y++) {
1548 for (x = 0; x < width; x++) {
1549 /* 3dfx style Intensity = R * 0.299 + G * 0.587 + B * 0.114 */
1550 ii = ((*src >> 16) & 0xFF) * 2990 +
1551 ((*src >> 8) & 0xFF) * 5870 +
1552 ((*src ) & 0xFF) * 1140;
1553 ia = ((*src >> 24) & 0xFF) * 10000;
1555 /* quantize pixel values.
1556 * qi * 0.4375 is the error from the pixel to the left,
1557 * errI is the error from the pixel to the top, top left, and top right */
1558 /* qi * 0.4375 is the error distrtibution to the EAST in
1559 * the previous loop */
1560 ii += errI[x] + qi * 4375 / 10000;
1561 ia += errA[x] + qa * 4375 / 10000;
1563 /* error distribution to the SOUTH-EAST in the previous loop.
1564 * cannot calculate in the previous loop because it steps on
1565 * the above quantization */
1566 errI[x] = qi * 625 / 10000;
1567 errA[x] = qa * 625 / 10000;
1573 if (qi < 0) qi = 0; else if (qi > 2550000) qi = 2550000;
1574 if (qa < 0) qa = 0; else if (qa > 2550000) qa = 2550000;
1577 qi = qi * 0xF / 2550000;
1578 qa = qa * 0xF / 2550000;
1580 /* this is the value to be returned */
1585 t |= ((*src >> 24) & 0xF0);
1588 /* compute the errors */
1589 qi = ((qi << 4) | qi) * 10000;
1590 qa = ((qa << 4) | qa) * 10000;
1594 /* compute the error distributions */
1595 /* Floyd-Steinberg filter
1596 * 7/16 (=0.4375) to the EAST
1597 * 5/16 (=0.3125) to the SOUTH
1598 * 1/16 (=0.0625) to the SOUTH-EAST
1599 * 3/16 (=0.1875) to the SOUTH-WEST
1606 errI[x - 1] += qi * 1875 / 10000;
1607 errA[x - 1] += qa * 1875 / 10000;
1611 errI[x] += qi * 3125 / 10000;
1612 errA[x] += qa * 3125 / 10000;
1626 TxQuantize::ARGB8888_AI88_Slow(uint32* src, uint32* dst, int width, int height)
1629 uint16 *dest = (uint16 *)dst;
1630 for (y = 0; y < height; y++) {
1631 for (x = 0; x < width; x++) {
1633 /* libpng style grayscale conversion.
1634 * Reduce RGB files to grayscale with or without alpha
1635 * using the equation given in Poynton's ColorFAQ at
1636 * <http://www.inforamp.net/~poynton/>
1637 * Copyright (c) 1998-01-04 Charles Poynton poynton at inforamp.net
1639 * Y = 0.212671 * R + 0.715160 * G + 0.072169 * B
1641 * We approximate this with
1643 * Y = 0.21268 * R + 0.7151 * G + 0.07217 * B
1645 * which can be expressed with integers as
1647 * Y = (6969 * R + 23434 * G + 2365 * B)/32768
1649 * The calculation is to be done in a linear colorspace.
1651 *dest = (((int)((((*src >> 16) & 0xFF) * 6969 +
1652 ((*src >> 8) & 0xFF) * 23434 +
1653 ((*src ) & 0xFF) * 2365) / 32768) & 0xFF) |
1654 (uint16)((*src >> 16) & 0xFF00));
1656 /* 3dfx style Intensity = R * 0.299 + G * 0.587 + B * 0.114
1657 * this is same as the standard NTSC gray scale conversion. */
1658 *dest = (((int)((((*src >> 16) & 0xFF) * 299 +
1659 ((*src >> 8) & 0xFF) * 587 +
1660 ((*src ) & 0xFF) * 114) / 1000) & 0xFF) |
1661 (uint16)((*src >> 16) & 0xFF00));
1670 TxQuantize::ARGB8888_I8_Slow(uint32* src, uint32* dst, int width, int height)
1673 uint8 *dest = (uint8 *)dst;
1674 for (y = 0; y < height; y++) {
1675 for (x = 0; x < width; x++) {
1677 /* libpng style Intensity = (6969 * R + 23434 * G + 2365 * B)/32768 */
1678 *dest = (int)((((*src >> 16) & 0xFF) * 6969 +
1679 ((*src >> 8) & 0xFF) * 23434 +
1680 ((*src ) & 0xFF) * 2365) / 32768) & 0xFF;
1682 /* 3dfx style Intensity = R * 0.299 + G * 0.587 + B * 0.114
1683 * this is same as the standard NTSC gray scale conversion. */
1684 *dest = (int)((((*src >>16) & 0xFF) * 299 +
1685 ((*src >> 8) & 0xFF) * 587 +
1686 ((*src ) & 0xFF) * 114) / 1000) & 0xFF;
1695 TxQuantize::P8_16BPP(uint32* src, uint32* dest, int width, int height, uint32* palette)
1697 /* passed in palette is RGBA5551 format */
1700 int size = width * height;
1701 for (i = 0; i < size; i++) {
1702 ((uint16*)dest)[i] = ((uint16*)palette)[(int)(((uint8*)src)[i])];
1703 ((uint16*)dest)[i] = ((((uint16*)dest)[i] << 15) | (((uint16*)dest)[i] >> 1));
1707 /* not finished yet... */
1709 int siz = (width * height) >> 2;
1716 mov esi, dword ptr [src];
1717 mov edi, dword ptr [dest];
1718 mov ecx, dword ptr [siz];
1719 mov edx, dword ptr [palette];
1722 mov eax, dword ptr [esi];
1736 TxQuantize::quantize(uint8* src, uint8* dest, int width, int height, uint16 srcformat, uint16 destformat, boolean fastQuantizer)
1738 typedef void (TxQuantize::*quantizerFunc)(uint32* src, uint32* dest, int width, int height);
1739 quantizerFunc quantizer;
1742 if (destformat == GR_TEXFMT_ARGB_8888) {
1743 switch (srcformat) {
1744 case GR_TEXFMT_ARGB_1555:
1745 quantizer = &TxQuantize::ARGB1555_ARGB8888;
1748 case GR_TEXFMT_ARGB_4444:
1749 quantizer = &TxQuantize::ARGB4444_ARGB8888;
1752 case GR_TEXFMT_RGB_565:
1753 quantizer = &TxQuantize::RGB565_ARGB8888;
1756 case GR_TEXFMT_ALPHA_8:
1757 quantizer = &TxQuantize::A8_ARGB8888;
1760 case GR_TEXFMT_ALPHA_INTENSITY_44:
1761 quantizer = &TxQuantize::AI44_ARGB8888;
1764 case GR_TEXFMT_ALPHA_INTENSITY_88:
1765 quantizer = &TxQuantize::AI88_ARGB8888;
1772 #if !defined(NO_FILTER_THREAD)
1773 unsigned int numcore = _numcore;
1774 unsigned int blkrow = 0;
1775 while (numcore > 1 && blkrow == 0) {
1776 blkrow = (height >> 2) / numcore;
1779 if (blkrow > 0 && numcore > 1) {
1780 std::thread *thrd[MAX_NUMCORE];
1782 int blkheight = blkrow << 2;
1783 unsigned int srcStride = (width * blkheight) << (2 - bpp_shift);
1784 unsigned int destStride = srcStride << bpp_shift;
1785 for (i = 0; i < numcore - 1; i++) {
1786 thrd[i] = new std::thread(std::bind(quantizer,
1795 thrd[i] = new std::thread(std::bind(quantizer,
1800 height - blkheight * i));
1801 for (i = 0; i < numcore; i++) {
1806 (*this.*quantizer)((uint32*)src, (uint32*)dest, width, height);
1809 (*this.*quantizer)((uint32*)src, (uint32*)dest, width, height);
1812 } else if (srcformat == GR_TEXFMT_ARGB_8888) {
1813 switch (destformat) {
1814 case GR_TEXFMT_ARGB_1555:
1815 quantizer = fastQuantizer ? &TxQuantize::ARGB8888_ARGB1555 : &TxQuantize::ARGB8888_ARGB1555_ErrD;
1818 case GR_TEXFMT_ARGB_4444:
1819 quantizer = fastQuantizer ? &TxQuantize::ARGB8888_ARGB4444 : &TxQuantize::ARGB8888_ARGB4444_ErrD;
1822 case GR_TEXFMT_RGB_565:
1823 quantizer = fastQuantizer ? &TxQuantize::ARGB8888_RGB565 : &TxQuantize::ARGB8888_RGB565_ErrD;
1826 case GR_TEXFMT_ALPHA_8:
1827 case GR_TEXFMT_INTENSITY_8:
1828 quantizer = fastQuantizer ? &TxQuantize::ARGB8888_A8 : &TxQuantize::ARGB8888_I8_Slow;
1831 case GR_TEXFMT_ALPHA_INTENSITY_44:
1832 quantizer = fastQuantizer ? &TxQuantize::ARGB8888_AI44 : &TxQuantize::ARGB8888_AI44_ErrD;
1835 case GR_TEXFMT_ALPHA_INTENSITY_88:
1836 quantizer = fastQuantizer ? &TxQuantize::ARGB8888_AI88 : &TxQuantize::ARGB8888_AI88_Slow;
1843 #if !defined(NO_FILTER_THREAD)
1844 unsigned int numcore = _numcore;
1845 unsigned int blkrow = 0;
1846 while (numcore > 1 && blkrow == 0) {
1847 blkrow = (height >> 2) / numcore;
1850 if (blkrow > 0 && numcore > 1) {
1851 std::thread *thrd[MAX_NUMCORE];
1853 int blkheight = blkrow << 2;
1854 unsigned int srcStride = (width * blkheight) << 2;
1855 unsigned int destStride = srcStride >> bpp_shift;
1856 for (i = 0; i < numcore - 1; i++) {
1857 thrd[i] = new std::thread(std::bind(quantizer,
1866 thrd[i] = new std::thread(std::bind(quantizer,
1871 height - blkheight * i));
1872 for (i = 0; i < numcore; i++) {
1877 (*this.*quantizer)((uint32*)src, (uint32*)dest, width, height);
1880 (*this.*quantizer)((uint32*)src, (uint32*)dest, width, height);
1891 TxQuantize::FXT1(uint8 *src, uint8 *dest,
1892 int srcwidth, int srcheight, uint16 srcformat,
1893 int *destwidth, int *destheight, uint16 *destformat)
1896 * NOTE: src must be in ARGB8888 format, srcformat describes
1897 * the closest 16bbp representation of src.
1899 * NOTE: I have modified the dxtn library to use ARGB format
1900 * which originaly was ABGR format.
1905 if (_tx_compress_fxt1 &&
1906 srcwidth >= 8 && srcheight >= 4) {
1908 * width and height must be larger than 8 and 4 respectively
1910 int dstRowStride = ((srcwidth + 7) & ~7) << 1;
1911 int srcRowStride = (srcwidth << 2);
1913 #if !defined(NO_FILTER_THREAD)
1914 unsigned int numcore = _numcore;
1915 unsigned int blkrow = 0;
1916 while (numcore > 1 && blkrow == 0) {
1917 blkrow = (srcheight >> 2) / numcore;
1920 if (blkrow > 0 && numcore > 1) {
1921 std::thread *thrd[MAX_NUMCORE];
1923 int blkheight = blkrow << 2;
1924 unsigned int srcStride = (srcwidth * blkheight) << 2;
1925 unsigned int destStride = dstRowStride * blkrow;
1926 for (i = 0; i < numcore - 1; i++) {
1927 thrd[i] = new std::thread(std::bind(_tx_compress_fxt1,
1938 thrd[i] = new std::thread(std::bind(_tx_compress_fxt1,
1940 srcheight - blkheight * i,
1946 for (i = 0; i < numcore; i++) {
1951 (*_tx_compress_fxt1)(srcwidth, /* width */
1952 srcheight, /* height */
1953 4, /* comps: ARGB8888=4, RGB888=3 */
1955 srcRowStride, /* width*comps */
1956 dest, /* destination */
1957 dstRowStride); /* 16 bytes per 8x4 texel */
1960 (*_tx_compress_fxt1)(srcwidth, /* width */
1961 srcheight, /* height */
1962 4, /* comps: ARGB8888=4, RGB888=3 */
1964 srcRowStride, /* width*comps */
1965 dest, /* destination */
1966 dstRowStride); /* 16 bytes per 8x4 texel */
1969 /* dxtn adjusts width and height to M8 and M4 respectively by replication */
1970 *destwidth = (srcwidth + 7) & ~7;
1971 *destheight = (srcheight + 3) & ~3;
1972 *destformat = GR_TEXFMT_ARGB_CMP_FXT1;
1981 TxQuantize::DXTn(uint8 *src, uint8 *dest,
1982 int srcwidth, int srcheight, uint16 srcformat,
1983 int *destwidth, int *destheight, uint16 *destformat)
1986 * NOTE: src must be in ARGB8888 format, srcformat describes
1987 * the closest 16bbp representation of src.
1989 * NOTE: I have modified the dxtn library to use ARGB format
1990 * which originaly was ABGR format.
1995 if (_tx_compress_dxtn_rgba &&
1996 srcwidth >= 4 && srcheight >= 4) {
1998 * width and height must be larger than 4
2001 /* skip formats that DXTn won't help in size. */
2002 if (srcformat == GR_TEXFMT_ALPHA_8 ||
2003 srcformat == GR_TEXFMT_ALPHA_INTENSITY_44) {
2004 ; /* shutup compiler */
2006 int dstRowStride = ((srcwidth + 3) & ~3) << 2;
2007 int compression = GL_COMPRESSED_RGBA_S3TC_DXT5_EXT;
2009 *destformat = GR_TEXFMT_ARGB_CMP_DXT5;
2012 /* okay... we are going to disable DXT1 with 1bit alpha
2013 * for Glide64. some textures have all 0 alpha values.
2014 * see "N64 Kobe Bryant in NBA Courtside"
2016 if (srcformat == GR_TEXFMT_ARGB_1555) {
2018 compression = GL_COMPRESSED_RGBA_S3TC_DXT1_EXT;
2019 *destformat = GR_TEXFMT_ARGB_CMP_DXT1;
2022 if (srcformat == GR_TEXFMT_RGB_565 ||
2023 srcformat == GR_TEXFMT_INTENSITY_8) {
2025 compression = GL_COMPRESSED_RGB_S3TC_DXT1_EXT;
2026 *destformat = GR_TEXFMT_ARGB_CMP_DXT1;
2029 #if !defined(NO_FILTER_THREAD)
2030 unsigned int numcore = _numcore;
2031 unsigned int blkrow = 0;
2032 while (numcore > 1 && blkrow == 0) {
2033 blkrow = (srcheight >> 2) / numcore;
2036 if (blkrow > 0 && numcore > 1) {
2037 std::thread *thrd[MAX_NUMCORE];
2039 int blkheight = blkrow << 2;
2040 unsigned int srcStride = (srcwidth * blkheight) << 2;
2041 unsigned int destStride = dstRowStride * blkrow;
2042 for (i = 0; i < numcore - 1; i++) {
2043 thrd[i] = new std::thread(std::bind(_tx_compress_dxtn_rgba,
2054 thrd[i] = new std::thread(std::bind(_tx_compress_dxtn_rgba,
2057 srcheight - blkheight * i,
2062 for (i = 0; i < numcore; i++) {
2067 (*_tx_compress_dxtn_rgba)(4, /* comps: ARGB8888=4, RGB888=3 */
2068 srcwidth, /* width */
2069 srcheight, /* height */
2071 compression, /* format */
2072 dest, /* destination */
2073 dstRowStride); /* DXT1 = 8 bytes per 4x4 texel
2074 * others = 16 bytes per 4x4 texel */
2077 (*_tx_compress_dxtn_rgba)(4, /* comps: ARGB8888=4, RGB888=3 */
2078 srcwidth, /* width */
2079 srcheight, /* height */
2081 compression, /* format */
2082 dest, /* destination */
2083 dstRowStride); /* DXT1 = 8 bytes per 4x4 texel
2084 * others = 16 bytes per 4x4 texel */
2087 /* dxtn adjusts width and height to M4 by replication */
2088 *destwidth = (srcwidth + 3) & ~3;
2089 *destheight = (srcheight + 3) & ~3;
2099 TxQuantize::compress(uint8 *src, uint8 *dest,
2100 int srcwidth, int srcheight, uint16 srcformat,
2101 int *destwidth, int *destheight, uint16 *destformat,
2102 int compressionType)
2106 switch (compressionType) {
2107 case FXT1_COMPRESSION:
2108 bRet = FXT1(src, dest,
2109 srcwidth, srcheight, srcformat,
2110 destwidth, destheight, destformat);
2112 case S3TC_COMPRESSION:
2113 bRet = DXTn(src, dest,
2114 srcwidth, srcheight, srcformat,
2115 destwidth, destheight, destformat);
2117 case NCC_COMPRESSION:
2118 /* TODO: narrow channel compression */
2127 TxQuantize::I8_ARGB8888(uint32* src, uint32* dest, int width, int height)
2129 int siz = (width * height) >> 2;
2136 mov esi, dword ptr [src];
2137 mov edi, dword ptr [dest];
2138 mov ecx, dword ptr [siz];
2141 mov eax, dword ptr [esi];
2145 // 11111111 aaaaaaaa aaaaaaaa aaaaaaaa
2147 and eax, 0x000000ff;
2148 mov ebx, eax; // 00000000 00000000 00000000 aaaaaaaa
2149 shl ebx, 8; // 00000000 00000000 aaaaaaaa 00000000
2150 or eax, ebx; // 00000000 00000000 aaaaaaaa aaaaaaaa
2151 shl ebx, 8; // 00000000 aaaaaaaa 00000000 00000000
2152 or eax, ebx; // 00000000 aaaaaaaa aaaaaaaa aaaaaaaa
2153 or eax, 0xff000000; // 11111111 aaaaaaaa aaaaaaaa aaaaaaaa
2155 mov dword ptr [edi], eax;
2159 and eax, 0x0000ff00;
2160 mov ebx, eax; // 00000000 00000000 aaaaaaaa 00000000
2161 shr ebx, 8; // 00000000 00000000 00000000 aaaaaaaa
2162 or eax, ebx; // 00000000 00000000 aaaaaaaa aaaaaaaa
2163 shl ebx, 16; // 00000000 aaaaaaaa 00000000 00000000
2164 or eax, ebx; // 00000000 aaaaaaaa aaaaaaaa aaaaaaaa
2165 or eax, 0xff000000; // 11111111 aaaaaaaa aaaaaaaa aaaaaaaa
2167 mov dword ptr [edi], eax;
2171 and eax, 0x00ff0000;
2172 mov ebx, eax; // 00000000 aaaaaaaa 00000000 00000000
2173 shr ebx, 8; // 00000000 00000000 aaaaaaaa 00000000
2174 or eax, ebx; // 00000000 aaaaaaaa aaaaaaaa 00000000
2175 shr ebx, 8; // 00000000 00000000 00000000 aaaaaaaa
2176 or eax, ebx; // 00000000 aaaaaaaa aaaaaaaa aaaaaaaa
2177 or eax, 0xff000000; // 11111111 aaaaaaaa aaaaaaaa aaaaaaaa
2179 mov dword ptr [edi], eax;
2183 and eax, 0xff000000;
2184 mov ebx, eax; // aaaaaaaa 00000000 00000000 00000000
2185 shr ebx, 8; // 00000000 aaaaaaaa 00000000 00000000
2186 or eax, ebx; // aaaaaaaa aaaaaaaa 00000000 00000000
2187 shr ebx, 8; // 00000000 00000000 aaaaaaaa 00000000
2188 or eax, ebx; // aaaaaaaa aaaaaaaa aaaaaaaa 00000000
2189 shr eax, 8; // 00000000 aaaaaaaa aaaaaaaa aaaaaaaa
2190 or eax, 0xff000000; // 11111111 aaaaaaaa aaaaaaaa aaaaaaaa
2192 mov dword ptr [edi], eax;
2205 TxQuantize::ARGB8888_I8(uint32* src, uint32* dest, int width, int height)
2207 ARGB8888_A8(src, dest, width, height);
2211 TxQuantize::ARGB1555_ABGR8888(uint32* src, uint32* dest, int width, int height)
2213 int siz = (width * height) >> 1;
2220 mov esi, dword ptr [src];
2221 mov edi, dword ptr [dest];
2222 mov ecx, dword ptr [siz];
2225 mov eax, dword ptr [esi];
2228 // arrr rrgg gggb bbbb
2229 // aaaaaaaa bbbbbbbb gggggggg rrrrrrrr
2230 mov edx, eax; // edx = arrrrrgg gggbbbbb arrrrrgg gggbbbbb
2231 and ebx, 0x00000000;
2232 and eax, 0x00008000; // eax = 00000000 00000000 a0000000 00000000
2234 or ebx, 0xff000000; // ebx = aaaaaaaa 00000000 00000000 00000000
2237 mov eax, edx; // eax = arrrrrgg gggbbbbb arrrrrgg gggbbbbb
2238 and edx, 0x0000001f; // edx = 00000000 00000000 00000000 000bbbbb
2239 shl edx, 14; // edx = 00000000 00000bbb bb000000 00000000
2240 or ebx, edx; // ebx = aaaaaaaa 00000bbb bb000000 00000000
2241 shl edx, 5; // edx = 00000000 bbbbb000 00000000 00000000
2242 or ebx, edx; // ebx = aaaaaaaa bbbbbbbb bb000000 00000000
2243 and ebx, 0xffff0000; // ebx = aaaaaaaa bbbbbbbb 00000000 00000000
2245 and edx, 0x000003e0; // edx = 00000000 00000000 000000gg ggg00000
2246 shl edx, 1; // edx = 00000000 00000000 00000ggg gg000000
2247 or ebx, edx; // ebx = aaaaaaaa bbbbbbbb 00000ggg gg000000
2248 shl edx, 5; // edx = 00000000 00000000 ggggg000 00000000
2249 or ebx, edx; // ebx = aaaaaaaa bbbbbbbb gggggggg gg000000
2250 and ebx, 0xffffff00; // ebx = aaaaaaaa bbbbbbbb gggggggg 00000000
2252 and edx, 0x00007c00; // edx = 00000000 00000000 0rrrrr00 00000000
2253 shr edx, 7; // edx = 00000000 00000000 00000000 rrrrr000
2254 or ebx, edx; // ebx = aaaaaaaa bbbbbbbb gggggggg rrrrr000
2255 shr edx, 5; // edx = 00000000 00000000 00000000 00000rrr
2256 or ebx, edx; // ebx = aaaaaaaa bbbbbbbb gggggggg rrrrrrrr
2258 mov dword ptr [edi], ebx;
2261 shr eax, 16; // eax = 00000000 00000000 arrrrrgg gggbbbbb
2262 mov edx, eax; // edx = 00000000 00000000 arrrrrgg gggbbbbb
2263 and ebx, 0x00000000;
2264 and eax, 0x00008000; // eax = 00000000 00000000 a0000000 00000000
2266 or ebx, 0xff000000; // ebx = aaaaaaaa 00000000 00000000 00000000
2269 mov eax, edx; // eax = arrrrrgg gggbbbbb arrrrrgg gggbbbbb
2270 and edx, 0x0000001f; // edx = 00000000 00000000 00000000 000bbbbb
2271 shl edx, 14; // edx = 00000000 00000bbb bb000000 00000000
2272 or ebx, edx; // ebx = aaaaaaaa 00000bbb bb000000 00000000
2273 shl edx, 5; // edx = 00000000 bbbbb000 00000000 00000000
2274 or ebx, edx; // ebx = aaaaaaaa bbbbbbbb bb000000 00000000
2275 and ebx, 0xffff0000; // ebx = aaaaaaaa bbbbbbbb 00000000 00000000
2277 and edx, 0x000003e0; // edx = 00000000 00000000 000000gg ggg00000
2278 shl edx, 1; // edx = 00000000 00000000 00000ggg gg000000
2279 or ebx, edx; // ebx = aaaaaaaa bbbbbbbb 00000ggg gg000000
2280 shl edx, 5; // edx = 00000000 00000000 ggggg000 00000000
2281 or ebx, edx; // ebx = aaaaaaaa bbbbbbbb gggggggg gg000000
2282 and ebx, 0xffffff00; // ebx = aaaaaaaa bbbbbbbb gggggggg 00000000
2284 and edx, 0x00007c00; // edx = 00000000 00000000 0rrrrr00 00000000
2285 shr edx, 7; // edx = 00000000 00000000 00000000 rrrrr000
2286 or ebx, edx; // ebx = aaaaaaaa bbbbbbbb gggggggg rrrrr000
2287 shr edx, 5; // edx = 00000000 00000000 00000000 00000rrr
2288 or ebx, edx; // ebx = aaaaaaaa bbbbbbbb gggggggg rrrrrrrr
2290 mov dword ptr [edi], ebx;
2303 TxQuantize::ARGB4444_ABGR8888(uint32* src, uint32* dest, int width, int height)
2305 int siz = (width * height) >> 1;
2312 mov esi, dword ptr [src];
2313 mov edi, dword ptr [dest];
2314 mov ecx, dword ptr [siz];
2317 mov eax, dword ptr [esi];
2320 // aaaa rrrr gggg bbbb
2321 // aaaaaaaa bbbbbbbb gggggggg rrrrrrrr
2323 and eax, 0x0000ffff;
2324 mov ebx, eax; // 00000000 00000000 aaaarrrr ggggbbbb
2325 and ebx, 0x0000f000; // 00000000 00000000 aaaa0000 00000000
2326 shl ebx, 12; // 0000aaaa 00000000 00000000 00000000
2327 or eax, ebx; // 0000aaaa 00000000 aaaarrrr ggggbbbb
2329 and ebx, 0x0000000f; // 00000000 00000000 00000000 0000bbbb
2330 shl ebx, 16; // 00000000 0000bbbb 00000000 00000000
2331 or eax, ebx; // 0000aaaa 0000bbbb aaaarrrr ggggbbbb
2333 and ebx, 0x00000f00; // 00000000 00000000 0000rrrr 00000000
2334 shr ebx, 8; // 00000000 00000000 00000000 0000rrrr
2335 and eax, 0xfffffff0;
2336 or eax, ebx; // 0000aaaa 0000bbbb aaaarrrr ggggrrrr
2338 and ebx, 0x000000f0; // 00000000 00000000 00000000 gggg0000
2339 shl ebx, 4; // 00000000 00000000 0000gggg 00000000
2340 and eax, 0x0f0f000f; // 0000aaaa 0000bbbb 00000000 0000rrrr
2341 or eax, ebx; // 0000aaaa 0000bbbb 0000gggg 0000rrrr
2343 shl ebx, 4; // aaaa0000 bbbb0000 gggg0000 rrrr0000
2344 or eax, ebx; // aaaaaaaa bbbbbbbb gggggggg rrrrrrrr
2346 mov dword ptr [edi], eax;
2351 mov ebx, edx; // 00000000 00000000 aaaarrrr ggggbbbb
2352 and ebx, 0x0000f000; // 00000000 00000000 aaaa0000 00000000
2353 shl ebx, 12; // 0000aaaa 00000000 00000000 00000000
2354 or edx, ebx; // 0000aaaa 00000000 aaaarrrr ggggbbbb
2356 and ebx, 0x0000000f; // 00000000 00000000 00000000 0000bbbb
2357 shl ebx, 16; // 00000000 0000bbbb 00000000 00000000
2358 or edx, ebx; // 0000aaaa 0000bbbb aaaarrrr ggggbbbb
2360 and ebx, 0x00000f00; // 00000000 00000000 0000rrrr 00000000
2361 shr ebx, 8; // 00000000 00000000 00000000 0000rrrr
2362 and edx, 0xfffffff0;
2363 or edx, ebx; // 0000aaaa 0000bbbb aaaarrrr ggggrrrr
2365 and ebx, 0x000000f0; // 00000000 00000000 00000000 gggg0000
2366 shl ebx, 4; // 00000000 00000000 0000gggg 00000000
2367 and edx, 0x0f0f000f; // 0000aaaa 0000bbbb 00000000 0000rrrr
2368 or edx, ebx; // 0000aaaa 0000bbbb 0000gggg 0000rrrr
2370 shl ebx, 4; // aaaa0000 bbbb0000 gggg0000 rrrr0000
2371 or edx, ebx; // aaaaaaaa bbbbbbbb gggggggg rrrrrrrr
2373 mov dword ptr [edi], edx;
2386 TxQuantize::ARGB8888_ABGR8888(uint32* src, uint32* dest, int width, int height)
2388 int siz = width * height;
2395 mov esi, dword ptr [src];
2396 mov edi, dword ptr [dest];
2397 mov ecx, dword ptr [siz];
2400 mov eax, dword ptr [esi];
2403 // aaaaaaaa bbbbbbbb gggggggg rrrrrrrr
2407 and eax, 0xff000000;
2411 mov dword ptr [edi], eax;