Skip to content

Commit

Permalink
Fixed|DisplayMode: Factor in the original color transfer curve
Browse files Browse the repository at this point in the history
When Doomsday modifies the display's color transfer function, it
shouldn't override the monitor color calibration that the user has
done. Now the user's native color curve is factored in to the curve
that Doomsday specifies (which is based on a linear color space).
  • Loading branch information
skyjake committed Dec 10, 2012
1 parent 62d995e commit 48477bf
Showing 1 changed file with 30 additions and 8 deletions.
38 changes: 30 additions & 8 deletions doomsday/engine/src/ui/displaymode.cpp
Expand Up @@ -340,18 +340,40 @@ int DisplayMode_Change(const DisplayMode* mode, boolean shouldCapture)
return DisplayMode_Native_Change(mode, shouldCapture || (originalMode != *mode));
}

void DisplayMode_GetColorTransfer(displaycolortransfer_t* colors)
static inline de::duint16 intensity8To16(de::duint8 b)
{
/// @todo Factor in the original color transfer function, which may be
/// set up specifically by the user.
return (b << 8) | b; // 0xFF => 0xFFFF
}

void DisplayMode_GetColorTransfer(displaycolortransfer_t *colors)
{
displaycolortransfer_t mapped;
DisplayMode_Native_GetColorTransfer(&mapped);

DisplayMode_Native_GetColorTransfer(colors);
// Factor out the original color transfer function, which may be set up
// specifically by the user.
for(int i = 0; i < 256; ++i)
{
#define LINEAR_UNMAP(i, c) ( (unsigned short) (float(mapped.table[i]) / float(originalColorTransfer.table[i]) * intensity8To16(c) ) )
colors->table[i] = LINEAR_UNMAP(i, i);
colors->table[i + 256] = LINEAR_UNMAP(i + 256, i);
colors->table[i + 512] = LINEAR_UNMAP(i + 512, i);
}
}

void DisplayMode_SetColorTransfer(const displaycolortransfer_t* colors)
void DisplayMode_SetColorTransfer(displaycolortransfer_t const *colors)
{
/// @todo Factor in the original color transfer function, which may be
/// set up specifically by the user.
displaycolortransfer_t mapped;

// Factor in the original color transfer function, which may be set up
// specifically by the user.
for(int i = 0; i < 256; ++i)
{
#define LINEAR_MAP(i, c) ( (unsigned short) (float(colors->table[i]) / float(intensity8To16(c)) * originalColorTransfer.table[i]) )
mapped.table[i] = LINEAR_MAP(i, i);
mapped.table[i + 256] = LINEAR_MAP(i + 256, i);
mapped.table[i + 512] = LINEAR_MAP(i + 512, i);
}

DisplayMode_Native_SetColorTransfer(colors);
DisplayMode_Native_SetColorTransfer(&mapped);
}

0 comments on commit 48477bf

Please sign in to comment.