Skip to content

Commit 3b00f79

Browse files
author
Chuck Walbourn
committed
Code review for non-turbo path
1 parent 173ab3f commit 3b00f79

1 file changed

Lines changed: 18 additions & 14 deletions

File tree

‎Auxiliary/DirectXTexJPEG.cpp‎

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -163,17 +163,20 @@ namespace
163163

164164
#ifndef LIBJPEG_TURBO_VERSION
165165
// shift pixels with padding in reverse order (to make it work in-memory)
166-
void ShiftPixels(ScratchImage& image) noexcept
166+
void ShiftPixels(const Image& image) noexcept
167167
{
168-
size_t num_pixels = dec.output_width * dec.output_height;
169-
uint8_t* dst = image.GetPixels();
170-
const uint8_t* src = dst;
171-
for (size_t i = num_pixels - 1; i > 0; i -= 1)
168+
uint8_t* scanline = image.pixels;
169+
for (size_t y = 0; y < image.height; ++y)
172170
{
173-
dst[4*i + 0] = src[3*i + 0];
174-
dst[4*i + 1] = src[3*i + 1];
175-
dst[4*i + 2] = src[3*i + 2];
176-
dst[4*i + 3] = 0;
171+
for (size_t i = (image.width - 1); i > 0; i -= 1)
172+
{
173+
scanline[4*i + 0] = scanline[3*i + 0];
174+
scanline[4*i + 1] = scanline[3*i + 1];
175+
scanline[4*i + 2] = scanline[3*i + 2];
176+
scanline[4*i + 3] = 0xff;
177+
}
178+
179+
scanline += image.rowPitch;
177180
}
178181
}
179182
#endif
@@ -225,10 +228,9 @@ namespace
225228

226229
#ifndef LIBJPEG_TURBO_VERSION
227230
// if NOT TurboJPEG, we need to make 3 component images to 4 component image
228-
if (dec.out_color_space != JCS_GRAYSCALE
229-
&& dec.out_color_space != JCS_RGB565)
231+
if (dec.out_color_space != JCS_GRAYSCALE)
230232
{
231-
ShiftPixels(image);
233+
ShiftPixels(img);
232234
}
233235
#endif
234236

@@ -292,8 +294,10 @@ namespace
292294
break;
293295
#else
294296
case DXGI_FORMAT_R8G8B8A8_UNORM:
297+
case DXGI_FORMAT_R8G8B8A8_UNORM_SRGB:
295298
enc.input_components = 3;
296299
enc.in_color_space = JCS_RGB;
300+
break;
297301
#endif
298302

299303
default:
@@ -313,15 +317,15 @@ namespace
313317
#ifndef LIBJPEG_TURBO_VERSION
314318
if (enc.input_components == 3)
315319
{
316-
const size_t stride = enc.image_width * static_cast<size_t>(enc.input_components)
320+
const size_t stride = enc.image_width * static_cast<size_t>(enc.input_components);
317321
auto scanline = std::make_unique<uint8_t[]>(stride);
318322
JSAMPROW rows[1]{ scanline.get() };
319323

320324
while (enc.next_scanline < enc.image_height)
321325
{
322326
// Copy 4 to 3 components
323327
const uint8_t* src = image.pixels + enc.next_scanline * image.rowPitch;
324-
const uint8_t* dst = scanline.get();
328+
uint8_t* dst = scanline.get();
325329
for(size_t i=0; i < image.width; ++i)
326330
{
327331
dst[3*i + 0] = src[4*i + 0];

0 commit comments

Comments
 (0)