Skip to content

Commit

Permalink
Stephen's work on the lcms2 migration.
Browse files Browse the repository at this point in the history
Signed-off-by: Stephen Shaw <sshaw@decriptor.com>
  • Loading branch information
polymeris authored and decriptor committed Oct 9, 2013
1 parent b069f06 commit 9c52d5f
Show file tree
Hide file tree
Showing 9 changed files with 126 additions and 281 deletions.
18 changes: 9 additions & 9 deletions configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ GTKSHARPBEANS_REQUIRED=2.13.92
GTK_REQUIRED=2.14
MONO_CAIRO_REQUIRED=1.2.5
CAIRO_REQUIRED=1.4.0
LCMS_REQUIRED=1.12
LCMS2_REQUIRED=2.4

PKG_CHECK_MODULES(F, gnome-desktop-2.0 >= $LIBGNOMEDESKTOP_REQUIRED gtk+-2.0 >= $GTK_REQUIRED mono-cairo >= $MONO_CAIRO_REQUIRED cairo >= $CAIRO_REQUIRED)
AC_SUBST(F_CFLAGS)
Expand Down Expand Up @@ -180,12 +180,12 @@ LIBJPEG='-ljpeg'

dnl --- lcms

PKG_CHECK_MODULES(LCMS, lcms >= $LCMS_REQUIRED, [],
[AC_CHECK_LIB(lcms, cmsCreateBCHSWabstractProfile, [],
[AC_MSG_ERROR([liblcms not found])], -lm)
AC_CHECK_HEADER(lcms.h, , [AC_MSG_ERROR([liblcms not found])])
LCMS_LIBS='-llcms'
LCMS_CFLAGS=''])
PKG_CHECK_MODULES(LCMS2, lcms2 >= $LCMS2_REQUIRED, [],
[AC_CHECK_LIB(lcms2, cmsCreateBCHSWabstractProfile, [],
[AC_MSG_ERROR([liblcms2 not found])], -lm)
AC_CHECK_HEADER(lcms2.h, , [AC_MSG_ERROR([liblcms2 not found])])
LCMS2_LIBS='-llcms2'
LCMS2_CFLAGS=''])

dnl --- libunique check
PKG_CHECK_MODULES(UNIQUE, unique-1.0 >= 1.0)
Expand Down Expand Up @@ -237,8 +237,8 @@ AM_GLIB_GNU_GETTEXT
dnl --- Prologue

AC_SUBST(LIBJPEG)
AC_SUBST(LCMS_LIBS)
AC_SUBST(LCMS_CFLAGS)
AC_SUBST(LCMS2_LIBS)
AC_SUBST(LCMS2_CFLAGS)
AC_SUBST(CFLAGS)
AC_SUBST(CPPFLAGS)
AC_SUBST(LDFLAGS)
Expand Down
90 changes: 50 additions & 40 deletions lib/libfspot/f-screen-utils.c
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@
#include <X11/Xlib.h>
#include <X11/Xatom.h>
#include <gdk/gdkx.h>
#include <lcms.h>
#include <lcms2.h>
#include <lcms2_plugin.h>

cmsHPROFILE *
f_screen_get_profile (GdkScreen *screen)
Expand Down Expand Up @@ -51,7 +52,7 @@ typedef struct {


static
int bchswSampler(register WORD In[], register WORD Out[], register LPVOID Cargo)
int bchswSampler(register const cmsUInt16Number In[], register cmsUInt16Number Out[], register void* Cargo)
{
cmsCIELab LabIn, LabOut;
cmsCIELCh LChIn, LChOut;
Expand Down Expand Up @@ -111,99 +112,108 @@ int bchswSampler(register WORD In[], register WORD Out[], register LPVOID Cargo)
// Creates an abstract profile operating in Lab space for Brightness,
// contrast, Saturation and white point displacement

cmsHPROFILE LCMSEXPORT f_cmsCreateBCHSWabstractProfile(int nLUTPoints,
cmsHPROFILE CMSEXPORT f_cmsCreateBCHSWabstractProfile(int nLUTPoints,
double Exposure,
double Bright,
double Contrast,
double Hue,
double Saturation,
LPcmsCIExyY current_wp,
LPcmsCIExyY destination_wp,
LPGAMMATABLE Tables [])
cmsCIExyY current_wp,
cmsCIExyY destination_wp)
{
cmsHPROFILE hICC;
LPLUT Lut;
cmsPipeline* Pipeline;
cmsStage* CLUT;
BCHSWADJUSTS bchsw;
cmsCIExyY WhitePnt;
cmsUInt32Number Dimensions[MAX_INPUT_DIMENSIONS];
int i;

bchsw.Exposure = Exposure;
bchsw.Brightness = Bright;
bchsw.Contrast = Contrast;
bchsw.Hue = Hue;
bchsw.Saturation = Saturation;

cmsxyY2XYZ(&bchsw.WPsrc, current_wp);
cmsxyY2XYZ(&bchsw.WPdest, destination_wp);
cmsxyY2XYZ(&bchsw.WPsrc, &current_wp);
cmsxyY2XYZ(&bchsw.WPdest, &destination_wp);

hICC = _cmsCreateProfilePlaceholder();
hICC = cmsCreateProfilePlaceholder(NULL);
if (!hICC) // can't allocate
return NULL;

cmsSetDeviceClass(hICC, icSigAbstractClass);
cmsSetColorSpace(hICC, icSigLabData);
cmsSetPCS(hICC, icSigLabData);
cmsSetDeviceClass(hICC, cmsSigAbstractClass);
cmsSetColorSpace(hICC, cmsSigLabData);
cmsSetPCS(hICC, cmsSigLabData);

cmsSetRenderingIntent(hICC, INTENT_PERCEPTUAL);

// Creates a LUT with 3D grid only
Lut = cmsAllocLUT();

cmsAlloc3DGrid(Lut, nLUTPoints, 3, 3);

if (Tables != NULL)
cmsAllocLinearTable (Lut, Tables, 1);
// Creates a Pipeline with 3D grid only
Pipeline = cmsPipelineAlloc(NULL, 3, 3);
if (Pipeline == NULL) {
cmsCloseProfile(hICC);
return NULL;
}


for (i=0; i < MAX_INPUT_DIMENSIONS; i++) Dimensions[i] = nLUTPoints;
CLUT = cmsStageAllocCLut16bitGranular(NULL, Dimensions, 3, 3, NULL);
if (CLUT == NULL) return NULL;

if (!cmsSample3DGrid(Lut, bchswSampler, (LPVOID) &bchsw, 0)) {
if (!cmsStageSampleCLut16bit(CLUT, bchswSampler, (void*) &bchsw, 0)) {
// Shouldn't reach here
cmsFreeLUT(Lut);
cmsPipelineFree(Pipeline);
cmsCloseProfile(hICC);
return NULL;
}
}

cmsPipeInsertStage(Pipeline, cmsAT_END, CLUT);

// Create tags

cmsAddTag(hICC, icSigDeviceMfgDescTag, (LPVOID) "(f-spot internal)");
cmsAddTag(hICC, icSigProfileDescriptionTag, (LPVOID) "f-spot BCHSW abstract profile");
cmsAddTag(hICC, icSigDeviceModelDescTag, (LPVOID) "BCHSW built-in");
cmsAddTag(hICC, cmsSigDeviceMfgDescTag, (void*) "(f-spot internal)");
cmsAddTag(hICC, cmsSigProfileDescriptionTag, (void*) "f-spot BCHSW abstract profile");
cmsAddTag(hICC, cmsSigDeviceModelDescTag, (void*) "BCHSW built-in");

cmsAddTag(hICC, icSigMediaWhitePointTag, (LPVOID) cmsD50_XYZ());
cmsAddTag(hICC, cmsSigMediaWhitePointTag, (void*) cmsD50_XYZ());

cmsAddTag(hICC, icSigAToB0Tag, (LPVOID) Lut);
cmsAddTag(hICC, cmsSigAToB0Tag, (void*) Pipeline);

// LUT is already on virtual profile
cmsFreeLUT(Lut);
// Pipeline is already on virtual profile
cmsPipelineFree(Pipeline);

// Ok, done
return hICC;
}

LPGAMMATABLE
cmsToneCurve*
f_cms_gamma_table_new (unsigned short data[], int start, int length)
{
LPGAMMATABLE table = cmsAllocGamma (length);
cmsToneCurve* table = (cmsToneCurve*) _cmsMallocZero(NULL, sizeof(cmsToneCurve));
int i;
if (!table)
return NULL;

data += start;

table->Table16 = (cmsUInt16Number*) _cmsCalloc(NULL, length, sizeof(cmsUInt16Number));

for (i = 0; i < length; i++)
table->GammaTable [i] = data [i];
table->Table16 [i] = data [i];

g_warning ("table %p, count = %d v[0] = %d", table, table->nEntries, table->GammaTable [0]);
g_warning ("table %p, count = %d v[0] = %d", table, table->nEntries, table->Table16 [0]);

return table;
}

ushort *
f_cms_gamma_table_get_values (LPGAMMATABLE table)
f_cms_gamma_table_get_values (cmsToneCurve* table)
{
return &(table->GammaTable [0]);
return &(table->Table16 [0]);
}

int
f_cms_gamma_table_get_count (LPGAMMATABLE table)
uint
f_cms_gamma_table_get_count (cmsToneCurve* const table)
{
return table->nEntries;
}
16 changes: 8 additions & 8 deletions src/Clients/MainApp/FSpot.ColorAdjustment/AutoStretch.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,27 +38,27 @@

namespace FSpot.ColorAdjustment {
public class AutoStretch : Adjustment {
public AutoStretch (Pixbuf input, Cms.Profile input_profile) : base (input, input_profile)
public AutoStretch (Pixbuf input, Profile input_profile) : base (input, input_profile)
{
}

protected override List <Cms.Profile> GenerateAdjustments ()
protected override List <Profile> GenerateAdjustments ()
{
List <Cms.Profile> profiles = new List <Cms.Profile> ();
List <Profile> profiles = new List <Profile> ();
Histogram hist = new Histogram (Input);
tables = new GammaTable [3];
tables = new GammaCurve [3];

for (int channel = 0; channel < tables.Length; channel++) {
int high, low;
hist.GetHighLow (channel, out high, out low);
Log.DebugFormat ("high = {0}, low = {1}", high, low);
tables [channel] = StretchChannel (255, low / 255.0, high / 255.0);
}
profiles.Add (new Cms.Profile (IccColorSpace.Rgb, tables));
profiles.Add (new Profile (IccColorSpace.Rgb, tables));
return profiles;
}

GammaTable StretchChannel (int count, double low, double high)
GammaCurve StretchChannel (int count, double low, double high)
{
ushort [] entries = new ushort [count];
for (int i = 0; i < entries.Length; i++) {
Expand All @@ -73,9 +73,9 @@ GammaTable StretchChannel (int count, double low, double high)
entries [i] = (ushort) Math.Min (Math.Round (ushort.MaxValue * val), ushort.MaxValue);
//System.Console.WriteLine ("val {0}, result {1}", Math.Round (val * ushort.MaxValue), entries [i]);
}
return new GammaTable (entries);
return new GammaCurve (entries);
}

GammaTable [] tables;
GammaCurve [] tables;
}
}
4 changes: 2 additions & 2 deletions src/Clients/MainApp/MainApp.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@
<Compile Include="FSpot\App.cs" />
<Compile Include="FSpot\BitConverter.cs" />
<Compile Include="FSpot.ColorAdjustment\Adjustment.cs" />
<Compile Include="FSpot.ColorAdjustment\AutoStretch.cs" />
<Compile Include="FSpot.ColorAdjustment\Desaturate.cs" />
<Compile Include="FSpot.ColorAdjustment\FullColorAdjustment.cs" />
<Compile Include="FSpot.ColorAdjustment\SepiaTone.cs" />
Expand All @@ -53,7 +52,6 @@
<Compile Include="FSpot.Database\Tests\UpdaterTests.cs" />
<Compile Include="FSpot.Database\Updater.cs" />
<Compile Include="FSpot\DragDropTargets.cs" />
<Compile Include="FSpot.Editors\AutoStretchEditor.cs" />
<Compile Include="FSpot.Editors\ColorEditor.cs" />
<Compile Include="FSpot.Editors\CropEditor.cs" />
<Compile Include="FSpot.Editors\DesaturateEditor.cs" />
Expand Down Expand Up @@ -212,6 +210,8 @@
<Compile Include="FSpot\Literal.cs" />
<Compile Include="FSpot.Imaging\IImageFile.cs" />
<Compile Include="FSpot.Import\IImportSource.cs" />
<Compile Include="FSpot.ColorAdjustment\AutoStretch.cs" />
<Compile Include="FSpot.Editors\AutoStretchEditor.cs" />
</ItemGroup>
<ItemGroup>
<EmbeddedResource Include="..\..\..\icons\f-spot-not.png">
Expand Down

0 comments on commit 9c52d5f

Please sign in to comment.