@@ -71,9 +71,10 @@ MLConverter::MLConverter(void)
71
71
void
72
72
MLConverter::Argb8bitToR8G8B8A8 (const uint32_t * pFrom, uint32_t * pTo, const int width, const int height)
73
73
{
74
- int pos = 0 ;
75
74
for (int y = 0 ; y < height; ++y) {
76
75
for (int x = 0 ; x < width; ++x) {
76
+ const int pos = x + y * width;
77
+
77
78
// bmdFormat8BitARGB
78
79
// ビッグエンディアンのA8R8G8B8 → リトルエンディアンのR8G8B8A8
79
80
const uint32_t v = NtoHL (pFrom[pos]);
@@ -87,8 +88,6 @@ MLConverter::Argb8bitToR8G8B8A8(const uint32_t* pFrom, uint32_t* pTo, const int
87
88
const uint32_t g = (v >> 8 ) & 0xff ;
88
89
const uint32_t b = (v >> 0 ) & 0xff ;
89
90
pTo[pos] = (a << 24 ) + (b << 16 ) + (g << 8 ) + r;
90
-
91
- ++pos;
92
91
}
93
92
}
94
93
}
97
96
MLConverter::Rgb10bitToRGBA8bit (const uint32_t *pFrom, uint32_t *pTo, const int width, const int height, const uint8_t alpha)
98
97
{
99
98
const uint32_t a = alpha;
100
- int pos = 0 ;
101
99
for (int y = 0 ; y < height; ++y) {
102
100
for (int x = 0 ; x < width; ++x) {
101
+ const int pos = x + y * width;
102
+
103
103
// bmdFormat10BitRGB
104
104
// ビッグエンディアンのX2R10G10B10 → リトルエンディアンのR8G8B8A8
105
105
const uint32_t v = NtoHL (pFrom[pos]);
@@ -112,8 +112,6 @@ MLConverter::Rgb10bitToRGBA8bit(const uint32_t *pFrom, uint32_t *pTo, const int
112
112
const uint32_t g = (v >> 12 ) & 0xff ;
113
113
const uint32_t b = (v >> 2 ) & 0xff ;
114
114
pTo[pos] = (a << 24 ) + (b << 16 ) + (g << 8 ) + r;
115
-
116
- ++pos;
117
115
}
118
116
}
119
117
}
@@ -125,9 +123,10 @@ void
125
123
MLConverter::Rgb10bitToR10G10B10A2 (const uint32_t * pFrom, uint32_t * pTo, const int width, const int height, const uint8_t alpha)
126
124
{
127
125
const uint32_t a = (alpha >> 6 ) & 0x3 ;
128
- int pos = 0 ;
129
126
for (int y = 0 ; y < height; ++y) {
130
127
for (int x = 0 ; x < width; ++x) {
128
+ const int pos = x + y * width;
129
+
131
130
// bmdFormat10BitRGB
132
131
// ビッグエンディアンのX2R10G10B10 → リトルエンディアンのR8G8B8A8
133
132
const uint32_t v = NtoHL (pFrom[pos]);
@@ -140,8 +139,6 @@ MLConverter::Rgb10bitToR10G10B10A2(const uint32_t* pFrom, uint32_t* pTo, const i
140
139
const uint32_t g = (v >> 10 ) & 0x3ff ;
141
140
const uint32_t b = (v >> 0 ) & 0x3ff ;
142
141
pTo[pos] = (a << 30 ) + (b << 20 ) + (g << 10 ) + r;
143
-
144
- ++pos;
145
142
}
146
143
}
147
144
}
@@ -156,10 +153,11 @@ MLConverter::R10G10B10A2ToExrHalfFloat(const uint32_t* pFrom, uint16_t* pTo, con
156
153
// 0.0~1.0の範囲の値。
157
154
half aF = (float )(alpha /255 .0f );
158
155
159
- int readPos = 0 ;
160
- int writePos = 0 ;
161
156
for (int y = 0 ; y < height; ++y) {
162
157
for (int x = 0 ; x < width; ++x) {
158
+ const int readPos = x + y * width;
159
+ const int writePos = readPos * 4 ;
160
+
163
161
const uint32_t v = pFrom[readPos];
164
162
// v LSB
165
163
// XXRRRRRR RRRRGGGG GGGGGGBB BBBBBBBB
@@ -199,9 +197,6 @@ MLConverter::R10G10B10A2ToExrHalfFloat(const uint32_t* pFrom, uint16_t* pTo, con
199
197
assert (0 );
200
198
break ;
201
199
}
202
-
203
- ++readPos;
204
- writePos += 4 ;
205
200
}
206
201
}
207
202
}
@@ -213,9 +208,11 @@ void
213
208
MLConverter::R10G10B10A2ToR210 (const uint32_t * pFrom, uint32_t * pTo, const int width, const int height, const uint8_t alpha)
214
209
{
215
210
const uint32_t a = (alpha >> 6 ) & 0x3 ;
216
- int pos = 0 ;
211
+
217
212
for (int y = 0 ; y < height; ++y) {
218
213
for (int x = 0 ; x < width; ++x) {
214
+ const int pos = x + y * width;
215
+
219
216
const uint32_t v = pFrom[pos];
220
217
// v LSB
221
218
// XXRRRRRR RRRRGGGG GGGGGGBB BBBBBBBB
@@ -230,7 +227,6 @@ MLConverter::R10G10B10A2ToR210(const uint32_t* pFrom, uint32_t* pTo, const int w
230
227
231
228
const uint32_t r210 = (a << 30 ) + (r << 20 ) + (g << 10 ) + b;
232
229
pTo[pos] = HtoNL (r210);
233
- ++pos;
234
230
}
235
231
}
236
232
}
@@ -241,12 +237,16 @@ MLConverter::R10G10B10A2ToR210(const uint32_t* pFrom, uint32_t* pTo, const int w
241
237
void
242
238
MLConverter::Rgb12bitToR8G8B8A8 (const uint32_t * pFrom, uint32_t * pTo, const int width, const int height, const uint8_t alpha)
243
239
{
240
+ // / widthは8で割り切れます。
241
+ assert ((width & 7 ) == 0 );
242
+
244
243
const uint8_t a = alpha;
245
- int fromPos = 0 ;
246
- int toPos = 0 ;
247
244
const int pixelCount = width * height;
248
245
249
- while (toPos < pixelCount) {
246
+ for (int i=0 ; i<pixelCount/8 ; ++i) {
247
+ const int fromPos = i * 9 ;
248
+ const int toPos = i * 8 ;
249
+
250
250
// 8pixelsのRGB3チャンネルのデータが36バイト=9個のuint32に入っている。
251
251
// 3ch * 8px * 12bit / 8bit = 36バイト。
252
252
const uint32_t w0 = NtoHL (pFrom[fromPos + 0 ]);
@@ -348,9 +348,6 @@ MLConverter::Rgb12bitToR8G8B8A8(const uint32_t* pFrom, uint32_t* pTo, const int
348
348
pTo[toPos + 5 ] = (a << 24 ) + (b5 << 16 ) + (g5 << 8 ) + r5;
349
349
pTo[toPos + 6 ] = (a << 24 ) + (b6 << 16 ) + (g6 << 8 ) + r6;
350
350
pTo[toPos + 7 ] = (a << 24 ) + (b7 << 16 ) + (g7 << 8 ) + r7;
351
-
352
- fromPos += 9 ;
353
- toPos += 8 ;
354
351
}
355
352
}
356
353
@@ -360,12 +357,16 @@ MLConverter::Rgb12bitToR8G8B8A8(const uint32_t* pFrom, uint32_t* pTo, const int
360
357
void
361
358
MLConverter::Rgb12bitToR10G10B10A2 (const uint32_t * pFrom, uint32_t * pTo, const int width, const int height, const uint8_t alpha)
362
359
{
360
+ // / widthは8で割り切れます。
361
+ assert ((width & 7 ) == 0 );
362
+
363
363
const uint8_t a = (alpha>>6 ) & 0x3 ;
364
- int fromPos = 0 ;
365
- int toPos = 0 ;
366
364
const int pixelCount = width * height;
367
365
368
- while (toPos < pixelCount) {
366
+ for (int i=0 ; i<pixelCount/8 ; ++i) {
367
+ const int fromPos = i * 9 ;
368
+ const int toPos = i * 8 ;
369
+
369
370
// 8pixelsのRGB3チャンネルのデータが36バイト=9個のuint32に入っている。
370
371
// 3ch * 8px * 12bit / 8bit = 36バイト。
371
372
const uint32_t w0 = NtoHL (pFrom[fromPos + 0 ]);
@@ -468,9 +469,6 @@ MLConverter::Rgb12bitToR10G10B10A2(const uint32_t* pFrom, uint32_t* pTo, const i
468
469
pTo[toPos + 5 ] = (a << 30 ) + (b5 << 20 ) + (g5 << 10 ) + r5;
469
470
pTo[toPos + 6 ] = (a << 30 ) + (b6 << 20 ) + (g6 << 10 ) + r6;
470
471
pTo[toPos + 7 ] = (a << 30 ) + (b7 << 20 ) + (g7 << 10 ) + r7;
471
-
472
- fromPos += 9 ;
473
- toPos += 8 ;
474
472
}
475
473
}
476
474
@@ -480,12 +478,16 @@ MLConverter::Rgb12bitToR10G10B10A2(const uint32_t* pFrom, uint32_t* pTo, const i
480
478
void
481
479
MLConverter::Rgb12bitToR210 (const uint32_t * pFrom, uint32_t * pTo, const int width, const int height)
482
480
{
481
+ // / widthは8で割り切れます。
482
+ assert ((width & 7 ) == 0 );
483
+
483
484
const uint8_t a = 0x3 ;
484
- int fromPos = 0 ;
485
- int toPos = 0 ;
486
485
const int pixelCount = width * height;
487
486
488
- while (toPos < pixelCount) {
487
+ for (int i=0 ; i<pixelCount/8 ; ++i) {
488
+ const int fromPos = i * 9 ;
489
+ const int toPos = i * 8 ;
490
+
489
491
// 8pixelsのRGB3チャンネルのデータが36バイト=9個のuint32に入っている。
490
492
// 3ch * 8px * 12bit / 8bit = 36バイト。
491
493
const uint32_t w0 = NtoHL (pFrom[fromPos + 0 ]);
@@ -601,9 +603,6 @@ MLConverter::Rgb12bitToR210(const uint32_t* pFrom, uint32_t* pTo, const int widt
601
603
pTo[toPos + 5 ] = HtoNL (r210_5);
602
604
pTo[toPos + 6 ] = HtoNL (r210_6);
603
605
pTo[toPos + 7 ] = HtoNL (r210_7);
604
-
605
- fromPos += 9 ;
606
- toPos += 8 ;
607
606
}
608
607
}
609
608
@@ -614,12 +613,16 @@ MLConverter::Rgb12bitToR210(const uint32_t* pFrom, uint32_t* pTo, const int widt
614
613
void
615
614
MLConverter::Rgb12bitToR16G16B16A16 (const uint32_t * pFrom, uint64_t * pTo, const int width, const int height, const uint8_t alpha)
616
615
{
616
+ // / widthは8で割り切れます。
617
+ assert ((width & 7 ) == 0 );
618
+
617
619
const uint16_t a = alpha * 257 ; // < 255 * 257 = 65535
618
- int fromPos = 0 ;
619
- int toPos = 0 ;
620
620
const int pixelCount = width * height;
621
621
622
- while (toPos < pixelCount) {
622
+ for (int i = 0 ; i < pixelCount / 8 ; ++i) {
623
+ const int fromPos = i * 9 ;
624
+ const int toPos = i * 8 ;
625
+
623
626
// 8pixelsのRGB3チャンネルのデータが36バイト=9個のuint32に入っている。
624
627
// 3ch * 8px * 12bit / 8bit = 36バイト。
625
628
const uint32_t w0 = NtoHL (pFrom[fromPos + 0 ]);
@@ -721,9 +724,6 @@ MLConverter::Rgb12bitToR16G16B16A16(const uint32_t* pFrom, uint64_t* pTo, const
721
724
pTo[toPos + 5 ] = ((uint64_t )a << 48 ) + ((uint64_t )b5 << 32 ) + ((uint32_t )g5 << 16 ) + r5;
722
725
pTo[toPos + 6 ] = ((uint64_t )a << 48 ) + ((uint64_t )b6 << 32 ) + ((uint32_t )g6 << 16 ) + r6;
723
726
pTo[toPos + 7 ] = ((uint64_t )a << 48 ) + ((uint64_t )b7 << 32 ) + ((uint32_t )g7 << 16 ) + r7;
724
-
725
- fromPos += 9 ;
726
- toPos += 8 ;
727
727
}
728
728
729
729
}
0 commit comments