/* Shuts down various transforms and profiles for CMS. */ static void ShutdownCMS() { if (gCMSRGBTransform) { qcms_transform_release(gCMSRGBTransform); gCMSRGBTransform = nsnull; } if (gCMSInverseRGBTransform) { qcms_transform_release(gCMSInverseRGBTransform); gCMSInverseRGBTransform = nsnull; } if (gCMSRGBATransform) { qcms_transform_release(gCMSRGBATransform); gCMSRGBATransform = nsnull; } if (gCMSOutputProfile) { qcms_profile_release(gCMSOutputProfile); // handle the aliased case if (gCMSsRGBProfile == gCMSOutputProfile) gCMSsRGBProfile = nsnull; gCMSOutputProfile = nsnull; } if (gCMSsRGBProfile) { qcms_profile_release(gCMSsRGBProfile); gCMSsRGBProfile = nsnull; } // Reset the state variables gCMSIntent = -2; gCMSMode = eCMSMode_Off; gCMSInitialized = PR_FALSE; }
// ----------------------------------------------------------------------------- // Color profile handling static int ApplyColorProfile(const WebPData* const profile, WebPDecBuffer* const rgba) { #ifdef WEBP_HAVE_QCMS int i, ok = 0; uint8_t* line; uint8_t major_revision; qcms_profile* input_profile = NULL; qcms_profile* output_profile = NULL; qcms_transform* transform = NULL; const qcms_data_type input_type = QCMS_DATA_RGBA_8; const qcms_data_type output_type = QCMS_DATA_RGBA_8; const qcms_intent intent = QCMS_INTENT_DEFAULT; if (profile == NULL || rgba == NULL) return 0; if (profile->bytes == NULL || profile->size < 10) return 1; major_revision = profile->bytes[8]; qcms_enable_iccv4(); input_profile = qcms_profile_from_memory(profile->bytes, profile->size); // qcms_profile_is_bogus() is broken with ICCv4. if (input_profile == NULL || (major_revision < 4 && qcms_profile_is_bogus(input_profile))) { fprintf(stderr, "Color profile is bogus!\n"); goto Error; } output_profile = qcms_profile_sRGB(); if (output_profile == NULL) { fprintf(stderr, "Error creating output color profile!\n"); goto Error; } qcms_profile_precache_output_transform(output_profile); transform = qcms_transform_create(input_profile, input_type, output_profile, output_type, intent); if (transform == NULL) { fprintf(stderr, "Error creating color transform!\n"); goto Error; } line = rgba->u.RGBA.rgba; for (i = 0; i < rgba->height; ++i, line += rgba->u.RGBA.stride) { qcms_transform_data(transform, line, line, rgba->width); } ok = 1; Error: if (input_profile != NULL) qcms_profile_release(input_profile); if (output_profile != NULL) qcms_profile_release(output_profile); if (transform != NULL) qcms_transform_release(transform); return ok; #else (void)profile; (void)rgba; return 1; #endif // WEBP_HAVE_QCMS }
void WEBPImageDecoder::clear() { #ifdef QCMS_WEBP_COLOR_CORRECTION if (m_transform) qcms_transform_release(m_transform); m_transform = 0; #endif if (m_decoder) WebPIDelete(m_decoder); m_decoder = 0; }
void WEBPImageDecoder::clear() { #if USE(QCMSLIB) if (m_transform) qcms_transform_release(m_transform); m_transform = 0; #endif WebPDemuxDelete(m_demux); m_demux = 0; clearDecoder(); }
static void transform(qcms_profile* src_profile, qcms_profile* dst_profile, size_t size) { // qcms supports GRAY and RGB profiles as input, and RGB as output. uint32_t src_color_space = qcms_profile_get_color_space(src_profile); qcms_data_type src_type = size & 1 ? QCMS_DATA_RGBA_8 : QCMS_DATA_RGB_8; if (src_color_space == icSigGrayData) { src_type = size & 1 ? QCMS_DATA_GRAYA_8 : QCMS_DATA_GRAY_8; } else if (src_color_space != icSigRgbData) { return; } uint32_t dst_color_space = qcms_profile_get_color_space(dst_profile); if (dst_color_space != icSigRgbData) { return; } qcms_data_type dst_type = size & 2 ? QCMS_DATA_RGBA_8 : QCMS_DATA_RGB_8; qcms_intent intent = qcms_profile_get_rendering_intent(src_profile); // Firefox calls this on the display profile to increase performance. // Skip with low probability to increase coverage. if (size % 15) { qcms_profile_precache_output_transform(dst_profile); } qcms_transform* transform = qcms_transform_create(src_profile, src_type, dst_profile, dst_type, intent); if (!transform) { return; } static uint8_t src[] = { 0x7F, 0x7F, 0x7F, 0x00, 0x00, 0x7F, 0x7F, 0xFF, 0x7F, 0x10, 0x20, 0x30, 0x00, 0x00, 0x00, 0x00, 0xFF, 0xFF, 0xFF, 0xFF, 0xB0, 0xBF, 0xEF, 0x6F, 0x3F, 0xC0, 0x9F, 0xE0, 0x90, 0xCF, 0x40, 0xAF, 0x0F, 0x01, 0x60, 0xF0, }; static uint8_t dst[sizeof(src) * 4]; // 4x in case of GRAY to RGBA int src_bytes_per_pixel = 4; // QCMS_DATA_RGBA_8 if (src_type == QCMS_DATA_RGB_8) { src_bytes_per_pixel = 3; } else if (src_type == QCMS_DATA_GRAYA_8) { src_bytes_per_pixel = 2; } else if (src_type == QCMS_DATA_GRAY_8) { src_bytes_per_pixel = 1; } qcms_transform_data(transform, src, dst, sizeof(src) / src_bytes_per_pixel); qcms_transform_release(transform); }
void close() { decoder_source_mgr* src = (decoder_source_mgr*)m_info.src; if (src) fastFree(src); m_info.src = 0; #if USE(QCMSLIB) if (m_transform) qcms_transform_release(m_transform); m_transform = 0; #endif jpeg_destroy_decompress(&m_info); }
void close() { if (m_png && m_info) // This will zero the pointers. png_destroy_read_struct(&m_png, &m_info, 0); #if USE(QCMSLIB) if (m_transform) qcms_transform_release(m_transform); m_transform = 0; #endif delete[] m_interlaceBuffer; m_interlaceBuffer = 0; m_readOffset = 0; }
nsJPEGDecoder::~nsJPEGDecoder() { // Step 8: Release JPEG decompression object mInfo.src = nullptr; jpeg_destroy_decompress(&mInfo); PR_FREEIF(mBackBuffer); if (mTransform) qcms_transform_release(mTransform); if (mInProfile) qcms_profile_release(mInProfile); PR_LOG(gJPEGDecoderAccountingLog, PR_LOG_DEBUG, ("nsJPEGDecoder::~nsJPEGDecoder: Destroying JPEG decoder %p", this)); }
void test_gray(qcms_profile *output_profile) { unsigned char srct[3] = { 221, 79, 129}; unsigned char outt[3]; qcms_transform *transform; qcms_profile *gray_profile = qcms_profile_from_memory(gray_icc, sizeof(gray_icc)); if (gray_profile) { transform = qcms_transform_create(gray_profile, QCMS_DATA_GRAY_8, output_profile, QCMS_DATA_RGB_8, QCMS_INTENT_PERCEPTUAL); if (transform) { qcms_transform_data(transform, srct, outt, 1); qcms_transform_release(transform); } qcms_profile_release(gray_profile); } }
nsPNGDecoder::~nsPNGDecoder() { if (mPNG) png_destroy_read_struct(&mPNG, mInfo ? &mInfo : nullptr, nullptr); if (mCMSLine) nsMemory::Free(mCMSLine); if (interlacebuf) nsMemory::Free(interlacebuf); if (mInProfile) { qcms_profile_release(mInProfile); /* mTransform belongs to us only if mInProfile is non-null */ if (mTransform) qcms_transform_release(mTransform); } }
nsPNGDecoder::~nsPNGDecoder() { if (mPNG) { png_destroy_read_struct(&mPNG, mInfo ? &mInfo : nullptr, nullptr); } if (mCMSLine) { free(mCMSLine); } if (interlacebuf) { free(interlacebuf); } if (mInProfile) { qcms_profile_release(mInProfile); // mTransform belongs to us only if mInProfile is non-null if (mTransform) { qcms_transform_release(mTransform); } } }
void createColorTransform(const ColorProfile& colorProfile, bool hasAlpha) { if (m_transform) qcms_transform_release(m_transform); m_transform = 0; if (colorProfile.isEmpty()) return; qcms_profile* deviceProfile = ImageDecoder::qcmsOutputDeviceProfile(); if (!deviceProfile) return; qcms_profile* inputProfile = qcms_profile_from_memory(colorProfile.data(), colorProfile.size()); if (!inputProfile) return; // We currently only support color profiles for RGB profiled images. ASSERT(icSigRgbData == qcms_profile_get_color_space(inputProfile)); qcms_data_type dataFormat = hasAlpha ? QCMS_DATA_RGBA_8 : QCMS_DATA_RGB_8; // FIXME: Don't force perceptual intent if the image profile contains an intent. m_transform = qcms_transform_create(inputProfile, dataFormat, deviceProfile, dataFormat, QCMS_INTENT_PERCEPTUAL); qcms_profile_release(inputProfile); }
void WEBPImageDecoder::createColorTransform(const char* data, size_t size) { if (m_transform) qcms_transform_release(m_transform); m_transform = 0; qcms_profile* deviceProfile = ImageDecoder::qcmsOutputDeviceProfile(); if (!deviceProfile) return; qcms_profile* inputProfile = qcms_profile_from_memory(data, size); if (!inputProfile) return; // We currently only support color profiles for RGB profiled images. ASSERT(icSigRgbData == qcms_profile_get_color_space(inputProfile)); // The input image pixels are RGBA format. qcms_data_type format = QCMS_DATA_RGBA_8; // FIXME: Don't force perceptual intent if the image profile contains an intent. m_transform = qcms_transform_create(inputProfile, format, deviceProfile, QCMS_DATA_RGBA_8, QCMS_INTENT_PERCEPTUAL); qcms_profile_release(inputProfile); }
void clearColorTransform() { if (m_transform) qcms_transform_release(m_transform); m_transform = 0; }
void WEBPImageDecoder::clearColorTransform() { if (m_transform) qcms_transform_release(m_transform); m_transform = 0; }