PHWinfo banniere

Titres
PORTAIL ANNUAIRE ARTICLES COMPARATEUR HÉBERGEURS DEVIS FORUMS RÉDUCTEUR D'URL
Précédent   PHWinfo > Autres forums > Forum Programmation & Conception > comp.lang.cplus > Processing PNG files... again..
S'inscrire FAQ Membres Recherche Messages du jour Marquer les forums comme lus
Processing PNG files... again..

Réponse
 
LinkBack Outils de la discussion
Vieux 17/10/2007, 16h37   #1
kaveee@gmail.com
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Processing PNG files... again..

Ok guys..

here's the code..
Of course I'm getting an error in the function.. imageMalloc_8u_C1..
cuz its not defined.. I'm not able to understand what its supposed to
do.. any wud be appreciated.



#include<iostream>
#include<math.h>
#include<string>
#include<sstream>
#include <fstream>
#include <png.h>
#include <zlib.h>
using namespace std;

int load_image_gray(const char *fn)
{
png_byte header[8]; // 8 is the maximum size that can be checked
png_structp png_ptr;
png_infop info_ptr;

/* open file and test for it being a png */
FILE *fp = fopen(fn, "rb");
if (!fp)
{
fprintf(stderr,"[read_png_file] File %s could not be opened for
reading", fn);
return 0x0;
}
fread(header, 1, 8, fp);
if (png_sig_cmp(header, 0, 8))
{
fprintf(stderr,"[read_png_file] File %s is not recognized as a PNG
file", fn);
return 0x0;
}

/* initialize stuff */
png_ptr = png_create_read_struct(PNG_LIBPNG_VER_STRING, NULL, NULL,
NULL);

if (!png_ptr)
{
fprintf(stderr,"[read_png_file] png_create_read_struct failed");
return 0x0;
}

info_ptr = png_create_info_struct(png_ptr);
if (!info_ptr)
{
fprintf(stderr,"[read_png_file] png_create_info_struct failed");
return 0x0;
}

if (setjmp(png_jmpbuf(png_ptr)))
{
fprintf(stderr,"[read_png_file] Error during init_io");
return 0x0;
}

png_init_io(png_ptr, fp);
png_set_sig_bytes(png_ptr, 8);

png_read_info(png_ptr, info_ptr);

int width = info_ptr->width;
int height = info_ptr->height;

if (info_ptr->bit_depth == 16)
png_set_strip_16(png_ptr);
if (info_ptr->color_type == PNG_COLOR_TYPE_RGB ||
info_ptr->color_type == PNG_COLOR_TYPE_RGB_ALPHA)
png_set_rgb_to_gray_fixed(png_ptr, 1, -1, -1);

png_set_interlace_handling(png_ptr);

// this call updates the info_ptr's members based on our calls...
png_read_update_info(png_ptr, info_ptr);

/* read file */
if (setjmp(png_jmpbuf(png_ptr)))
{
fprintf(stderr,"[read_png_file] Error during read_image");
return 0x0;
}

int step;
byte* buffer= imageMalloc_8u_C1(width,height,&step);

byte** row_pointers = (byte**) malloc(sizeof(byte) * height);
for (int y=0; y<height; y++)
row_pointers[y] = buffer + y*step;

png_read_image(png_ptr, row_pointers);

png_read_end(png_ptr,0x0);

//free(row_pointers); // this call is killing the program
// comment it out for now, but need to
understand
// why the crash is happening
png_free_data(png_ptr, info_ptr, PNG_FREE_ALL,-1);

fclose(fp);
return 0;
}

int main(int argc, char **argv)
{
if (argc != 1)
cout << "Usage: program_name <file_in>";
load_image_gray(argv[0]);
return 0;
}

  Réponse avec citation
Vieux 17/10/2007, 16h59   #2
Ben Bacarisse
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Processing PNG files... again..

kaveee@gmail.com writes:

> here's the code..

<snip>
> byte** row_pointers = (byte**) malloc(sizeof(byte) * height);


You want sizeof(byte *) here.

--
Ben.
  Réponse avec citation
Vieux 17/10/2007, 20h54   #3
Puppet_Sock
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Processing PNG files... again..

On Oct 17, 11:37 am, kav...@gmail.com wrote:
> Ok guys..
>
> here's the code..
> Of course I'm getting an error in the function.. imageMalloc_8u_C1..
> cuz its not defined.. I'm not able to understand what its supposed to
> do.. any wud be appreciated.
>
> #include<iostream>
> #include<math.h>
> #include<string>
> #include<sstream>
> #include <fstream>
> #include <png.h>
> #include <zlib.h>
> using namespace std;

[snip]

Insert the usual remarks about this.

Get used to prepending std:: to standard stuff.

> byte* buffer= imageMalloc_8u_C1(width,height,&step);

[snip]

That sure looks like it ought to be allocating some
memory for you. Note that I didn't check if you are
then deallocating it someplace.

Since that's the only place in your code the name
appears, and it's not standard, you need to "round
up the usual suspects."

- Did you spell the function name correctly? Don't
forget upper/lower case have to match, and the
numeral 1 looks a lot like the letter l.
- Did you give it the right list of args?
- Did you include the right header file and library?
- Is it in a namespace?
Socks

  Réponse avec citation
Réponse


Outils de la discussion

Règles de messages
Vous ne pouvez pas créer de nouvelles discussions
Vous ne pouvez pas envoyer des réponses
Vous ne pouvez pas envoyer des pièces jointes
Vous ne pouvez pas modifier vos messages

Les balises BB sont activées : oui
Les smileys sont activés : oui
La balise [IMG] est activée : oui
Le code HTML peut être employé : non
Trackbacks are oui
Pingbacks are oui
Refbacks are oui


Fuseau horaire GMT +1. Il est actuellement 05h43.


Édité par : vBulletin® version 3.7.2
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0 RC5 Tous droits réservés.
Version française #16 par l'association vBulletin francophone
PHWinfo est un site Éducation Sans Frontières
Ad Management by RedTyger
©Tous droits réservés par les parties respectives
Page generated in 0,09797 seconds with 11 queries