Beispiel #1
0
/*
 *   <dict>  .set_outputintent  -
 *
 * Set and use the specified output intent.  
 *
 */
static int
zset_outputintent(i_ctx_t * i_ctx_p)
{
    os_ptr                  op = osp;
    int                     code = 0;
    gx_device *dev = gs_currentdevice(igs);
    gs_imager_state *pis = (gs_imager_state *)igs;
    cmm_dev_profile_t       *dev_profile;
    stream *                s = 0L;
    ref *                   pnval;
    ref *                   pstrmval;
    int                     ncomps, dev_comps;
    cmm_profile_t           *picc_profile;
    int                     expected = 0;
    gs_color_space_index    index;
    gsicc_manager_t         *icc_manager = pis->icc_manager;
    cmm_profile_t           *source_profile = NULL;

    check_type(*op, t_dictionary);
    check_dict_read(*op);
    if_debug0m(gs_debug_flag_icc, imemory, "[icc] Using OutputIntent\n");

    /* Get the device structure */
    code = dev_proc(dev, get_profile)(dev,  &dev_profile);
    if (dev_profile == NULL) { 
        code = gsicc_init_device_profile_struct(dev, NULL, 0);
        code = dev_proc(dev, get_profile)(dev,  &dev_profile);
    }
    if (dev_profile->oi_profile != NULL) {
        return 0;  /* Allow only one setting of this object */
    }
    code = dict_find_string(op, "N", &pnval);
    if (code < 0)
        return code;
    ncomps = pnval->value.intval;

    /* verify the DataSource entry. Creat profile from stream */
    if (dict_find_string(op, "DataSource", &pstrmval) <= 0)
        return_error(e_undefined);
    check_read_file(i_ctx_p, s, pstrmval);

    picc_profile = gsicc_profile_new(s, gs_state_memory(igs), NULL, 0);
    picc_profile->num_comps = ncomps;
    picc_profile->profile_handle =
        gsicc_get_profile_handle_buffer(picc_profile->buffer,
                                        picc_profile->buffer_size,
                                        gs_state_memory(igs));
    if (picc_profile->profile_handle == NULL) {
        rc_decrement(picc_profile,"zset_outputintent");
        return -1;
    }
    picc_profile->data_cs = gscms_get_profile_data_space(picc_profile->profile_handle);
    switch (picc_profile->data_cs) {
        case gsCIEXYZ:
        case gsCIELAB:
        case gsRGB:
            expected = 3;
            source_profile = icc_manager->default_rgb;
            break;
        case gsGRAY:
            expected = 1;
            source_profile = icc_manager->default_gray;
            break;
        case gsCMYK:
            expected = 4;
            source_profile = icc_manager->default_cmyk;
            break;
        case gsNCHANNEL:
            expected = 0;
            break;
        case gsNAMED:            
        case gsUNDEFINED:        
            break;
    }
    if (expected && ncomps != expected) {
        rc_decrement(picc_profile,"zset_outputintent");
        return_error(e_rangecheck);
    }
    gsicc_init_hash_cs(picc_profile, pis);

    /* All is well with the profile.  Lets set the stuff that needs to be set */
    dev_profile->oi_profile = picc_profile;
    picc_profile->name = (char *) gs_alloc_bytes(picc_profile->memory, 
                                                 MAX_DEFAULT_ICC_LENGTH,
                                                 "zset_outputintent");
    strncpy(picc_profile->name, OI_PROFILE, strlen(OI_PROFILE));
    picc_profile->name[strlen(OI_PROFILE)] = 0;
    picc_profile->name_length = strlen(OI_PROFILE);
    /* Set the range of the profile */
    gscms_set_icc_range(&picc_profile);

    /* If the output device has a different number of componenets, then we are 
       going to set the output intent as the proofing profile, unless the 
       proofing profile has already been set. 

       If the device has the same number of components (and color model) then as 
       the profile we will use this as the output profile, unless someone has 
       explicitly set the output profile.

       Finally, we will use the output intent profile for the default profile
       of the proper Device profile in the icc manager, again, unless someone
       has explicitly set this default profile. */

    dev_comps = dev_profile->device_profile[0]->num_comps;
    index = gsicc_get_default_type(dev_profile->device_profile[0]);
    if (ncomps == dev_comps && index < gs_color_space_index_DevicePixel) {
        /* The OI profile is the same type as the profile for the device and a 
           "default" profile for the device was not externally set. So we go 
           ahead and use the OI profile as the device profile.  Care needs to be 
           taken here to keep from screwing up any device parameters.   We will 
           use a keyword of OIProfile for the user/device parameter to indicate 
           its usage.  Also, note conflicts if one is setting object dependent 
           color management */
        rc_assign(dev_profile->device_profile[0], picc_profile, 
                  "zset_outputintent");
        if_debug0m(gs_debug_flag_icc, imemory, "[icc] OutputIntent used for device profile\n");
    } else {
        if (dev_profile->proof_profile == NULL) {
            /* This means that we should use the OI profile as the proofing 
               profile.  Note that if someone already has specified a 
               proofing profile it is unclear what they are trying to do
               with the output intent.  In this case, we will use it 
               just for the source data below */
            dev_profile->proof_profile = picc_profile;
            rc_increment(picc_profile);
            if_debug0m(gs_debug_flag_icc, imemory, "[icc] OutputIntent used for proof profile\n");
        }
    }
    /* Now the source colors.  See which source color space needs to use the
       output intent ICC profile */
    index = gsicc_get_default_type(source_profile);
    if (index < gs_color_space_index_DevicePixel) {
        /* source_profile is currently the default.  Set it to the OI profile */
        switch (picc_profile->data_cs) {
            case gsGRAY:
                if_debug0m(gs_debug_flag_icc, imemory, "[icc] OutputIntent used source Gray\n");
                rc_assign(icc_manager->default_gray, picc_profile, 
                          "zset_outputintent");
                break;
            case gsRGB:
                if_debug0m(gs_debug_flag_icc, imemory, "[icc] OutputIntent used source RGB\n");
                rc_assign(icc_manager->default_rgb, picc_profile, 
                          "zset_outputintent");
                break;
            case gsCMYK:
                if_debug0m(gs_debug_flag_icc, imemory, "[icc] OutputIntent used source CMYK\n");
                rc_assign(icc_manager->default_cmyk, picc_profile, 
                          "zset_outputintent");
                break;
            default:
                break;
        }
    }
    /* Remove the output intent dict from the stack */
    pop(1);
    return code;
}
Beispiel #2
0
/* Get standard parameters. */
int
gx_default_get_params(gx_device * dev, gs_param_list * plist)
{
    int code;

    /* Standard page device parameters: */

    bool seprs = false;
    gs_param_string dns, pcms, profile_array[NUM_DEVICE_PROFILES];
    gsicc_rendering_intents_t profile_intents[NUM_DEVICE_PROFILES];
    bool devicegraytok = true;  /* Default if device profile stuct not set */
    int k;
    gs_param_float_array msa, ibba, hwra, ma;
    gs_param_string_array scna;
    char null_str[1]={'\0'};
    gs_param_string temp_str;

#define set_param_array(a, d, s)\
  (a.data = d, a.size = s, a.persistent = false);

    /* Non-standard parameters: */
    int colors = dev->color_info.num_components;
    int mns = colors;
    int depth = dev->color_info.depth;
    int GrayValues = dev->color_info.max_gray + 1;
    int HWSize[2];
    gs_param_int_array hwsa;
    gs_param_float_array hwma, mhwra;
    cmm_dev_profile_t *dev_profile;

    /* Fill in page device parameters. */

    param_string_from_string(dns, dev->dname);
    {
        const char *cms = get_process_color_model_name(dev);

        /* We might have an uninitialized device with */
        /* color_info.num_components = 0.... */
        if ((cms != NULL) && (*cms != '\0'))
            param_string_from_string(pcms, cms);
        else
            pcms.data = 0;
    }

    set_param_array(hwra, dev->HWResolution, 2);
    set_param_array(msa, dev->MediaSize, 2);
    set_param_array(ibba, dev->ImagingBBox, 4);
    set_param_array(ma, dev->Margins, 2);
    set_param_array(scna, NULL, 0);

    /* Fill in non-standard parameters. */
    HWSize[0] = dev->width;
    HWSize[1] = dev->height;
    set_param_array(hwsa, HWSize, 2);
    set_param_array(hwma, dev->HWMargins, 4);
    set_param_array(mhwra, dev->MarginsHWResolution, 2);
    /* Check if the device profile is null.  If it is, then we need to
       go ahead and get it set up at this time.  If the proc is not
       set up yet then we are not going to do anything yet */
    if (dev->procs.get_profile != NULL) {
        code = dev_proc(dev, get_profile)(dev,  &dev_profile);
        if (dev_profile == NULL) { 
            code = gsicc_init_device_profile_struct(dev, NULL, 0);
            code = dev_proc(dev, get_profile)(dev,  &dev_profile);
        } 
        for (k = 0; k < NUM_DEVICE_PROFILES; k++) {
            if (dev_profile->device_profile[k] == NULL) {
                param_string_from_string(profile_array[k], null_str);
                profile_intents[k] = gsPERCEPTUAL;
            } else {
                param_string_from_string(profile_array[k], 
                    dev_profile->device_profile[k]->name);
                profile_intents[k] = dev_profile->intent[k];
            }
        }
        devicegraytok = dev_profile->devicegraytok;
    } else {
        for (k = 0; k < NUM_DEVICE_PROFILES; k++) {
            param_string_from_string(profile_array[k], null_str);
            profile_intents[k] = gsPERCEPTUAL;
        }
    }
    /* Transmit the values. */
       if (
        /* Standard parameters */
        (code = param_write_name(plist, "OutputDevice", &dns)) < 0 ||
#ifdef PAGESIZE_IS_MEDIASIZE
        (code = param_write_float_array(plist, "PageSize", &msa)) < 0 ||
#endif
        (code = (pcms.data == 0 ? 0 :
                 param_write_name(plist, "ProcessColorModel", &pcms))) < 0 ||
        (code = param_write_float_array(plist, "HWResolution", &hwra)) < 0 ||
        (code = (dev->ImagingBBox_set ?
                 param_write_float_array(plist, "ImagingBBox", &ibba) :
                 param_write_null(plist, "ImagingBBox"))) < 0 ||
        (code = param_write_float_array(plist, "Margins", &ma)) < 0 ||
        (code = param_write_int(plist, "MaxSeparations", &mns)) < 0 ||
        (code = (dev->NumCopies_set < 0 ||
                 (*dev_proc(dev, get_page_device))(dev) == 0 ? 0:
                 dev->NumCopies_set ?
                 param_write_int(plist, "NumCopies", &dev->NumCopies) :
                 param_write_null(plist, "NumCopies"))) < 0 ||
        (code = param_write_name_array(plist, "SeparationColorNames", &scna)) < 0 ||
        (code = param_write_bool(plist, "Separations", &seprs)) < 0 ||
        (code = param_write_bool(plist, "UseCIEColor", &dev->UseCIEColor)) < 0 ||
        /* Non-standard parameters */
        /* Note:  if change is made in NUM_DEVICE_PROFILES we need to name
           that profile here for the device parameter on the command line */
        (code = param_write_bool(plist, "DeviceGrayToK", &devicegraytok)) < 0 ||
        (code = param_write_string(plist,"OutputICCProfile", &(profile_array[0]))) < 0 ||
        (code = param_write_string(plist,"GraphicICCProfile", &(profile_array[1]))) < 0 ||
        (code = param_write_string(plist,"ImageICCProfile", &(profile_array[2]))) < 0 ||
        (code = param_write_string(plist,"TextICCProfile", &(profile_array[3]))) < 0 ||
        (code = param_write_int(plist,"RenderIntent", &(profile_intents[0]))) < 0 ||
        (code = param_write_int(plist,"GraphicIntent", &(profile_intents[1]))) < 0 ||
        (code = param_write_int(plist,"ImageIntent", &(profile_intents[2]))) < 0 ||
        (code = param_write_int(plist,"TextIntent", &(profile_intents[3]))) < 0 ||
        (code = param_write_int_array(plist, "HWSize", &hwsa)) < 0 ||
        (code = param_write_float_array(plist, ".HWMargins", &hwma)) < 0 ||
        (code = param_write_float_array(plist, ".MarginsHWResolution", &mhwra)) < 0 ||
        (code = param_write_float_array(plist, ".MediaSize", &msa)) < 0 ||
        (code = param_write_string(plist, "Name", &dns)) < 0 ||
        (code = param_write_int(plist, "Colors", &colors)) < 0 ||
        (code = param_write_int(plist, "BitsPerPixel", &depth)) < 0 ||
        (code = param_write_int(plist, "GrayValues", &GrayValues)) < 0 ||
        (code = param_write_long(plist, "PageCount", &dev->PageCount)) < 0 ||
        (code = param_write_bool(plist, ".IgnoreNumCopies", &dev->IgnoreNumCopies)) < 0 ||
        (code = param_write_int(plist, "TextAlphaBits",
                                &dev->color_info.anti_alias.text_bits)) < 0 ||
        (code = param_write_int(plist, "GraphicsAlphaBits",
                                &dev->color_info.anti_alias.graphics_bits)) < 0 ||
        (code = param_write_bool(plist, ".LockSafetyParams", &dev->LockSafetyParams)) < 0 ||
        (code = param_write_int(plist, "MaxPatternBitmap", &dev->MaxPatternBitmap)) < 0
        )
        return code;

    /* If LeadingEdge was set explicitly, report it here. */
    if (dev->LeadingEdge & LEADINGEDGE_SET_MASK) {
        int leadingedge = dev->LeadingEdge & LEADINGEDGE_MASK;
        code = param_write_int(plist, "LeadingEdge", &leadingedge);
    }
    if (code < 0)
        return code;

    /* Fill in color information. */

    if (colors > 1) {
        int RGBValues = dev->color_info.max_color + 1;
        long ColorValues = (depth >= 32 ? -1 : 1L << depth); /* value can only be 32 bits */

        if ((code = param_write_int(plist, "RedValues", &RGBValues)) < 0 ||
            (code = param_write_int(plist, "GreenValues", &RGBValues)) < 0 ||
            (code = param_write_int(plist, "BlueValues", &RGBValues)) < 0 ||
            (code = param_write_long(plist, "ColorValues", &ColorValues)) < 0
            )
            return code;
    }
    if (param_requested(plist, "HWColorMap")) {
        byte palette[3 << 8];

        if (param_HWColorMap(dev, palette)) {
            gs_param_string hwcms;

            hwcms.data = palette, hwcms.size = colors << depth,
                hwcms.persistent = false;
            if ((code = param_write_string(plist, "HWColorMap", &hwcms)) < 0)
                return code;
        }
    }

    return 0;
}