Results 1 to 3 of 3
  1. #1
    EmuTalk Member GbaGuy's Avatar
    Join Date
    May 2004
    Posts
    36

    Help put equation into code

    What I'm struggling with is understanding JPEG.

    Now that noone is reading anymore , what I don't understand is the DCT.
    Wikipedia shows it as (in Discrete cosine transform - Wikipedia, the free encyclopedia) (DCT-II):
    Assuming N = 8, in doing one row (or column, but lets just assume row):

    Xk = sum(0..7) { Xn * cos((PI/8)(n+.5)(k)) }

    Now if X is a 8 element array of ints, and k and n are indeces, then:
    Code:
    float sum = 0;
    for(int n=0;n<8;n++)
    {
    sum += X[n] * cos((PI/8)*(n+.5)*k);
    }
    I have no idea what 'k' is supposed to be. I think it's either 1..8, or it could be
    1..7. It could be one of those ranges incrementing through the sum, or incrementing for each new Xk.



    Can anyone help me out?

    Many thanks in advance!


    • Advertising

      advertising
      EmuTalk.net
      has no influence
      on the ads that
      are displayed
        
       

  2. #2
    Keeper of The Iron Tail zAlbee's Avatar
    Join Date
    Jan 2002
    Location
    California
    Posts
    590
    You have to read this sentence again :

    Quote Originally Posted by Wikipedia
    Formal definition

    Formally, the discrete cosine transform is a linear, invertible function F : RN -> RN (where R denotes the set of real numbers), or equivalently an N × N square matrix. There are several variants of the DCT with slightly modified definitions. The N real numbers x0, ..., xN-1 are transformed into the N real numbers X0, ..., XN-1 according to one of the formulas:
    So your original 8-element array x determines the values of your new 8-element array X. Make sure the variables are different, you don't want to overwrite the original values of x, or you won't compute it correctly.

    Therefore k will also be 0..7.

    And you want:

    Code:
    for(int k=0;k<8;k++)
    {
        xnew[k]=0;
        for(int n=0;n<8;n++)
        {
            xnew[k] += X[n] * cos((PI/8)*(n+.5)*k);
        }
    }
    Last edited by zAlbee; October 3rd, 2006 at 01:37.

  3. #3
    EmuTalk Member GbaGuy's Avatar
    Join Date
    May 2004
    Posts
    36
    Thank you! I had forgotten about the other question (new array, or replacement). So, essentially, you answered two (rather many) questions at once!

    Later tomorrow I'm going to try implementing the 2-d formula described and see what I get inputting the array in the Wikipedia article about JPEG. Although... it looks like I can do it again on the results of the above (the columns) into the original array (save space, and I don't need the original values anymore I don't think), and that'll get it done.

    My mind is already spinning on how slow this is gonna be. I suck .

Similar Threads

  1. Donkey Kong 64 - Moon Jump Code Sorted
    By Rastaman360 in forum PJ64 Cheats
    Replies: 3
    Last Post: September 7th, 2006, 14:31
  2. PJ 64 and geforce 66gt error
    By ryosableng in forum Project64
    Replies: 11
    Last Post: July 21st, 2006, 19:30
  3. Guess What
    By kylethedarkn2 in forum Dolphin
    Replies: 7
    Last Post: April 7th, 2006, 12:00
  4. Replies: 95
    Last Post: January 20th, 2004, 11:45

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •