Hello sdl,
Hello sdl,
tested under win2k, tnt2/m64/zx/pro, sdl-1.2.3
what is wrong with that code ? wrong shifting ?
please help, because i am getting out of my mind.
you need pic.bmp 800x600
— main.cpp
#include <stdio.h>
#include <stdlib.h>
#include <windows.h>
#include <SDL.h>
#include <math.h>
#include “Bitmap.h”
#include “BitmapMask.h”
#include “YTable.h”
long h1,h2,h3,h4;
unsigned long r,g,b;
unsigned long offset;
CBitmap *xtable;
CBitmap *rysunek;
CBitmapMask *vaddr01,*vaddr02,*vaddr03;
CYtable *ytable;
unsigned char temp_liner[800];
unsigned char temp_lineg[800];
unsigned char temp_lineb[800];
main (int argc, char **argv)
{
SDL_Surface *screen;
if ( SDL_Init(SDL_INIT_VIDEO) < 0 ) {
fprintf(stderr, "Couldn't initialize SDL: %s\n",SDL_GetError());
exit(2);
}
atexit(SDL_Quit);
screen = SDL_SetVideoMode(800, 600, 16,
(SDL_FULLSCREEN|SDL_HWSURFACE));
if ( screen == NULL ) {
fprintf(stderr, "Couldn't set video mode %dx%d: %s\n",
800, 600, SDL_GetError());
exit(3);
}
SDL_WM_SetCaption("Main", "main");
/* Ignore app focus and mouse motion events */
SDL_EventState(SDL_ACTIVEEVENT, SDL_IGNORE);
SDL_EventState(SDL_MOUSEMOTION, SDL_IGNORE);
//ytable = new CYtable(600,800);
rysunek = new CBitmap(480000,"pic.bmp");
vaddr01 = new CBitmapMask(480000);
vaddr02 = new CBitmapMask(480000);
vaddr03 = new CBitmapMask(480000);
for (h1=0;h1<480000;h1++)
{
vaddr01->mBitmapMaskData[h1]=rysunek->mBitmapDataB[h1];
vaddr02->mBitmapMaskData[h1]=rysunek->mBitmapDataG[h1];
vaddr03->mBitmapMaskData[h1]=rysunek->mBitmapDataR[h1];
}
while ( SDL_PollEvent(NULL) == 0 ) {
/* Lock the video surface */
if ( SDL_LockSurface(screen) < 0 ) {
continue;
}
for (int h1=0;h1<480000;h1++)
{
//r = (vaddr01->mBitmapMaskData[h1]&0xf80000)>>8;
//g = (vaddr02->mBitmapMaskData[h1]&0xfc00)>>5;
//b = (vaddr03->mBitmapMaskData[h1]&0xf8)>>3;
//((r>>3)<<11) +
// ((g>>2)<<5 ) +
// ((b>>3) );
// target_red = (source_color & 0xf80000) >> 8;
// target_green = (source_color & 0xfc00) >> 5;
// target_blue = (source_color & 0xf8) >> 3;
// r = col >> 4;
// g = b = col >> 3;
// *(tmp++) = (word) ((r<<11) + (g<<5) + b);
//r = (((pixel&0xF800)>>11)<<3); \
//g = (((pixel&0x07E0)>>5)<<2); \
//b = ((pixel&0x001F)<<3); \
RGB_FROM_RGB565(screen->pixels[h1]>>2,vaddr01->mBitmapMaskData[h1],
vaddr02->mBitmapMaskData[h1],
vaddr03->mBitmapMaskData[h1]);
//((long*)screen->pixels)[h1>>1] = RGB_FROM_RGB565(pixel, r, g, b)
//(((vaddr01->mBitmapMaskData[h1]&0xf800)>>11)<<3)|
//(((vaddr02->mBitmapMaskData[h1]&0x07e0)>>5)<<2)|
//(((vaddr03->mBitmapMaskData[h1]&0x001f)<<3));
}
/* Unlock and update the screen */
SDL_UnlockSurface(screen);
SDL_Flip(screen);
}
exit(0);
return 0;
}
– Bitmap.cpp
// Bitmap.cpp: implementation of the CBitmap class.
#include “Bitmap.h”
#include <stdlib.h>
#include <stdio.h>
#include <windows.h>
CBitmap::CBitmap()
{
}
CBitmap::~CBitmap()
{
if (mBitmapDataR!=NULL) free(mBitmapDataR);
if (mBitmapDataG!=NULL) free(mBitmapDataG);
if (mBitmapDataB!=NULL) free(mBitmapDataB);
}
CBitmap::CBitmap(unsigned long size)
{
mBitmapDataR = (unsigned char*)malloc(size);
mBitmapDataG = (unsigned char*)malloc(size);
mBitmapDataB = (unsigned char*)malloc(size);
}
CBitmap::CBitmap(unsigned long size, char filename[])
{
unsigned char *mTemp;
FILE *bmp_file;
unsigned long b1, b2;
mTemp = (unsigned char *)malloc(54+(size*3));
mBitmapDataR = (unsigned char*)malloc(size);
mBitmapDataG = (unsigned char*)malloc(size);
mBitmapDataB = (unsigned char*)malloc(size);
if ((bmp_file=fopen(filename,"rb"))==NULL) MessageBox(0,"error","error",MB_OK);
fread(mTemp,54+(size*3),1,bmp_file);
fclose(bmp_file);
for (b1=0, b2=0; b1<size; b1++, b2+=3)
{
mBitmapDataB[b1]=mTemp[51+(size*3)-b2];
mBitmapDataG[b1]=mTemp[52+(size*3)-b2];
mBitmapDataR[b1]=mTemp[53+(size*3)-b2];
}
}
— Bitmap.h
// Bitmap.h: interface for the CBitmap class.
#if !defined(AFX_BITMAP_H__04D6417F_81DA_4E1A_90EA_CA05C8102BDE__INCLUDED_)
#define AFX_BITMAP_H__04D6417F_81DA_4E1A_90EA_CA05C8102BDE__INCLUDED_
#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
class CBitmap
{
public:
unsigned char *mBitmapDataR; // dane bitmapy
unsigned char *mBitmapDataG; // dane bitmapy
unsigned char *mBitmapDataB; // dane bitmapy
CBitmap();
CBitmap(unsigned long size); // rozmiar bitmapy
CBitmap(unsigned long size, char filename[]);
virtual ~CBitmap();
};
#endif // !defined(AFX_BITMAP_H__04D6417F_81DA_4E1A_90EA_CA05C8102BDE__INCLUDED_)
— BitmapMask.cpp
// BitmapMask.cpp: implementation of the CBitmapMask class.
#include <stdio.h>
#include <stdlib.h>
#include <windows.h>
#include “BitmapMask.h”
CBitmapMask::CBitmapMask()
{
}
CBitmapMask::~CBitmapMask()
{
if (mBitmapMaskData!=NULL) free(mBitmapMaskData);
}
CBitmapMask::CBitmapMask(unsigned long size, char filename[])
{
FILE *bmp_file;
mBitmapMaskData = (unsigned char *) malloc (size);
if ((bmp_file=fopen(filename,"rb"))==NULL) MessageBox(0,"error","error",MB_OK);
fread(mBitmapMaskData,size,1,bmp_file);
fclose(bmp_file);
}
CBitmapMask::CBitmapMask(unsigned long size)
{
mBitmapMaskData = (unsigned char *) malloc (size);
}
— BitmapMask.h
// BitmapMask.h: interface for the CBitmapMask class.
#if !defined(AFX_BITMAPMASK_H__8B804C6F_78E3_4931_BA35_A18F02A5F470__INCLUDED_)
#define AFX_BITMAPMASK_H__8B804C6F_78E3_4931_BA35_A18F02A5F470__INCLUDED_
#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
class CBitmapMask
{
public:
unsigned char *mBitmapMaskData;
CBitmapMask();
CBitmapMask(unsigned long size); // od razu alokuj pamiec
CBitmapMask(unsigned long size, char filename[]); // wczytaj z pliku
virtual ~CBitmapMask();
};
#endif // !defined(AFX_BITMAPMASK_H__8B804C6F_78E3_4931_BA35_A18F02A5F470__INCLUDED_)–
Best regards,
firefox mailto:@palpetine
–
Tego nie znajdziesz w zadnym sklepie!
[ http://oferty.onet.pl ]