-
Notifications
You must be signed in to change notification settings - Fork 77
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add Linux Port #9
Conversation
Hi, Did you get #8? |
I have #8,but it doesnot fix the issue, |
If I understand you correctly, writing PSDs now works, but reading the image resources section is still broken? |
Yes,But not all image resources sections were broken,only two sections are still broken |
After debugging And this section type is WINDOWS_DEVMODE
I don’t think the issue come from I/O Reading and writing psd now works normally,except for this secetion Sorry for my poor english |
One byte off sounds like a round-up-to-2/4/8 is missing somewhere. If you look at PsdParseDocument.cpp, the offsets into different sections are all grabbed when creating the document in Create(). I'm not sure if the code has to round up those offsets to the next even value, I'll have to check the PSD spec on that. One question though: does this happen with the default PSD file that ships with the sample code? |
It does |
Ah wait, this is not an off-by-one error. If your code is pointing at offset 16635, I would think GetPosition() does not work correctly on Linux yet. |
Emm,SyncFileReader::GetPosition just return m_postion
I donnot know which part was wrong Reading the section at offset 34 is succeed, |
Apologies, I just noticed that the Windows code also reads from offset 16635, so there's still a bug in there somewhere. |
I just fixed this in 91643c3, can you please give this another try? |
OK,It works on Linux |
@MolecularMatters Did you complete the code review?It now works |
src/Samples/PsdSamples.cpp
Outdated
#ifdef _WIN32 | ||
//In Windows wchar_t is utf16 | ||
static_assert(sizeof(wchar_t) == sizeof(uint16_t)); | ||
layerName << reinterpret_cast<wchar_t*>(layer->utf16Name); | ||
#else | ||
//In Linux, wchar_t is utf32 | ||
//Convert code from https://stackoverflow.com/questions/23919515/how-to-convert-from-utf-16-to-utf-32-on-linux-with-std-library#comment95663809_23920015 | ||
//We cannot use C++11,so use macro instead of lambda | ||
#define is_surrogate(uc) ( (uc - 0xd800u) < 2048u ) | ||
#define is_high_surrogate(uc) ( (uc & 0xfffffc00) == 0xd800 ) | ||
#define is_low_surrogate(uc) ( (uc & 0xfffffc00) == 0xdc00 ) | ||
#define surrogate_to_utf32(high,low) ((high << 10) + low - 0x35fdc00) | ||
static_assert(sizeof(wchar_t) == sizeof(uint32_t)); | ||
|
||
//Begin convert | ||
size_t u16len = 0; | ||
const uint16_t * cur = layer->utf16Name; | ||
while(*cur != uint16_t('\0')){ | ||
cur++; | ||
u16len++; | ||
} | ||
//Len it | ||
|
||
const uint16_t * const end = layer->utf16Name + u16len; | ||
const uint16_t * input = layer->utf16Name; | ||
while (input < end) { | ||
const uint16_t uc = *input++; | ||
if (!is_surrogate(uc)) { | ||
layerName << wchar_t(uc); | ||
} | ||
else { | ||
if (is_high_surrogate(uc) && input < end && is_low_surrogate(*input)){ | ||
layerName << wchar_t(surrogate_to_utf32(uc, *input++)); | ||
} | ||
else{ | ||
// Error | ||
// Impossible | ||
std::abort(); | ||
} | ||
} | ||
} | ||
#undef is_surrogate | ||
#undef is_high_surrogate | ||
#undef is_low_surrogate | ||
#undef surrogate_to_utf32 | ||
#endif |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it would be fine to use C++11 in this part of the sample code, which would probably simplify it a lot.
We could also make it so that when using a pre-C++11 compiler under Linux, the layername simply won't be output, so that the code doesn't require C++11, but rather uses it if available.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I could not find the way to convert utf16 to utf32 with std library
src/Samples/PsdTgaExporter.cpp
Outdated
#include <cwchar> | ||
#include <cstring> | ||
#include <cstdlib> | ||
#define OutputDebugStringA(S) fputs(S,stderr) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it would be better to also put this into a separate file.
Maybe get rid of OutputDebugString altogether and change it into something platform-agnostic, which then calls OutputDebugStringA on Windows, and fputs on Linux?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I had put them into PsdDebug.h
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for your effort so far!
I think the code can be improved by paying a bit more attention to details, see my review comments.
Ok,I had finished it |
Did any where need to be changed? |
Apologies, this fell off the radar last week. |
Hi,
I have made a linux port for it,It can be compiled
But when I run the test,the tga file has be exported
the psd file could not be exoported,