1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888
|
//---------------------------------------------------------------------------------
//
// Little Color Management System, multithreaded extensions
// Copyright (c) 1998-2023 Marti Maria Saguer, all rights reserved
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
//
//---------------------------------------------------------------------------------
#include "threaded_internal.h"
#include <stdlib.h>
#include <memory.h>
#include <time.h>
// On Visual Studio, use debug CRT
#ifdef _MSC_VER
# include "crtdbg.h"
#define HAVE_TIMESPEC_GET 1
#endif
#ifndef PROFILES_DIR
#define PROFILES_DIR "../../test_profiles/"
#endif
#define FLAGS cmsFLAGS_NOOPTIMIZE
// A fast way to convert from/to 16 <-> 8 bits
#define FROM_8_TO_16(rgb) (cmsUInt16Number) ((((cmsUInt16Number) (rgb)) << 8)|(rgb))
#define FROM_16_TO_8(rgb) (cmsUInt8Number) ((((rgb) * 65281 + 8388608) >> 24) & 0xFF)
// Some pixel representations
typedef struct { cmsUInt8Number r, g, b; } Scanline_rgb8bits;
typedef struct { cmsUInt8Number r, g, b, a; } Scanline_rgba8bits;
typedef struct { cmsUInt8Number c, m, y, k; } Scanline_cmyk8bits;
typedef struct { cmsUInt16Number r, g, b; } Scanline_rgb16bits;
typedef struct { cmsUInt16Number r, g, b, a; } Scanline_rgba16bits;
typedef struct { cmsUInt16Number c, m, y, k; } Scanline_cmyk16bits;
static struct timespec start, finish;
cmsINLINE void MeasureTimeStart(void)
{
#if defined(HAVE_TIMESPEC_GET)
timespec_get(&start, TIME_UTC);
#else
clock_gettime(CLOCK_MONOTONIC, &start);
#endif
}
cmsINLINE double MeasureTimeStop(void)
{
double elapsed;
#if defined(HAVE_TIMESPEC_GET)
timespec_get(&finish, TIME_UTC);
#else
clock_gettime(CLOCK_MONOTONIC, &finish);
#endif
elapsed = ((double) finish.tv_sec - start.tv_sec);
elapsed += ((double) finish.tv_nsec - start.tv_nsec) / 1000000000.0;
return elapsed;
}
// A flushed printf
static
void trace(const char* frm, ...)
{
va_list args;
va_start(args, frm);
vfprintf(stderr, frm, args);
fflush(stderr);
va_end(args);
}
// The callback function used by cmsSetLogErrorHandler()
static
void FatalErrorQuit(cmsContext ContextID, cmsUInt32Number ErrorCode, const char *Text)
{
UNUSED_PARAMETER(ContextID);
UNUSED_PARAMETER(ErrorCode);
trace("** Fatal error: %s\n", Text);
exit(1);
}
// Rise an error and exit
static
void Fail(const char* frm, ...)
{
char ReasonToFailBuffer[1024];
va_list args;
va_start(args, frm);
vsprintf(ReasonToFailBuffer, frm, args);
FatalErrorQuit(0, 0, ReasonToFailBuffer);
// unreachable va_end(args);
}
// Creates a fake profile that only has a curve. Used in several places
static
cmsHPROFILE CreateCurves(void)
{
cmsToneCurve* Gamma = cmsBuildGamma(0, 1.1);
cmsToneCurve* Transfer[3];
cmsHPROFILE h;
Transfer[0] = Transfer[1] = Transfer[2] = Gamma;
h = cmsCreateLinearizationDeviceLink(cmsSigRgbData, Transfer);
cmsFreeToneCurve(Gamma);
return h;
}
// --------------------------------------------------------------------------------------------------
// A C C U R A C Y C H E C K S
// --------------------------------------------------------------------------------------------------
// Check change format feature
static
void CheckChangeFormat(void)
{
cmsHPROFILE hsRGB, hLab;
cmsHTRANSFORM xform;
cmsUInt8Number rgb8[3] = { 10, 120, 40 };
cmsUInt16Number rgb16[3] = { 10* 257, 120*257, 40*257 };
cmsUInt16Number lab16_1[3], lab16_2[3];
trace("Checking change format feature...");
hsRGB = cmsCreate_sRGBProfile();
hLab = cmsCreateLab4Profile(NULL);
xform = cmsCreateTransform(hsRGB, TYPE_RGB_16, hLab, TYPE_Lab_16, INTENT_PERCEPTUAL, FLAGS);
cmsCloseProfile(hsRGB);
cmsCloseProfile(hLab);
cmsDoTransform(xform, rgb16, lab16_1, 1);
cmsChangeBuffersFormat(xform, TYPE_RGB_8, TYPE_Lab_16);
cmsDoTransform(xform, rgb8, lab16_2, 1);
cmsDeleteTransform(xform);
if (memcmp(lab16_1, lab16_2, sizeof(lab16_1)) != 0)
Fail("Change format failed!");
trace("Ok\n");
}
// Next test checks results of optimized 8 bits versus raw 8 bits.
static
void TryAllValues8bits(cmsHPROFILE hlcmsProfileIn, cmsHPROFILE hlcmsProfileOut, cmsInt32Number Intent)
{
cmsContext Raw = cmsCreateContext(NULL, NULL);
cmsContext Plugin = cmsCreateContext(cmsThreadedExtensions(CMS_THREADED_GUESS_MAX_THREADS, 0), NULL);
Scanline_rgba8bits* bufferIn;
Scanline_rgba8bits* bufferRawOut;
Scanline_rgba8bits* bufferPluginOut;
int r, g, b;
int j;
cmsUInt32Number npixels = 256 * 256 * 256;
cmsHTRANSFORM xformRaw = cmsCreateTransformTHR(Raw, hlcmsProfileIn, TYPE_RGBA_8, hlcmsProfileOut, TYPE_RGBA_8, Intent, FLAGS|cmsFLAGS_NOCACHE | cmsFLAGS_COPY_ALPHA);
cmsHTRANSFORM xformPlugin = cmsCreateTransformTHR(Plugin, hlcmsProfileIn, TYPE_RGBA_8, hlcmsProfileOut, TYPE_RGBA_8, Intent, FLAGS|cmsFLAGS_NOCACHE | cmsFLAGS_COPY_ALPHA);
cmsCloseProfile(hlcmsProfileIn);
cmsCloseProfile(hlcmsProfileOut);
if (xformRaw == NULL || xformPlugin == NULL) {
Fail("NULL transforms on check float conversions");
}
// Again, no checking on mem alloc because this is just a test
bufferIn = (Scanline_rgba8bits*)malloc(npixels * sizeof(Scanline_rgba8bits));
bufferRawOut = (Scanline_rgba8bits*)malloc(npixels * sizeof(Scanline_rgba8bits));
bufferPluginOut = (Scanline_rgba8bits*)malloc(npixels * sizeof(Scanline_rgba8bits));
// Same input to both transforms
j = 0;
for (r = 0; r < 256; r++)
for (g = 0; g < 256; g++)
for (b = 0; b < 256; b++) {
bufferIn[j].r = (cmsUInt8Number) r;
bufferIn[j].g = (cmsUInt8Number) g;
bufferIn[j].b = (cmsUInt8Number) b;
bufferIn[j].a = 0xff;
j++;
}
// Different transforms, different output buffers
cmsDoTransform(xformRaw, bufferIn, bufferRawOut, npixels);
cmsDoTransform(xformPlugin, bufferIn, bufferPluginOut, npixels);
// Lets compare results
j = 0;
for (r = 0; r < 256; r++)
for (g = 0; g < 256; g++)
for (b = 0; b < 256; b++) {
if (bufferRawOut[j].r != bufferPluginOut[j].r ||
bufferRawOut[j].g != bufferPluginOut[j].g ||
bufferRawOut[j].b != bufferPluginOut[j].b ||
bufferRawOut[j].a != bufferPluginOut[j].a)
Fail(
"Conversion failed at [%x %x %x %x] (%x %x %x %x) != (%x %x %x %x)",
bufferIn[j].r, bufferIn[j].g, bufferIn[j].b, bufferIn[j].a,
bufferRawOut[j].r, bufferRawOut[j].g, bufferRawOut[j].b, bufferRawOut[j].a,
bufferPluginOut[j].r, bufferPluginOut[j].g, bufferPluginOut[j].b, bufferPluginOut[j].a);
j++;
}
free(bufferIn); free(bufferRawOut);
free(bufferPluginOut);
cmsDeleteTransform(xformRaw);
cmsDeleteTransform(xformPlugin);
cmsDeleteContext(Plugin);
cmsDeleteContext(Raw);
}
static
void CheckAccuracy8Bits(void)
{
trace("Checking accuracy of 8 bits CLUT...");
TryAllValues8bits(cmsOpenProfileFromFile(PROFILES_DIR "test5.icc", "r"), cmsOpenProfileFromFile(PROFILES_DIR "test3.icc", "r"), INTENT_PERCEPTUAL);
trace("OK\n");
}
// Next test checks results of optimized 16 bits versus raw 16 bits.
static
void TryAllValues16bits(cmsHPROFILE hlcmsProfileIn, cmsHPROFILE hlcmsProfileOut, cmsInt32Number Intent)
{
cmsContext Raw = cmsCreateContext(NULL, NULL);
cmsContext Plugin = cmsCreateContext(cmsThreadedExtensions(CMS_THREADED_GUESS_MAX_THREADS, 0), NULL);
Scanline_rgba16bits* bufferIn;
Scanline_rgba16bits* bufferRawOut;
Scanline_rgba16bits* bufferPluginOut;
int r, g, b;
int j;
cmsUInt32Number npixels = 256 * 256 * 256;
cmsHTRANSFORM xformRaw = cmsCreateTransformTHR(Raw, hlcmsProfileIn, TYPE_RGBA_16, hlcmsProfileOut, TYPE_RGBA_16, Intent, FLAGS|cmsFLAGS_NOCACHE | cmsFLAGS_COPY_ALPHA);
cmsHTRANSFORM xformPlugin = cmsCreateTransformTHR(Plugin, hlcmsProfileIn, TYPE_RGBA_16, hlcmsProfileOut, TYPE_RGBA_16, Intent, FLAGS|cmsFLAGS_NOCACHE | cmsFLAGS_COPY_ALPHA);
cmsCloseProfile(hlcmsProfileIn);
cmsCloseProfile(hlcmsProfileOut);
if (xformRaw == NULL || xformPlugin == NULL) {
Fail("NULL transforms on check float conversions");
}
// Again, no checking on mem alloc because this is just a test
bufferIn = (Scanline_rgba16bits*)malloc(npixels * sizeof(Scanline_rgba16bits));
bufferRawOut = (Scanline_rgba16bits*)malloc(npixels * sizeof(Scanline_rgba16bits));
bufferPluginOut = (Scanline_rgba16bits*)malloc(npixels * sizeof(Scanline_rgba16bits));
// Same input to both transforms
j = 0;
for (r = 0; r < 256; r++)
for (g = 0; g < 256; g++)
for (b = 0; b < 256; b++) {
bufferIn[j].r = FROM_8_TO_16(r);
bufferIn[j].g = FROM_8_TO_16(g);
bufferIn[j].b = FROM_8_TO_16(b);
bufferIn[j].a = 0xffff;
j++;
}
// Different transforms, different output buffers
cmsDoTransform(xformRaw, bufferIn, bufferRawOut, npixels);
cmsDoTransform(xformPlugin, bufferIn, bufferPluginOut, npixels);
// Lets compare results
j = 0;
for (r = 0; r < 256; r++)
for (g = 0; g < 256; g++)
for (b = 0; b < 256; b++) {
if (bufferRawOut[j].r != bufferPluginOut[j].r ||
bufferRawOut[j].g != bufferPluginOut[j].g ||
bufferRawOut[j].b != bufferPluginOut[j].b ||
bufferRawOut[j].a != bufferPluginOut[j].a)
Fail(
"Conversion failed at [%x %x %x %x] (%x %x %x %x) != (%x %x %x %x)",
bufferIn[j].r, bufferIn[j].g, bufferIn[j].b, bufferIn[j].a,
bufferRawOut[j].r, bufferRawOut[j].g, bufferRawOut[j].b, bufferRawOut[j].a,
bufferPluginOut[j].r, bufferPluginOut[j].g, bufferPluginOut[j].b, bufferPluginOut[j].a);
j++;
}
free(bufferIn); free(bufferRawOut);
free(bufferPluginOut);
cmsDeleteTransform(xformRaw);
cmsDeleteTransform(xformPlugin);
cmsDeleteContext(Plugin);
cmsDeleteContext(Raw);
}
static
void CheckAccuracy16Bits(void)
{
// CLUT should be as 16 bits or better
trace("Checking accuracy of 16 bits CLUT...");
TryAllValues16bits(cmsOpenProfileFromFile(PROFILES_DIR "test5.icc", "r"), cmsOpenProfileFromFile(PROFILES_DIR "test3.icc", "r"), INTENT_PERCEPTUAL);
trace("OK\n");
}
// --------------------------------------------------------------------------------------------------
// P E R F O R M A N C E C H E C K S
// --------------------------------------------------------------------------------------------------
static
cmsFloat64Number MPixSec(cmsFloat64Number seconds)
{
return (256.0 * 256.0 * 256.0) / (1024.0*1024.0*seconds);
}
typedef cmsFloat64Number(*perf_fn)(cmsContext ct, cmsHPROFILE hlcmsProfileIn, cmsHPROFILE hlcmsProfileOut);
static
void PerformanceHeader(void)
{
trace(" MPixel/sec. MByte/sec.\n");
}
static
cmsHPROFILE loadProfile(const char* name)
{
if (*name == '*')
{
if (strcmp(name, "*lab") == 0)
{
return cmsCreateLab4Profile(NULL);
}
else
if (strcmp(name, "*xyz") == 0)
{
return cmsCreateXYZProfile();
}
else
if (strcmp(name, "*curves") == 0)
{
return CreateCurves();
}
else
Fail("Unknown builtin '%s'", name);
}
return cmsOpenProfileFromFile(name, "r");
}
static
cmsFloat64Number Performance(const char* Title, perf_fn fn, cmsContext ct, const char* inICC, const char* outICC, size_t sz, cmsFloat64Number prev)
{
cmsHPROFILE hlcmsProfileIn = loadProfile(inICC);
cmsHPROFILE hlcmsProfileOut = loadProfile(outICC);
cmsFloat64Number n = fn(ct, hlcmsProfileIn, hlcmsProfileOut);
trace("%-30s: ", Title); fflush(stdout);
trace("%-12.2f %-12.2f", n, n * sz);
if (prev > 0.0) {
cmsFloat64Number imp = n / prev;
if (imp > 1)
trace(" (x %-2.1f)", imp);
}
trace("\n"); fflush(stdout);
return n;
}
static
void ComparativeCt(cmsContext ct1, cmsContext ct2, const char* Title, perf_fn fn1, perf_fn fn2, const char* inICC, const char* outICC)
{
cmsHPROFILE hlcmsProfileIn;
cmsHPROFILE hlcmsProfileOut;
if (inICC == NULL)
hlcmsProfileIn = CreateCurves();
else
hlcmsProfileIn = cmsOpenProfileFromFile(inICC, "r");
if (outICC == NULL)
hlcmsProfileOut = CreateCurves();
else
hlcmsProfileOut = cmsOpenProfileFromFile(outICC, "r");
cmsFloat64Number n1 = fn1(ct1, hlcmsProfileIn, hlcmsProfileOut);
if (inICC == NULL)
hlcmsProfileIn = CreateCurves();
else
hlcmsProfileIn = cmsOpenProfileFromFile(inICC, "r");
if (outICC == NULL)
hlcmsProfileOut = CreateCurves();
else
hlcmsProfileOut = cmsOpenProfileFromFile(outICC, "r");
cmsFloat64Number n2 = fn2(ct2, hlcmsProfileIn, hlcmsProfileOut);
trace("%-30s: ", Title); fflush(stdout);
trace("%-12.2f %-12.2f\n", n1, n2);
}
static
void Comparative(const char* Title, perf_fn fn1, perf_fn fn2, const char* inICC, const char* outICC)
{
ComparativeCt(0, 0, Title, fn1, fn2, inICC, outICC);
}
// The worst case is used, no cache and all rgb combinations
static
cmsFloat64Number SpeedTest8bitsRGB(cmsContext ct, cmsHPROFILE hlcmsProfileIn, cmsHPROFILE hlcmsProfileOut)
{
cmsInt32Number r, g, b, j;
cmsFloat64Number diff;
cmsHTRANSFORM hlcmsxform;
Scanline_rgb8bits* In;
cmsUInt32Number Mb;
if (hlcmsProfileIn == NULL || hlcmsProfileOut == NULL)
Fail("Unable to open profiles");
hlcmsxform = cmsCreateTransformTHR(ct, hlcmsProfileIn, TYPE_RGB_8, hlcmsProfileOut, TYPE_RGB_8, INTENT_PERCEPTUAL, FLAGS|cmsFLAGS_NOCACHE);
cmsCloseProfile(hlcmsProfileIn);
cmsCloseProfile(hlcmsProfileOut);
Mb = 256 * 256 * 256 * sizeof(Scanline_rgb8bits);
In = (Scanline_rgb8bits*)malloc(Mb);
j = 0;
for (r = 0; r < 256; r++)
for (g = 0; g < 256; g++)
for (b = 0; b < 256; b++) {
In[j].r = (cmsUInt8Number)r;
In[j].g = (cmsUInt8Number)g;
In[j].b = (cmsUInt8Number)b;
j++;
}
MeasureTimeStart();
cmsDoTransform(hlcmsxform, In, In, 256 * 256 * 256);
diff = MeasureTimeStop();
free(In);
cmsDeleteTransform(hlcmsxform);
return MPixSec(diff);
}
static
cmsFloat64Number SpeedTest8bitsRGBA(cmsContext ct, cmsHPROFILE hlcmsProfileIn, cmsHPROFILE hlcmsProfileOut)
{
cmsInt32Number r, g, b, j;
cmsFloat64Number diff;
cmsHTRANSFORM hlcmsxform;
Scanline_rgba8bits* In;
cmsUInt32Number Mb;
if (hlcmsProfileIn == NULL || hlcmsProfileOut == NULL)
Fail("Unable to open profiles");
hlcmsxform = cmsCreateTransformTHR(ct, hlcmsProfileIn, TYPE_RGBA_8, hlcmsProfileOut, TYPE_RGBA_8, INTENT_PERCEPTUAL, FLAGS|cmsFLAGS_NOCACHE);
cmsCloseProfile(hlcmsProfileIn);
cmsCloseProfile(hlcmsProfileOut);
Mb = 256 * 256 * 256 * sizeof(Scanline_rgba8bits);
In = (Scanline_rgba8bits*)malloc(Mb);
j = 0;
for (r = 0; r < 256; r++)
for (g = 0; g < 256; g++)
for (b = 0; b < 256; b++) {
In[j].r = (cmsUInt8Number)r;
In[j].g = (cmsUInt8Number)g;
In[j].b = (cmsUInt8Number)b;
In[j].a = 0;
j++;
}
MeasureTimeStart();
cmsDoTransform(hlcmsxform, In, In, 256 * 256 * 256);
diff = MeasureTimeStop();
free(In);
cmsDeleteTransform(hlcmsxform);
return MPixSec(diff);
}
// The worst case is used, no cache and all rgb combinations
static
cmsFloat64Number SpeedTest16bitsRGB(cmsContext ct, cmsHPROFILE hlcmsProfileIn, cmsHPROFILE hlcmsProfileOut)
{
cmsInt32Number r, g, b, j;
cmsFloat64Number diff;
cmsHTRANSFORM hlcmsxform;
Scanline_rgb16bits *In;
cmsUInt32Number Mb;
if (hlcmsProfileIn == NULL || hlcmsProfileOut == NULL)
Fail("Unable to open profiles");
hlcmsxform = cmsCreateTransformTHR(ct, hlcmsProfileIn, TYPE_RGB_16, hlcmsProfileOut, TYPE_RGB_16, INTENT_PERCEPTUAL, FLAGS | cmsFLAGS_NOCACHE);
cmsCloseProfile(hlcmsProfileIn);
cmsCloseProfile(hlcmsProfileOut);
Mb = 256 * 256 * 256 * sizeof(Scanline_rgb16bits);
In = (Scanline_rgb16bits*)malloc(Mb);
j = 0;
for (r = 0; r < 256; r++)
for (g = 0; g < 256; g++)
for (b = 0; b < 256; b++) {
In[j].r = (cmsUInt16Number)FROM_8_TO_16(r);
In[j].g = (cmsUInt16Number)FROM_8_TO_16(g);
In[j].b = (cmsUInt16Number)FROM_8_TO_16(b);
j++;
}
MeasureTimeStart();
cmsDoTransform(hlcmsxform, In, In, 256 * 256 * 256);
diff = MeasureTimeStop();
free(In);
cmsDeleteTransform(hlcmsxform);
return MPixSec(diff);
}
static
cmsFloat64Number SpeedTest16bitsCMYK(cmsContext ct, cmsHPROFILE hlcmsProfileIn, cmsHPROFILE hlcmsProfileOut)
{
cmsInt32Number r, g, b, j;
cmsFloat64Number diff;
cmsHTRANSFORM hlcmsxform;
Scanline_cmyk16bits* In;
cmsUInt32Number Mb;
if (hlcmsProfileIn == NULL || hlcmsProfileOut == NULL)
Fail("Unable to open profiles");
hlcmsxform = cmsCreateTransformTHR(ct, hlcmsProfileIn, TYPE_CMYK_16, hlcmsProfileOut, TYPE_CMYK_16, INTENT_PERCEPTUAL, FLAGS | cmsFLAGS_NOCACHE);
cmsCloseProfile(hlcmsProfileIn);
cmsCloseProfile(hlcmsProfileOut);
Mb = 256 * 256 * 256 * sizeof(Scanline_cmyk16bits);
In = (Scanline_cmyk16bits*)malloc(Mb);
j = 0;
for (r = 0; r < 256; r++)
for (g = 0; g < 256; g++)
for (b = 0; b < 256; b++) {
In[j].c = (cmsUInt16Number)r;
In[j].m = (cmsUInt16Number)g;
In[j].y = (cmsUInt16Number)b;
In[j].k = (cmsUInt16Number)r;
j++;
}
MeasureTimeStart();
cmsDoTransform(hlcmsxform, In, In, 256 * 256 * 256);
diff = MeasureTimeStop();
free(In);
cmsDeleteTransform(hlcmsxform);
return MPixSec(diff);
}
static
void SpeedTest8(void)
{
cmsContext noPlugin = cmsCreateContext(0, 0);
cmsFloat64Number t[10];
trace("\n\n");
trace("P E R F O R M A N C E T E S T S 8 B I T S (D E F A U L T)\n");
trace("==============================================================\n\n");
fflush(stdout);
PerformanceHeader();
t[0] = Performance("8 bits on CLUT profiles ", SpeedTest8bitsRGB, noPlugin, PROFILES_DIR "test5.icc", PROFILES_DIR "test3.icc", sizeof(Scanline_rgb8bits), 0);
t[1] = Performance("8 bits on Matrix-Shaper ", SpeedTest8bitsRGB, noPlugin, PROFILES_DIR "test5.icc", PROFILES_DIR "test0.icc", sizeof(Scanline_rgb8bits), 0);
t[2] = Performance("8 bits on same MatrixSh ", SpeedTest8bitsRGB, noPlugin, PROFILES_DIR "test0.icc", PROFILES_DIR "test0.icc", sizeof(Scanline_rgb8bits), 0);
t[3] = Performance("8 bits on curves ", SpeedTest8bitsRGB, noPlugin, "*curves", "*curves", sizeof(Scanline_rgb8bits), 0);
// Note that context 0 has the plug-in installed
trace("\n\n");
trace("P E R F O R M A N C E T E S T S 8 B I T S (P L U G I N)\n");
trace("===========================================================\n\n");
fflush(stdout);
PerformanceHeader();
Performance("8 bits on CLUT profiles ", SpeedTest8bitsRGB, 0, PROFILES_DIR "test5.icc", PROFILES_DIR "test3.icc", sizeof(Scanline_rgb8bits), t[0]);
Performance("8 bits on Matrix-Shaper ", SpeedTest8bitsRGB, 0, PROFILES_DIR "test5.icc", PROFILES_DIR "test0.icc", sizeof(Scanline_rgb8bits), t[1]);
Performance("8 bits on same MatrixSh ", SpeedTest8bitsRGB, 0, PROFILES_DIR "test0.icc", PROFILES_DIR "test0.icc", sizeof(Scanline_rgb8bits), t[2]);
Performance("8 bits on curves ", SpeedTest8bitsRGB, 0, "*curves", "*curves", sizeof(Scanline_rgb8bits), t[3]);
cmsDeleteContext(noPlugin);
}
static
void SpeedTest16(void)
{
cmsContext noPlugin = cmsCreateContext(0, 0);
cmsFloat64Number t[10];
trace("\n\n");
trace("P E R F O R M A N C E T E S T S 1 6 B I T S (D E F A U L T)\n");
trace("=================================================================\n\n");
PerformanceHeader();
t[0] = Performance("16 bits on CLUT profiles ", SpeedTest16bitsRGB, noPlugin, PROFILES_DIR "test5.icc", PROFILES_DIR "test3.icc", sizeof(Scanline_rgb16bits), 0);
t[1] = Performance("16 bits on Matrix-Shaper profiles", SpeedTest16bitsRGB, noPlugin, PROFILES_DIR "test5.icc", PROFILES_DIR "test0.icc", sizeof(Scanline_rgb16bits), 0);
t[2] = Performance("16 bits on same Matrix-Shaper ", SpeedTest16bitsRGB, noPlugin, PROFILES_DIR "test0.icc", PROFILES_DIR "test0.icc", sizeof(Scanline_rgb16bits), 0);
t[3] = Performance("16 bits on curves ", SpeedTest16bitsRGB, noPlugin, "*curves", "*curves", sizeof(Scanline_rgb16bits), 0);
t[4] = Performance("16 bits on CMYK CLUT profiles ", SpeedTest16bitsCMYK, noPlugin, PROFILES_DIR "test1.icc", PROFILES_DIR "test2.icc", sizeof(Scanline_cmyk16bits), 0);
trace("\n\n");
trace("P E R F O R M A N C E T E S T S 1 6 B I T S (P L U G I N)\n");
trace("===============================================================\n\n");
PerformanceHeader();
Performance("16 bits on CLUT profiles ", SpeedTest16bitsRGB, 0, PROFILES_DIR "test5.icc", PROFILES_DIR "test3.icc", sizeof(Scanline_rgb16bits), t[0]);
Performance("16 bits on Matrix-Shaper profiles", SpeedTest16bitsRGB, 0, PROFILES_DIR "test5.icc", PROFILES_DIR "test0.icc", sizeof(Scanline_rgb16bits), t[1]);
Performance("16 bits on same Matrix-Shaper ", SpeedTest16bitsRGB, 0, PROFILES_DIR "test0.icc", PROFILES_DIR "test0.icc", sizeof(Scanline_rgb16bits), t[2]);
Performance("16 bits on curves ", SpeedTest16bitsRGB, 0, "*curves", "*curves", sizeof(Scanline_rgb16bits), t[3]);
Performance("16 bits on CMYK CLUT profiles ", SpeedTest16bitsCMYK, 0, PROFILES_DIR "test1.icc", PROFILES_DIR "test2.icc", sizeof(Scanline_cmyk16bits), t[4]);
cmsDeleteContext(noPlugin);
}
typedef struct
{
Scanline_rgba8bits pixels[256][256];
cmsUInt8Number padding[4];
} padded_line;
typedef struct
{
padded_line line[256];
} big_bitmap;
static
cmsFloat64Number SpeedTest8bitDoTransform(cmsContext ct, cmsHPROFILE hlcmsProfileIn, cmsHPROFILE hlcmsProfileOut)
{
cmsInt32Number r, g, b, j;
cmsFloat64Number diff;
cmsHTRANSFORM hlcmsxform;
big_bitmap* In;
big_bitmap* Out;
cmsUInt32Number Mb;
if (hlcmsProfileIn == NULL || hlcmsProfileOut == NULL)
Fail("Unable to open profiles");
hlcmsxform = cmsCreateTransformTHR(ct, hlcmsProfileIn, TYPE_RGBA_8, hlcmsProfileOut, TYPE_RGBA_8, INTENT_PERCEPTUAL, FLAGS | cmsFLAGS_NOCACHE);
cmsCloseProfile(hlcmsProfileIn);
cmsCloseProfile(hlcmsProfileOut);
// Our test bitmap is 256 x 256 padded lines
Mb = sizeof(big_bitmap);
In = (big_bitmap*)malloc(Mb);
Out = (big_bitmap*)malloc(Mb);
for (r = 0; r < 256; r++)
for (g = 0; g < 256; g++)
for (b = 0; b < 256; b++) {
In->line[r].pixels[g][b].r = (cmsUInt8Number)r;
In->line[r].pixels[g][b].g = (cmsUInt8Number)g;
In->line[r].pixels[g][b].b = (cmsUInt8Number)b;
In->line[r].pixels[g][b].a = 0;
}
MeasureTimeStart();
for (j = 0; j < 256; j++) {
cmsDoTransform(hlcmsxform, In->line[j].pixels, Out->line[j].pixels, 256 * 256);
}
diff = MeasureTimeStop();
free(In); free(Out);
cmsDeleteTransform(hlcmsxform);
return MPixSec(diff);
}
static
cmsFloat64Number SpeedTest8bitLineStride(cmsContext ct, cmsHPROFILE hlcmsProfileIn, cmsHPROFILE hlcmsProfileOut)
{
cmsInt32Number r, g, b;
cmsFloat64Number diff;
cmsHTRANSFORM hlcmsxform;
big_bitmap* In;
big_bitmap* Out;
cmsUInt32Number Mb;
if (hlcmsProfileIn == NULL || hlcmsProfileOut == NULL)
Fail("Unable to open profiles");
hlcmsxform = cmsCreateTransformTHR(ct, hlcmsProfileIn, TYPE_RGBA_8, hlcmsProfileOut, TYPE_RGBA_8, INTENT_PERCEPTUAL, FLAGS | cmsFLAGS_NOCACHE);
cmsCloseProfile(hlcmsProfileIn);
cmsCloseProfile(hlcmsProfileOut);
// Our test bitmap is 256 x 256 padded lines
Mb = sizeof(big_bitmap);
In = (big_bitmap*)malloc(Mb);
Out = (big_bitmap*)malloc(Mb);
for (r = 0; r < 256; r++)
for (g = 0; g < 256; g++)
for (b = 0; b < 256; b++) {
In->line[r].pixels[g][b].r = (cmsUInt8Number)r;
In->line[r].pixels[g][b].g = (cmsUInt8Number)g;
In->line[r].pixels[g][b].b = (cmsUInt8Number)b;
In->line[r].pixels[g][b].a = 0;
}
MeasureTimeStart();
cmsDoTransformLineStride(hlcmsxform, In, Out, 256 * 256, 256, sizeof(padded_line), sizeof(padded_line), 0, 0);
diff = MeasureTimeStop();
free(In); free(Out);
cmsDeleteTransform(hlcmsxform);
return MPixSec(diff);
}
static
void ComparativeLineStride8bits(void)
{
cmsContext NoPlugin, Plugin;
trace("\n\n");
trace("C O M P A R A T I V E cmsDoTransform() vs. cmsDoTransformLineStride()\n");
trace(" values given in MegaPixels per second.\n");
trace("====================================================================\n");
fflush(stdout);
NoPlugin = cmsCreateContext(NULL, NULL);
Plugin = cmsCreateContext(cmsThreadedExtensions(CMS_THREADED_GUESS_MAX_THREADS, 0), NULL);
ComparativeCt(NoPlugin, Plugin, "CLUT profiles ", SpeedTest8bitDoTransform, SpeedTest8bitLineStride, PROFILES_DIR "test5.icc", PROFILES_DIR "test3.icc");
ComparativeCt(NoPlugin, Plugin, "CLUT 16 bits ", SpeedTest16bitsRGB, SpeedTest16bitsRGB, PROFILES_DIR "test5.icc", PROFILES_DIR "test3.icc");
ComparativeCt(NoPlugin, Plugin, "Matrix-Shaper ", SpeedTest8bitDoTransform, SpeedTest8bitLineStride, PROFILES_DIR "test5.icc", PROFILES_DIR "test0.icc");
ComparativeCt(NoPlugin, Plugin, "same MatrixSh ", SpeedTest8bitDoTransform, SpeedTest8bitLineStride, PROFILES_DIR "test0.icc", PROFILES_DIR "test0.icc");
ComparativeCt(NoPlugin, Plugin, "curves ", SpeedTest8bitDoTransform, SpeedTest8bitLineStride, NULL, NULL);
cmsDeleteContext(Plugin);
cmsDeleteContext(NoPlugin);
}
// The harness test
int main()
{
#ifdef _MSC_VER
_CrtSetDbgFlag(_CRTDBG_ALLOC_MEM_DF | _CRTDBG_LEAK_CHECK_DF);
#endif
trace("Multithreaded extensions testbed - 1.1\n");
trace("Copyright (c) 1998-2023 Marti Maria Saguer, all rights reserved\n");
trace("\nInstalling error logger ... ");
cmsSetLogErrorHandler(FatalErrorQuit);
trace("done.\n");
trace("Installing plug-in ... ");
cmsPlugin(cmsThreadedExtensions(CMS_THREADED_GUESS_MAX_THREADS, 0));
trace("done.\n\n");
// Change format
CheckChangeFormat();
// Accuracy
CheckAccuracy8Bits();
CheckAccuracy16Bits();
// Check speed
SpeedTest8();
SpeedTest16();
ComparativeLineStride8bits();
cmsUnregisterPlugins();
trace("\nAll tests passed OK\n");
return 0;
}
|