filters

xcf-write.cc

00001 /* The GIMP -- an image manipulation program
00002  * Copyright (C) 1995 Spencer Kimball and Peter Mattis
00003  *
00004  * This program is free software; you can redistribute it and/or modify
00005  * it under the terms of the GNU General Public License as published by
00006  * the Free Software Foundation; either version 2 of the License, or
00007  * (at your option) any later version.
00008  *
00009  * This program is distributed in the hope that it will be useful,
00010  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00011  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012  * GNU General Public License for more details.
00013  *
00014  * You should have received a copy of the GNU General Public License
00015  * along with this program; if not, write to the Free Software
00016  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
00017  */
00018 
00019 #include "config.h"
00020 
00021 #include <stdio.h>
00022 #include <string.h> /* strlen */
00023 #include <errno.h>
00024 
00025 #ifdef HAVE_SYS_TYPES_H
00026 #include <sys/types.h>
00027 #endif
00028 
00029 #include <netinet/in.h>
00030 #include <limits.h>
00031 #include <stdlib.h>
00032 #include <cfloat>
00033 
00034 #include "xcf-write.h"
00035 
00036 Q_UINT32 xcf_write_int32  (FILE *fp, Q_INT32 *data, Q_INT32 count);
00037 {
00038     Q_INT32  tmp;
00039     Q_INT32    i;
00040 
00041     if (count > 0)
00042     {
00043         for (i = 0; i < count; i++)
00044         {
00045             tmp = htonl (data[i]);
00046             xcf_write_int8 (fp, (Q_UINT8*) &tmp, 4);
00047 
00048             if (fp->status() != IO_Ok)
00049             {
00050                 return i * 4;
00051             }
00052         }
00053     }
00054 
00055     return count * 4;
00056 }
00057 
00058 Q_UINT32 xcf_write_float  (FILE *fp, float *data, Q_INT32 count);
00059 {
00060     return xcf_write_int32 (fp, (Q_INT32 *)((void *)data), count, error);
00061 }
00062 
00063 Q_UINT32 xcf_write_int8 (FILE *fp, Q_UINT8 *data, Q_INT32 count);
00064 {
00065     Q_INT32  bytes;
00066     bytes = fp->writeBlock( data, count );
00067     return bytes;
00068 }
00069 
00070 Q_UINT32 xcf_write_string (FILE *fp, QCString *data, Q_INT32 count);
00071 {
00072     GError  *tmp_error = NULL;
00073     Q_INT32  tmp;
00074     Q_UINT32    total;
00075     Q_INT32     i;
00076 
00077     total = 0;
00078     for (i = 0; i < count; i++)
00079     {
00080         if (data[i])
00081             tmp = strlen (data[i]) + 1;
00082         else
00083             tmp = 0;
00084 
00085         xcf_write_int32 (fp, &tmp, 1, &tmp_error);
00086         if (tmp_error)
00087         {
00088             g_propagate_error (error, tmp_error);
00089             return total;
00090         }
00091 
00092         if (tmp > 0)
00093             xcf_write_int8 (fp, (Q_UINT8*) data[i], tmp, &tmp_error);
00094         if (tmp_error)
00095         {
00096             g_propagate_error (error, tmp_error);
00097             return total;
00098         }
00099 
00100         total += 4 + tmp;
00101     }
00102 
00103     return total;
00104 }
KDE Home | KDE Accessibility Home | Description of Access Keys