~ubuntu-branches/debian/stretch/colord/stretch

« back to all changes in this revision

Viewing changes to lib/colord/cd-test-private.c

  • Committer: Package Import Robot
  • Author(s): Christopher James Halse Rogers
  • Date: 2015-08-13 08:56:11 UTC
  • mfrom: (1.1.10)
  • Revision ID: package-import@ubuntu.com-20150813085611-946sqkendiafealo
Tags: 1.2.11-1
* Add missing GFDL licence for documentation
* Merge new upstream 1.2.11 release. (Closes: 782477)
* Cherry pick commit to check for, and prefer, libsystemd over
  libsystemd-login. (Closes: 779777)
* debian/libcolorhug2.symbols: Add new ch_device_close symbol.
* Remove no-longer-used colord.conf (Closes: 751212)
* Add new symbols to libcolord-private symbols file
* Add new functions to libcolorhug2 symbols file
* Add newly-introduced symbols to symbols file
* Update DEP8 control for libtool-bin split
* Output better logs on DEP8 failures
* Add colord-sensor-argyll package
* Disable strangely-failing DEP8 test

Show diffs side-by-side

added added

removed removed

Lines of Context:
26
26
#include <string.h>
27
27
#include <fcntl.h>
28
28
#include <math.h>
 
29
#include <lcms2.h>
29
30
 
30
31
#include <glib.h>
31
32
#include <glib/gstdio.h>
47
48
#include "cd-transform.h"
48
49
#include "cd-version.h"
49
50
 
 
51
#include "cd-cleanup.h"
50
52
#include "cd-test-shared.h"
51
53
 
52
54
static void
115
117
        CdSpectrum *unity;
116
118
        GError *error = NULL;
117
119
        GFile *file;
 
120
        GPtrArray *array;
118
121
        gboolean ret;
119
122
        gchar *filename;
120
123
 
141
144
        g_assert_cmpint (cd_it8_get_kind (spectra), ==, CD_IT8_KIND_SPECT);
142
145
 
143
146
        /* calculate the XYZ value */
144
 
        data = g_ptr_array_index (cd_it8_get_spectrum_array (spectra), 0);
 
147
        array = cd_it8_get_spectrum_array (spectra);
 
148
        data = g_ptr_array_index (array, 0);
145
149
        unity = cd_spectrum_new ();
146
150
        ret = cd_it8_utils_calculate_xyz_from_cmf (cmf, unity, data, &value, 1.f, &error);
147
151
        g_assert_no_error (error);
153
157
        g_assert_cmpfloat (value.Y, <, 1.f + 0.01);
154
158
        g_assert_cmpfloat (value.Z, >, 0.813050f - 0.01);
155
159
        g_assert_cmpfloat (value.Z, <, 0.813050f + 0.01);
 
160
        g_ptr_array_unref (array);
156
161
 
157
162
        cd_spectrum_free (unity);
158
163
        g_object_unref (cmf);
211
216
        g_assert_cmpint (cd_spectrum_get_size (s), ==, 3);
212
217
        g_assert_cmpstr (cd_spectrum_get_id (s), ==, "dave");
213
218
 
 
219
        /* get resolution of the spectra */
 
220
        val = cd_spectrum_get_resolution (s);
 
221
        g_assert_cmpfloat (ABS (val - 66.66f), <, 0.01f);
 
222
 
214
223
        /* test interpolation */
215
224
        val = cd_spectrum_get_value_for_nm (s, 100.1f);
216
225
        g_assert_cmpfloat (ABS (val - 0.50f), <, 0.001f);
223
232
        g_assert_cmpfloat (ABS (cd_spectrum_get_value_for_nm (s, 50) - 0.5), <, 0.0001f);
224
233
        g_assert_cmpfloat (ABS (cd_spectrum_get_value_for_nm (s, 350) - 1.0f), <, 0.0001f);
225
234
 
226
 
        /* test normalisation */
 
235
        /* test normalisation to a specific wavelength */
227
236
        cd_spectrum_normalize (s, 200, 1.f);
228
237
        g_assert_cmpfloat (ABS (cd_spectrum_get_value (s, 0) - 0.666f), <, 0.001f);
229
238
        g_assert_cmpfloat (ABS (cd_spectrum_get_value (s, 1) - 1.000f), <, 0.001f);
230
239
        g_assert_cmpfloat (ABS (cd_spectrum_get_value (s, 2) - 1.333f), <, 0.001f);
231
240
        g_assert_cmpfloat (ABS (cd_spectrum_get_norm (s) - 1.333f), <, 0.001f);
232
241
 
 
242
        /* test normalisation */
 
243
        cd_spectrum_normalize_max (s, 100.f);
 
244
        g_assert_cmpfloat (ABS (cd_spectrum_get_value (s, 0) - 50.f), <, 0.001f);
 
245
        g_assert_cmpfloat (ABS (cd_spectrum_get_value (s, 1) - 75.f), <, 0.001f);
 
246
        g_assert_cmpfloat (ABS (cd_spectrum_get_value (s, 2) - 100.f), <, 0.001f);
 
247
        g_assert_cmpfloat (ABS (cd_spectrum_get_norm (s) - 100.f), <, 0.001f);
 
248
 
 
249
        /* test raw value */
 
250
        g_assert_cmpfloat (ABS (cd_spectrum_get_value_raw (s, 0) - 0.5f), <, 0.001f);
 
251
        g_assert_cmpfloat (ABS (cd_spectrum_get_value_raw (s, 1) - 0.75f), <, 0.001f);
 
252
        g_assert_cmpfloat (ABS (cd_spectrum_get_value_raw (s, 2) - 1.f), <, 0.001f);
 
253
 
 
254
        /* test setting of data */
 
255
        cd_spectrum_set_value (s, 0, 10.f);
 
256
        g_assert_cmpfloat (ABS (cd_spectrum_get_value (s, 0) - 10.0f), <, 0.001f);
 
257
 
233
258
        cd_spectrum_free (s);
234
259
}
235
260
 
521
546
        g_assert_no_error (error);
522
547
        g_assert (ret);
523
548
        g_object_unref (file);
 
549
        g_free (filename);
524
550
 
525
551
        /* load measured */
526
552
        filename = cd_test_get_filename ("measured.ti3");
530
556
        g_assert_no_error (error);
531
557
        g_assert (ret);
532
558
        g_object_unref (file);
 
559
        g_free (filename);
533
560
 
534
561
        /* calculate CCMX */
535
562
        ccmx = cd_it8_new_with_kind (CD_IT8_KIND_CCMX);
1198
1225
        tmp = cd_icc_get_model (icc, NULL, &error);
1199
1226
        g_assert_error (error, CD_ICC_ERROR, CD_ICC_ERROR_NO_DATA);
1200
1227
        g_assert (tmp == NULL);
 
1228
        g_error_free (error);
1201
1229
 
1202
1230
        g_bytes_unref (payload);
1203
1231
        g_object_unref (icc);
1983
2011
        g_assert_cmpfloat (cd_edid_get_gamma (edid), <, 2.2f + 0.01);
1984
2012
        g_free (data);
1985
2013
 
 
2014
        /* Dell external Panel */
 
2015
        filename = cd_test_get_filename ("DELL-U2713H.bin");
 
2016
        g_assert (filename != NULL);
 
2017
        ret = g_file_get_contents (filename, &data, &length, &error);
 
2018
        g_assert_no_error (error);
 
2019
        g_assert (ret);
 
2020
        data_edid = g_bytes_new (data, length);
 
2021
        ret = cd_edid_parse (edid, data_edid, &error);
 
2022
        g_assert_no_error (error);
 
2023
        g_assert (ret);
 
2024
        g_free (filename);
 
2025
        g_bytes_unref (data_edid);
 
2026
        g_assert_cmpstr (cd_edid_get_monitor_name (edid), ==, "DELL U2713H");
 
2027
        g_assert_cmpstr (cd_edid_get_vendor_name (edid), ==, "Dell");
 
2028
        g_assert_cmpstr (cd_edid_get_serial_number (edid), ==, "C6F0K34T1CWL");
 
2029
        g_assert_cmpstr (cd_edid_get_eisa_id (edid), ==, NULL);
 
2030
        g_assert_cmpstr (cd_edid_get_checksum (edid), ==, "ac6dab5272cfbd2e87dd9c635f4c0e9d");
 
2031
        g_assert_cmpstr (cd_edid_get_pnp_id (edid), ==, "DEL");
 
2032
        g_assert_cmpint (cd_edid_get_height (edid), ==, 34);
 
2033
        g_assert_cmpint (cd_edid_get_width (edid), ==, 60);
 
2034
        g_assert_cmpfloat (cd_edid_get_gamma (edid), >=, 2.2f - 0.01);
 
2035
        g_assert_cmpfloat (cd_edid_get_gamma (edid), <, 2.2f + 0.01);
 
2036
        g_free (data);
 
2037
 
1986
2038
        g_object_unref (edid);
1987
2039
}
1988
2040
 
2038
2090
        g_assert_no_error (error);
2039
2091
        cd_icc_set_tag_data (icc, "xxxx", data, &error);
2040
2092
        g_assert_no_error (error);
 
2093
        g_bytes_unref (data);
2041
2094
 
2042
2095
        /* re-get raw tag data */
2043
2096
        data = cd_icc_get_tag_data (icc, "desc", &error);
2049
2102
        g_object_unref (icc);
2050
2103
}
2051
2104
 
 
2105
static void
 
2106
colord_it8_gamma_func (void)
 
2107
{
 
2108
        CdColorRGB rgb;
 
2109
        CdColorXYZ xyz;
 
2110
        CdColorXYZ *tmp;
 
2111
        GError *error = NULL;
 
2112
        cmsToneCurve *curve;
 
2113
        gboolean ret;
 
2114
        gdouble gamma_est;
 
2115
        guint i;
 
2116
        _cleanup_object_unref_ CdIt8 *it8 = NULL;
 
2117
 
 
2118
        /* add some dummy primary data  */
 
2119
        it8 = cd_it8_new_with_kind (CD_IT8_KIND_TI3);
 
2120
        cd_color_rgb_set (&rgb, 1.f, 0.f, 0.f);
 
2121
        cd_color_xyz_set (&xyz, 0.9f, 0.f, 0.f);
 
2122
        cd_it8_add_data (it8, &rgb, &xyz);
 
2123
        cd_color_rgb_set (&rgb, 0.f, 1.f, 0.f);
 
2124
        cd_color_xyz_set (&xyz, 0.f, 0.9f, 0.f);
 
2125
        cd_it8_add_data (it8, &rgb, &xyz);
 
2126
        cd_color_rgb_set (&rgb, 0.f, 9.f, 1.f);
 
2127
        cd_color_xyz_set (&xyz, 0.f, 0.f, 0.9f);
 
2128
        cd_it8_add_data (it8, &rgb, &xyz);
 
2129
 
 
2130
        /* find green */
 
2131
        tmp = cd_it8_get_xyz_for_rgb (it8, 0.f, 1.f, 0.f, 0.01f);
 
2132
        g_assert (tmp != NULL);
 
2133
        g_assert_cmpfloat (ABS (tmp->X - 0.0f), <, 0.01);
 
2134
        g_assert_cmpfloat (ABS (tmp->Y - 0.9f), <, 0.01);
 
2135
        g_assert_cmpfloat (ABS (tmp->Z - 0.0f), <, 0.01);
 
2136
 
 
2137
        /* add some ramp data with a gamma of 2.4 */
 
2138
        curve = cmsBuildGamma (NULL, 2.4);
 
2139
        for (i = 0; i < 11; i++) {
 
2140
                gdouble slice = 0.1f * (gdouble) i;
 
2141
                gdouble y = cmsEvalToneCurveFloat (curve, slice);
 
2142
                cd_color_rgb_set (&rgb, slice, slice, slice);
 
2143
                cd_color_xyz_set (&xyz, 1.f, y, 1.f);
 
2144
                cd_it8_add_data (it8, &rgb, &xyz);
 
2145
        }
 
2146
        cmsFreeToneCurve (curve);
 
2147
 
 
2148
        /* find the data and estimate */
 
2149
        ret = cd_it8_utils_calculate_gamma (it8, &gamma_est, &error);
 
2150
        g_assert_no_error (error);
 
2151
        g_assert (ret);
 
2152
        g_assert_cmpfloat (gamma_est, <, 2.5);
 
2153
        g_assert_cmpfloat (gamma_est, >, 2.3);
 
2154
}
 
2155
 
2052
2156
int
2053
2157
main (int argc, char **argv)
2054
2158
{
2085
2189
        g_test_add_func ("/colord/color{blackbody}", colord_color_blackbody_func);
2086
2190
        g_test_add_func ("/colord/math", cd_test_math_func);
2087
2191
        g_test_add_func ("/colord/it8{raw}", colord_it8_raw_func);
 
2192
        g_test_add_func ("/colord/it8{gamma}", colord_it8_gamma_func);
2088
2193
        g_test_add_func ("/colord/it8{locale}", colord_it8_locale_func);
2089
2194
        g_test_add_func ("/colord/it8{normalized}", colord_it8_normalized_func);
2090
2195
        g_test_add_func ("/colord/it8{ccmx}", colord_it8_ccmx_func);