seperating pixel values to DCT blocks

K

khaleel.alyasini

Hi, currently I'm working on DCT algorithm on C++. I was wondering if
anyone out there could point me out how to seperate the pixel values
into DCT blocks. Here, i have enclosed my source code(incomplete).

specs:
1. seperates pixels values into block of 8x8
2. stores the values in a new pointer.

#include <iostream.h>
#include <fstream.h>
#include <stdlib.h>
#include <iomanip.h>

const int pix=256;
static const double pi = 3.141593;




int main()
{
int l=0, k=0, x=0, kh=0, countA;
int * arraytwo;
arraytwo = new int [pix*pix];
unsigned char * pixelvalues;
pixelvalues = new unsigned char [pix*pix];
if(pixelvalues == 0)
{
cout<<"Memory allocation failed !\n";
exit(1);
}


/********************/
/* READ */

ifstream rawimage("lena.raw", ios::in|ios::binary);
if(!rawimage)
{
cerr<<"Error in reading file\n";
exit(1);
}


ofstream dctblock("dct.txt", ios::eek:ut|ios::binary);
if(!dctblock)
{
cerr<<"Error in reading file\n";
exit(1);
}

for(int i=0; i<pix; i++)
{
for(int j=0; j<pix; j++, k++)
{
rawimage>>pixelvalues[k];
}
}


/********************/
/* DCT BLOCK */

for(int jumper=0; jumper<pix; jumper=jumper+8)
{
for(int vertjump=1; vertjump<2304; vertjump=vertjump+255)
{
for(int count=0; count<8; count++)
{
countA=(count*vertjump);
arraytwo[x++]=pixelvalues[countA];
}
}
}


for(int test=0; test<pix; test++)
{
for(int mest=0; mest<pix; mest++, kh++)
{
dctblock<<arraytwo[kh]<<" ";
}
}
 
R

red floyd

Hi, currently I'm working on DCT algorithm on C++. I was wondering if
anyone out there could point me out how to seperate the pixel values
into DCT blocks. Here, i have enclosed my source code(incomplete).

specs:
1. seperates pixels values into block of 8x8
2. stores the values in a new pointer.

#include <iostream.h>
#include <fstream.h>
#include <stdlib.h>
#include <iomanip.h>

With the exception of stdlib.h, all of these are non-standard headers.
#include <iostream>
#include <fstream>
#include said:
const int pix=256;
static const double pi = 3.141593;




int main()
{
[redacted by red floyd]
if(pixelvalues == 0)
{
cout<<"Memory allocation failed !\n";

cout is not defined in the global namespace -- should be std::cout.
exit(1);
}


/********************/
/* READ */

ifstream rawimage("lena.raw", ios::in|ios::binary);
ifstream and ios are in namespace std

if(!rawimage)
{
cerr<<"Error in reading file\n";
exit(1);
}


ofstream dctblock("dct.txt", ios::eek:ut|ios::binary);
ditto for ofstream.
[remainder redacted by red floyd]
> }
 
B

BigBrian

pixelvalues = new unsigned char [pix*pix];
if(pixelvalues == 0)
{
cout<<"Memory allocation failed !\n";
exit(1);
}


new() will not return 0 even if memory cannot be allocated unless you
use std::nothrow, so your if test will never be true.
 
K

khaleel.alyasini

thanks for the info. any ideas on how to implement DCT formulas in C++?
1-D DCT should be okay ;) thanks in advance
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,020
Latest member
GenesisGai

Latest Threads

Top