I made a class that will add noise to an image. However when i try to create the image again from the memblock, It only creates part of an image(an incomplete one but of the same size). I need to add noise to the complte image. Can someone help me fix this problem?
Image before noise generation..
Image after noise generation..
main.cpp
#include "DarkGDK.h"
#include "ImageMemblock.h"
void DarkGDK ( void )
{
dbSyncOn ( );
dbSyncRate ( 60 );
dbLoadImage( "HappyValentines.png", 1 );
DMFX_Image stx( 1 );
dbInk( 0, dbRgb( 255, 255, 255 ) );
while ( LoopGDK ( ) )
{
dbCLS(dbRgb( 255, 255, 255 ));
dbText( 0,0, "Press/Hold Up Key to generate noise" );
if ( dbUpKey() )
stx.GenerateNoise(1);
if ( dbDownKey() )
stx.RecreateImage();
dbPasteImage(1,100,100);
dbSync ( );
}
return;
}
Imagememblock.h
#include "DarkGDK.h"
class DMFX_Image
{
private:
int ImageID;
int MemblockID;
static int IDRoll;
int height;
int width;
int depth;
public:
DMFX_Image( int ImgID );
~DMFX_Image();
int generate_ID();
int StayInByteRange( int ByteValue );
void GenerateNoise( int NoiseValue );
void RecreateImage();
};
Imagememblock.cpp
#include "ImageMemblock.h"
int DMFX_Image::IDRoll = 1;
DMFX_Image::DMFX_Image( int ImgID ){
ImageID=ImgID;
MemblockID=generate_ID();
dbMakeMemblockFromImage ( MemblockID, ImgID );
width=dbMemblockDWORD ( MemblockID, 0 );
height=dbMemblockDWORD ( MemblockID, 4 );
depth=dbMemblockDWORD ( MemblockID, 8 );}
DMFX_Image::~DMFX_Image(){
if (MemblockID>IDRoll);
IDRoll=MemblockID;
dbDeleteMemblock( MemblockID );}
int DMFX_Image::generate_ID(){
while ( dbMemblockExist(IDRoll) )
IDRoll++;
return IDRoll;}
void DMFX_Image::GenerateNoise( int NoiseValue ){
int N=2*NoiseValue;
long int mPos;
DWORD color,newcolor;
int x,y,k,R,G,B;
dbRandomize( dbTimer() );
dbWriteMemblockDWORD ( MemblockID, 0, width );
dbWriteMemblockDWORD ( MemblockID, 4, height );
dbWriteMemblockDWORD ( MemblockID, 8, depth );
for ( y = 0; y<height; y++ )
for ( x = 0; x<width; x++ ){
mPos = 4*(y*width+x)+12;
color=dbMemblockDword(MemblockID,mPos);
R=dbRgbR(color);
G=dbRgbG(color);
B=dbRgbB(color);
R=StayInByteRange( R+dbRnd(N)-NoiseValue );
G=StayInByteRange( G+dbRnd(N)-NoiseValue );
B=StayInByteRange( B+dbRnd(N)-NoiseValue );
dbWriteMemblockDword( MemblockID,mPos, dbRgb(R,G,B) );}
dbDeleteImage(ImageID);
dbMakeImageFromMemblock(ImageID,MemblockID);
}
int DMFX_Image::StayInByteRange( int ByteValue ){
if ( ByteValue>255 ) ByteValue=255;
if ( ByteValue<0 ) ByteValue=0;
return ByteValue;
}
void DMFX_Image::RecreateImage(){
long int mPos;
DWORD color;
int x,y,k,R,G,B;
for ( y = 0; y<height; y++ )
for ( x = 0; x<width; x++ ){
mPos = 4*(y*width+x)+12;
color=dbMemblockDword(MemblockID,mPos);
R=dbRgbR(color);
G=dbRgbG(color);
B=dbRgbB(color);
dbWriteMemblockDword( MemblockID,mPos, dbRgb(R,G,B) );}
dbDeleteImage(ImageID);
dbMakeImageFromMemblock(ImageID,MemblockID);
}
Aside from this incomplete image creation from memblock,
How do I manipulate the alpha(transparency) of a pixel?I noticed that some image file formats have RGBA including an alpha but I only saw dbRgb that creates DWORD for RGB.
Please help me understand why im getting an impartial image and how to fix it.
When a person has nothing but a dream, can he dare to dream.