filters
xcf-read.cc00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019 #include "config.h"
00020
00021 #include <stdio.h>
00022
00023 #include <glib-object.h>
00024
00025 #include "libgimpbase/gimpbase.h"
00026
00027 #include "xcf-read.h"
00028
00029 #include "gimp-intl.h"
00030
00031
00032 Q_UINT32
00033 xcf_read_int32 (FILE *fp,
00034 Q_INT32 *data,
00035 Q_INT32 count)
00036 {
00037 Q_UINT32 total;
00038
00039 total = count;
00040 if (count > 0)
00041 {
00042 xcf_read_int8 (fp, (Q_UINT8 *) data, count * 4);
00043
00044 while (count--)
00045 {
00046 *data = g_ntohl (*data);
00047 data++;
00048 }
00049 }
00050
00051 return total * 4;
00052 }
00053
00054 Q_UINT32
00055 xcf_read_float (FILE *fp,
00056 float *data,
00057 Q_INT32 count)
00058 {
00059 return xcf_read_int32 (fp, (Q_INT32 *) ((void *) data), count);
00060 }
00061
00062 Q_UINT32
00063 xcf_read_int8 (FILE *fp,
00064 Q_UINT8 *data,
00065 Q_INT32 count)
00066 {
00067 Q_UINT32 total;
00068 Q_INT32 bytes;
00069
00070 total = count;
00071 while (count > 0)
00072 {
00073 bytes = fread ((char *) data, sizeof (char), count, fp);
00074 if (bytes <= 0)
00075 break;
00076 count -= bytes;
00077 data += bytes;
00078 }
00079
00080 return total;
00081 }
00082
00083 Q_UINT32
00084 xcf_read_string (FILE *fp,
00085 QCString **data,
00086 Q_INT32 count)
00087 {
00088 Q_INT32 tmp;
00089 Q_UINT32 total;
00090 Q_INT32 i;
00091
00092 total = 0;
00093 for (i = 0; i < count; i++)
00094 {
00095 total += xcf_read_int32 (fp, &tmp, 1);
00096 if (tmp > 0)
00097 {
00098 QCString *str;
00099
00100 str = g_new (QCString, tmp);
00101 total += xcf_read_int8 (fp, (Q_UINT8*) str, tmp);
00102
00103 if (str[tmp - 1] != '\0')
00104 str[tmp - 1] = '\0';
00105
00106 data[i] = gimp_any_to_utf8 (str, -1,
00107 _("Invalid UTF-8 string in XCF file"));
00108
00109 g_free (str);
00110 }
00111 else
00112 {
00113 data[i] = NULL;
00114 }
00115 }
00116
00117 return total;
00118 }
|