Εμφάνιση εικόνας raw στην οθόνη

...του ubuntu και έργων ΕΛ/ΛΑΚ (Έργα-Οδηγοί-Προτάσεις)

Συντονιστής: konnn

Εμφάνιση εικόνας raw στην οθόνη

Δημοσίευσηαπό pc_magas » 14 Οκτ 2012, 01:37

Έχω κάνει τον εξής κώδικα που φορτώνει μαι εικόνα σαν unsigned char ** από ένα αρχεί και την αντιγράφει σε ένα άλλο αρχείο

Κώδικας: Επιλογή όλων

#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include<malloc.h>
#include"imageio.h"

// ---------------------------------------------------------------
// Usefull defines
// ---------------------------------------------------------------
#define INPUT_FILENAME "lenaGrey256.raw" // defining input filename
#define OUTPUT_FILENAME "lenaGrey256out.raw" // defining output filename
#define ROWS 256 // Picture height
#define COLUMNS 256 // Picture width
#define GREYLEVELS 256 // Graylevel sampling

#define OUTPUT_ROWS ROWS // Output height
#define OUTPUT_COLUMNS COLUMNS // Output width


int main(void)
{
unsigned char **inputImage, **outputImage;//table that will store the output image

FILE *inputFile,//Input
*outputFile;//Output file


/*
Usefull variables for the loops for storing and processing the image
*/
int i = 0,
j = 0;

//----------------------------------------
//Other variables
//----------------------------------------


//-------------------------------------------------
//Main Code
//-------------------------------------------------

inputImage=load_grayscale(INPUT_FILENAME,COLUMNS,ROWS);
outputImage=alocate_image(OUTPUT_ROWS,OUTPUT_COLUMNS);

if(inputImage==NULL || outputImage==NULL)
{
exit(-1);
}



// -----------------------------------------------------------
// Processing the Image
// -----------------------------------------------------------



for (i = 0; i < OUTPUT_ROWS; i++)
{

for (j = 0; j < OUTPUT_COLUMNS; j++)
{
outputImage[i][j] = inputImage[i][j];
}
}

store_grayscale(OUTPUT_FILENAME,outputImage,OUTPUT_ROWS,OUTPUT_COLUMNS);


}


Χρησιμοποιεί και τον εξής header (Imageio.h)
Κώδικας: Επιλογή όλων

#ifndef IMAGEIO
#define IMAGEIO
#include<stdio.h>
#include<stdlib.h>
unsigned char ** load_grayscale(unsigned char path[], unsigned int height, unsigned int width);
int store_grayscale(unsigned char * path, unsigned char **outputImage, unsigned int height, unsigned int width);
unsigned char ** alocate_image(int width, int height);
#endif


Και τις εξής συναρτήσεις του header (imageio.h)
Κώδικας: Επιλογή όλων

#include"imageio.h"
unsigned char ** load_grayscale(unsigned char path[], unsigned int height, unsigned int width)
{
FILE *inputFile;//Input
unsigned char **inputImage;

int i,j;

if ( ((inputFile = fopen(path,"rb")) != NULL))
{

inputImage = calloc(height,sizeof(unsigned char *));

if(inputImage==NULL)
{
return NULL;
}

for (i = 0; i < height; i++)
{
inputImage[i] = calloc(width, sizeof(unsigned char));

if(inputImage[i]==NULL)
{
free(inputImage);
return NULL;
}

for (j = 0; j < width; j++)
{
fscanf(inputFile, "%c", &inputImage[i][j]);
}
}
}
else
{
fprintf(stderr,"Error loading image.");
free(inputImage);
return NULL;
}
fclose(inputFile);
return inputImage;
}

int store_grayscale(unsigned char path[], unsigned char **outputImage, unsigned int height, unsigned int width)
{

FILE *outputFile;
int i,j;

if ( ((outputFile = fopen(path,"wb")) != NULL))
{
for (i = 0; i < height; i++)
{
for (j = 0; j < width; j++)
{
fprintf(outputFile, "%c",outputImage[i][j]);
}
}
}
else
{
fprintf(stderr,"Error saving image.");
return 0;
}
fclose(outputFile);

return 1;
}


unsigned char ** alocate_image(int height, int width)
{
int i;
unsigned char **image;

if((image=(unsigned char**)calloc(height,sizeof(unsigned char *)))==NULL)
{
return NULL;
}

for(i=0;i<height;i++)
{
if((image[i]=(unsigned char*)calloc(width,sizeof(unsigned char)))==NULL)
{
free(image);
return NULL;
}
}

return image;
}


Θ'ελω τις τιμές πτου πίνακων τύπου unssigned char να τους προβάλλω στην οθόνη σε ένα παράθυρο αλλα πως?

Η εικόνα είναι grayscale.

Ψ'αχνω στο youtube δίχως κανένα αποτέλεσμα
My blog|Κυπριακή Κοινότητα Ελευθέρου Λογισμικού Λογισμικού ανοικτού Κώδικα
Γνώσεις Linux:Ποτέ αρκετές|Προγραμματισμός: Php, javascript, nodejs, python, bash |Aγγλικά:Καλά
Οι υπολογιστές μου:
Spoiler: show
Ubuntu 16.04 64 bit σεIntel(R) Pentium(R) CPU G4400 @ 3.30GHz, 16Gib Ram, 500Gib Hard Disk, και κάρτα γραφικών Nvidia Geforce GT610
Lubuntu 14.04 σε Dell Inspiron mini 10(1010) intel Atom Z500 1Gb ram και gma500 (εδώθη σε άλλον)
Kubuntu 16.04 Lenovo G70 Intel i5 Nvidia Grapgics Card, Intel Graphics card (έχει 2) με Nouveau, 16Gb RAM, 126GB SSD Σκληρό Δίσκο
Άβαταρ μέλους
pc_magas
powerTUX
powerTUX
 
Δημοσιεύσεις: 2599
Εγγραφή: 12 Απρ 2009, 18:55
Τοποθεσία: Αχαρναί Αττικής
Launchpad: pc_magas
IRC: pc_magas
Εκτύπωση

Επιστροφή στο Ανάπτυξη Λογισμικού / Αλγόριθμοι

cron