[gs-commits] rev 11871 - trunk/gs/toolbin/color/icc_creator/ICC_Creator

mvrhel at ghostscript.com mvrhel at ghostscript.com
Thu Oct 28 20:41:15 UTC 2010


Author: mvrhel
Date: 2010-10-28 20:41:14 +0000 (Thu, 28 Oct 2010)
New Revision: 11871

Modified:
   trunk/gs/toolbin/color/icc_creator/ICC_Creator/ICC_Creator.rc
   trunk/gs/toolbin/color/icc_creator/ICC_Creator/ICC_CreatorDlg.cpp
   trunk/gs/toolbin/color/icc_creator/ICC_Creator/ICC_CreatorDlg.h
   trunk/gs/toolbin/color/icc_creator/ICC_Creator/icc_create.cpp
   trunk/gs/toolbin/color/icc_creator/ICC_Creator/icc_create.h
   trunk/gs/toolbin/color/icc_creator/ICC_Creator/resource.h
Log:
Addition in profile creation tool to create Gray ICC profiles with abrupt thresholds.   Needed for solution to bug 691737

Modified: trunk/gs/toolbin/color/icc_creator/ICC_Creator/ICC_Creator.rc
===================================================================
--- trunk/gs/toolbin/color/icc_creator/ICC_Creator/ICC_Creator.rc	2010-10-28 19:57:51 UTC (rev 11870)
+++ trunk/gs/toolbin/color/icc_creator/ICC_Creator/ICC_Creator.rc	2010-10-28 20:41:14 UTC (rev 11871)
@@ -105,6 +105,8 @@
     PUSHBUTTON      "PS RGB2CMYK Profile",IDC_RGB2CMYK,130,147,82,15
     PUSHBUTTON      "PS CMYK2GRAY Profile",IDC_CMYK2GRAY2,31,121,82,15
     PUSHBUTTON      "PS ICC Profiles",IDC_PSICC,32,176,82,15
+    PUSHBUTTON      "Gray Threshold Profile",IDC_GRAYTHRESH,31,205,82,15
+    EDITTEXT        IDC_EDITTHRESH,158,206,40,14,ES_AUTOHSCROLL | ES_NUMBER
 END
 
 

Modified: trunk/gs/toolbin/color/icc_creator/ICC_Creator/ICC_CreatorDlg.cpp
===================================================================
--- trunk/gs/toolbin/color/icc_creator/ICC_Creator/ICC_CreatorDlg.cpp	2010-10-28 19:57:51 UTC (rev 11870)
+++ trunk/gs/toolbin/color/icc_creator/ICC_Creator/ICC_CreatorDlg.cpp	2010-10-28 20:41:14 UTC (rev 11871)
@@ -69,6 +69,7 @@
 void CICC_CreatorDlg::DoDataExchange(CDataExchange* pDX)
 {
 	CDialog::DoDataExchange(pDX);
+    DDX_Control(pDX, IDC_EDITTHRESH, m_graythreshold);
 }
 
 BEGIN_MESSAGE_MAP(CICC_CreatorDlg, CDialog)
@@ -85,6 +86,8 @@
         ON_BN_CLICKED(IDC_RGB2CMYK, &CICC_CreatorDlg::OnBnClickedRgb2cmyk)
         ON_BN_CLICKED(IDC_CMYK2GRAY2, &CICC_CreatorDlg::OnBnClickedCmyk2gray2)
         ON_BN_CLICKED(IDC_PSICC, &CICC_CreatorDlg::OnBnClickedPsicc)
+        ON_BN_CLICKED(IDC_GRAYTHRESH, &CICC_CreatorDlg::OnBnClickedGraythresh)
+        ON_EN_CHANGE(IDC_EDITTHRESH, &CICC_CreatorDlg::OnEnChangeEditthresh)
 END_MESSAGE_MAP()
 
 
@@ -125,8 +128,9 @@
         this->m_cielab = NULL;
         this->m_colorant_names = NULL;  
         this->SetDlgItemText(IDC_STATUS,_T("Ready."));
+        this->m_floatthreshold = 50;
+        this->m_graythreshold.SetWindowText(_T("50"));
 
-
 	return TRUE;  // return TRUE  unless you set the focus to a control
 }
 
@@ -618,3 +622,56 @@
 
 
 }
+
+void CICC_CreatorDlg::OnBnClickedGraythresh()
+{
+
+    int ok;
+    TCHAR szFile[MAX_PATH];
+    ZeroMemory(szFile, MAX_PATH);
+    OPENFILENAME ofn;
+    ZeroMemory(&ofn, sizeof(OPENFILENAME));
+    ofn.lStructSize	= sizeof(OPENFILENAME);
+    ofn.Flags		= OFN_FILEMUSTEXIST | OFN_PATHMUSTEXIST |OFN_HIDEREADONLY;
+    ofn.hwndOwner	= this->m_hWnd;
+    ofn.lpstrFilter	= _T("Supported Files Types(*.icc)\0*.icc;*.ICC\0\0");
+    ofn.lpstrTitle	= _T("Save Gray ICC Profile");
+    ofn.lpstrFile	= szFile;
+    ofn.nMaxFile	= MAX_PATH;
+
+    if (IDOK == GetSaveFileName(&ofn)) {
+         ok = create_gray_threshold_profile(szFile, this->m_floatthreshold);
+        if (ok == 0)
+            this->SetDlgItemText(IDC_STATUS,_T("Created Gray Threshhold Profile"));
+    } 
+}
+
+void CICC_CreatorDlg::OnEnChangeEditthresh()
+{
+    // TODO:  If this is a RICHEDIT control, the control will not
+    // send this notification unless you override the CDialog::OnInitDialog()
+    // function and call CRichEditCtrl().SetEventMask()
+    // with the ENM_CHANGE flag ORed into the mask.
+
+    // TODO:  Add your control notification handler code here
+	// TODO: If this is a RICHEDIT control, the control will not
+	// send this notification unless you override the CDialog::OnInitDialog()
+	// function and call CRichEditCtrl().SetEventMask()
+	// with the ENM_CHANGE flag ORed into the mask.
+	
+	// TODO: Add your control notification handler code here
+
+	char str[25];
+	int data;
+
+	this->m_graythreshold.GetWindowText(str,24);
+        sscanf(str,"%f",&(this->m_floatthreshold));
+        if (this->m_floatthreshold < 0) {
+            this->m_floatthreshold = 0;
+            this->m_graythreshold.SetWindowText(_T("0"));
+        }
+        if (this->m_floatthreshold > 100) {
+            this->m_floatthreshold = 100;
+            this->m_graythreshold.SetWindowText(_T("100"));
+        }
+}

Modified: trunk/gs/toolbin/color/icc_creator/ICC_Creator/ICC_CreatorDlg.h
===================================================================
--- trunk/gs/toolbin/color/icc_creator/ICC_Creator/ICC_CreatorDlg.h	2010-10-28 19:57:51 UTC (rev 11870)
+++ trunk/gs/toolbin/color/icc_creator/ICC_Creator/ICC_CreatorDlg.h	2010-10-28 20:41:14 UTC (rev 11871)
@@ -15,6 +15,7 @@
 #pragma once
 
 #include "CIELAB.h"
+#include "afxwin.h"
 
 // CICC_CreatorDlg dialog
 class CICC_CreatorDlg : public CDialog
@@ -63,4 +64,8 @@
     afx_msg void OnBnClickedRgb2cmyk();
     afx_msg void OnBnClickedCmyk2gray2();
     afx_msg void OnBnClickedPsicc();
+    afx_msg void OnBnClickedGraythresh();
+    afx_msg void OnEnChangeEditthresh();
+    CEdit m_graythreshold;
+    float m_floatthreshold;
 };

Modified: trunk/gs/toolbin/color/icc_creator/ICC_Creator/icc_create.cpp
===================================================================
--- trunk/gs/toolbin/color/icc_creator/ICC_Creator/icc_create.cpp	2010-10-28 19:57:51 UTC (rev 11870)
+++ trunk/gs/toolbin/color/icc_creator/ICC_Creator/icc_create.cpp	2010-10-28 20:41:14 UTC (rev 11871)
@@ -1,4 +1,4 @@
-/* Copyright (C) 2001-2009 Artifex Software, Inc.
+/* Copyright (C) 2001-2010 Artifex Software, Inc.
    All Rights Reserved.
   
    This software is provided AS-IS with no warranty, either express or
@@ -52,6 +52,7 @@
 /* Names of interest */
 static const char desc_deviceN_name[] = "Artifex DeviceN Profile";
 static const char desc_psgray_name[] = "Artifex PS Gray Profile";
+static const char desc_thresh_gray_name[] = "Artifex Gray Threshold Profile";
 static const char desc_psrgb_name[] = "Artifex PS RGB Profile";
 static const char desc_pscmyk_name[] = "Artifex PS CMYK Profile";
 static const char desc_link_name[] = "Artifex Link Profile";
@@ -425,6 +426,34 @@
 }
 
 static void
+add_curve(unsigned char *input_ptr, float *curve_data, int num_samples)
+{
+    unsigned char *curr_ptr;
+    unsigned short value;
+    int k;
+
+   /* Signature */
+    curr_ptr = input_ptr;
+    write_bigendian_4bytes(curr_ptr,icSigCurveType);
+    curr_ptr += 4;
+    /* Reserved */
+    memset(curr_ptr,0,4);
+    curr_ptr += 4;
+    /* Count */
+    write_bigendian_4bytes(curr_ptr, num_samples);
+    curr_ptr += 4;
+    /* Now the data uInt16 Number 0 to 65535.  For now assume input is 0 to 1.  
+            Need to fix this.  MJV */
+    for (k = 0; k < num_samples; k++) {
+        if (curve_data[k] < 0) curve_data[k] = 0;
+        if (curve_data[k] > 1) curve_data[k] = 1; 
+        value = (unsigned int) (curve_data[k]*65535.0);
+        write_bigendian_2bytes(curr_ptr,value);
+        curr_ptr+=2;
+    }
+}
+
+static void
 add_gammadata(unsigned char *input_ptr, unsigned short gamma, 
               icTagTypeSignature curveType)
 {
@@ -1282,6 +1311,100 @@
     return(0);
 }
 
+
+/* Create a gray threshold profile */
+int create_gray_threshold_profile(TCHAR FileName[], float threshhold)
+{
+    icProfile iccprofile;
+    icHeader  *header = &(iccprofile.header);
+    int profile_size,k;
+    int num_tags;
+    gsicc_tag *tag_list;
+    int tag_offset = 0;
+    unsigned char *curr_ptr;
+    int last_tag;
+    icS15Fixed16Number temp_XYZ[3];
+    int tag_location;
+    int debug_catch = 1;
+    unsigned char *buffer;
+    int numout = 3;              /* Number of output colorants */
+    int num_colors = 1;
+    int num_samples = 2;
+    float encode_gamma;
+    int trc_tag_size;
+    float *table_data;
+    int midpoint;
+
+    /* Create the curve */
+    table_data = (float*) malloc(CURVE_SIZE*sizeof(float));
+    /* init it all to 0 */
+    memset(table_data,0,CURVE_SIZE*sizeof(float));
+    midpoint = (float) CURVE_SIZE * (threshhold / 100.0);
+
+    /* Set the points from midpoint to white to 1.0 */
+    for ( k = midpoint; k < CURVE_SIZE; k++) {
+        table_data[k] = 1.0;
+    }
+    
+    /* Fill in the common stuff */
+    setheader_common(header);
+    header->pcs = icSigXYZData;
+    profile_size = HEADER_SIZE;
+    header->deviceClass = icSigDisplayClass;
+    header->colorSpace = icSigGrayData;
+    num_tags = 5;  /* common (2) ,wtpt bkpt + TRC */   
+    tag_list = (gsicc_tag*) malloc(sizeof(gsicc_tag)*num_tags);
+    /* Let us precompute the sizes of everything and all our offsets */
+    profile_size += TAG_SIZE*num_tags;
+    profile_size += 4; /* number of tags.... */
+    last_tag = -1;
+    init_common_tags(tag_list, num_tags, &last_tag, desc_thresh_gray_name);  
+    init_tag(tag_list, &last_tag, icSigMediaWhitePointTag, XYZPT_SIZE);
+    init_tag(tag_list, &last_tag, icSigMediaBlackPointTag, XYZPT_SIZE);
+    trc_tag_size = 12 + CURVE_SIZE*2;  
+    init_tag(tag_list, &last_tag, icSigGrayTRCTag, trc_tag_size);
+    for(k = 0; k < num_tags; k++) {
+        profile_size += tag_list[k].size;
+    }
+    /* Now we can go ahead and fill our buffer with the data */
+    buffer = (unsigned char*) malloc(profile_size);
+    curr_ptr = buffer;
+
+    /* The header */
+    header->size = profile_size;
+    copy_header(curr_ptr,header);
+    curr_ptr += HEADER_SIZE;
+    /* Tag table */
+    copy_tagtable(curr_ptr,tag_list,num_tags);
+    curr_ptr += TAG_SIZE*num_tags;
+    curr_ptr += 4;
+
+    /* Now the data.  Must be in same order as we created the tag table */
+    /* First the common tags */
+    add_common_tag_data(curr_ptr, tag_list, desc_psgray_name);
+    for (k = 0; k< NUMBER_COMMON_TAGS; k++) {
+        curr_ptr += tag_list[k].size;
+    }
+    tag_location = NUMBER_COMMON_TAGS;
+    /* White and black points */
+    get_XYZ_floatptr(temp_XYZ,(float*) &(D50WhitePoint[0]));
+    add_xyzdata(curr_ptr,temp_XYZ);
+    curr_ptr += tag_list[tag_location].size;
+    tag_location++;
+    get_XYZ_floatptr(temp_XYZ,(float*) &(BlackPoint[0]));
+    add_xyzdata(curr_ptr,temp_XYZ);
+    curr_ptr += tag_list[tag_location].size;
+    tag_location++;
+    /* Now the curve data */
+    add_curve(curr_ptr, table_data, CURVE_SIZE);
+    curr_ptr += tag_list[tag_location].size;
+    tag_location++;
+    /* Dump the buffer to a file for testing if its a valid ICC profile */
+    save_profile(buffer,FileName,profile_size);
+    free(table_data);
+    return(0);
+}
+
 /* Create the ps rgb profile */
 int create_psrgb_profile(TCHAR FileName[])
 {

Modified: trunk/gs/toolbin/color/icc_creator/ICC_Creator/icc_create.h
===================================================================
--- trunk/gs/toolbin/color/icc_creator/ICC_Creator/icc_create.h	2010-10-28 19:57:51 UTC (rev 11870)
+++ trunk/gs/toolbin/color/icc_creator/ICC_Creator/icc_create.h	2010-10-28 20:41:14 UTC (rev 11871)
@@ -26,11 +26,9 @@
 } link_t;
 
 int create_devicen_profile(cielab_t *cielab, colornames_t *colorant_names, int num_colors, int num_samples, TCHAR FileName[]);
-
 int create_devicelink_profile(TCHAR FileName[],link_t link_type);
-
 int create_psrgb_profile(TCHAR FileName[]);
 int create_pscmyk_profile(TCHAR FileName[], bool pcs_islab);
 int create_psgray_profile(TCHAR FileName[]);
-
+int  create_gray_threshold_profile(TCHAR FileName[], float threshold);
 #endif

Modified: trunk/gs/toolbin/color/icc_creator/ICC_Creator/resource.h
===================================================================
--- trunk/gs/toolbin/color/icc_creator/ICC_Creator/resource.h	2010-10-28 19:57:51 UTC (rev 11870)
+++ trunk/gs/toolbin/color/icc_creator/ICC_Creator/resource.h	2010-10-28 20:41:14 UTC (rev 11871)
@@ -20,6 +20,9 @@
 #define IDC_CMYK2GRAY2                  1008
 #define IDC_GRAY2CMYK2                  1009
 #define IDC_PSICC                       1009
+#define IDC_GRAYTHRESH                  1010
+#define IDC_EDIT1                       1011
+#define IDC_EDITTHRESH                  1011
 
 // Next default values for new objects
 // 
@@ -27,7 +30,7 @@
 #ifndef APSTUDIO_READONLY_SYMBOLS
 #define _APS_NEXT_RESOURCE_VALUE        132
 #define _APS_NEXT_COMMAND_VALUE         32771
-#define _APS_NEXT_CONTROL_VALUE         1005
+#define _APS_NEXT_CONTROL_VALUE         1012
 #define _APS_NEXT_SYMED_VALUE           101
 #endif
 #endif



More information about the gs-commits mailing list