source: trunk/src/3rdparty/libmng/libmng_write.c

Last change on this file was 2, checked in by dmik, 20 years ago

Imported xplatform parts of the official release 3.3.1 from Trolltech

  • Property svn:keywords set to Id
File size: 6.2 KB
Line 
1/* ************************************************************************** */
2/* * For conditions of distribution and use, * */
3/* * see copyright notice in libmng.h * */
4/* ************************************************************************** */
5/* * * */
6/* * project : libmng * */
7/* * file : libmng_write.c copyright (c) 2000 G.Juyn * */
8/* * version : 1.0.0 * */
9/* * * */
10/* * purpose : Write management (implementation) * */
11/* * * */
12/* * author : G.Juyn * */
13/* * web : http://www.3-t.com * */
14/* * email : mailto:info@3-t.com * */
15/* * * */
16/* * comment : implementation of the write management routines * */
17/* * * */
18/* * changes : 0.5.1 - 05/08/2000 - G.Juyn * */
19/* * - changed strict-ANSI stuff * */
20/* * 0.5.1 - 05/12/2000 - G.Juyn * */
21/* * - changed trace to macro for callback error-reporting * */
22/* * 0.5.1 - 05/16/2000 - G.Juyn * */
23/* * - moved the actual write_graphic functionality from * */
24/* * mng_hlapi to it's appropriate function here * */
25/* * * */
26/* * 0.9.1 - 07/19/2000 - G.Juyn * */
27/* * - fixed writing of signature * */
28/* * * */
29/* * 0.9.2 - 08/05/2000 - G.Juyn * */
30/* * - changed file-prefixes * */
31/* * * */
32/* ************************************************************************** */
33
34#include "libmng.h"
35#include "libmng_data.h"
36#include "libmng_error.h"
37#include "libmng_trace.h"
38#ifdef __BORLANDC__
39#pragma hdrstop
40#endif
41#include "libmng_memory.h"
42#include "libmng_chunks.h"
43#include "libmng_chunk_io.h"
44#include "libmng_write.h"
45
46#if defined(__BORLANDC__) && defined(MNG_STRICT_ANSI)
47#pragma option -A /* force ANSI-C */
48#endif
49
50/* ************************************************************************** */
51
52#ifdef MNG_INCLUDE_WRITE_PROCS
53
54/* ************************************************************************** */
55
56mng_retcode write_graphic (mng_datap pData)
57{
58 mng_chunkp pChunk;
59 mng_retcode iRetcode;
60 mng_uint32 iWritten;
61
62#ifdef MNG_SUPPORT_TRACE
63 MNG_TRACE (pData, MNG_FN_WRITE_GRAPHIC, MNG_LC_START)
64#endif
65
66 pChunk = pData->pFirstchunk; /* we'll start with the first, thank you */
67
68 if (pChunk) /* is there anything to write ? */
69 { /* open the file */
70 if (!pData->fOpenstream ((mng_handle)pData))
71 MNG_ERROR (pData, MNG_APPIOERROR)
72 else
73 {
74 pData->bWriting = MNG_TRUE; /* indicate writing */
75 pData->iWritebufsize = 32768; /* get a temporary write buffer */
76 /* reserve 12 bytes for length, chunkname & crc */
77 MNG_ALLOC (pData, pData->pWritebuf, pData->iWritebufsize+12)
78 /* write the signature */
79 if (((mng_chunk_headerp)pChunk)->iChunkname == MNG_UINT_IHDR)
80 mng_put_uint32 (pData->pWritebuf, PNG_SIG);
81 else
82 if (((mng_chunk_headerp)pChunk)->iChunkname == MNG_UINT_JHDR)
83 mng_put_uint32 (pData->pWritebuf, JNG_SIG);
84 else
85 mng_put_uint32 (pData->pWritebuf, MNG_SIG);
86
87 mng_put_uint32 (pData->pWritebuf+4, POST_SIG);
88
89 if (!pData->fWritedata ((mng_handle)pData, pData->pWritebuf, 8, &iWritten))
90 {
91 MNG_FREE (pData, pData->pWritebuf, pData->iWritebufsize+12)
92 MNG_ERROR (pData, MNG_APPIOERROR)
93 }
94
95 if (iWritten != 8) /* disk full ? */
96 {
97 MNG_FREE (pData, pData->pWritebuf, pData->iWritebufsize+12)
98 MNG_ERROR (pData, MNG_OUTPUTERROR)
99 }
100
101 while (pChunk) /* so long as there's something to write */
102 { /* let's call it's output routine */
103 iRetcode = ((mng_chunk_headerp)pChunk)->fWrite (pData, pChunk);
104
105 if (iRetcode) /* on error bail out */
106 {
107 MNG_FREE (pData, pData->pWritebuf, pData->iWritebufsize+12)
108 return iRetcode;
109 }
110 /* neeeext */
111 pChunk = ((mng_chunk_headerp)pChunk)->pNext;
112 }
113 /* free the temporary buffer */
114 MNG_FREE (pData, pData->pWritebuf, pData->iWritebufsize+12)
115
116 pData->bWriting = MNG_FALSE; /* done writing */
117 /* close the stream now */
118 if (!pData->fClosestream ((mng_handle)pData))
119 MNG_ERROR (pData, MNG_APPIOERROR)
120
121 }
122 }
123
124#ifdef MNG_SUPPORT_TRACE
125 MNG_TRACE (pData, MNG_FN_WRITE_GRAPHIC, MNG_LC_END)
126#endif
127
128 return MNG_NOERROR;
129}
130
131/* ************************************************************************** */
132
133#endif /* MNG_INCLUDE_WRITE_PROCS */
134
135/* ************************************************************************** */
136/* * end of file * */
137/* ************************************************************************** */
138
139
Note: See TracBrowser for help on using the repository browser.