PROHARDVER! témák
Mobilarena témák
IT café témák
Aktív témák
-
doors
tag
Van egy progi ami most 8 bites bmp-kel dolgozik, és szeretném átalakítaní úgy hogy 24 bites bmp-vel lehessen dolgozni.Ebben kérném a segítségeteket.
A forráskód: -
kraftxld
nagyúr
Tisztességes (Photoshop, PSP9) képszerkesztő progi használata?
| MCSE+M/S, MCITP, VCP6.5-DCV - ''Life can be hard, but Scooter is harder :)'
-
doors
tag
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <alloc.h>
#include <glut.h>
#include <stdio.h>
#define SIZE 800
#define NEAR_Z 1.0
#define FAR_Z 500.0 // For the frustum size.
int *matrix2;
int kepdb;
int *matrix;
/*-------STRUCTURES---------*/
typedef struct {int rows; int cols; unsigned char* data;} sImage;
sImage originalImage;
/*-------PROTOTYPES---------*/
long getImageInfo(FILE*, long, int);
void copyImageInfo(FILE* inputFile, FILE* outputFile);
void copyColorTable(FILE* inputFile, FILE* outputFile, int nColors);
//***
float x_Angle ; // The rotation angles about x, y and z axis.
float y_Angle ;
float z_Angle ;
typedef GLfloat Point[3];
Point pt[] = {
{ -0.1, -0.1, 0.1 }, //-0,1+i*0,2,-0,1+j*0,2
{ -0.1, 0.1, 0.1 },
{ 0.1, 0.1, 0.1 },
{ 0.1, -0.1, 0.1 },
{ -0.1, -0.1, -0.1 },
{ -0.1, 0.1, -0.1 },
{ 0.1, 0.1, -0.1 },
{ 0.1, -0.1, -0.1 } }; // Definition of the vertices of the cube.
typedef GLfloat COLOR[3];
COLOR arrColor[] = {
{ 1.0, 0.0, 0.0 },
{ 0.0, 1.0, 0.0 },
{ 0.0, 0.0, 1.0 },
{ 1.0, 0.0, 1.0 },
{ 0.1, 1.0, 1.0 },
{ 1.0, 1.0, 1.0 }
}; // Definition of the RGB color codes for each side of the cube.
/****************************************************************************************/
void displayCallbackProc (void);
void drawSide (int v0, int v1, int v2, int v3,int iColor)
// Draws one side of the cube and colors it.
{
glColor3fv(arrColor[iColor]); // Specifying color
glBegin(GL_POLYGON);
glVertex3fv(pt[v0]);
glVertex3fv(pt[v1]);
glVertex3fv(pt[v2]);
glVertex3fv(pt[v3]);
glEnd();
}
/****************************************************************************************/
void drawCube (void) // Draws the color cube.
{
drawSide(0, 3, 2, 1, 5);
drawSide(2, 3, 7, 6, 5);
drawSide(0, 4, 7, 3, 5);
drawSide(1, 2, 6, 5, 5);
drawSide(4, 5, 6, 7, 5);
drawSide(0, 1, 5, 4, 5);
}
/****************************************************************************************/
void init (void) // Initializes the gl Graphics env and the program variables.
{
x_Angle = 45.0;
y_Angle = 0.0;
z_Angle = 45.0;
glEnable(GL_DEPTH_TEST); // Enable z-Buffering.
}
/****************************************************************************************/
void keyboardCallbackProc(unsigned char key, int x, int y)
// This is the callback procedure for capturing OpenGL Keyboard events.
{
switch(key)
{
case 'x':
x_Angle += 3;
break;
case 'X':
x_Angle -= 3;
break;
case 'y':
y_Angle += 3;
break;
case 'Y':
y_Angle -= 3;
break;
case 'z':
z_Angle += 3;
break;
case 'Z':
z_Angle -= 3;
break;
case 27 : //ESCAPE Code for exiting program.
exit(0);
}
glutPostRedisplay();
}
/****************************************************************************************/
void reShapeCallbackProc(int w, int h)
// This is the callback procedure for capturing reShape event for window resizing.
{
glViewport(0, 0, w, h);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluPerspective(60.0, GLfloat(w)/GLfloat(h), NEAR_Z, FAR_Z);
glMatrixMode(GL_MODELVIEW);
}
/****************************************************************************************/
unsigned int row, col;
int main(int argc, char* argv[])
{
FILE *bmpInput, *bmpOutput;
sImage originalImage;
sImage edgeImage;
unsigned int X, Y;
int I, J;
long sumX, sumY;
int nColors, SUM;
unsigned long vectorSize;
unsigned long fileSize;
int GX[3][3];
int GY[3][3];
unsigned char *pChar, someChar;
someChar = '0'; pChar = &someChar;
/* 3x3 GX Sobel mask. Ref: www.cee.hw.ac.uk/hipr/html/sobel.html */
GX[0][0] = -1; GX[0][1] = 0; GX[0][2] = 1;
GX[1][0] = -2; GX[1][1] = 0; GX[1][2] = 2;
GX[2][0] = -1; GX[2][1] = 0; GX[2][2] = 1;
/* 3x3 GY Sobel mask. Ref: www.cee.hw.ac.uk/hipr/html/sobel.html */
GY[0][0] = 1; GY[0][1] = 2; GY[0][2] = 1;
GY[1][0] = 0; GY[1][1] = 0; GY[1][2] = 0;
GY[2][0] = -1; GY[2][1] = -2; GY[2][2] = -1;
/*if(argc < 2) {
printf(''Usage: %s bmpInput.bmp\n'', argv[0]);
exit(0);
};
printf(''Reading filename %s\n'', argv[1]);
*/
printf(''Hany képet akarsz beolvasni: '');
scanf(''%d'',&kepdb);
matrix=(int*)malloc(vectorSize*sizeof(int));
matrix2=(int*)malloc(512*512*kepdb*sizeof(int));
char filenev[122];
for (int iii=0; iii<kepdb; iii++)
{
printf(''Filenev: '');
scanf(''%s'',&filenev);
/*-------DECLARE INPUT & OUTPUT FILES-------*/
bmpInput = fopen(filenev, ''rb'');
bmpOutput = fopen(''edgeSob.bmp'', ''wb'');
/*---SET POINTER TO BEGINNING OF FILE----*/
fseek(bmpInput, 0L, SEEK_END);
/*-------GET INPUT BMP DATA--------*/
fileSize = getImageInfo(bmpInput, 2, 4);
originalImage.cols = (int)getImageInfo(bmpInput, 18, 4);
originalImage.rows = (int)getImageInfo(bmpInput, 22, 4);
row=originalImage.rows;
col=originalImage.cols;
edgeImage.rows = originalImage.rows;
edgeImage.cols = originalImage.cols;
/*--------PRINT DATA TO SCREEN----------*/
/*printf(''Width: %d\n'', originalImage.cols);
printf(''Height: %d\n'', originalImage.rows);
printf(''File size: %lu\n'', fileSize);
*/
nColors = (int)getImageInfo(bmpInput, 46, 4);
//printf(''nColors: %d\n'', nColors);
/*------ALLOCATE MEMORY FOR FILES--------*/
vectorSize = fileSize - (14+40+4*nColors);
//printf(''vectorSize: %lu\n'', vectorSize);
edgeImage.data =(unsigned char*) malloc(vectorSize*sizeof(unsigned char));
if(edgeImage.data == NULL) {
printf(''Failed to malloc edgeImage.data\n'');
exit(0);
}
// printf(''%lu bytes malloc'ed for edgeImage.data\n'', vectorSize);
originalImage.data = (unsigned char*)malloc(vectorSize*sizeof(unsigned char));
if(originalImage.data == NULL) {
printf(''Failed to malloc originalImage.data\n'');
exit(0);
}
printf(''%lu bytes malloc'ed for originalImage.datt\n'', vectorSize);
/*------COPY HEADER AND COLOR TABLE---------*/
copyImageInfo(bmpInput, bmpOutput);
copyColorTable(bmpInput, bmpOutput, 256);
fseek(bmpInput, (14+40+4*nColors), SEEK_SET);
fseek(bmpOutput, (14+40+4*nColors), SEEK_SET);
/* Read input.bmp and store it's raster data into originalImage.data */
for(row=0; row<=originalImage.rows-1; row++) {
for(col=0; col<=originalImage.cols-1; col++) {
fread(pChar, sizeof(char), 1, bmpInput);
*(originalImage.data + row*originalImage.cols + col) = *pChar;
}
}
/*---------------------------------------------------
SOBEL ALGORITMUS KEZDETE
---------------------------------------------------*/
for(Y=0; Y<=(originalImage.rows-1); Y++) {
for(X=0; X<=(originalImage.cols-1); X++) {
sumX = 0;
sumY = 0;
/* image boundaries */
if(Y==0 || Y==originalImage.rows-1)
SUM = 0;
else if(X==0 || X==originalImage.cols-1)
SUM = 0;
/* Konvolúció kezdet */
else {
/*-------X GRADIENT APPROXIMATION------*/
for(I=-1; I<=1; I++) {
for(J=-1; J<=1; J++) {
sumX = sumX + (int)( (*(originalImage.data + X + I + (Y + J)*originalImage.cols)) * GX[I+1][J+1]);
}
}
if(sumX>255) sumX=255;
if(sumX<0) sumX=0;
/*-------Y GRADIENT APPROXIMATION-------*/
for(I=-1; I<=1; I++) {
for(J=-1; J<=1; J++) {
sumY = sumY + (int)( (*(originalImage.data + X + I + (Y + J)*originalImage.cols)) * GY[I+1][J+1]);
}
}
if(sumY>255) sumY=255;
if(sumY<0) sumY=0;
SUM = abs(sumX) + abs(sumY); /*---GRADIENT MAGNITUDE APPROXIMATION (Myler p.218)----*/
}
*(edgeImage.data + X + Y*originalImage.cols) = 255 - (unsigned char)(SUM); /* make edges black and background white */
fwrite( (edgeImage.data + X + Y*originalImage.cols), sizeof(char), 1, bmpOutput);
}
}
//***** Saját***
matrix=(int*)malloc(vectorSize*sizeof(int));
for(int i=0; i<=(originalImage.rows-1); i++) {
for(int j=0; j<=(originalImage.cols-1); j++) {
*(matrix+i+j*originalImage.cols)=1;
}}
printf(''4'');
for(int i=0; i<=(originalImage.rows-1); i++) {
for(int j=0; j<=(originalImage.cols-1); j++) {
if( (int)*(edgeImage.data + i + j*originalImage.cols)==255)
*(matrix+i+j*originalImage.cols)=0;
}}
printf(''5'');
for(int i=0; i<=(originalImage.rows-1); i++) {
for(int j=0; j<=(originalImage.cols-1); j++) {
*(matrix2+iii*originalImage.rows*originalImage.cols+i+j*originalImage.cols)=*(matrix+i+j*originalImage.cols);
}
}
//printf(''%d\n'',*matrix2);
}//nagyciklus vége
printf(''6'');
/* for(int i=0; i<=(originalImage.rows-1); i++) {
for(int j=0; j<=(originalImage.cols-1); j++) {
// printf(''%d'',*(matrix+i+j*originalImage.cols));;
}//printf(''\n'');
} */
// printf(''See edgeSob.bmp for results\n'');
fclose(bmpInput);
fclose(bmpOutput);
free(edgeImage.data); /* Finished with edgeImage.data */
free(originalImage.data); /* Finished with originalImage.data */
// The main program.
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH);
glutInitWindowSize(SIZE, SIZE);
glutInitWindowPosition(0, 0);
glutCreateWindow(''CT'');
init(); // Initialize the env. variables and the program global variables.
/* Callback registrations with the OpenGL env are done here */
glutDisplayFunc(displayCallbackProc);
glutKeyboardFunc(keyboardCallbackProc);
glutReshapeFunc(reShapeCallbackProc);
/* Callback registrations done.*/
glutMainLoop();
return 1;
}
/*----------GET IMAGE INFO SUBPROGRAM--------------*/
long getImageInfo(FILE* inputFile, long offset, int numberOfChars)
{
unsigned char *ptrC;
long value = 0L;
unsigned char dummy;
int i;
dummy = '0';
ptrC = &dummy;
fseek(inputFile, offset, SEEK_SET);
for(i=1; i<=numberOfChars; i++)
{
fread(ptrC, sizeof(char), 1, inputFile);
/* calculate value based on adding bytes */
value = (long)(value + (*ptrC)*(pow(256, (i-1))));
}
return(value);
} /* end of getImageInfo */
/*-------------COPIES HEADER AND INFO HEADER----------------*/
void copyImageInfo(FILE* inputFile, FILE* outputFile)
{
unsigned char *ptrC;
unsigned char dummy;
int i;
dummy = '0';
ptrC = &dummy;
fseek(inputFile, 0L, SEEK_SET);
fseek(outputFile, 0L, SEEK_SET);
for(i=0; i<=50; i++)
{
fread(ptrC, sizeof(char), 1, inputFile);
fwrite(ptrC, sizeof(char), 1, outputFile);
}
}
/*----------------COPIES COLOR TABLE-----------------------------*/
void copyColorTable(FILE* inputFile, FILE* outputFile, int nColors)
{
unsigned char *ptrC;
unsigned char dummy;
int i;
dummy = '0';
ptrC = &dummy;
fseek(inputFile, 54L, SEEK_SET);
fseek(outputFile, 54L, SEEK_SET);
for(i=0; i<=(4*nColors); i++) /* there are (4*nColors) bytesin color table */
{
fread(ptrC, sizeof(char), 1, inputFile);
fwrite(ptrC, sizeof(char), 1, outputFile);
}
}
void displayCallbackProc (void)
// This is the callback procedure for capturing OpenGL Display events.
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glTranslatef(0, 0, -200);
glRotatef(x_Angle, 1.0, 0.0, 0.0); // Rotate the object by x_Angle about x-axis
glRotatef(y_Angle, 0.0, 1.0, 0.0); // Rotate the object by y_Angle about y-axis
glRotatef(z_Angle, 0.0, 0.0, 1.0); // Rotate the object by z_Angle about z-axis
for(int k=0;k<kepdb;k++){
for(int i=1;i<row-1;i++){
for(int j=1;j<col-1;j++){
if(*(matrix2+k*col*row+i+j*col)==1)
drawCube(); // kirajzolja a kockat
glTranslatef(0.2, 0, 0); //jobbre leptet 0.2t
}
glTranslatef(-102, 0, 0);
glTranslatef(0, 0.2, 0);
}
glTranslatef(0, 0, -30); //előre ötöt
glTranslatef(0, -102, 0);
}
glutSwapBuffers();
}
Aktív témák
Aktív témák
- Azonnali VGA-s kérdések órája
- Feltörték a PROHARDVER!-es regisztrációmat! (vagy elvesztettem a belépési emailcímemet)
- CASIO órák kedvelők topicja!
- Luck Dragon: Asszociációs játék. :)
- Azonnali processzoros kérdések órája
- Békéscsaba és környéke adok-veszek-beszélgetek
- Politika
- Mobil flották
- A fociról könnyedén, egy baráti társaságban
- Milyen egeret válasszak?
- További aktív témák...
Új prémium hirdetések
Állásajánlatok
Cég: Alpha Laptopszerviz Kft.
Város: Pécs
Cég: Ozeki Kft.
Város: Debrecen