Skip to content

Commit

Permalink
Remove code duplication from dealing with left over pixels in rgba ->…
Browse files Browse the repository at this point in the history
… rgba conversion.
  • Loading branch information
xwidghet committed Jun 18, 2017
1 parent 9b33207 commit 1a819db
Showing 1 changed file with 4 additions and 41 deletions.
45 changes: 4 additions & 41 deletions src/RageSurfaceUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -589,6 +589,10 @@ static bool blit_rgba_to_rgba( const RageSurface *src_surf, const RageSurface *d
int localHeight = segmentSize + segmentSize*curThread;
int localEnd = localHeight - segmentSize;

// Ensure no pixels are missed when the height isn't divisible by thread count
if (curThread == numThreads - 1)
localHeight = height;

auto localSrc = src;
auto localDst = dst;

Expand Down Expand Up @@ -632,47 +636,6 @@ static bool blit_rgba_to_rgba( const RageSurface *src_surf, const RageSurface *d
for (auto& t : threads)
t.join();

// Convert any left over pixels
int endHeight = segmentSize + segmentSize*(numThreads-1);
if (endHeight < height)
{
int startingPoint = segmentSize*numThreads;
// Skip pixels until we arrive at this thread's starting point
// -
// handle width
src += src_surf->format->BytesPerPixel*width*startingPoint;
dst += dst_surf->format->BytesPerPixel*width*startingPoint;
// handle height
src += srcskip*startingPoint;
dst += dstskip*startingPoint;

while (height-- > endHeight)
{
int x = 0;
while (x++ < width)
{
unsigned int pixel = RageSurfaceUtils::decodepixel(src, src_surf->format->BytesPerPixel);

// Convert pixel to the destination format.
unsigned int opixel = 0;
for (int c = 0; c < 4; ++c)
{
int lSrc = (pixel & src_masks[c]) >> src_shifts[c];
opixel |= lookup[c][lSrc] << dst_shifts[c];
}

// Store it.
RageSurfaceUtils::encodepixel(dst, dst_surf->format->BytesPerPixel, opixel);

src += src_surf->format->BytesPerPixel;
dst += dst_surf->format->BytesPerPixel;
}

src += srcskip;
dst += dstskip;
}
}

return true;
}

Expand Down

0 comments on commit 1a819db

Please sign in to comment.