efficiency problem..

This is a discussion on efficiency problem.. within the C++ Programming forums, part of the General Programming Boards category; Hi, i am writing a bit of code that uses the following equation: tot=(i*top)+((1-i)*btm); basically this derives a merged value ...

  1. #1
    Registered User
    Join Date
    Jul 2002
    Posts
    6

    efficiency problem..

    Hi,
    i am writing a bit of code that uses the following equation:
    tot=(i*top)+((1-i)*btm);

    basically this derives a merged value based on alpha transparency value when merging 2 images.
    Now, i am kinda reversing it to obtain the alpha info. The following variables in this situation are known values:
    tot, top, btm
    i (alpha info) isnt known.

    I cant rearrange this equation however, it seems to cancel out..
    My current solution is extremely inefficient, it involves looping through for all values of i (255 of em) with the known variables until the lhs==rhs. Then i know the alpha. This has to be done for each pixel and its too slow to be practical.

    Does anybody know either 1)how to rearrange the above to get i, or if this is impossible 2)some more efficient method of getting i from the above without looping through all values until i is found..

    thx in advance
    bob

  2. #2
    geek SilentStrike's Avatar
    Join Date
    Aug 2001
    Location
    NJ
    Posts
    1,141
    I think this is what you want...

    Code:
    tot = i*top + (1 - i)*btm
    tot = i*top + btm - i*btm
    tot - btm = i*top - i*btm
    tot - btm = i*(top - btm)
    (tot - btm) / (top - btm) = i

  3. #3
    Registered User
    Join Date
    Jul 2002
    Posts
    6
    ah yes, thats it, feel kinda stupid for not being able to figure that out for myself
    thanks
    bob

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Memory problem with Borland C 3.1
    By AZ1699 in forum C Programming
    Replies: 16
    Last Post: 11-16-2007, 11:22 AM
  2. Someone having same problem with Code Block?
    By ofayto in forum C++ Programming
    Replies: 1
    Last Post: 07-12-2007, 09:38 AM
  3. A question related to strcmp
    By meili100 in forum C++ Programming
    Replies: 6
    Last Post: 07-07-2007, 03:51 PM
  4. WS_POPUP, continuation of old problem
    By blurrymadness in forum Windows Programming
    Replies: 1
    Last Post: 04-20-2007, 07:54 PM
  5. Laptop Problem
    By Boomba in forum Tech Board
    Replies: 1
    Last Post: 03-07-2006, 06:24 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21