• Viernes 26 de Abril de 2024, 05:11

Autor Tema:  Problema Reservando Array  (Leído 1273 veces)

warren

  • Nuevo Miembro
  • *
  • Mensajes: 10
    • Ver Perfil
Problema Reservando Array
« en: Viernes 9 de Marzo de 2007, 19:01 »
0
Hola,

Tengo un problema en un proyecto q estoy realizando.
El proyecto consiste en leer un fichero .bmp
Todo muy bien, la lectura y tal..
El problema viene al declarar una structura para almacenar los Pixeles:

Código: Text
  1. struct Pixel{
  2.  
  3.     int R,G,B;
  4. };
  5.  
  6.  

tmb declaro un array de esa estructura, el array bidimensional lo defino de tamaño 500x500

Pixel Data[MAXWIDTH][MAXHEIGHT];

pero al compilar el programa me peta al llegar (supongo) a la declaracion del array,
si pruebo con un tamaño menor q 500 funciona. Pero un dato mas importante, el proyecto lo estoy haciendo con el Code::Blocks, pero si pruebo el proyecto con el Dev-Cpp funciona perfectamente. Pero necesito hacerlo obligatoriamente con Code::Blocks.
El debugger no me da demasiada informacion, el backtrace me dice q la rotura se produce en la funcion probe(), q yo no defino, ni sé q es...

La verdad, no tengo ni idea de por q puede ser esto.
Alguien me puede ayudar??
Gracias por adelantado

JuanK

  • Miembro de ORO
  • ******
  • Mensajes: 5393
  • Nacionalidad: co
    • Ver Perfil
    • http://juank.io
Re: Problema Reservando Array
« Respuesta #1 en: Viernes 9 de Marzo de 2007, 19:47 »
0
hay muy poca informacion, seria mejor si colocas el código completo.

por otro lado puede que este mal configurado el code blocks.
[size=109]Juan Carlos Ruiz Pacheco
[/size]
Microsoft Technical Evangelist
@JuanKRuiz
http://juank.io

warren

  • Nuevo Miembro
  • *
  • Mensajes: 10
    • Ver Perfil
Re: Problema Reservando Array
« Respuesta #2 en: Viernes 9 de Marzo de 2007, 19:49 »
0
ahi va el codigo completo:


Código: Text
  1.  
  2.  
  3. #define MAXWIDTH 400
  4. #define MAXHEIGHT 400
  5.  
  6. struct BITMAPFILEHEADER{
  7.  
  8.     //bfType 2bytes
  9.     int bfSize;
  10.     //bfReserved1
  11.     //bfReserved2
  12.     int bfOffBits;
  13. };
  14.  
  15. struct BITMAPINFOHEADER{
  16.  
  17.     int biSize; //tamaño de esta estructura
  18.     int biWidth; //ancho en pixels
  19.     int biHeight; // alto en pixels
  20.     //biPlanes 2bytes must be zero
  21.     //biBitCount 2bytes nº de bytes per pixel
  22.     int biCompression; //tipo de compresion, 0= no compresion
  23.     int biSizeImage; //tamaño de la imagen, sin compresion = 0
  24.     int biXPelsPerMeter; //specifies the the horizontal pixels per meter on the
  25.                         //designated targer device, usually set to zero
  26.     int biYPelsPerMeter;//specifies the the vertical pixels per meter on the
  27.                         //designated targer device, usually set to zero.
  28.     int biClrUsed;//specifies the number of colors used in the bitmap, if set to
  29.                 //zero the number of colors is calculated using the biBitCount member.
  30.     int biClrImportant;//specifies the number of color that are 'important' for the bitmap,
  31.                       // if set to zero, all colors are important
  32. };
  33.  
  34.  
  35.  
  36. /*****************************************
  37. Struct pixel: tres componentes RGB
  38. Su lectura se realiza al reves: BGR
  39. y se leen del fichero sobre un char
  40. para cuadrar con  el Byte q ocupa cada una
  41. ******************************************/
  42. struct Pixel{
  43.  
  44.     int R,G,B;
  45. };
  46.  
  47.  
  48.  
  49.  
  50. /*********************************************
  51. clase BitMap
  52. Almacena el fichero bmp para el pathfinding
  53. Dos estructuras básicas y la image data
  54. **********************************************/
  55. class BitMap{
  56.  
  57.  
  58.     public:
  59.         void loadFile(char* cad);
  60.         void ParseFile(void);
  61.     private:
  62.  
  63.         struct BITMAPFILEHEADER fileHeader;
  64.         struct BITMAPINFOHEADER infoHeader;
  65.         FILE* fichero;
  66.         Pixel Data[MAXWIDTH][MAXHEIGHT];
  67.  
  68.  
  69.  
  70. };
  71.  
  72.  
  73.  
  74.  
  75.                 /*****************************************
  76.                 Abre el fichero a partir de la ruta a éste
  77.                 ******************************************/
  78. void BitMap::loadFile(char* cad){
  79.  
  80.     if(!(fichero= fopen(cad, "rb")))  printf("\nfichero no abierto");
  81. };
  82.  
  83.  
  84.  
  85.  
  86.  
  87.  
  88.                 /***************************************************************
  89.                 Rellena las estructuras
  90.                 La Informacion de cada Pixel se almacena en un array de
  91.                 !!Importante!!
  92.                 La image data está al reves
  93.                 Boca-abajo
  94.                 ****************************************************************/
  95. void BitMap::ParseFile(void){
  96.  
  97.     //Nos colocamos en la primera posicion
  98.     fseek(fichero, 0, 0);
  99.  
  100.     ///rellenamos la estructura fileHeader
  101.     //despreciamos algunas lecturas usando char c
  102.     char c;
  103.     //bfType 2bytes
  104.     fread(&c, 1,1, fichero);
  105.     fread(&c, 1,1, fichero);
  106.  
  107. //  bfsize
  108.     fread( &fileHeader.bfSize, 4, 1, fichero);
  109.     printf("\n%d", fileHeader.bfSize);
  110.  
  111.     //bfReserved1 y 2
  112.     fread(&c, 1,1, fichero);
  113.     fread(&c, 1,1, fichero);
  114.     fread(&c, 1,1, fichero);
  115.     fread(&c, 1,1, fichero);
  116.  
  117.     //bfOffBits
  118.     fread( &fileHeader.bfOffBits, 4, 1, fichero);
  119.     printf("\n%d", fileHeader.bfOffBits);
  120.  
  121.     ///rellenamos la estructura infoHeader
  122.     //biSize
  123.     fread( &infoHeader.biSize, 4, 1, fichero);
  124.     printf("\n%d", infoHeader.biSize);
  125.  
  126.     //biWidth
  127.     fread( &infoHeader.biWidth, 4, 1, fichero);
  128.     printf("\n%d", infoHeader.biWidth);
  129.  
  130.     //biHeigth
  131.     fread( &infoHeader.biHeight, 4, 1, fichero);
  132.     printf("\n%d", infoHeader.biHeight);
  133.  
  134.     //biPlanes y biBitCount
  135.     fread(&c, 1,1, fichero);
  136.     fread(&c, 1,1, fichero);
  137.     fread(&c, 1,1, fichero);
  138.     fread(&c, 1,1, fichero);
  139.  
  140.     //biCompression
  141.     fread( &infoHeader.biCompression, 4, 1, fichero);
  142.     printf("\n%d", infoHeader.biCompression);
  143.  
  144.     //biSizeImage
  145.     fread( &infoHeader.biSizeImage, 4, 1, fichero);
  146.     printf("\n%d", infoHeader.biSizeImage);
  147.     printf("\n%d\n", ftell(fichero));
  148.     ///Omitimos el resto de lecturas por ser inecesarias para nuestra tarea
  149.  
  150.  
  151.  
  152.     ///Lectura del Image Data
  153.     fseek(fichero, fileHeader.bfOffBits, 0); //nos colocamos donde empieza
  154.     int x=0;
  155.     int y=0;
  156.  
  157.     while( !feof(fichero))
  158.     {
  159.  
  160.         fread( &c, 1, 1, fichero);
  161.         if(c<0) Data[x][y].B= 256+c; else Data[x][y].B= c;
  162.         fread( &c, 1, 1, fichero);
  163.         if(c<0) Data[x][y].G= 256+c; else Data[x][y].G= c;
  164.         fread( &c, 1, 1, fichero);
  165.         if(c<0) Data[x][y].R= 256+c; else Data[x][y].R= c;
  166.  
  167.         printf("\npixel= R(%d),G(%d),B(%d)", Data[x][y].R, Data[x][y].G, Data[x][y].B);
  168.  
  169.         x++;
  170.         //si alcanzamos el final de la linea
  171.         if(x>= infoHeader.biWidth)
  172.         {
  173.             x=0; y++; //saltamos a la siguiente
  174.         }
  175.  
  176.     }
  177.  
  178. };
  179.  
  180.  
  181.  

warren

  • Nuevo Miembro
  • *
  • Mensajes: 10
    • Ver Perfil
Re: Problema Reservando Array
« Respuesta #3 en: Viernes 16 de Marzo de 2007, 16:52 »
0
por favor, alguien ha podido probar el codigo???
Ademas, no se me ocurre q opciones de configuracion del Code::Blocks pueden afectar a este caso.
A alguien se le ocurre algo??


Gracias de nuevo

JuanK

  • Miembro de ORO
  • ******
  • Mensajes: 5393
  • Nacionalidad: co
    • Ver Perfil
    • http://juank.io
Re: Problema Reservando Array
« Respuesta #4 en: Viernes 16 de Marzo de 2007, 17:04 »
0
no has pasado el punto de entrada del código (el main) y no ando con mucho tiempo para hacerlo yo mismo.
adjunta todo el código en un archivo .zip
[size=109]Juan Carlos Ruiz Pacheco
[/size]
Microsoft Technical Evangelist
@JuanKRuiz
http://juank.io