11ab64890Smrg 21ab64890Smrg/* 31ab64890Smrg * Code and supporting documentation (c) Copyright 1990 1991 Tektronix, Inc. 41ab64890Smrg * All Rights Reserved 561b2299dSmrg * 61ab64890Smrg * This file is a component of an X Window System-specific implementation 71ab64890Smrg * of Xcms based on the TekColor Color Management System. Permission is 81ab64890Smrg * hereby granted to use, copy, modify, sell, and otherwise distribute this 91ab64890Smrg * software and its documentation for any purpose and without fee, provided 101ab64890Smrg * that this copyright, permission, and disclaimer notice is reproduced in 111ab64890Smrg * all copies of this software and in supporting documentation. TekColor 121ab64890Smrg * is a trademark of Tektronix, Inc. 1361b2299dSmrg * 141ab64890Smrg * Tektronix makes no representation about the suitability of this software 151ab64890Smrg * for any purpose. It is provided "as is" and with all faults. 1661b2299dSmrg * 171ab64890Smrg * TEKTRONIX DISCLAIMS ALL WARRANTIES APPLICABLE TO THIS SOFTWARE, 181ab64890Smrg * INCLUDING THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A 191ab64890Smrg * PARTICULAR PURPOSE. IN NO EVENT SHALL TEKTRONIX BE LIABLE FOR ANY 201ab64890Smrg * SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER 211ab64890Smrg * RESULTING FROM LOSS OF USE, DATA, OR PROFITS, WHETHER IN AN ACTION OF 221ab64890Smrg * CONTRACT, NEGLIGENCE, OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN 231ab64890Smrg * CONNECTION WITH THE USE OR THE PERFORMANCE OF THIS SOFTWARE. 241ab64890Smrg * 251ab64890Smrg * 261ab64890Smrg * NAME 271ab64890Smrg * XcmsStCols.c 281ab64890Smrg * 291ab64890Smrg * DESCRIPTION 301ab64890Smrg * Source for XcmsStoreColors 311ab64890Smrg * 321ab64890Smrg * 331ab64890Smrg */ 341ab64890Smrg 351ab64890Smrg#ifdef HAVE_CONFIG_H 361ab64890Smrg#include <config.h> 371ab64890Smrg#endif 381ab64890Smrg#include "Xlibint.h" 391ab64890Smrg#include "Xcmsint.h" 401ab64890Smrg#include "Cv.h" 41258a0ebeSmrg#include "reallocarray.h" 421ab64890Smrg 431ab64890Smrg 441ab64890Smrg/************************************************************************ 451ab64890Smrg * * 461ab64890Smrg * PUBLIC ROUTINES * 471ab64890Smrg * * 481ab64890Smrg ************************************************************************/ 491ab64890Smrg 501ab64890Smrg/* 511ab64890Smrg * NAME 521ab64890Smrg * XcmsStoreColors - Store Colors 531ab64890Smrg * 541ab64890Smrg * SYNOPSIS 551ab64890Smrg */ 561ab64890SmrgStatus 571ab64890SmrgXcmsStoreColors( 581ab64890Smrg Display *dpy, 591ab64890Smrg Colormap colormap, 601ab64890Smrg XcmsColor *pColors_in, 611ab64890Smrg unsigned int nColors, 621ab64890Smrg Bool *pCompressed) 631ab64890Smrg/* 641ab64890Smrg * DESCRIPTION 651ab64890Smrg * Given device-dependent or device-independent color 661ab64890Smrg * specifications, this routine will convert them to X RGB 671ab64890Smrg * values then use it in a call to XStoreColors. 681ab64890Smrg * 691ab64890Smrg * RETURNS 701ab64890Smrg * XcmsFailure if failed; 711ab64890Smrg * XcmsSuccess if it succeeded without gamut compression; 721ab64890Smrg * XcmsSuccessWithCompression if it succeeded with gamut 731ab64890Smrg * compression; 741ab64890Smrg * 751ab64890Smrg * Since XStoreColors has no return value, this routine 761ab64890Smrg * does not return color specifications of the colors actually 771ab64890Smrg * stored. 781ab64890Smrg */ 791ab64890Smrg{ 801ab64890Smrg XcmsColor Color1; 811ab64890Smrg XcmsColor *pColors_tmp; 821ab64890Smrg Status retval; 831ab64890Smrg 841ab64890Smrg /* 851ab64890Smrg * Make copy of array of color specifications so we don't 861ab64890Smrg * overwrite the contents. 871ab64890Smrg */ 881ab64890Smrg if (nColors > 1) { 89258a0ebeSmrg pColors_tmp = Xmallocarray(nColors, sizeof(XcmsColor)); 90258a0ebeSmrg if (pColors_tmp == NULL) 91258a0ebeSmrg return(XcmsFailure); 921ab64890Smrg } else { 931ab64890Smrg pColors_tmp = &Color1; 941ab64890Smrg } 951ab64890Smrg memcpy((char *)pColors_tmp, (char *)pColors_in, 961ab64890Smrg nColors * sizeof(XcmsColor)); 971ab64890Smrg 981ab64890Smrg /* 991ab64890Smrg * Call routine to store colors using the copied color structures 1001ab64890Smrg */ 1011ab64890Smrg retval = _XcmsSetGetColors (XStoreColors, dpy, colormap, 1021ab64890Smrg pColors_tmp, nColors, XcmsRGBFormat, pCompressed); 1031ab64890Smrg 1041ab64890Smrg /* 1051ab64890Smrg * Free copies as needed. 1061ab64890Smrg */ 1071ab64890Smrg if (nColors > 1) { 108818534a1Smrg Xfree(pColors_tmp); 1091ab64890Smrg } 1101ab64890Smrg 1111ab64890Smrg /* 1121ab64890Smrg * Ah, finally return. 1131ab64890Smrg */ 1141ab64890Smrg return(retval); 1151ab64890Smrg} 116