~barcc/+junk/antigrav-bc

« back to all changes in this revision

Viewing changes to src/m3dtexture.cpp

  • Committer: B. Clausius
  • Date: 2011-11-04 15:44:46 UTC
  • mfrom: (6.1.1 oneiric)
  • Revision ID: barcc@gmx.de-20111104154446-nei9eub99e3fb3ou
* Merged from oneiric
* Upload to unstable
* Switched to format 3.0 (quilt)
* Applied patch courtesy of Mario Lang <mlang@debian.org> to fix few
  DACA-detected problems (closes: #610305) (03_daca_fixes.diff)
* Adding ${misc:Depends} for potential dh-induced dependencies
* Switched build system to a pure dh 7 debian/rules (and, in passing, I
  cannot help but express my gratitude to the authors of the dh sequencer)
* Conforms to standards 3.9.1
* Patch 04-height-selection.diff to provide a -H option to allow the
  user to change the aspect ratio (closes: #538910)

Show diffs side-by-side

added added

removed removed

Lines of Context:
104
104
                if(loadPNG(texUnits[n].filename.c_str(), &data, &(texUnits[n].width), &(texUnits[n].height)) != 0)
105
105
                {
106
106
                        fprintf(stderr, "Invalid: can't load texture %s\n", texUnits[n].filename.c_str());
 
107
                        fprintf(stderr, "Width %u, Height %u\n",&(texUnits[n].width), &(texUnits[n].height));
107
108
                        return -1;
108
109
                }
109
110
                
148
149
                if(loadPNG(texUnits[n].filename.c_str(), &data, &(texUnits[n].width), &(texUnits[n].height)) != 0)
149
150
                {
150
151
                        fprintf(stderr, "Invalid: can't load texture %s\n", texUnits[n].filename.c_str());
 
152
                        fprintf(stderr, "Width %u, Height %u\n",&(texUnits[n].width), &(texUnits[n].height));
151
153
                        return -1;
152
154
                }
153
155
                
204
206
        @param height a pointer where to store the image width
205
207
        @return 0 on success, -1 on failure
206
208
*/
207
 
int m3dTexture::loadPNG(const char *filename, unsigned char **data, unsigned int *width, unsigned int *height)
 
209
int m3dTexture::loadPNG(const char *filename, unsigned char **data, png_uint_32 *width, png_uint_32 *height)
208
210
{
209
211
        FILE *f;
210
212
        int result;
221
223
        return result;
222
224
}
223
225
 
224
 
int m3dTexture::loadPNG(unsigned char **data, unsigned int *width, unsigned int *height, void *handle, void (*pngReadCallback)(png_structp ctx, png_bytep area, png_size_t size))
 
226
int m3dTexture::loadPNG(unsigned char **data, png_uint_32 *width, png_uint_32 *height, void *handle, void (*pngReadCallback)(png_structp ctx, png_bytep area, png_size_t size))
225
227
{
226
228
        png_structp pngPtr;
227
229
        png_infop pngInfoPtr;
258
260
        png_set_read_fn(pngPtr, handle, pngReadCallback);
259
261
 
260
262
        png_read_info(pngPtr, pngInfoPtr);
261
 
        png_get_IHDR(pngPtr, pngInfoPtr, (png_uint_32*)width, (png_uint_32*)height, &bitDepth, &colorType, &interlaceType, NULL, NULL);
 
263
        png_get_IHDR(pngPtr, pngInfoPtr, width, height, &bitDepth, &colorType, &interlaceType, NULL, NULL);
262
264
 
263
265
        png_set_strip_16(pngPtr);
264
266
 
279
281
        }
280
282
        
281
283
        png_read_update_info(pngPtr, pngInfoPtr);
282
 
        png_get_IHDR(pngPtr, pngInfoPtr, (png_uint_32*)width, (png_uint_32*)height, &bitDepth, &colorType, &interlaceType, NULL, NULL);
 
284
        png_get_IHDR(pngPtr, pngInfoPtr, width, height, &bitDepth, &colorType, &interlaceType, NULL, NULL);
283
285
        
284
286
        (*data) = new unsigned char[(*width) * (*height) * pngInfoPtr->channels];
285
287
        if((*data) == NULL)
312
314
        return 0;
313
315
}
314
316
 
315
 
int m3dTexture::savePNG(const char *filename, const unsigned char *data, unsigned int width, unsigned int height)
 
317
int m3dTexture::savePNG(const char *filename, const unsigned char *data, png_uint_32 width, png_uint_32 height)
316
318
{
317
319
        FILE *f;
318
320
        int result;
345
347
        fflush(f);
346
348
}
347
349
 
348
 
int m3dTexture::savePNG(const unsigned char *data, unsigned int width, unsigned int height, void *handle, void (*pngWriteCallback)(png_structp pngPtr, png_bytep data, png_size_t length), void (*pngFlushCallback)(png_structp pngPtr))
 
350
int m3dTexture::savePNG(const unsigned char *data, png_uint_32 width, png_uint_32 height, void *handle, void (*pngWriteCallback)(png_structp pngPtr, png_bytep data, png_size_t length), void (*pngFlushCallback)(png_structp pngPtr))
349
351
{
350
352
        png_structp pngPtr;
351
353
        png_infop pngInfoPtr;
382
384
 
383
385
        png_write_image(pngPtr, rowPointers);
384
386
        png_write_end(pngPtr, pngInfoPtr);
385
 
        delete rowPointers;
 
387
        delete[] rowPointers;
386
388
        png_destroy_write_struct(&pngPtr, &pngInfoPtr);
387
389
        return 0;
388
390
}
423
425
        
424
426
        if(savePNG(filename, data, width, height) != 0)
425
427
        {
426
 
                delete data;
 
428
                delete[] data;
427
429
                return -1;
428
430
        }
429
431
        
430
 
        delete data;
 
432
        delete[] data;
431
433
        return 0;
432
434
}
433
435
 
435
437
GLuint m3dTexture::loadTexture(const char *filename)
436
438
{
437
439
        unsigned char *data;
438
 
        unsigned int width, height;
 
440
        png_uint_32 width, height;
439
441
        GLuint tex;
440
442
        
441
443
        glGenTextures(1, &tex);
443
445
        if(m3dTexture::loadPNG(filename, &data, &width, &height) != 0)
444
446
        {
445
447
                fprintf(stderr, "Can't load texture %s\n", filename);
 
448
                fprintf(stderr, "Width %d, Height %d\n",&width, &height);
446
449
                return 0;
447
450
        }
448
451