seperating pixel values to DCT blocks

Discussion in 'C++' started by khaleel.alyasini@gmail.com, Mar 19, 2006.

  1. Guest

    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]<<" ";
    }
    }
    , Mar 19, 2006
    #1
    1. Advertising

  2. red floyd Guest

    wrote:
    > 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 <iomanip>

    >
    > 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]
    > }
    red floyd, Mar 19, 2006
    #2
    1. Advertising

  3. BigBrian Guest

    wrote:
    > 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.
    BigBrian, Mar 20, 2006
    #3
  4. Guest

    thanks for the info. any ideas on how to implement DCT formulas in C++?
    1-D DCT should be okay ;) thanks in advance
    , Mar 20, 2006
    #4
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Salim Afþar

    seperating ascx and cs files

    Salim Afþar, Jul 10, 2003, in forum: ASP .Net
    Replies:
    0
    Views:
    385
    Salim Afþar
    Jul 10, 2003
  2. Aaron Kornbluth

    Seperating IIS from Application

    Aaron Kornbluth, May 5, 2004, in forum: ASP .Net
    Replies:
    2
    Views:
    370
    Aaron Kornbluth
    May 5, 2004
  3. =?Utf-8?B?Sm9l?=

    Seperating code from HTML markup

    =?Utf-8?B?Sm9l?=, Feb 15, 2006, in forum: ASP .Net
    Replies:
    2
    Views:
    397
    =?Utf-8?B?Sm9l?=
    Feb 15, 2006
  4. André Wagner

    Fastest pixel by pixel operation

    André Wagner, Mar 17, 2008, in forum: Java
    Replies:
    12
    Views:
    1,042
    Larry A Barowski
    Mar 19, 2008
  5. matt
    Replies:
    1
    Views:
    261
    George Ogata
    Aug 6, 2004
Loading...

Share This Page