jdk/src/share/native/sun/java2d/cmm/lcms/cmsio0.c
author malenkov
Tue, 29 Oct 2013 17:01:06 +0400
changeset 21278 ef8a3a2a72f2
parent 20807 841e21c03f0f
child 21589 7bb6e98b1dfb
permissions -rw-r--r--
8022746: List of spelling errors in API doc Reviewed-by: alexsch, smarks
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
     2
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * under the terms of the GNU General Public License version 2 only, as
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2395
diff changeset
     6
 * published by the Free Software Foundation.  Oracle designates this
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     7
 * particular file as subject to the "Classpath" exception as provided
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2395
diff changeset
     8
 * by Oracle in the LICENSE file that accompanied this code.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     9
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    19
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2395
diff changeset
    20
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2395
diff changeset
    21
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2395
diff changeset
    22
 * questions.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    23
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
// This file is available under and governed by the GNU General Public
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
// License version 2 only, as published by the Free Software Foundation.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
// However, the following notice accompanied the original version of this
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
// file:
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
//
6482
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
    30
//---------------------------------------------------------------------------------
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
//
6482
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
    32
//  Little Color Management System
14300
117dc9b98a7b 7053526: Upgrade JDK 8 to use Little CMS 2.4
bae
parents: 9784
diff changeset
    33
//  Copyright (c) 1998-2012 Marti Maria Saguer
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
//
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
// Permission is hereby granted, free of charge, to any person obtaining
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
// a copy of this software and associated documentation files (the "Software"),
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
// to deal in the Software without restriction, including without limitation
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
// the rights to use, copy, modify, merge, publish, distribute, sublicense,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
// and/or sell copies of the Software, and to permit persons to whom the Software
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
// is furnished to do so, subject to the following conditions:
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
//
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
// The above copyright notice and this permission notice shall be included in
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
// all copies or substantial portions of the Software.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
//
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
// THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
//
6482
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
    53
//---------------------------------------------------------------------------------
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
    54
//
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
    55
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
    56
#include "lcms2_internal.h"
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
// Generic I/O, tag dictionary management, profile struct
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
6482
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
    60
// IOhandlers are abstractions used by littleCMS to read from whatever file, stream,
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
    61
// memory block or any storage. Each IOhandler provides implementations for read,
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
    62
// write, seek and tell functions. LittleCMS code deals with IO across those objects.
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
    63
// In this way, is easier to add support for new storage media.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
6482
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
    65
// NULL stream, for taking care of used space -------------------------------------
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
6482
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
    67
// NULL IOhandler basically does nothing but keep track on how many bytes have been
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
    68
// written. This is handy when creating profiles, where the file size is needed in the
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
    69
// header. Then, whole profile is serialized across NULL IOhandler and a second pass
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
    70
// writes the bytes to the pertinent IOhandler.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
typedef struct {
6482
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
    73
    cmsUInt32Number Pointer;         // Points to current location
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
    74
} FILENULL;
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
    75
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
    76
static
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
    77
cmsUInt32Number NULLRead(cmsIOHANDLER* iohandler, void *Buffer, cmsUInt32Number size, cmsUInt32Number count)
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
    78
{
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
    79
    FILENULL* ResData = (FILENULL*) iohandler ->stream;
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
    80
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
    81
    cmsUInt32Number len = size * count;
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
    82
    ResData -> Pointer += len;
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
    83
    return count;
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
    84
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
    85
    cmsUNUSED_PARAMETER(Buffer);
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
    86
}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
6482
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
    88
static
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
    89
cmsBool  NULLSeek(cmsIOHANDLER* iohandler, cmsUInt32Number offset)
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
    90
{
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
    91
    FILENULL* ResData = (FILENULL*) iohandler ->stream;
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
    92
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
    93
    ResData ->Pointer = offset;
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
    94
    return TRUE;
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
    95
}
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
    96
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
    97
static
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
    98
cmsUInt32Number NULLTell(cmsIOHANDLER* iohandler)
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
    99
{
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   100
    FILENULL* ResData = (FILENULL*) iohandler ->stream;
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   101
    return ResData -> Pointer;
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   102
}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
static
6482
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   105
cmsBool  NULLWrite(cmsIOHANDLER* iohandler, cmsUInt32Number size, const void *Ptr)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
{
6482
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   107
    FILENULL* ResData = (FILENULL*) iohandler ->stream;
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   108
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   109
    ResData ->Pointer += size;
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   110
    if (ResData ->Pointer > iohandler->UsedSpace)
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   111
        iohandler->UsedSpace = ResData ->Pointer;
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   112
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   113
    return TRUE;
2394
404cbe399601 6821031: Upgrade OpenJDK's LittleCMS version to 1.18
prr
parents: 2392
diff changeset
   114
6482
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   115
    cmsUNUSED_PARAMETER(Ptr);
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   116
}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
6482
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   118
static
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   119
cmsBool  NULLClose(cmsIOHANDLER* iohandler)
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   120
{
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   121
    FILENULL* ResData = (FILENULL*) iohandler ->stream;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
6482
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   123
    _cmsFree(iohandler ->ContextID, ResData);
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   124
    _cmsFree(iohandler ->ContextID, iohandler);
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   125
    return TRUE;
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   126
}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
6482
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   128
// The NULL IOhandler creator
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   129
cmsIOHANDLER*  CMSEXPORT cmsOpenIOhandlerFromNULL(cmsContext ContextID)
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   130
{
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   131
    struct _cms_io_handler* iohandler = NULL;
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   132
    FILENULL* fm = NULL;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
6482
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   134
    iohandler = (struct _cms_io_handler*) _cmsMallocZero(ContextID, sizeof(struct _cms_io_handler));
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   135
    if (iohandler == NULL) return NULL;
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   136
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   137
    fm = (FILENULL*) _cmsMallocZero(ContextID, sizeof(FILENULL));
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   138
    if (fm == NULL) goto Error;
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   139
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
    fm ->Pointer = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
6482
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   142
    iohandler ->ContextID = ContextID;
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   143
    iohandler ->stream  = (void*) fm;
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   144
    iohandler ->UsedSpace = 0;
14300
117dc9b98a7b 7053526: Upgrade JDK 8 to use Little CMS 2.4
bae
parents: 9784
diff changeset
   145
    iohandler ->ReportedSize = 0;
6482
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   146
    iohandler ->PhysicalFile[0] = 0;
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   147
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   148
    iohandler ->Read    = NULLRead;
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   149
    iohandler ->Seek    = NULLSeek;
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   150
    iohandler ->Close   = NULLClose;
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   151
    iohandler ->Tell    = NULLTell;
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   152
    iohandler ->Write   = NULLWrite;
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   153
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   154
    return iohandler;
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   155
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   156
Error:
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   157
    if (fm) _cmsFree(ContextID, fm);
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   158
    if (iohandler) _cmsFree(ContextID, iohandler);
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   159
    return NULL;
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   160
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
6482
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   164
// Memory-based stream --------------------------------------------------------------
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   165
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   166
// Those functions implements an iohandler which takes a block of memory as storage medium.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
6482
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   168
typedef struct {
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   169
    cmsUInt8Number* Block;    // Points to allocated memory
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   170
    cmsUInt32Number Size;     // Size of allocated memory
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   171
    cmsUInt32Number Pointer;  // Points to current location
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   172
    int FreeBlockOnClose;     // As title
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   173
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   174
} FILEMEM;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
6482
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   176
static
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   177
cmsUInt32Number MemoryRead(struct _cms_io_handler* iohandler, void *Buffer, cmsUInt32Number size, cmsUInt32Number count)
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   178
{
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   179
    FILEMEM* ResData = (FILEMEM*) iohandler ->stream;
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   180
    cmsUInt8Number* Ptr;
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   181
    cmsUInt32Number len = size * count;
2394
404cbe399601 6821031: Upgrade OpenJDK's LittleCMS version to 1.18
prr
parents: 2392
diff changeset
   182
6482
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   183
    if (ResData -> Pointer + len > ResData -> Size){
2394
404cbe399601 6821031: Upgrade OpenJDK's LittleCMS version to 1.18
prr
parents: 2392
diff changeset
   184
6482
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   185
        len = (ResData -> Size - ResData -> Pointer);
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   186
        cmsSignalError(iohandler ->ContextID, cmsERROR_READ, "Read from memory error. Got %d bytes, block should be of %d bytes", len, count * size);
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   187
        return 0;
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   188
    }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
    Ptr  = ResData -> Block;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
    Ptr += ResData -> Pointer;
6482
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   192
    memmove(Buffer, Ptr, len);
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   193
    ResData -> Pointer += len;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
    return count;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
// SEEK_CUR is assumed
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
static
6482
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   200
cmsBool  MemorySeek(struct _cms_io_handler* iohandler, cmsUInt32Number offset)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
{
6482
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   202
    FILEMEM* ResData = (FILEMEM*) iohandler ->stream;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
    if (offset > ResData ->Size) {
6482
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   205
        cmsSignalError(iohandler ->ContextID, cmsERROR_SEEK,  "Too few data; probably corrupted profile");
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   206
        return FALSE;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
6482
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   209
    ResData ->Pointer = offset;
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   210
    return TRUE;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
6482
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   213
// Tell for memory
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
static
6482
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   215
cmsUInt32Number MemoryTell(struct _cms_io_handler* iohandler)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
{
6482
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   217
    FILEMEM* ResData = (FILEMEM*) iohandler ->stream;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
6482
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   219
    if (ResData == NULL) return 0;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
    return ResData -> Pointer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
6482
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   224
// Writes data to memory, also keeps used space for further reference.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
static
6482
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   226
cmsBool  MemoryWrite(struct _cms_io_handler* iohandler, cmsUInt32Number size, const void *Ptr)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
{
6482
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   228
    FILEMEM* ResData = (FILEMEM*) iohandler ->stream;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
6482
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   230
    if (ResData == NULL) return FALSE; // Housekeeping
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
6482
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   232
    if (size == 0) return TRUE;     // Write zero bytes is ok, but does nothing
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
6482
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   234
    memmove(ResData ->Block + ResData ->Pointer, Ptr, size);
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   235
    ResData ->Pointer += size;
14300
117dc9b98a7b 7053526: Upgrade JDK 8 to use Little CMS 2.4
bae
parents: 9784
diff changeset
   236
    iohandler->UsedSpace += size;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
6482
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   238
    if (ResData ->Pointer > iohandler->UsedSpace)
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   239
        iohandler->UsedSpace = ResData ->Pointer;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
2392
738be5224b3f 6733501: Apply IcedTea little cms patches
avu
parents: 2
diff changeset
   241
    return TRUE;
738be5224b3f 6733501: Apply IcedTea little cms patches
avu
parents: 2
diff changeset
   242
}
738be5224b3f 6733501: Apply IcedTea little cms patches
avu
parents: 2
diff changeset
   243
738be5224b3f 6733501: Apply IcedTea little cms patches
avu
parents: 2
diff changeset
   244
738be5224b3f 6733501: Apply IcedTea little cms patches
avu
parents: 2
diff changeset
   245
static
6482
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   246
cmsBool  MemoryClose(struct _cms_io_handler* iohandler)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
{
6482
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   248
    FILEMEM* ResData = (FILEMEM*) iohandler ->stream;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
    if (ResData ->FreeBlockOnClose) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
6482
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   252
        if (ResData ->Block) _cmsFree(iohandler ->ContextID, ResData ->Block);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
    }
6482
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   254
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   255
    _cmsFree(iohandler ->ContextID, ResData);
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   256
    _cmsFree(iohandler ->ContextID, iohandler);
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   257
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   258
    return TRUE;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
6482
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   261
// Create a iohandler for memory block. AccessMode=='r' assumes the iohandler is going to read, and makes
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   262
// a copy of the memory block for letting user to free the memory after invoking open profile. In write
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   263
// mode ("w"), Buffere points to the begin of memory block to be written.
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   264
cmsIOHANDLER* CMSEXPORT cmsOpenIOhandlerFromMem(cmsContext ContextID, void *Buffer, cmsUInt32Number size, const char* AccessMode)
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   265
{
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   266
    cmsIOHANDLER* iohandler = NULL;
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   267
    FILEMEM* fm = NULL;
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   268
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   269
    _cmsAssert(AccessMode != NULL);
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   270
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   271
    iohandler = (cmsIOHANDLER*) _cmsMallocZero(ContextID, sizeof(cmsIOHANDLER));
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   272
    if (iohandler == NULL) return NULL;
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   273
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   274
    switch (*AccessMode) {
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   275
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   276
    case 'r':
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   277
        fm = (FILEMEM*) _cmsMallocZero(ContextID, sizeof(FILEMEM));
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   278
        if (fm == NULL) goto Error;
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   279
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   280
        if (Buffer == NULL) {
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   281
            cmsSignalError(ContextID, cmsERROR_READ, "Couldn't read profile from NULL pointer");
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   282
            goto Error;
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   283
        }
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   284
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   285
        fm ->Block = (cmsUInt8Number*) _cmsMalloc(ContextID, size);
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   286
        if (fm ->Block == NULL) {
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   287
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   288
            _cmsFree(ContextID, fm);
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   289
            _cmsFree(ContextID, iohandler);
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   290
            cmsSignalError(ContextID, cmsERROR_READ, "Couldn't allocate %ld bytes for profile", size);
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   291
            return NULL;
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   292
        }
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   293
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   294
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   295
        memmove(fm->Block, Buffer, size);
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   296
        fm ->FreeBlockOnClose = TRUE;
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   297
        fm ->Size    = size;
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   298
        fm ->Pointer = 0;
14300
117dc9b98a7b 7053526: Upgrade JDK 8 to use Little CMS 2.4
bae
parents: 9784
diff changeset
   299
        iohandler -> ReportedSize = size;
6482
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   300
        break;
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   301
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   302
    case 'w':
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   303
        fm = (FILEMEM*) _cmsMallocZero(ContextID, sizeof(FILEMEM));
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   304
        if (fm == NULL) goto Error;
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   305
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   306
        fm ->Block = (cmsUInt8Number*) Buffer;
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   307
        fm ->FreeBlockOnClose = FALSE;
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   308
        fm ->Size    = size;
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   309
        fm ->Pointer = 0;
14300
117dc9b98a7b 7053526: Upgrade JDK 8 to use Little CMS 2.4
bae
parents: 9784
diff changeset
   310
        iohandler -> ReportedSize = 0;
6482
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   311
        break;
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   312
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   313
    default:
14300
117dc9b98a7b 7053526: Upgrade JDK 8 to use Little CMS 2.4
bae
parents: 9784
diff changeset
   314
        cmsSignalError(ContextID, cmsERROR_UNKNOWN_EXTENSION, "Unknown access mode '%c'", *AccessMode);
6482
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   315
        return NULL;
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   316
    }
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   317
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   318
    iohandler ->ContextID = ContextID;
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   319
    iohandler ->stream  = (void*) fm;
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   320
    iohandler ->UsedSpace = 0;
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   321
    iohandler ->PhysicalFile[0] = 0;
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   322
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   323
    iohandler ->Read    = MemoryRead;
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   324
    iohandler ->Seek    = MemorySeek;
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   325
    iohandler ->Close   = MemoryClose;
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   326
    iohandler ->Tell    = MemoryTell;
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   327
    iohandler ->Write   = MemoryWrite;
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   328
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   329
    return iohandler;
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   330
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   331
Error:
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   332
    if (fm) _cmsFree(ContextID, fm);
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   333
    if (iohandler) _cmsFree(ContextID, iohandler);
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   334
    return NULL;
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   335
}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   336
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
// File-based stream -------------------------------------------------------
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
6482
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   339
// Read count elements of size bytes each. Return number of elements read
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   340
static
6482
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   341
cmsUInt32Number FileRead(cmsIOHANDLER* iohandler, void *Buffer, cmsUInt32Number size, cmsUInt32Number count)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
{
6482
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   343
    cmsUInt32Number nReaded = (cmsUInt32Number) fread(Buffer, size, count, (FILE*) iohandler->stream);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   344
90ce3da70b43 Initial load
duke
parents:
diff changeset
   345
    if (nReaded != count) {
6482
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   346
            cmsSignalError(iohandler ->ContextID, cmsERROR_FILE, "Read error. Got %d bytes, block should be of %d bytes", nReaded * size, count * size);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   347
            return 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   348
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   349
90ce3da70b43 Initial load
duke
parents:
diff changeset
   350
    return nReaded;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   351
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   352
21278
ef8a3a2a72f2 8022746: List of spelling errors in API doc
malenkov
parents: 20807
diff changeset
   353
// Position file pointer in the file
6482
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   354
static
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   355
cmsBool  FileSeek(cmsIOHANDLER* iohandler, cmsUInt32Number offset)
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   356
{
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   357
    if (fseek((FILE*) iohandler ->stream, (long) offset, SEEK_SET) != 0) {
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   358
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   359
       cmsSignalError(iohandler ->ContextID, cmsERROR_FILE, "Seek error; probably corrupted file");
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   360
       return FALSE;
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   361
    }
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   362
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   363
    return TRUE;
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   364
}
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   365
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   366
// Returns file pointer position
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   367
static
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   368
cmsUInt32Number FileTell(cmsIOHANDLER* iohandler)
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   369
{
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   370
    return ftell((FILE*)iohandler ->stream);
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   371
}
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   372
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   373
// Writes data to stream, also keeps used space for further reference. Returns TRUE on success, FALSE on error
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   374
static
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   375
cmsBool  FileWrite(cmsIOHANDLER* iohandler, cmsUInt32Number size, const void* Buffer)
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   376
{
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   377
       if (size == 0) return TRUE;  // We allow to write 0 bytes, but nothing is written
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   378
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   379
       iohandler->UsedSpace += size;
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   380
       return (fwrite(Buffer, size, 1, (FILE*) iohandler->stream) == 1);
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   381
}
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   382
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   383
// Closes the file
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   384
static
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   385
cmsBool  FileClose(cmsIOHANDLER* iohandler)
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   386
{
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   387
    if (fclose((FILE*) iohandler ->stream) != 0) return FALSE;
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   388
    _cmsFree(iohandler ->ContextID, iohandler);
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   389
    return TRUE;
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   390
}
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   391
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   392
// Create a iohandler for disk based files. if FileName is NULL, then 'stream' member is also set
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   393
// to NULL and no real writting is performed. This only happens in writting access mode
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   394
cmsIOHANDLER* CMSEXPORT cmsOpenIOhandlerFromFile(cmsContext ContextID, const char* FileName, const char* AccessMode)
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   395
{
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   396
    cmsIOHANDLER* iohandler = NULL;
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   397
    FILE* fm = NULL;
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   398
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   399
    iohandler = (cmsIOHANDLER*) _cmsMallocZero(ContextID, sizeof(cmsIOHANDLER));
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   400
    if (iohandler == NULL) return NULL;
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   401
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   402
    switch (*AccessMode) {
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   403
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   404
    case 'r':
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   405
        fm = fopen(FileName, "rb");
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   406
        if (fm == NULL) {
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   407
            _cmsFree(ContextID, iohandler);
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   408
             cmsSignalError(ContextID, cmsERROR_FILE, "File '%s' not found", FileName);
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   409
            return NULL;
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   410
        }
14300
117dc9b98a7b 7053526: Upgrade JDK 8 to use Little CMS 2.4
bae
parents: 9784
diff changeset
   411
        iohandler -> ReportedSize = cmsfilelength(fm);
6482
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   412
        break;
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   413
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   414
    case 'w':
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   415
        fm = fopen(FileName, "wb");
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   416
        if (fm == NULL) {
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   417
            _cmsFree(ContextID, iohandler);
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   418
             cmsSignalError(ContextID, cmsERROR_FILE, "Couldn't create '%s'", FileName);
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   419
            return NULL;
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   420
        }
14300
117dc9b98a7b 7053526: Upgrade JDK 8 to use Little CMS 2.4
bae
parents: 9784
diff changeset
   421
        iohandler -> ReportedSize = 0;
6482
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   422
        break;
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   423
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   424
    default:
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   425
        _cmsFree(ContextID, iohandler);
14300
117dc9b98a7b 7053526: Upgrade JDK 8 to use Little CMS 2.4
bae
parents: 9784
diff changeset
   426
         cmsSignalError(ContextID, cmsERROR_FILE, "Unknown access mode '%c'", *AccessMode);
6482
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   427
        return NULL;
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   428
    }
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   429
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   430
    iohandler ->ContextID = ContextID;
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   431
    iohandler ->stream = (void*) fm;
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   432
    iohandler ->UsedSpace = 0;
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   433
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   434
    // Keep track of the original file
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   435
    if (FileName != NULL)  {
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   436
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   437
        strncpy(iohandler -> PhysicalFile, FileName, sizeof(iohandler -> PhysicalFile)-1);
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   438
        iohandler -> PhysicalFile[sizeof(iohandler -> PhysicalFile)-1] = 0;
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   439
    }
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   440
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   441
    iohandler ->Read    = FileRead;
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   442
    iohandler ->Seek    = FileSeek;
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   443
    iohandler ->Close   = FileClose;
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   444
    iohandler ->Tell    = FileTell;
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   445
    iohandler ->Write   = FileWrite;
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   446
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   447
    return iohandler;
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   448
}
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   449
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   450
// Create a iohandler for stream based files
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   451
cmsIOHANDLER* CMSEXPORT cmsOpenIOhandlerFromStream(cmsContext ContextID, FILE* Stream)
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   452
{
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   453
    cmsIOHANDLER* iohandler = NULL;
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   454
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   455
    iohandler = (cmsIOHANDLER*) _cmsMallocZero(ContextID, sizeof(cmsIOHANDLER));
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   456
    if (iohandler == NULL) return NULL;
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   457
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   458
    iohandler -> ContextID = ContextID;
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   459
    iohandler -> stream = (void*) Stream;
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   460
    iohandler -> UsedSpace = 0;
14300
117dc9b98a7b 7053526: Upgrade JDK 8 to use Little CMS 2.4
bae
parents: 9784
diff changeset
   461
    iohandler -> ReportedSize = cmsfilelength(Stream);
6482
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   462
    iohandler -> PhysicalFile[0] = 0;
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   463
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   464
    iohandler ->Read    = FileRead;
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   465
    iohandler ->Seek    = FileSeek;
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   466
    iohandler ->Close   = FileClose;
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   467
    iohandler ->Tell    = FileTell;
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   468
    iohandler ->Write   = FileWrite;
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   469
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   470
    return iohandler;
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   471
}
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   472
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   473
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   474
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   475
// Close an open IO handler
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   476
cmsBool CMSEXPORT cmsCloseIOhandler(cmsIOHANDLER* io)
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   477
{
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   478
    return io -> Close(io);
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   479
}
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   480
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   481
// -------------------------------------------------------------------------------------------------------
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   482
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   483
// Creates an empty structure holding all required parameters
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   484
cmsHPROFILE CMSEXPORT cmsCreateProfilePlaceholder(cmsContext ContextID)
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   485
{
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   486
    time_t now = time(NULL);
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   487
    _cmsICCPROFILE* Icc = (_cmsICCPROFILE*) _cmsMallocZero(ContextID, sizeof(_cmsICCPROFILE));
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   488
    if (Icc == NULL) return NULL;
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   489
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   490
    Icc ->ContextID = ContextID;
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   491
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   492
    // Set it to empty
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   493
    Icc -> TagCount   = 0;
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   494
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   495
    // Set default version
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   496
    Icc ->Version =  0x02100000;
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   497
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   498
    // Set creation date/time
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   499
    memmove(&Icc ->Created, gmtime(&now), sizeof(Icc ->Created));
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   500
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   501
    // Return the handle
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   502
    return (cmsHPROFILE) Icc;
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   503
}
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   504
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   505
cmsContext CMSEXPORT cmsGetProfileContextID(cmsHPROFILE hProfile)
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   506
{
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   507
     _cmsICCPROFILE* Icc = (_cmsICCPROFILE*) hProfile;
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   508
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   509
    if (Icc == NULL) return NULL;
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   510
    return Icc -> ContextID;
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   511
}
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   512
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   513
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   514
// Return the number of tags
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   515
cmsInt32Number CMSEXPORT cmsGetTagCount(cmsHPROFILE hProfile)
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   516
{
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   517
    _cmsICCPROFILE* Icc = (_cmsICCPROFILE*) hProfile;
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   518
    if (Icc == NULL) return -1;
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   519
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   520
    return  Icc->TagCount;
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   521
}
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   522
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   523
// Return the tag signature of a given tag number
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   524
cmsTagSignature CMSEXPORT cmsGetTagSignature(cmsHPROFILE hProfile, cmsUInt32Number n)
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   525
{
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   526
    _cmsICCPROFILE* Icc = (_cmsICCPROFILE*) hProfile;
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   527
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   528
    if (n > Icc->TagCount) return (cmsTagSignature) 0;  // Mark as not available
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   529
    if (n >= MAX_TABLE_TAG) return (cmsTagSignature) 0; // As double check
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   530
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   531
    return Icc ->TagNames[n];
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   532
}
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   533
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   534
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   535
static
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   536
int SearchOneTag(_cmsICCPROFILE* Profile, cmsTagSignature sig)
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   537
{
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   538
    cmsUInt32Number i;
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   539
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   540
    for (i=0; i < Profile -> TagCount; i++) {
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   541
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   542
        if (sig == Profile -> TagNames[i])
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   543
            return i;
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   544
    }
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   545
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   546
    return -1;
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   547
}
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   548
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   549
// Search for a specific tag in tag dictionary. Returns position or -1 if tag not found.
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   550
// If followlinks is turned on, then the position of the linked tag is returned
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   551
int _cmsSearchTag(_cmsICCPROFILE* Icc, cmsTagSignature sig, cmsBool lFollowLinks)
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   552
{
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   553
    int n;
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   554
    cmsTagSignature LinkedSig;
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   555
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   556
    do {
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   557
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   558
        // Search for given tag in ICC profile directory
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   559
        n = SearchOneTag(Icc, sig);
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   560
        if (n < 0)
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   561
            return -1;        // Not found
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   562
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   563
        if (!lFollowLinks)
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   564
            return n;         // Found, don't follow links
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   565
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   566
        // Is this a linked tag?
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   567
        LinkedSig = Icc ->TagLinked[n];
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   568
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   569
        // Yes, follow link
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   570
        if (LinkedSig != (cmsTagSignature) 0) {
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   571
            sig = LinkedSig;
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   572
        }
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   573
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   574
    } while (LinkedSig != (cmsTagSignature) 0);
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   575
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   576
    return n;
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   577
}
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   578
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   579
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   580
// Create a new tag entry
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   581
90ce3da70b43 Initial load
duke
parents:
diff changeset
   582
static
6482
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   583
cmsBool _cmsNewTag(_cmsICCPROFILE* Icc, cmsTagSignature sig, int* NewPos)
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   584
{
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   585
    int i;
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   586
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   587
    // Search for the tag
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   588
    i = _cmsSearchTag(Icc, sig, FALSE);
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   589
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   590
    // Now let's do it easy. If the tag has been already written, that's an error
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   591
    if (i >= 0) {
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   592
        cmsSignalError(Icc ->ContextID, cmsERROR_ALREADY_DEFINED, "Tag '%x' already exists", sig);
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   593
        return FALSE;
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   594
    }
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   595
    else  {
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   596
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   597
        // New one
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   598
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   599
        if (Icc -> TagCount >= MAX_TABLE_TAG) {
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   600
            cmsSignalError(Icc ->ContextID, cmsERROR_RANGE, "Too many tags (%d)", MAX_TABLE_TAG);
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   601
            return FALSE;
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   602
        }
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   603
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   604
        *NewPos = Icc ->TagCount;
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   605
        Icc -> TagCount++;
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   606
    }
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   607
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   608
    return TRUE;
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   609
}
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   610
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   611
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   612
// Check existance
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   613
cmsBool CMSEXPORT cmsIsTag(cmsHPROFILE hProfile, cmsTagSignature sig)
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   614
{
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   615
       _cmsICCPROFILE*  Icc = (_cmsICCPROFILE*) (void*) hProfile;
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   616
       return _cmsSearchTag(Icc, sig, FALSE) >= 0;
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   617
}
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   618
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   619
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   620
// Read profile header and validate it
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   621
cmsBool _cmsReadHeader(_cmsICCPROFILE* Icc)
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   622
{
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   623
    cmsTagEntry Tag;
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   624
    cmsICCHeader Header;
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   625
    cmsUInt32Number i, j;
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   626
    cmsUInt32Number HeaderSize;
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   627
    cmsIOHANDLER* io = Icc ->IOhandler;
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   628
    cmsUInt32Number TagCount;
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   629
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   630
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   631
    // Read the header
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   632
    if (io -> Read(io, &Header, sizeof(cmsICCHeader), 1) != 1) {
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   633
        return FALSE;
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   634
    }
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   635
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   636
    // Validate file as an ICC profile
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   637
    if (_cmsAdjustEndianess32(Header.magic) != cmsMagicNumber) {
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   638
        cmsSignalError(Icc ->ContextID, cmsERROR_BAD_SIGNATURE, "not an ICC profile, invalid signature");
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   639
        return FALSE;
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   640
    }
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   641
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   642
    // Adjust endianess of the used parameters
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   643
    Icc -> DeviceClass     = (cmsProfileClassSignature) _cmsAdjustEndianess32(Header.deviceClass);
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   644
    Icc -> ColorSpace      = (cmsColorSpaceSignature)   _cmsAdjustEndianess32(Header.colorSpace);
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   645
    Icc -> PCS             = (cmsColorSpaceSignature)   _cmsAdjustEndianess32(Header.pcs);
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   646
    Icc -> RenderingIntent = _cmsAdjustEndianess32(Header.renderingIntent);
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   647
    Icc -> flags           = _cmsAdjustEndianess32(Header.flags);
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   648
    Icc -> manufacturer    = _cmsAdjustEndianess32(Header.manufacturer);
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   649
    Icc -> model           = _cmsAdjustEndianess32(Header.model);
14300
117dc9b98a7b 7053526: Upgrade JDK 8 to use Little CMS 2.4
bae
parents: 9784
diff changeset
   650
    _cmsAdjustEndianess64(&Icc -> attributes, &Header.attributes);
6482
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   651
    Icc -> Version         = _cmsAdjustEndianess32(Header.version);
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   652
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   653
    // Get size as reported in header
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   654
    HeaderSize = _cmsAdjustEndianess32(Header.size);
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   655
14300
117dc9b98a7b 7053526: Upgrade JDK 8 to use Little CMS 2.4
bae
parents: 9784
diff changeset
   656
    // Make sure HeaderSize is lower than profile size
117dc9b98a7b 7053526: Upgrade JDK 8 to use Little CMS 2.4
bae
parents: 9784
diff changeset
   657
    if (HeaderSize >= Icc ->IOhandler ->ReportedSize)
117dc9b98a7b 7053526: Upgrade JDK 8 to use Little CMS 2.4
bae
parents: 9784
diff changeset
   658
            HeaderSize = Icc ->IOhandler ->ReportedSize;
117dc9b98a7b 7053526: Upgrade JDK 8 to use Little CMS 2.4
bae
parents: 9784
diff changeset
   659
117dc9b98a7b 7053526: Upgrade JDK 8 to use Little CMS 2.4
bae
parents: 9784
diff changeset
   660
6482
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   661
    // Get creation date/time
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   662
    _cmsDecodeDateTimeNumber(&Header.date, &Icc ->Created);
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   663
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   664
    // The profile ID are 32 raw bytes
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   665
    memmove(Icc ->ProfileID.ID32, Header.profileID.ID32, 16);
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   666
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   667
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   668
    // Read tag directory
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   669
    if (!_cmsReadUInt32Number(io, &TagCount)) return FALSE;
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   670
    if (TagCount > MAX_TABLE_TAG) {
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   671
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   672
        cmsSignalError(Icc ->ContextID, cmsERROR_RANGE, "Too many tags (%d)", TagCount);
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   673
        return FALSE;
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   674
    }
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   675
14300
117dc9b98a7b 7053526: Upgrade JDK 8 to use Little CMS 2.4
bae
parents: 9784
diff changeset
   676
6482
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   677
    // Read tag directory
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   678
    Icc -> TagCount = 0;
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   679
    for (i=0; i < TagCount; i++) {
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   680
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   681
        if (!_cmsReadUInt32Number(io, (cmsUInt32Number *) &Tag.sig)) return FALSE;
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   682
        if (!_cmsReadUInt32Number(io, &Tag.offset)) return FALSE;
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   683
        if (!_cmsReadUInt32Number(io, &Tag.size)) return FALSE;
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   684
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   685
        // Perform some sanity check. Offset + size should fall inside file.
14300
117dc9b98a7b 7053526: Upgrade JDK 8 to use Little CMS 2.4
bae
parents: 9784
diff changeset
   686
        if (Tag.offset + Tag.size > HeaderSize ||
117dc9b98a7b 7053526: Upgrade JDK 8 to use Little CMS 2.4
bae
parents: 9784
diff changeset
   687
            Tag.offset + Tag.size < Tag.offset)
6482
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   688
                  continue;
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   689
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   690
        Icc -> TagNames[Icc ->TagCount]   = Tag.sig;
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   691
        Icc -> TagOffsets[Icc ->TagCount] = Tag.offset;
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   692
        Icc -> TagSizes[Icc ->TagCount]   = Tag.size;
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   693
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   694
       // Search for links
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   695
        for (j=0; j < Icc ->TagCount; j++) {
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   696
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   697
            if ((Icc ->TagOffsets[j] == Tag.offset) &&
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   698
                (Icc ->TagSizes[j]   == Tag.size)) {
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   699
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   700
                Icc ->TagLinked[Icc ->TagCount] = Icc ->TagNames[j];
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   701
            }
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   702
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   703
        }
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   704
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   705
        Icc ->TagCount++;
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   706
    }
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   707
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   708
    return TRUE;
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   709
}
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   710
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   711
// Saves profile header
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   712
cmsBool _cmsWriteHeader(_cmsICCPROFILE* Icc, cmsUInt32Number UsedSpace)
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   713
{
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   714
    cmsICCHeader Header;
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   715
    cmsUInt32Number i;
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   716
    cmsTagEntry Tag;
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   717
    cmsInt32Number Count = 0;
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   718
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   719
    Header.size        = _cmsAdjustEndianess32(UsedSpace);
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   720
    Header.cmmId       = _cmsAdjustEndianess32(lcmsSignature);
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   721
    Header.version     = _cmsAdjustEndianess32(Icc ->Version);
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   722
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   723
    Header.deviceClass = (cmsProfileClassSignature) _cmsAdjustEndianess32(Icc -> DeviceClass);
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   724
    Header.colorSpace  = (cmsColorSpaceSignature) _cmsAdjustEndianess32(Icc -> ColorSpace);
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   725
    Header.pcs         = (cmsColorSpaceSignature) _cmsAdjustEndianess32(Icc -> PCS);
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   726
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   727
    //   NOTE: in v4 Timestamp must be in UTC rather than in local time
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   728
    _cmsEncodeDateTimeNumber(&Header.date, &Icc ->Created);
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   729
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   730
    Header.magic       = _cmsAdjustEndianess32(cmsMagicNumber);
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   731
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   732
#ifdef CMS_IS_WINDOWS_
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   733
    Header.platform    = (cmsPlatformSignature) _cmsAdjustEndianess32(cmsSigMicrosoft);
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   734
#else
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   735
    Header.platform    = (cmsPlatformSignature) _cmsAdjustEndianess32(cmsSigMacintosh);
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   736
#endif
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   737
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   738
    Header.flags        = _cmsAdjustEndianess32(Icc -> flags);
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   739
    Header.manufacturer = _cmsAdjustEndianess32(Icc -> manufacturer);
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   740
    Header.model        = _cmsAdjustEndianess32(Icc -> model);
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   741
14300
117dc9b98a7b 7053526: Upgrade JDK 8 to use Little CMS 2.4
bae
parents: 9784
diff changeset
   742
    _cmsAdjustEndianess64(&Header.attributes, &Icc -> attributes);
6482
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   743
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   744
    // Rendering intent in the header (for embedded profiles)
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   745
    Header.renderingIntent = _cmsAdjustEndianess32(Icc -> RenderingIntent);
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   746
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   747
    // Illuminant is always D50
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   748
    Header.illuminant.X = _cmsAdjustEndianess32(_cmsDoubleTo15Fixed16(cmsD50_XYZ()->X));
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   749
    Header.illuminant.Y = _cmsAdjustEndianess32(_cmsDoubleTo15Fixed16(cmsD50_XYZ()->Y));
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   750
    Header.illuminant.Z = _cmsAdjustEndianess32(_cmsDoubleTo15Fixed16(cmsD50_XYZ()->Z));
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   751
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   752
    // Created by LittleCMS (that's me!)
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   753
    Header.creator      = _cmsAdjustEndianess32(lcmsSignature);
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   754
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   755
    memset(&Header.reserved, 0, sizeof(Header.reserved));
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   756
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   757
    // Set profile ID. Endianess is always big endian
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   758
    memmove(&Header.profileID, &Icc ->ProfileID, 16);
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   759
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   760
    // Dump the header
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   761
    if (!Icc -> IOhandler->Write(Icc->IOhandler, sizeof(cmsICCHeader), &Header)) return FALSE;
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   762
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   763
    // Saves Tag directory
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   764
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   765
    // Get true count
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   766
    for (i=0;  i < Icc -> TagCount; i++) {
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   767
        if (Icc ->TagNames[i] != 0)
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   768
            Count++;
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   769
    }
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   770
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   771
    // Store number of tags
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   772
    if (!_cmsWriteUInt32Number(Icc ->IOhandler, Count)) return FALSE;
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   773
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   774
    for (i=0; i < Icc -> TagCount; i++) {
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   775
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   776
        if (Icc ->TagNames[i] == 0) continue;   // It is just a placeholder
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   777
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   778
        Tag.sig    = (cmsTagSignature) _cmsAdjustEndianess32((cmsInt32Number) Icc -> TagNames[i]);
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   779
        Tag.offset = _cmsAdjustEndianess32((cmsInt32Number) Icc -> TagOffsets[i]);
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   780
        Tag.size   = _cmsAdjustEndianess32((cmsInt32Number) Icc -> TagSizes[i]);
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   781
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   782
        if (!Icc ->IOhandler -> Write(Icc-> IOhandler, sizeof(cmsTagEntry), &Tag)) return FALSE;
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   783
    }
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   784
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   785
    return TRUE;
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   786
}
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   787
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   788
// ----------------------------------------------------------------------- Set/Get several struct members
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   789
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   790
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   791
cmsUInt32Number CMSEXPORT cmsGetHeaderRenderingIntent(cmsHPROFILE hProfile)
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   792
{
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   793
    _cmsICCPROFILE*  Icc = (_cmsICCPROFILE*) hProfile;
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   794
    return Icc -> RenderingIntent;
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   795
}
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   796
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   797
void CMSEXPORT cmsSetHeaderRenderingIntent(cmsHPROFILE hProfile, cmsUInt32Number RenderingIntent)
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   798
{
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   799
    _cmsICCPROFILE*  Icc = (_cmsICCPROFILE*) hProfile;
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   800
    Icc -> RenderingIntent = RenderingIntent;
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   801
}
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   802
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   803
cmsUInt32Number CMSEXPORT cmsGetHeaderFlags(cmsHPROFILE hProfile)
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   804
{
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   805
    _cmsICCPROFILE*  Icc = (_cmsICCPROFILE*) hProfile;
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   806
    return (cmsUInt32Number) Icc -> flags;
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   807
}
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   808
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   809
void CMSEXPORT cmsSetHeaderFlags(cmsHPROFILE hProfile, cmsUInt32Number Flags)
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   810
{
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   811
    _cmsICCPROFILE*  Icc = (_cmsICCPROFILE*) hProfile;
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   812
    Icc -> flags = (cmsUInt32Number) Flags;
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   813
}
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   814
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   815
cmsUInt32Number CMSEXPORT cmsGetHeaderManufacturer(cmsHPROFILE hProfile)
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   816
{
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   817
    _cmsICCPROFILE*  Icc = (_cmsICCPROFILE*) hProfile;
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   818
    return (cmsUInt32Number) Icc ->manufacturer;
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   819
}
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   820
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   821
void CMSEXPORT cmsSetHeaderManufacturer(cmsHPROFILE hProfile, cmsUInt32Number manufacturer)
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   822
{
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   823
    _cmsICCPROFILE*  Icc = (_cmsICCPROFILE*) hProfile;
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   824
    Icc -> manufacturer = (cmsUInt32Number) manufacturer;
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   825
}
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   826
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   827
cmsUInt32Number CMSEXPORT cmsGetHeaderModel(cmsHPROFILE hProfile)
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   828
{
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   829
    _cmsICCPROFILE*  Icc = (_cmsICCPROFILE*) hProfile;
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   830
    return (cmsUInt32Number) Icc ->model;
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   831
}
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   832
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   833
void CMSEXPORT cmsSetHeaderModel(cmsHPROFILE hProfile, cmsUInt32Number model)
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   834
{
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   835
    _cmsICCPROFILE*  Icc = (_cmsICCPROFILE*) hProfile;
14300
117dc9b98a7b 7053526: Upgrade JDK 8 to use Little CMS 2.4
bae
parents: 9784
diff changeset
   836
    Icc -> model = (cmsUInt32Number) model;
6482
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   837
}
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   838
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   839
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   840
void CMSEXPORT cmsGetHeaderAttributes(cmsHPROFILE hProfile, cmsUInt64Number* Flags)
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   841
{
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   842
    _cmsICCPROFILE*  Icc = (_cmsICCPROFILE*) hProfile;
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   843
    memmove(Flags, &Icc -> attributes, sizeof(cmsUInt64Number));
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   844
}
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   845
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   846
void CMSEXPORT cmsSetHeaderAttributes(cmsHPROFILE hProfile, cmsUInt64Number Flags)
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   847
{
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   848
    _cmsICCPROFILE*  Icc = (_cmsICCPROFILE*) hProfile;
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   849
    memmove(&Icc -> attributes, &Flags, sizeof(cmsUInt64Number));
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   850
}
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   851
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   852
void CMSEXPORT cmsGetHeaderProfileID(cmsHPROFILE hProfile, cmsUInt8Number* ProfileID)
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   853
{
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   854
    _cmsICCPROFILE*  Icc = (_cmsICCPROFILE*) hProfile;
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   855
    memmove(ProfileID, Icc ->ProfileID.ID8, 16);
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   856
}
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   857
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   858
void CMSEXPORT cmsSetHeaderProfileID(cmsHPROFILE hProfile, cmsUInt8Number* ProfileID)
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   859
{
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   860
    _cmsICCPROFILE*  Icc = (_cmsICCPROFILE*) hProfile;
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   861
    memmove(&Icc -> ProfileID, ProfileID, 16);
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   862
}
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   863
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   864
cmsBool  CMSEXPORT cmsGetHeaderCreationDateTime(cmsHPROFILE hProfile, struct tm *Dest)
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   865
{
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   866
    _cmsICCPROFILE*  Icc = (_cmsICCPROFILE*) hProfile;
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   867
    memmove(Dest, &Icc ->Created, sizeof(struct tm));
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   868
    return TRUE;
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   869
}
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   870
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   871
cmsColorSpaceSignature CMSEXPORT cmsGetPCS(cmsHPROFILE hProfile)
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   872
{
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   873
    _cmsICCPROFILE*  Icc = (_cmsICCPROFILE*) hProfile;
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   874
    return Icc -> PCS;
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   875
}
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   876
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   877
void CMSEXPORT cmsSetPCS(cmsHPROFILE hProfile, cmsColorSpaceSignature pcs)
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   878
{
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   879
    _cmsICCPROFILE*  Icc = (_cmsICCPROFILE*) hProfile;
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   880
    Icc -> PCS = pcs;
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   881
}
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   882
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   883
cmsColorSpaceSignature CMSEXPORT cmsGetColorSpace(cmsHPROFILE hProfile)
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   884
{
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   885
    _cmsICCPROFILE*  Icc = (_cmsICCPROFILE*) hProfile;
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   886
    return Icc -> ColorSpace;
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   887
}
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   888
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   889
void CMSEXPORT cmsSetColorSpace(cmsHPROFILE hProfile, cmsColorSpaceSignature sig)
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   890
{
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   891
    _cmsICCPROFILE*  Icc = (_cmsICCPROFILE*) hProfile;
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   892
    Icc -> ColorSpace = sig;
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   893
}
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   894
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   895
cmsProfileClassSignature CMSEXPORT cmsGetDeviceClass(cmsHPROFILE hProfile)
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   896
{
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   897
    _cmsICCPROFILE*  Icc = (_cmsICCPROFILE*) hProfile;
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   898
    return Icc -> DeviceClass;
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   899
}
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   900
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   901
void CMSEXPORT cmsSetDeviceClass(cmsHPROFILE hProfile, cmsProfileClassSignature sig)
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   902
{
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   903
    _cmsICCPROFILE*  Icc = (_cmsICCPROFILE*) hProfile;
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   904
    Icc -> DeviceClass = sig;
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   905
}
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   906
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   907
cmsUInt32Number CMSEXPORT cmsGetEncodedICCversion(cmsHPROFILE hProfile)
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   908
{
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   909
    _cmsICCPROFILE*  Icc = (_cmsICCPROFILE*) hProfile;
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   910
    return Icc -> Version;
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   911
}
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   912
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   913
void CMSEXPORT cmsSetEncodedICCversion(cmsHPROFILE hProfile, cmsUInt32Number Version)
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   914
{
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   915
    _cmsICCPROFILE*  Icc = (_cmsICCPROFILE*) hProfile;
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   916
    Icc -> Version = Version;
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   917
}
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   918
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   919
// Get an hexadecimal number with same digits as v
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   920
static
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   921
cmsUInt32Number BaseToBase(cmsUInt32Number in, int BaseIn, int BaseOut)
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   922
{
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   923
    char Buff[100];
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   924
    int i, len;
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   925
    cmsUInt32Number out;
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   926
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   927
    for (len=0; in > 0 && len < 100; len++) {
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   928
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   929
        Buff[len] = (char) (in % BaseIn);
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   930
        in /= BaseIn;
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   931
    }
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   932
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   933
    for (i=len-1, out=0; i >= 0; --i) {
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   934
        out = out * BaseOut + Buff[i];
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   935
    }
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   936
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   937
    return out;
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   938
}
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   939
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   940
void  CMSEXPORT cmsSetProfileVersion(cmsHPROFILE hProfile, cmsFloat64Number Version)
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   941
{
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   942
    _cmsICCPROFILE*  Icc = (_cmsICCPROFILE*) hProfile;
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   943
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   944
    // 4.2 -> 0x4200000
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   945
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   946
    Icc -> Version = BaseToBase((cmsUInt32Number) floor(Version * 100.0), 10, 16) << 16;
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   947
}
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   948
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   949
cmsFloat64Number CMSEXPORT cmsGetProfileVersion(cmsHPROFILE hProfile)
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   950
{
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   951
    _cmsICCPROFILE*  Icc = (_cmsICCPROFILE*) hProfile;
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   952
    cmsUInt32Number n = Icc -> Version >> 16;
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   953
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   954
    return BaseToBase(n, 16, 10) / 100.0;
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   955
}
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   956
// --------------------------------------------------------------------------------------------------------------
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   957
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   958
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   959
// Create profile from IOhandler
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   960
cmsHPROFILE CMSEXPORT cmsOpenProfileFromIOhandlerTHR(cmsContext ContextID, cmsIOHANDLER* io)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   961
{
6482
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   962
    _cmsICCPROFILE* NewIcc;
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   963
    cmsHPROFILE hEmpty = cmsCreateProfilePlaceholder(ContextID);
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   964
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   965
    if (hEmpty == NULL) return NULL;
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   966
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   967
    NewIcc = (_cmsICCPROFILE*) hEmpty;
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   968
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   969
    NewIcc ->IOhandler = io;
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   970
    if (!_cmsReadHeader(NewIcc)) goto Error;
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   971
    return hEmpty;
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   972
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   973
Error:
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   974
    cmsCloseProfile(hEmpty);
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   975
    return NULL;
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   976
}
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   977
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   978
// Create profile from disk file
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   979
cmsHPROFILE CMSEXPORT cmsOpenProfileFromFileTHR(cmsContext ContextID, const char *lpFileName, const char *sAccess)
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   980
{
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   981
    _cmsICCPROFILE* NewIcc;
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   982
    cmsHPROFILE hEmpty = cmsCreateProfilePlaceholder(ContextID);
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   983
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   984
    if (hEmpty == NULL) return NULL;
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   985
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   986
    NewIcc = (_cmsICCPROFILE*) hEmpty;
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   987
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   988
    NewIcc ->IOhandler = cmsOpenIOhandlerFromFile(ContextID, lpFileName, sAccess);
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   989
    if (NewIcc ->IOhandler == NULL) goto Error;
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   990
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   991
    if (*sAccess == 'W' || *sAccess == 'w') {
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   992
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   993
        NewIcc -> IsWrite = TRUE;
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   994
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   995
        return hEmpty;
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   996
    }
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   997
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   998
    if (!_cmsReadHeader(NewIcc)) goto Error;
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   999
    return hEmpty;
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
  1000
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
  1001
Error:
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
  1002
    cmsCloseProfile(hEmpty);
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
  1003
    return NULL;
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
  1004
}
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
  1005
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
  1006
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
  1007
cmsHPROFILE CMSEXPORT cmsOpenProfileFromFile(const char *ICCProfile, const char *sAccess)
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
  1008
{
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
  1009
    return cmsOpenProfileFromFileTHR(NULL, ICCProfile, sAccess);
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
  1010
}
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
  1011
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
  1012
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
  1013
cmsHPROFILE  CMSEXPORT cmsOpenProfileFromStreamTHR(cmsContext ContextID, FILE* ICCProfile, const char *sAccess)
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
  1014
{
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
  1015
    _cmsICCPROFILE* NewIcc;
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
  1016
    cmsHPROFILE hEmpty = cmsCreateProfilePlaceholder(ContextID);
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
  1017
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
  1018
    if (hEmpty == NULL) return NULL;
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
  1019
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
  1020
    NewIcc = (_cmsICCPROFILE*) hEmpty;
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
  1021
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
  1022
    NewIcc ->IOhandler = cmsOpenIOhandlerFromStream(ContextID, ICCProfile);
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
  1023
    if (NewIcc ->IOhandler == NULL) goto Error;
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
  1024
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
  1025
    if (*sAccess == 'w') {
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
  1026
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
  1027
        NewIcc -> IsWrite = TRUE;
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
  1028
        return hEmpty;
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
  1029
    }
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
  1030
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
  1031
    if (!_cmsReadHeader(NewIcc)) goto Error;
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
  1032
    return hEmpty;
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
  1033
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
  1034
Error:
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
  1035
    cmsCloseProfile(hEmpty);
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
  1036
    return NULL;
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
  1037
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
  1038
}
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
  1039
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
  1040
cmsHPROFILE  CMSEXPORT cmsOpenProfileFromStream(FILE* ICCProfile, const char *sAccess)
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
  1041
{
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
  1042
    return cmsOpenProfileFromStreamTHR(NULL, ICCProfile, sAccess);
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
  1043
}
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
  1044
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
  1045
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
  1046
// Open from memory block
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
  1047
cmsHPROFILE CMSEXPORT cmsOpenProfileFromMemTHR(cmsContext ContextID, const void* MemPtr, cmsUInt32Number dwSize)
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
  1048
{
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
  1049
    _cmsICCPROFILE* NewIcc;
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
  1050
    cmsHPROFILE hEmpty;
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
  1051
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
  1052
    hEmpty = cmsCreateProfilePlaceholder(ContextID);
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
  1053
    if (hEmpty == NULL) return NULL;
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
  1054
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
  1055
    NewIcc = (_cmsICCPROFILE*) hEmpty;
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
  1056
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
  1057
    // Ok, in this case const void* is casted to void* just because open IO handler
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
  1058
    // shares read and writting modes. Don't abuse this feature!
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
  1059
    NewIcc ->IOhandler = cmsOpenIOhandlerFromMem(ContextID, (void*) MemPtr, dwSize, "r");
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
  1060
    if (NewIcc ->IOhandler == NULL) goto Error;
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
  1061
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
  1062
    if (!_cmsReadHeader(NewIcc)) goto Error;
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
  1063
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
  1064
    return hEmpty;
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
  1065
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
  1066
Error:
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
  1067
    cmsCloseProfile(hEmpty);
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
  1068
    return NULL;
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
  1069
}
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
  1070
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
  1071
cmsHPROFILE CMSEXPORT cmsOpenProfileFromMem(const void* MemPtr, cmsUInt32Number dwSize)
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
  1072
{
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
  1073
    return cmsOpenProfileFromMemTHR(NULL, MemPtr, dwSize);
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
  1074
}
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
  1075
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
  1076
20807
841e21c03f0f 8014098: Better profile validation
jchen
parents: 14300
diff changeset
  1077
static
841e21c03f0f 8014098: Better profile validation
jchen
parents: 14300
diff changeset
  1078
cmsBool SanityCheck(_cmsICCPROFILE* profile)
841e21c03f0f 8014098: Better profile validation
jchen
parents: 14300
diff changeset
  1079
{
841e21c03f0f 8014098: Better profile validation
jchen
parents: 14300
diff changeset
  1080
    cmsIOHANDLER* io = profile->IOhandler;
841e21c03f0f 8014098: Better profile validation
jchen
parents: 14300
diff changeset
  1081
    if (!io) {
841e21c03f0f 8014098: Better profile validation
jchen
parents: 14300
diff changeset
  1082
        return FALSE;
841e21c03f0f 8014098: Better profile validation
jchen
parents: 14300
diff changeset
  1083
    }
841e21c03f0f 8014098: Better profile validation
jchen
parents: 14300
diff changeset
  1084
841e21c03f0f 8014098: Better profile validation
jchen
parents: 14300
diff changeset
  1085
    if (!io->Seek ||
841e21c03f0f 8014098: Better profile validation
jchen
parents: 14300
diff changeset
  1086
        !(io->Seek==NULLSeek || io->Seek==MemorySeek || io->Seek==FileSeek))
841e21c03f0f 8014098: Better profile validation
jchen
parents: 14300
diff changeset
  1087
    {
841e21c03f0f 8014098: Better profile validation
jchen
parents: 14300
diff changeset
  1088
        return FALSE;
841e21c03f0f 8014098: Better profile validation
jchen
parents: 14300
diff changeset
  1089
    }
841e21c03f0f 8014098: Better profile validation
jchen
parents: 14300
diff changeset
  1090
    if (!io->Read ||
841e21c03f0f 8014098: Better profile validation
jchen
parents: 14300
diff changeset
  1091
        !(io->Read==NULLRead || io->Read==MemoryRead || io->Read==FileRead))
841e21c03f0f 8014098: Better profile validation
jchen
parents: 14300
diff changeset
  1092
    {
841e21c03f0f 8014098: Better profile validation
jchen
parents: 14300
diff changeset
  1093
        return FALSE;
841e21c03f0f 8014098: Better profile validation
jchen
parents: 14300
diff changeset
  1094
    }
841e21c03f0f 8014098: Better profile validation
jchen
parents: 14300
diff changeset
  1095
841e21c03f0f 8014098: Better profile validation
jchen
parents: 14300
diff changeset
  1096
    return TRUE;
841e21c03f0f 8014098: Better profile validation
jchen
parents: 14300
diff changeset
  1097
}
6482
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
  1098
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
  1099
// Dump tag contents. If the profile is being modified, untouched tags are copied from FileOrig
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
  1100
static
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
  1101
cmsBool SaveTags(_cmsICCPROFILE* Icc, _cmsICCPROFILE* FileOrig)
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
  1102
{
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
  1103
    cmsUInt8Number* Data;
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
  1104
    cmsUInt32Number i;
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
  1105
    cmsUInt32Number Begin;
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
  1106
    cmsIOHANDLER* io = Icc ->IOhandler;
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
  1107
    cmsTagDescriptor* TagDescriptor;
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
  1108
    cmsTagTypeSignature TypeBase;
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
  1109
    cmsTagTypeHandler* TypeHandler;
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
  1110
20807
841e21c03f0f 8014098: Better profile validation
jchen
parents: 14300
diff changeset
  1111
    if (!SanityCheck(FileOrig)) return FALSE;
6482
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
  1112
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
  1113
    for (i=0; i < Icc -> TagCount; i++) {
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
  1114
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
  1115
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
  1116
        if (Icc ->TagNames[i] == 0) continue;
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
  1117
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
  1118
        // Linked tags are not written
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
  1119
        if (Icc ->TagLinked[i] != (cmsTagSignature) 0) continue;
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
  1120
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
  1121
        Icc -> TagOffsets[i] = Begin = io ->UsedSpace;
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
  1122
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
  1123
        Data = (cmsUInt8Number*)  Icc -> TagPtrs[i];
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
  1124
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
  1125
        if (!Data) {
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
  1126
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
  1127
            // Reach here if we are copying a tag from a disk-based ICC profile which has not been modified by user.
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
  1128
            // In this case a blind copy of the block data is performed
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
  1129
            if (FileOrig != NULL && Icc -> TagOffsets[i]) {
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
  1130
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
  1131
                cmsUInt32Number TagSize   = FileOrig -> TagSizes[i];
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
  1132
                cmsUInt32Number TagOffset = FileOrig -> TagOffsets[i];
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
  1133
                void* Mem;
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
  1134
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
  1135
                if (!FileOrig ->IOhandler->Seek(FileOrig ->IOhandler, TagOffset)) return FALSE;
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
  1136
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
  1137
                Mem = _cmsMalloc(Icc ->ContextID, TagSize);
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
  1138
                if (Mem == NULL) return FALSE;
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
  1139
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
  1140
                if (FileOrig ->IOhandler->Read(FileOrig->IOhandler, Mem, TagSize, 1) != 1) return FALSE;
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
  1141
                if (!io ->Write(io, TagSize, Mem)) return FALSE;
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
  1142
                _cmsFree(Icc ->ContextID, Mem);
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
  1143
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
  1144
                Icc -> TagSizes[i] = (io ->UsedSpace - Begin);
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
  1145
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
  1146
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
  1147
                // Align to 32 bit boundary.
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
  1148
                if (! _cmsWriteAlignment(io))
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
  1149
                    return FALSE;
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
  1150
            }
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
  1151
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
  1152
            continue;
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
  1153
        }
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
  1154
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
  1155
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
  1156
        // Should this tag be saved as RAW? If so, tagsizes should be specified in advance (no further cooking is done)
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
  1157
        if (Icc ->TagSaveAsRaw[i]) {
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
  1158
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
  1159
            if (io -> Write(io, Icc ->TagSizes[i], Data) != 1) return FALSE;
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
  1160
        }
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
  1161
        else {
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
  1162
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
  1163
            // Search for support on this tag
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
  1164
            TagDescriptor = _cmsGetTagDescriptor(Icc -> TagNames[i]);
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
  1165
            if (TagDescriptor == NULL) continue;                        // Unsupported, ignore it
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
  1166
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
  1167
            TypeHandler = Icc ->TagTypeHandlers[i];
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
  1168
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
  1169
            if (TypeHandler == NULL) {
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
  1170
                cmsSignalError(Icc ->ContextID, cmsERROR_INTERNAL, "(Internal) no handler for tag %x", Icc -> TagNames[i]);
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
  1171
                continue;
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
  1172
            }
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
  1173
14300
117dc9b98a7b 7053526: Upgrade JDK 8 to use Little CMS 2.4
bae
parents: 9784
diff changeset
  1174
            TypeBase = TypeHandler ->Signature;
6482
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
  1175
            if (!_cmsWriteTypeBase(io, TypeBase))
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
  1176
                return FALSE;
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
  1177
14300
117dc9b98a7b 7053526: Upgrade JDK 8 to use Little CMS 2.4
bae
parents: 9784
diff changeset
  1178
            TypeHandler ->ContextID  = Icc ->ContextID;
117dc9b98a7b 7053526: Upgrade JDK 8 to use Little CMS 2.4
bae
parents: 9784
diff changeset
  1179
            TypeHandler ->ICCVersion = Icc ->Version;
6482
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
  1180
            if (!TypeHandler ->WritePtr(TypeHandler, io, Data, TagDescriptor ->ElemCount)) {
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
  1181
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
  1182
                char String[5];
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1183
6482
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
  1184
                _cmsTagSignature2String(String, (cmsTagSignature) TypeBase);
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
  1185
                cmsSignalError(Icc ->ContextID, cmsERROR_WRITE, "Couldn't write type '%s'", String);
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
  1186
                return FALSE;
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
  1187
            }
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
  1188
        }
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
  1189
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
  1190
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
  1191
        Icc -> TagSizes[i] = (io ->UsedSpace - Begin);
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
  1192
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
  1193
        // Align to 32 bit boundary.
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
  1194
        if (! _cmsWriteAlignment(io))
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
  1195
            return FALSE;
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
  1196
    }
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
  1197
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
  1198
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
  1199
    return TRUE;
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
  1200
}
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
  1201
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
  1202
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
  1203
// Fill the offset and size fields for all linked tags
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
  1204
static
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
  1205
cmsBool SetLinks( _cmsICCPROFILE* Icc)
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
  1206
{
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
  1207
    cmsUInt32Number i;
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
  1208
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
  1209
    for (i=0; i < Icc -> TagCount; i++) {
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
  1210
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
  1211
        cmsTagSignature lnk = Icc ->TagLinked[i];
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
  1212
        if (lnk != (cmsTagSignature) 0) {
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
  1213
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
  1214
            int j = _cmsSearchTag(Icc, lnk, FALSE);
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
  1215
            if (j >= 0) {
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
  1216
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
  1217
                Icc ->TagOffsets[i] = Icc ->TagOffsets[j];
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
  1218
                Icc ->TagSizes[i]   = Icc ->TagSizes[j];
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
  1219
            }
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
  1220
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
  1221
        }
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
  1222
    }
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
  1223
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
  1224
    return TRUE;
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
  1225
}
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
  1226
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
  1227
// Low-level save to IOHANDLER. It returns the number of bytes used to
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
  1228
// store the profile, or zero on error. io may be NULL and in this case
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
  1229
// no data is written--only sizes are calculated
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
  1230
cmsUInt32Number CMSEXPORT cmsSaveProfileToIOhandler(cmsHPROFILE hProfile, cmsIOHANDLER* io)
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
  1231
{
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
  1232
    _cmsICCPROFILE* Icc = (_cmsICCPROFILE*) hProfile;
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
  1233
    _cmsICCPROFILE Keep;
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
  1234
    cmsIOHANDLER* PrevIO;
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
  1235
    cmsUInt32Number UsedSpace;
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
  1236
    cmsContext ContextID;
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
  1237
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
  1238
    memmove(&Keep, Icc, sizeof(_cmsICCPROFILE));
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
  1239
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
  1240
    ContextID = cmsGetProfileContextID(hProfile);
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
  1241
    PrevIO = Icc ->IOhandler = cmsOpenIOhandlerFromNULL(ContextID);
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
  1242
    if (PrevIO == NULL) return 0;
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
  1243
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
  1244
    // Pass #1 does compute offsets
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
  1245
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
  1246
    if (!_cmsWriteHeader(Icc, 0)) return 0;
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
  1247
    if (!SaveTags(Icc, &Keep)) return 0;
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
  1248
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
  1249
    UsedSpace = PrevIO ->UsedSpace;
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
  1250
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
  1251
    // Pass #2 does save to iohandler
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
  1252
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
  1253
    if (io != NULL) {
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
  1254
        Icc ->IOhandler = io;
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
  1255
        if (!SetLinks(Icc)) goto CleanUp;
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
  1256
        if (!_cmsWriteHeader(Icc, UsedSpace)) goto CleanUp;
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
  1257
        if (!SaveTags(Icc, &Keep)) goto CleanUp;
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
  1258
    }
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
  1259
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
  1260
    memmove(Icc, &Keep, sizeof(_cmsICCPROFILE));
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
  1261
    if (!cmsCloseIOhandler(PrevIO)) return 0;
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
  1262
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
  1263
    return UsedSpace;
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
  1264
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
  1265
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
  1266
CleanUp:
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
  1267
    cmsCloseIOhandler(PrevIO);
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
  1268
    memmove(Icc, &Keep, sizeof(_cmsICCPROFILE));
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
  1269
    return 0;
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
  1270
}
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
  1271
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
  1272
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
  1273
// Low-level save to disk.
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
  1274
cmsBool  CMSEXPORT cmsSaveProfileToFile(cmsHPROFILE hProfile, const char* FileName)
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
  1275
{
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
  1276
    cmsContext ContextID = cmsGetProfileContextID(hProfile);
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
  1277
    cmsIOHANDLER* io = cmsOpenIOhandlerFromFile(ContextID, FileName, "w");
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
  1278
    cmsBool rc;
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
  1279
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
  1280
    if (io == NULL) return FALSE;
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
  1281
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
  1282
    rc = (cmsSaveProfileToIOhandler(hProfile, io) != 0);
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
  1283
    rc &= cmsCloseIOhandler(io);
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
  1284
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
  1285
    if (rc == FALSE) {          // remove() is C99 per 7.19.4.1
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
  1286
            remove(FileName);   // We have to IGNORE return value in this case
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
  1287
    }
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
  1288
    return rc;
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
  1289
}
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
  1290
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
  1291
// Same as anterior, but for streams
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
  1292
cmsBool CMSEXPORT cmsSaveProfileToStream(cmsHPROFILE hProfile, FILE* Stream)
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
  1293
{
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
  1294
    cmsBool rc;
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
  1295
    cmsContext ContextID = cmsGetProfileContextID(hProfile);
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
  1296
    cmsIOHANDLER* io = cmsOpenIOhandlerFromStream(ContextID, Stream);
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
  1297
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
  1298
    if (io == NULL) return FALSE;
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
  1299
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
  1300
    rc = (cmsSaveProfileToIOhandler(hProfile, io) != 0);
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
  1301
    rc &= cmsCloseIOhandler(io);
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
  1302
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
  1303
    return rc;
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
  1304
}
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
  1305
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
  1306
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
  1307
// Same as anterior, but for memory blocks. In this case, a NULL as MemPtr means calculate needed space only
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
  1308
cmsBool CMSEXPORT cmsSaveProfileToMem(cmsHPROFILE hProfile, void *MemPtr, cmsUInt32Number* BytesNeeded)
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
  1309
{
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
  1310
    cmsBool rc;
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
  1311
    cmsIOHANDLER* io;
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
  1312
    cmsContext ContextID = cmsGetProfileContextID(hProfile);
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
  1313
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
  1314
    // Should we just calculate the needed space?
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
  1315
    if (MemPtr == NULL) {
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
  1316
20807
841e21c03f0f 8014098: Better profile validation
jchen
parents: 14300
diff changeset
  1317
        *BytesNeeded = cmsSaveProfileToIOhandler(hProfile, NULL);
841e21c03f0f 8014098: Better profile validation
jchen
parents: 14300
diff changeset
  1318
        return (*BytesNeeded == 0 ? FALSE : TRUE);
6482
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
  1319
    }
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
  1320
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
  1321
    // That is a real write operation
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
  1322
    io =  cmsOpenIOhandlerFromMem(ContextID, MemPtr, *BytesNeeded, "w");
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
  1323
    if (io == NULL) return FALSE;
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
  1324
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
  1325
    rc = (cmsSaveProfileToIOhandler(hProfile, io) != 0);
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
  1326
    rc &= cmsCloseIOhandler(io);
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
  1327
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
  1328
    return rc;
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
  1329
}
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
  1330
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
  1331
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
  1332
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
  1333
// Closes a profile freeing any involved resources
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
  1334
cmsBool  CMSEXPORT cmsCloseProfile(cmsHPROFILE hProfile)
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
  1335
{
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
  1336
    _cmsICCPROFILE* Icc = (_cmsICCPROFILE*) hProfile;
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
  1337
    cmsBool  rc = TRUE;
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
  1338
    cmsUInt32Number i;
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
  1339
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
  1340
    if (!Icc) return FALSE;
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
  1341
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
  1342
    // Was open in write mode?
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
  1343
    if (Icc ->IsWrite) {
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
  1344
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
  1345
        Icc ->IsWrite = FALSE;      // Assure no further writting
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
  1346
        rc &= cmsSaveProfileToFile(hProfile, Icc ->IOhandler->PhysicalFile);
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
  1347
    }
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
  1348
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
  1349
    for (i=0; i < Icc -> TagCount; i++) {
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
  1350
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
  1351
        if (Icc -> TagPtrs[i]) {
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
  1352
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
  1353
            cmsTagTypeHandler* TypeHandler = Icc ->TagTypeHandlers[i];
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
  1354
14300
117dc9b98a7b 7053526: Upgrade JDK 8 to use Little CMS 2.4
bae
parents: 9784
diff changeset
  1355
            if (TypeHandler != NULL) {
117dc9b98a7b 7053526: Upgrade JDK 8 to use Little CMS 2.4
bae
parents: 9784
diff changeset
  1356
117dc9b98a7b 7053526: Upgrade JDK 8 to use Little CMS 2.4
bae
parents: 9784
diff changeset
  1357
                TypeHandler ->ContextID = Icc ->ContextID;              // As an additional parameters
117dc9b98a7b 7053526: Upgrade JDK 8 to use Little CMS 2.4
bae
parents: 9784
diff changeset
  1358
                TypeHandler ->ICCVersion = Icc ->Version;
6482
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
  1359
                TypeHandler ->FreePtr(TypeHandler, Icc -> TagPtrs[i]);
14300
117dc9b98a7b 7053526: Upgrade JDK 8 to use Little CMS 2.4
bae
parents: 9784
diff changeset
  1360
            }
6482
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
  1361
            else
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
  1362
                _cmsFree(Icc ->ContextID, Icc ->TagPtrs[i]);
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
  1363
        }
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
  1364
    }
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
  1365
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
  1366
    if (Icc ->IOhandler != NULL) {
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
  1367
        rc &= cmsCloseIOhandler(Icc->IOhandler);
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
  1368
    }
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
  1369
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
  1370
    _cmsFree(Icc ->ContextID, Icc);   // Free placeholder memory
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
  1371
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
  1372
    return rc;
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
  1373
}
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
  1374
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
  1375
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
  1376
// -------------------------------------------------------------------------------------------------------------------
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
  1377
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
  1378
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
  1379
// Returns TRUE if a given tag is supported by a plug-in
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
  1380
static
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
  1381
cmsBool IsTypeSupported(cmsTagDescriptor* TagDescriptor, cmsTagTypeSignature Type)
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
  1382
{
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
  1383
    cmsUInt32Number i, nMaxTypes;
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
  1384
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
  1385
    nMaxTypes = TagDescriptor->nSupportedTypes;
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
  1386
    if (nMaxTypes >= MAX_TYPES_IN_LCMS_PLUGIN)
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
  1387
        nMaxTypes = MAX_TYPES_IN_LCMS_PLUGIN;
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
  1388
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
  1389
    for (i=0; i < nMaxTypes; i++) {
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
  1390
        if (Type == TagDescriptor ->SupportedTypes[i]) return TRUE;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1391
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1392
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1393
    return FALSE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1394
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1395
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1396
6482
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
  1397
// That's the main read function
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
  1398
void* CMSEXPORT cmsReadTag(cmsHPROFILE hProfile, cmsTagSignature sig)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1399
{
6482
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
  1400
    _cmsICCPROFILE* Icc = (_cmsICCPROFILE*) hProfile;
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
  1401
    cmsIOHANDLER* io = Icc ->IOhandler;
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
  1402
    cmsTagTypeHandler* TypeHandler;
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
  1403
    cmsTagDescriptor*  TagDescriptor;
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
  1404
    cmsTagTypeSignature BaseType;
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
  1405
    cmsUInt32Number Offset, TagSize;
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
  1406
    cmsUInt32Number ElemCount;
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
  1407
    int n;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1408
6482
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
  1409
    n = _cmsSearchTag(Icc, sig, TRUE);
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
  1410
    if (n < 0) return NULL;                 // Not found, return NULL
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1411
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1412
6482
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
  1413
    // If the element is already in memory, return the pointer
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
  1414
    if (Icc -> TagPtrs[n]) {
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
  1415
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
  1416
        if (Icc ->TagSaveAsRaw[n]) return NULL;  // We don't support read raw tags as cooked
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
  1417
        return Icc -> TagPtrs[n];
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
  1418
    }
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
  1419
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
  1420
    // We need to read it. Get the offset and size to the file
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
  1421
    Offset    = Icc -> TagOffsets[n];
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
  1422
    TagSize   = Icc -> TagSizes[n];
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1423
6482
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
  1424
    // Seek to its location
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
  1425
    if (!io -> Seek(io, Offset))
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
  1426
            return NULL;
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
  1427
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
  1428
    // Search for support on this tag
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
  1429
    TagDescriptor = _cmsGetTagDescriptor(sig);
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
  1430
    if (TagDescriptor == NULL) return NULL;     // Unsupported.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1431
6482
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
  1432
    // if supported, get type and check if in list
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
  1433
    BaseType = _cmsReadTypeBase(io);
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
  1434
    if (BaseType == 0) return NULL;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1435
6482
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
  1436
    if (!IsTypeSupported(TagDescriptor, BaseType)) return NULL;
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
  1437
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
  1438
    TagSize  -= 8;                      // Alredy read by the type base logic
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1439
6482
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
  1440
    // Get type handler
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
  1441
    TypeHandler = _cmsGetTagTypeHandler(BaseType);
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
  1442
    if (TypeHandler == NULL) return NULL;
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
  1443
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1444
6482
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
  1445
    // Read the tag
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
  1446
    Icc -> TagTypeHandlers[n] = TypeHandler;
14300
117dc9b98a7b 7053526: Upgrade JDK 8 to use Little CMS 2.4
bae
parents: 9784
diff changeset
  1447
117dc9b98a7b 7053526: Upgrade JDK 8 to use Little CMS 2.4
bae
parents: 9784
diff changeset
  1448
    TypeHandler ->ContextID = Icc ->ContextID;
117dc9b98a7b 7053526: Upgrade JDK 8 to use Little CMS 2.4
bae
parents: 9784
diff changeset
  1449
    TypeHandler ->ICCVersion = Icc ->Version;
6482
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
  1450
    Icc -> TagPtrs[n] = TypeHandler ->ReadPtr(TypeHandler, io, &ElemCount, TagSize);
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
  1451
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
  1452
    // The tag type is supported, but something wrong happend and we cannot read the tag.
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
  1453
    // let know the user about this (although it is just a warning)
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
  1454
    if (Icc -> TagPtrs[n] == NULL) {
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
  1455
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
  1456
        char String[5];
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1457
6482
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
  1458
        _cmsTagSignature2String(String, sig);
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
  1459
        cmsSignalError(Icc ->ContextID, cmsERROR_CORRUPTION_DETECTED, "Corrupted tag '%s'", String);
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
  1460
        return NULL;
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
  1461
    }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1462
6482
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
  1463
    // This is a weird error that may be a symptom of something more serious, the number of
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
  1464
    // stored item is actually less than the number of required elements.
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
  1465
    if (ElemCount < TagDescriptor ->ElemCount) {
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
  1466
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
  1467
        char String[5];
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
  1468
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
  1469
        _cmsTagSignature2String(String, sig);
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
  1470
        cmsSignalError(Icc ->ContextID, cmsERROR_CORRUPTION_DETECTED, "'%s' Inconsistent number of items: expected %d, got %d",
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
  1471
                                                             String, TagDescriptor ->ElemCount, ElemCount);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1472
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1473
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1474
6482
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
  1475
    // Return the data
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
  1476
    return Icc -> TagPtrs[n];
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1477
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1478
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1479
6482
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
  1480
// Get true type of data
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
  1481
cmsTagTypeSignature _cmsGetTagTrueType(cmsHPROFILE hProfile, cmsTagSignature sig)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1482
{
6482
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
  1483
    _cmsICCPROFILE* Icc = (_cmsICCPROFILE*) hProfile;
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
  1484
    cmsTagTypeHandler* TypeHandler;
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
  1485
    int n;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1486
6482
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
  1487
    // Search for given tag in ICC profile directory
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
  1488
    n = _cmsSearchTag(Icc, sig, TRUE);
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
  1489
    if (n < 0) return (cmsTagTypeSignature) 0;                // Not found, return NULL
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1490
6482
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
  1491
    // Get the handler. The true type is there
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
  1492
    TypeHandler =  Icc -> TagTypeHandlers[n];
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
  1493
    return TypeHandler ->Signature;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1494
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1495
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1496
6482
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
  1497
// Write a single tag. This just keeps track of the tak into a list of "to be written". If the tag is already
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
  1498
// in that list, the previous version is deleted.
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
  1499
cmsBool CMSEXPORT cmsWriteTag(cmsHPROFILE hProfile, cmsTagSignature sig, const void* data)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1500
{
6482
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
  1501
    _cmsICCPROFILE* Icc = (_cmsICCPROFILE*) hProfile;
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
  1502
    cmsTagTypeHandler* TypeHandler = NULL;
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
  1503
    cmsTagDescriptor* TagDescriptor = NULL;
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
  1504
    cmsTagTypeSignature Type;
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
  1505
    int i;
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
  1506
    cmsFloat64Number Version;
14300
117dc9b98a7b 7053526: Upgrade JDK 8 to use Little CMS 2.4
bae
parents: 9784
diff changeset
  1507
    char TypeString[5], SigString[5];
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1508
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1509
6482
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
  1510
    if (data == NULL) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1511
14300
117dc9b98a7b 7053526: Upgrade JDK 8 to use Little CMS 2.4
bae
parents: 9784
diff changeset
  1512
         i = _cmsSearchTag(Icc, sig, FALSE);
117dc9b98a7b 7053526: Upgrade JDK 8 to use Little CMS 2.4
bae
parents: 9784
diff changeset
  1513
         if (i >= 0)
117dc9b98a7b 7053526: Upgrade JDK 8 to use Little CMS 2.4
bae
parents: 9784
diff changeset
  1514
             Icc ->TagNames[i] = (cmsTagSignature) 0;
117dc9b98a7b 7053526: Upgrade JDK 8 to use Little CMS 2.4
bae
parents: 9784
diff changeset
  1515
         // Unsupported by now, reserved for future ampliations (delete)
6482
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
  1516
         return FALSE;
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
  1517
    }
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
  1518
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
  1519
    i = _cmsSearchTag(Icc, sig, FALSE);
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
  1520
    if (i >=0) {
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
  1521
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
  1522
        if (Icc -> TagPtrs[i] != NULL) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1523
6482
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
  1524
            // Already exists. Free previous version
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
  1525
            if (Icc ->TagSaveAsRaw[i]) {
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
  1526
                _cmsFree(Icc ->ContextID, Icc ->TagPtrs[i]);
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
  1527
            }
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
  1528
            else {
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
  1529
                TypeHandler = Icc ->TagTypeHandlers[i];
14300
117dc9b98a7b 7053526: Upgrade JDK 8 to use Little CMS 2.4
bae
parents: 9784
diff changeset
  1530
117dc9b98a7b 7053526: Upgrade JDK 8 to use Little CMS 2.4
bae
parents: 9784
diff changeset
  1531
                if (TypeHandler != NULL) {
117dc9b98a7b 7053526: Upgrade JDK 8 to use Little CMS 2.4
bae
parents: 9784
diff changeset
  1532
117dc9b98a7b 7053526: Upgrade JDK 8 to use Little CMS 2.4
bae
parents: 9784
diff changeset
  1533
                    TypeHandler ->ContextID = Icc ->ContextID;              // As an additional parameter
117dc9b98a7b 7053526: Upgrade JDK 8 to use Little CMS 2.4
bae
parents: 9784
diff changeset
  1534
                    TypeHandler ->ICCVersion = Icc ->Version;
117dc9b98a7b 7053526: Upgrade JDK 8 to use Little CMS 2.4
bae
parents: 9784
diff changeset
  1535
                    TypeHandler->FreePtr(TypeHandler, Icc -> TagPtrs[i]);
117dc9b98a7b 7053526: Upgrade JDK 8 to use Little CMS 2.4
bae
parents: 9784
diff changeset
  1536
                }
6482
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
  1537
            }
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
  1538
        }
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
  1539
    }
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
  1540
    else  {
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
  1541
        // New one
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
  1542
        i = Icc -> TagCount;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1543
6482
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
  1544
        if (i >= MAX_TABLE_TAG) {
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
  1545
            cmsSignalError(Icc ->ContextID, cmsERROR_RANGE, "Too many tags (%d)", MAX_TABLE_TAG);
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
  1546
            return FALSE;
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
  1547
        }
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
  1548
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
  1549
        Icc -> TagCount++;
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
  1550
    }
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
  1551
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
  1552
    // This is not raw
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
  1553
    Icc ->TagSaveAsRaw[i] = FALSE;
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
  1554
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
  1555
    // This is not a link
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
  1556
    Icc ->TagLinked[i] = (cmsTagSignature) 0;
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
  1557
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
  1558
    // Get information about the TAG.
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
  1559
    TagDescriptor = _cmsGetTagDescriptor(sig);
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
  1560
    if (TagDescriptor == NULL){
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
  1561
         cmsSignalError(Icc ->ContextID, cmsERROR_UNKNOWN_EXTENSION, "Unsupported tag '%x'", sig);
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
  1562
        return FALSE;
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
  1563
    }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1564
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1565
6482
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
  1566
    // Now we need to know which type to use. It depends on the version.
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
  1567
    Version = cmsGetProfileVersion(hProfile);
14300
117dc9b98a7b 7053526: Upgrade JDK 8 to use Little CMS 2.4
bae
parents: 9784
diff changeset
  1568
6482
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
  1569
    if (TagDescriptor ->DecideType != NULL) {
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
  1570
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
  1571
        // Let the tag descriptor to decide the type base on depending on
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
  1572
        // the data. This is useful for example on parametric curves, where
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
  1573
        // curves specified by a table cannot be saved as parametric and needs
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
  1574
        // to be revented to single v2-curves, even on v4 profiles.
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
  1575
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
  1576
        Type = TagDescriptor ->DecideType(Version, data);
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
  1577
    }
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
  1578
    else {
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
  1579
14300
117dc9b98a7b 7053526: Upgrade JDK 8 to use Little CMS 2.4
bae
parents: 9784
diff changeset
  1580
6482
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
  1581
        Type = TagDescriptor ->SupportedTypes[0];
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
  1582
    }
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
  1583
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
  1584
    // Does the tag support this type?
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
  1585
    if (!IsTypeSupported(TagDescriptor, Type)) {
14300
117dc9b98a7b 7053526: Upgrade JDK 8 to use Little CMS 2.4
bae
parents: 9784
diff changeset
  1586
117dc9b98a7b 7053526: Upgrade JDK 8 to use Little CMS 2.4
bae
parents: 9784
diff changeset
  1587
        _cmsTagSignature2String(TypeString, (cmsTagSignature) Type);
117dc9b98a7b 7053526: Upgrade JDK 8 to use Little CMS 2.4
bae
parents: 9784
diff changeset
  1588
        _cmsTagSignature2String(SigString,  sig);
117dc9b98a7b 7053526: Upgrade JDK 8 to use Little CMS 2.4
bae
parents: 9784
diff changeset
  1589
117dc9b98a7b 7053526: Upgrade JDK 8 to use Little CMS 2.4
bae
parents: 9784
diff changeset
  1590
        cmsSignalError(Icc ->ContextID, cmsERROR_UNKNOWN_EXTENSION, "Unsupported type '%s' for tag '%s'", TypeString, SigString);
6482
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
  1591
        return FALSE;
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
  1592
    }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1593
6482
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
  1594
    // Does we have a handler for this type?
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
  1595
    TypeHandler =  _cmsGetTagTypeHandler(Type);
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
  1596
    if (TypeHandler == NULL) {
14300
117dc9b98a7b 7053526: Upgrade JDK 8 to use Little CMS 2.4
bae
parents: 9784
diff changeset
  1597
117dc9b98a7b 7053526: Upgrade JDK 8 to use Little CMS 2.4
bae
parents: 9784
diff changeset
  1598
        _cmsTagSignature2String(TypeString, (cmsTagSignature) Type);
117dc9b98a7b 7053526: Upgrade JDK 8 to use Little CMS 2.4
bae
parents: 9784
diff changeset
  1599
        _cmsTagSignature2String(SigString,  sig);
117dc9b98a7b 7053526: Upgrade JDK 8 to use Little CMS 2.4
bae
parents: 9784
diff changeset
  1600
117dc9b98a7b 7053526: Upgrade JDK 8 to use Little CMS 2.4
bae
parents: 9784
diff changeset
  1601
        cmsSignalError(Icc ->ContextID, cmsERROR_UNKNOWN_EXTENSION, "Unsupported type '%s' for tag '%s'", TypeString, SigString);
6482
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
  1602
        return FALSE;           // Should never happen
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
  1603
    }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1604
14300
117dc9b98a7b 7053526: Upgrade JDK 8 to use Little CMS 2.4
bae
parents: 9784
diff changeset
  1605
6482
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
  1606
    // Fill fields on icc structure
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
  1607
    Icc ->TagTypeHandlers[i]  = TypeHandler;
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
  1608
    Icc ->TagNames[i]         = sig;
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
  1609
    Icc ->TagSizes[i]         = 0;
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
  1610
    Icc ->TagOffsets[i]       = 0;
14300
117dc9b98a7b 7053526: Upgrade JDK 8 to use Little CMS 2.4
bae
parents: 9784
diff changeset
  1611
117dc9b98a7b 7053526: Upgrade JDK 8 to use Little CMS 2.4
bae
parents: 9784
diff changeset
  1612
    TypeHandler ->ContextID  = Icc ->ContextID;
117dc9b98a7b 7053526: Upgrade JDK 8 to use Little CMS 2.4
bae
parents: 9784
diff changeset
  1613
    TypeHandler ->ICCVersion = Icc ->Version;
117dc9b98a7b 7053526: Upgrade JDK 8 to use Little CMS 2.4
bae
parents: 9784
diff changeset
  1614
    Icc ->TagPtrs[i]         = TypeHandler ->DupPtr(TypeHandler, data, TagDescriptor ->ElemCount);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1615
6482
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
  1616
    if (Icc ->TagPtrs[i] == NULL)  {
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
  1617
14300
117dc9b98a7b 7053526: Upgrade JDK 8 to use Little CMS 2.4
bae
parents: 9784
diff changeset
  1618
        _cmsTagSignature2String(TypeString, (cmsTagSignature) Type);
117dc9b98a7b 7053526: Upgrade JDK 8 to use Little CMS 2.4
bae
parents: 9784
diff changeset
  1619
        _cmsTagSignature2String(SigString,  sig);
117dc9b98a7b 7053526: Upgrade JDK 8 to use Little CMS 2.4
bae
parents: 9784
diff changeset
  1620
        cmsSignalError(Icc ->ContextID, cmsERROR_CORRUPTION_DETECTED, "Malformed struct in type '%s' for tag '%s'", TypeString, SigString);
6482
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
  1621
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
  1622
        return FALSE;
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
  1623
    }
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
  1624
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1625
    return TRUE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1626
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1627
6482
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
  1628
// Read and write raw data. The only way those function would work and keep consistence with normal read and write
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
  1629
// is to do an additional step of serialization. That means, readRaw would issue a normal read and then convert the obtained
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
  1630
// data to raw bytes by using the "write" serialization logic. And vice-versa. I know this may end in situations where
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
  1631
// raw data written does not exactly correspond with the raw data proposed to cmsWriteRaw data, but this approach allows
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
  1632
// to write a tag as raw data and the read it as handled.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1633
6482
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
  1634
cmsInt32Number CMSEXPORT cmsReadRawTag(cmsHPROFILE hProfile, cmsTagSignature sig, void* data, cmsUInt32Number BufferSize)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1635
{
6482
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
  1636
    _cmsICCPROFILE* Icc = (_cmsICCPROFILE*) hProfile;
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
  1637
    void *Object;
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
  1638
    int i;
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
  1639
    cmsIOHANDLER* MemIO;
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
  1640
    cmsTagTypeHandler* TypeHandler = NULL;
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
  1641
    cmsTagDescriptor* TagDescriptor = NULL;
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
  1642
    cmsUInt32Number rc;
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
  1643
    cmsUInt32Number Offset, TagSize;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1644
6482
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
  1645
    // Search for given tag in ICC profile directory
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
  1646
    i = _cmsSearchTag(Icc, sig, TRUE);
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
  1647
    if (i < 0) return 0;                 // Not found, return 0
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1648
6482
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
  1649
    // It is already read?
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
  1650
    if (Icc -> TagPtrs[i] == NULL) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1651
6482
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
  1652
        // No yet, get original position
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
  1653
        Offset   = Icc ->TagOffsets[i];
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
  1654
        TagSize  = Icc ->TagSizes[i];
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1655
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1656
6482
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
  1657
        // read the data directly, don't keep copy
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
  1658
        if (data != NULL) {
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
  1659
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
  1660
            if (BufferSize < TagSize)
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
  1661
                 TagSize = BufferSize;
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
  1662
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
  1663
            if (!Icc ->IOhandler ->Seek(Icc ->IOhandler, Offset)) return 0;
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
  1664
            if (!Icc ->IOhandler ->Read(Icc ->IOhandler, data, 1, TagSize)) return 0;
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
  1665
        }
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
  1666
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
  1667
        return Icc ->TagSizes[i];
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
  1668
    }
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
  1669
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
  1670
    // The data has been already read, or written. But wait!, maybe the user choosed to save as
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
  1671
    // raw data. In this case, return the raw data directly
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
  1672
    if (Icc ->TagSaveAsRaw[i]) {
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
  1673
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
  1674
        if (data != NULL)  {
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
  1675
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
  1676
            TagSize  = Icc ->TagSizes[i];
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
  1677
            if (BufferSize < TagSize)
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
  1678
                       TagSize = BufferSize;
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
  1679
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
  1680
            memmove(data, Icc ->TagPtrs[i], TagSize);
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
  1681
        }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1682
6482
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
  1683
        return Icc ->TagSizes[i];
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
  1684
    }
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
  1685
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
  1686
    // Already readed, or previously set by cmsWriteTag(). We need to serialize that
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
  1687
    // data to raw in order to maintain consistency.
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
  1688
    Object = cmsReadTag(hProfile, sig);
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
  1689
    if (Object == NULL) return 0;
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
  1690
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
  1691
    // Now we need to serialize to a memory block: just use a memory iohandler
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1692
6482
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
  1693
    if (data == NULL) {
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
  1694
        MemIO = cmsOpenIOhandlerFromNULL(cmsGetProfileContextID(hProfile));
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
  1695
    } else{
14300
117dc9b98a7b 7053526: Upgrade JDK 8 to use Little CMS 2.4
bae
parents: 9784
diff changeset
  1696
      MemIO = cmsOpenIOhandlerFromMem(cmsGetProfileContextID(hProfile), data, BufferSize, "w");
6482
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
  1697
    }
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
  1698
    if (MemIO == NULL) return 0;
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
  1699
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
  1700
    // Obtain type handling for the tag
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
  1701
    TypeHandler = Icc ->TagTypeHandlers[i];
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
  1702
    TagDescriptor = _cmsGetTagDescriptor(sig);
14300
117dc9b98a7b 7053526: Upgrade JDK 8 to use Little CMS 2.4
bae
parents: 9784
diff changeset
  1703
    if (TagDescriptor == NULL) {
117dc9b98a7b 7053526: Upgrade JDK 8 to use Little CMS 2.4
bae
parents: 9784
diff changeset
  1704
         cmsCloseIOhandler(MemIO);
117dc9b98a7b 7053526: Upgrade JDK 8 to use Little CMS 2.4
bae
parents: 9784
diff changeset
  1705
         return 0;
117dc9b98a7b 7053526: Upgrade JDK 8 to use Little CMS 2.4
bae
parents: 9784
diff changeset
  1706
    }
6482
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
  1707
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
  1708
    // Serialize
14300
117dc9b98a7b 7053526: Upgrade JDK 8 to use Little CMS 2.4
bae
parents: 9784
diff changeset
  1709
    TypeHandler ->ContextID  = Icc ->ContextID;
117dc9b98a7b 7053526: Upgrade JDK 8 to use Little CMS 2.4
bae
parents: 9784
diff changeset
  1710
    TypeHandler ->ICCVersion = Icc ->Version;
117dc9b98a7b 7053526: Upgrade JDK 8 to use Little CMS 2.4
bae
parents: 9784
diff changeset
  1711
9784
3a0ebf0b855d 7042594: 3 testis api/java_awt/Color/ICC_ProfileRGB/index.html fail against RI b138 OEL6x64.
bae
parents: 6482
diff changeset
  1712
    if (!_cmsWriteTypeBase(MemIO, TypeHandler ->Signature)) {
3a0ebf0b855d 7042594: 3 testis api/java_awt/Color/ICC_ProfileRGB/index.html fail against RI b138 OEL6x64.
bae
parents: 6482
diff changeset
  1713
        cmsCloseIOhandler(MemIO);
3a0ebf0b855d 7042594: 3 testis api/java_awt/Color/ICC_ProfileRGB/index.html fail against RI b138 OEL6x64.
bae
parents: 6482
diff changeset
  1714
        return 0;
3a0ebf0b855d 7042594: 3 testis api/java_awt/Color/ICC_ProfileRGB/index.html fail against RI b138 OEL6x64.
bae
parents: 6482
diff changeset
  1715
    }
3a0ebf0b855d 7042594: 3 testis api/java_awt/Color/ICC_ProfileRGB/index.html fail against RI b138 OEL6x64.
bae
parents: 6482
diff changeset
  1716
14300
117dc9b98a7b 7053526: Upgrade JDK 8 to use Little CMS 2.4
bae
parents: 9784
diff changeset
  1717
    if (!TypeHandler ->WritePtr(TypeHandler, MemIO, Object, TagDescriptor ->ElemCount)) {
117dc9b98a7b 7053526: Upgrade JDK 8 to use Little CMS 2.4
bae
parents: 9784
diff changeset
  1718
        cmsCloseIOhandler(MemIO);
117dc9b98a7b 7053526: Upgrade JDK 8 to use Little CMS 2.4
bae
parents: 9784
diff changeset
  1719
        return 0;
117dc9b98a7b 7053526: Upgrade JDK 8 to use Little CMS 2.4
bae
parents: 9784
diff changeset
  1720
    }
6482
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
  1721
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
  1722
    // Get Size and close
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
  1723
    rc = MemIO ->Tell(MemIO);
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
  1724
    cmsCloseIOhandler(MemIO);      // Ignore return code this time
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
  1725
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
  1726
    return rc;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1727
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1728
6482
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
  1729
// Similar to the anterior. This function allows to write directly to the ICC profile any data, without
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
  1730
// checking anything. As a rule, mixing Raw with cooked doesn't work, so writting a tag as raw and then reading
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
  1731
// it as cooked without serializing does result into an error. If that is wha you want, you will need to dump
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
  1732
// the profile to memry or disk and then reopen it.
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
  1733
cmsBool CMSEXPORT cmsWriteRawTag(cmsHPROFILE hProfile, cmsTagSignature sig, const void* data, cmsUInt32Number Size)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1734
{
6482
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
  1735
    _cmsICCPROFILE* Icc = (_cmsICCPROFILE*) hProfile;
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
  1736
    int i;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1737
6482
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
  1738
    if (!_cmsNewTag(Icc, sig, &i)) return FALSE;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1739
6482
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
  1740
    // Mark the tag as being written as RAW
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
  1741
    Icc ->TagSaveAsRaw[i] = TRUE;
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
  1742
    Icc ->TagNames[i]     = sig;
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
  1743
    Icc ->TagLinked[i]    = (cmsTagSignature) 0;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1744
6482
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
  1745
    // Keep a copy of the block
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
  1746
    Icc ->TagPtrs[i]  = _cmsDupMem(Icc ->ContextID, data, Size);
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
  1747
    Icc ->TagSizes[i] = Size;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1748
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1749
    return TRUE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1750
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1751
6482
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
  1752
// Using this function you can collapse several tag entries to the same block in the profile
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
  1753
cmsBool CMSEXPORT cmsLinkTag(cmsHPROFILE hProfile, cmsTagSignature sig, cmsTagSignature dest)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1754
{
6482
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
  1755
     _cmsICCPROFILE* Icc = (_cmsICCPROFILE*) hProfile;
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
  1756
    int i;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1757
6482
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
  1758
    if (!_cmsNewTag(Icc, sig, &i)) return FALSE;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1759
6482
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
  1760
    // Keep necessary information
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
  1761
    Icc ->TagSaveAsRaw[i] = FALSE;
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
  1762
    Icc ->TagNames[i]     = sig;
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
  1763
    Icc ->TagLinked[i]    = dest;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1764
6482
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
  1765
    Icc ->TagPtrs[i]    = NULL;
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
  1766
    Icc ->TagSizes[i]   = 0;
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
  1767
    Icc ->TagOffsets[i] = 0;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1768
2394
404cbe399601 6821031: Upgrade OpenJDK's LittleCMS version to 1.18
prr
parents: 2392
diff changeset
  1769
    return TRUE;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1770
}
14300
117dc9b98a7b 7053526: Upgrade JDK 8 to use Little CMS 2.4
bae
parents: 9784
diff changeset
  1771
117dc9b98a7b 7053526: Upgrade JDK 8 to use Little CMS 2.4
bae
parents: 9784
diff changeset
  1772
117dc9b98a7b 7053526: Upgrade JDK 8 to use Little CMS 2.4
bae
parents: 9784
diff changeset
  1773
// Returns the tag linked to sig, in the case two tags are sharing same resource
117dc9b98a7b 7053526: Upgrade JDK 8 to use Little CMS 2.4
bae
parents: 9784
diff changeset
  1774
cmsTagSignature  CMSEXPORT cmsTagLinkedTo(cmsHPROFILE hProfile, cmsTagSignature sig)
117dc9b98a7b 7053526: Upgrade JDK 8 to use Little CMS 2.4
bae
parents: 9784
diff changeset
  1775
{
117dc9b98a7b 7053526: Upgrade JDK 8 to use Little CMS 2.4
bae
parents: 9784
diff changeset
  1776
    _cmsICCPROFILE* Icc = (_cmsICCPROFILE*) hProfile;
117dc9b98a7b 7053526: Upgrade JDK 8 to use Little CMS 2.4
bae
parents: 9784
diff changeset
  1777
    int i;
117dc9b98a7b 7053526: Upgrade JDK 8 to use Little CMS 2.4
bae
parents: 9784
diff changeset
  1778
117dc9b98a7b 7053526: Upgrade JDK 8 to use Little CMS 2.4
bae
parents: 9784
diff changeset
  1779
    // Search for given tag in ICC profile directory
117dc9b98a7b 7053526: Upgrade JDK 8 to use Little CMS 2.4
bae
parents: 9784
diff changeset
  1780
    i = _cmsSearchTag(Icc, sig, FALSE);
117dc9b98a7b 7053526: Upgrade JDK 8 to use Little CMS 2.4
bae
parents: 9784
diff changeset
  1781
    if (i < 0) return (cmsTagSignature) 0;                 // Not found, return 0
117dc9b98a7b 7053526: Upgrade JDK 8 to use Little CMS 2.4
bae
parents: 9784
diff changeset
  1782
117dc9b98a7b 7053526: Upgrade JDK 8 to use Little CMS 2.4
bae
parents: 9784
diff changeset
  1783
    return Icc -> TagLinked[i];
117dc9b98a7b 7053526: Upgrade JDK 8 to use Little CMS 2.4
bae
parents: 9784
diff changeset
  1784
}