Subversion Repositories pentevo

Rev

Rev 883 | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 883 Rev 1081
Line 43... Line 43...
43
static png_set_filter_ptr png_set_filter_p = nullptr;
43
static png_set_filter_ptr png_set_filter_p = nullptr;
44
 
44
 
45
static HMODULE PngDll = nullptr;
45
static HMODULE PngDll = nullptr;
46
bool PngInit()
46
bool PngInit()
47
{
47
{
-
 
48
#if defined(_WIN64) || defined(AMD64)
-
 
49
        PngDll = LoadLibrary("libpng64.dll");
-
 
50
#else
48
    PngDll = LoadLibrary("libpng12.dll");
51
        PngDll = LoadLibrary("libpng16.dll");
-
 
52
#endif
49
    if(!PngDll)
53
    if(!PngDll)
50
        return false;
54
        return false;
51
    png_error_p = (png_error_ptr)GetProcAddress(PngDll, "png_error");
55
    png_error_p = (png_error_ptr)GetProcAddress(PngDll, "png_error");
52
    if(!png_error_p)
56
    if(!png_error_p)
53
        return false;
57
        return false;
Line 93... Line 97...
93
        FreeLibrary(PngDll);
97
        FreeLibrary(PngDll);
94
}
98
}
95
 
99
 
96
static png_structp png_ptr = nullptr;
100
static png_structp png_ptr = nullptr;
97
static png_infop info_ptr = nullptr;
101
static png_infop info_ptr = nullptr;
-
 
102
static FILE *io_ptr;
98
 
103
 
99
static void
104
static void
100
PNGAPI
105
PNGAPI
101
png_write_data(png_structp png_ptr, png_bytep data, png_size_t length)
106
png_write_data(png_structp png_ptr, png_bytep data, png_size_t length)
102
{
107
{
103
   size_t check;
108
   size_t check;
104
 
109
 
105
   check = fwrite(data, 1, length, (FILE *)(png_ptr->io_ptr));
110
   check = fwrite(data, 1, length, (FILE *)(io_ptr));
106
   if (check != length)
111
   if (check != length)
107
   {
112
   {
108
      png_error_p(png_ptr, "Write Error");
113
      png_error_p(png_ptr, "Write Error");
109
   }
114
   }
110
}
115
}
111
 
116
 
112
static void
117
static void
113
PNGAPI
118
PNGAPI
114
png_flush(png_structp png_ptr)
119
png_flush(png_structp png_ptr)
115
{
120
{
-
 
121
        /*
116
   FILE *io_ptr;
122
   FILE *io_ptr;
117
   io_ptr = (FILE *)CVT_PTR((png_ptr->io_ptr));
123
   io_ptr = (FILE *)CVT_PTR((png_ptr->io_ptr));
-
 
124
   */
118
   if (io_ptr != nullptr)
125
        if (io_ptr != nullptr)
119
      fflush(io_ptr);
126
      fflush(io_ptr);
-
 
127
 
120
}
128
}
121
 
129
 
122
BOOL PngSaveImage (FILE *pfFile, png_byte *pDiData,
130
BOOL PngSaveImage (FILE *pfFile, png_byte *pDiData,
123
                   int iWidth, int iHeight, png_color bkgColor)
131
                   int iWidth, int iHeight, png_color bkgColor)
124
{
132
{
Line 148... Line 156...
148
        png_destroy_write_struct_p(&png_ptr, (png_infopp) nullptr);
156
        png_destroy_write_struct_p(&png_ptr, (png_infopp) nullptr);
149
        return FALSE;
157
        return FALSE;
150
    }
158
    }
151
 
159
 
152
    // initialize the png structure
160
    // initialize the png structure
-
 
161
        io_ptr = pfFile;
153
    png_set_write_fn_p(png_ptr, (png_voidp)pfFile, png_write_data, png_flush);
162
    png_set_write_fn_p(png_ptr, (png_voidp)pfFile, (png_rw_ptr)png_write_data, png_flush);
154
   
163
   
155
    // we're going to write a very simple 3x8 bit RGB image
164
    // we're going to write a very simple 3x8 bit RGB image
156
    png_set_IHDR_p(png_ptr, info_ptr, png_uint_32(iWidth), png_uint_32(iHeight), ciBitDepth,
165
    png_set_IHDR_p(png_ptr, info_ptr, png_uint_32(iWidth), png_uint_32(iHeight), ciBitDepth,
157
        PNG_COLOR_TYPE_RGB, PNG_INTERLACE_NONE, PNG_COMPRESSION_TYPE_BASE,
166
        PNG_COLOR_TYPE_RGB, PNG_INTERLACE_NONE, PNG_COMPRESSION_TYPE_BASE,
158
        PNG_FILTER_TYPE_BASE);
167
        PNG_FILTER_TYPE_BASE);
Line 181... Line 190...
181
   
190
   
182
    // and we're done
191
    // and we're done
183
    free (ppbRowPointers);
192
    free (ppbRowPointers);
184
    ppbRowPointers = nullptr;
193
    ppbRowPointers = nullptr;
185
   
194
 
-
 
195
       
-
 
196
   
186
    // clean up after the write, and free any memory allocated
197
    // clean up after the write, and free any memory allocated
187
    png_destroy_write_struct_p(&png_ptr, (png_infopp) nullptr);
198
    png_destroy_write_struct_p(&png_ptr, (png_infopp) nullptr);
188
   
199
   
189
    return TRUE;
200
    return TRUE;
190
}
201
}