Skip to content

Commit

Permalink
GUF and PicoTXT files now contain the 8BF filename
Browse files Browse the repository at this point in the history
GUF files are not loaded and saved as UTF-8 (without BOM)


git-svn-id: https://svn.viathinksoft.com/svn/filter_foundry/trunk@606 1b5a0048-3058-4200-831f-25aa9e3a14b9
  • Loading branch information
danielmarschall committed Nov 12, 2024
1 parent 242278a commit 73e6323
Show file tree
Hide file tree
Showing 4 changed files with 334 additions and 25 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
## 1.7.0.23 [??-Nov-2024]
- `src()`, `rad()`, and `cnv()` are now compatible with 16-bit and 32-bit color spaces
- Changed upper limit of Lab a-axis and b-axis to from 16383 to 16256
- GUF and PicoTXT files now contain the 8BF filename
- GUF files are not loaded and saved as UTF-8 (without BOM)

## 1.7.0.22 [10-Nov-2024]
- Added support for 16-bit and 32-bit color spaces!
Expand Down
4 changes: 2 additions & 2 deletions ff.h
Original file line number Diff line number Diff line change
Expand Up @@ -189,8 +189,8 @@ FFLoadingResult readPARM(PARM_T* parm,Ptr h);
// from save.c:

FFSavingResult saveparams_afs_pff(Handle h, Boolean premiereOrder);
FFSavingResult saveparams_picotxt(Handle h);
FFSavingResult saveparams_guf(Handle h);
FFSavingResult saveparams_picotxt(Handle h, TCHAR* filename);
FFSavingResult saveparams_guf(Handle h, TCHAR* filename);
OSErr savehandleintofile(Handle h,FILEREF r);
FFSavingResult savefile_afs_pff_picotxt_guf(StandardFileReply *sfr);

Expand Down
71 changes: 69 additions & 2 deletions read.c
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/

// TODO: Change Windows1252 methods to the current codepage of the system. Note that we should stay compatible with Windows 3.11 if possible

#include "ff.h"

#include "file_compat.h"
Expand Down Expand Up @@ -844,19 +846,84 @@ Boolean _gufReadProperty(char* fileContents, size_t argMaxInputLength, const cha
return true;
}

// Funktion zur Konvertierung von UTF-8 nach Windows-1252 in-place
void _utf8_to_windows1252(unsigned char* utf8, unsigned char* ansi, FILECOUNT* count) {
int togo = *count;
while (togo > 0) {
unsigned char byte = *utf8;

if (byte <= 0x7F) {
// Ein einzelnes Byte für ASCII-Zeichen
*ansi = byte;
ansi++;
utf8++; // Gehe zum nächsten Zeichen
togo -= 1;
} else if ((byte >= 0xC2 && byte <= 0xDF) && (*(utf8 + 1) >= 0x80 && *(utf8 + 1) <= 0xBF)) {
// Zwei-Byte UTF-8-Zeichen
unsigned char byte2 = *(utf8 + 1);
unsigned int codepoint = ((byte & 0x1F) << 6) | (byte2 & 0x3F);

if (codepoint <= 0xFF) {
// Wenn der Codepoint im Bereich von Windows-1252 liegt, füge ihn hinzu
*ansi = (char)codepoint;
ansi++;
utf8 += 2;
togo -= 2;
*count -= 1;
} else {
// Andernfalls ersetze es durch '?'
*ansi = '?';
ansi++;
utf8++;
togo -= 1;
}
}
else if ((byte >= 0xE0 && byte <= 0xEF) && (*(utf8 + 1) >= 0x80 && *(utf8 + 1) <= 0xBF) && (*(utf8 + 2) >= 0x80 && *(utf8 + 2) <= 0xBF)) {
// Drei-Byte UTF-8-Zeichen
unsigned char byte2 = *(utf8 + 1);
unsigned char byte3 = *(utf8 + 2);
unsigned int codepoint = ((byte & 0x0F) << 12) | ((byte2 & 0x3F) << 6) | (byte3 & 0x3F);

if (codepoint <= 0xFF) {
// Wenn der Codepoint im Bereich von Windows-1252 liegt, füge ihn hinzu
*ansi = (char)codepoint;
ansi++;
utf8 += 3;
togo -= 3;
*count -= 2;
} else {
// Andernfalls ersetze es durch '?'
*ansi = '?';
ansi++;
utf8++;
togo -= 1;
}
} else {
// Ungültige UTF-8-Zeichen oder Zeichen, die nicht konvertiert werden können, ersetzen
*ansi = '?';
ansi++;
utf8++;
togo -= 1;
}
}
}

FFLoadingResult readfile_guf(StandardFileReply* sfr) {
Handle h;
FFLoadingResult res = FF_LOADING_RESULT(MSG_LOADFILE_UNKNOWN_FORMAT_ID);
FILEREF refnum;

// TODO: Decode UTF-8 to ANSI (or "?" for unknown characters)

if (FSpOpenDF(&sfr->sfFile, fsRdPerm, &refnum) == noErr) {
if ((h = readfileintohandle(refnum))) {
FILECOUNT count = (FILECOUNT)PIGETHANDLESIZE(h);
char* q = PILOCKHANDLE(h, false);
char protocol[256];

unsigned char* ansiFileContents = (unsigned char*)malloc(count);
_utf8_to_windows1252((unsigned char*)q, ansiFileContents, &count);
memcpy(q, ansiFileContents, count);
free(ansiFileContents);

if (!_gufReadProperty(q, count, "GUF", "Protocol", protocol, sizeof(protocol))) {
res = FF_LOADING_RESULT(MSG_INVALID_FILE_SIGNATURE_ID);
} else if (strcmp(protocol, "1") != 0) {
Expand Down
Loading

0 comments on commit 73e6323

Please sign in to comment.