Fix #4565 : Segfault saving image using RTv2_sRGB.icc

Also, replace identing tabs by spaces in some files
This commit is contained in:
Hombre 2018-05-19 00:19:06 +02:00
parent aca72b5641
commit b06e07034e
5 changed files with 100 additions and 76 deletions

View File

@ -1684,7 +1684,6 @@ cmsHPROFILE rtengine::ICCStore::createCustomGammaOutputProfile(const procparams:
}
cmsMLUsetWide(mlu, "en", "US", gammaWs.str().c_str());
cmsMLUfree(description);
// instruction with //ICC are used to generate ICC profile

View File

@ -330,12 +330,19 @@ Imagefloat* ImProcFunctions::lab2rgbOut(LabImage* lab, int cx, int cy, int cw, i
if (count) {
wchar_t *buffer = new wchar_t[count];
count = cmsMLUgetWide(modelDescMLU, "eng", "USA", buffer, count); // now put the string in the buffer
Glib::ustring modelDesc;
#if __SIZEOF_WCHAR_T__ == 2
char* cModelDesc = g_utf16_to_utf8((unsigned short int*)buffer, -1, nullptr, nullptr, nullptr); // convert to utf-8 in a buffer allocated by glib
delete [] buffer;
if (cModelDesc) {
Glib::ustring modelDesc(cModelDesc);
modelDesc.assign(cModelDesc);
g_free(cModelDesc);
// printf("dmdd=%s\n", modelDesc.c_str());
}
#else
modelDesc = utf32_to_utf8(buffer, count);
#endif
delete [] buffer;
if (!modelDesc.empty()) {
printf("dmdd=%s\n", modelDesc.c_str());
std::size_t pos = modelDesc.find("g");
std::size_t posmid = modelDesc.find("s");
@ -569,14 +576,12 @@ Imagefloat* ImProcFunctions::workingtrc(Imagefloat* working, int cw, int ch, int
p[4] = 0.0366;
p[5] = 0.0001;
} else {
p[0] = 0.7347; //default primaries always unused
p[1] = 0.2653;
p[2] = 0.1596;
p[3] = 0.8404;
p[4] = 0.0366;
p[5] = 0.0001;
}
if (slpos == 0) {
@ -632,18 +637,15 @@ Imagefloat* ImProcFunctions::workingtrc(Imagefloat* working, int cw, int ch, int
float* ya = (float*)image->g(i);
float* za = (float*)image->b(i);
for (int j = 0; j < cw; j++) {
float r1 = rr[j];
float g1 = rg[j];
float b1 = rb[j];
float x_ = toxyz[0][0] * r1 + toxyz[0][1] * g1 + toxyz[0][2] * b1;
float y_ = toxyz[1][0] * r1 + toxyz[1][1] * g1 + toxyz[1][2] * b1;
float z_ = toxyz[2][0] * r1 + toxyz[2][1] * g1 + toxyz[2][2] * b1;
xa[j] = ( x_) ;
ya[j] = ( y_);
za[j] = ( z_);

View File

@ -265,3 +265,21 @@ void swab(const void* from, void* to, ssize_t n)
}
}
#if __SIZEOF_WCHAR_T__ == 4
Glib::ustring utf32_to_utf8(wchar_t* UTF32Buffer, size_t sizeOfUTF32Buffer)
{
char *buffer2 = new char[sizeOfUTF32Buffer];
char *pBuffer2 = buffer2;
gchar a[6];
for (size_t i=0; i < sizeOfUTF32Buffer/4; ++i) {
gint bytesWritten = g_unichar_to_utf8((gunichar)UTF32Buffer[i], a);
for (gint j=0; j < bytesWritten; ++j) {
*(pBuffer2++) = a[j];
}
}
Glib::ustring modelDesc(buffer2);
delete [] buffer2;
return buffer2;
}
#endif

View File

@ -55,3 +55,8 @@ bool hasPngExtension(const Glib::ustring& filename);
void swab(const void* from, void* to, ssize_t n);
}
#if __SIZEOF_WCHAR_T__ == 4
Glib::ustring utf32_to_utf8(wchar_t* UTF32Buffer, size_t sizeOfUTF32Buffer);
#endif