Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Visual C++ .NET bug?

Visual C++ .NET bug?

Scheduled Pinned Locked Moved C / C++ / MFC
c++csharphelpquestion
3 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • D Offline
    D Offline
    Davide Pizzolato
    wrote on last edited by
    #1

    this code works if compiled with VS6, but gives wrong results with VC++.NET

    int Y,U,V,R,G,B;
    Y = lYUVColor.rgbRed;
    U = lYUVColor.rgbGreen - 128;
    V = lYUVColor.rgbBlue - 128;
    
    R = (int)(Y + 1.403 \* V);
    G = (int)(Y - 0.344 \* U - 0.714 \* V);
    B = (int)(Y + 1.770 \* U);
    

    replaceing the declaration of Y, everything is ok.

    int U,V,R,G,B;
    float Y = lYUVColor.rgbRed;
    U = lYUVColor.rgbGreen - 128;
    V = lYUVColor.rgbBlue - 128;
    
    R = (int)(Y + 1.403 \* V);
    G = (int)(Y - 0.344 \* U - 0.714 \* V);
    B = (int)(Y + 1.770 \* U);
    

    where is the bug? in the compiler or in the code?

    H 1 Reply Last reply
    0
    • D Davide Pizzolato

      this code works if compiled with VS6, but gives wrong results with VC++.NET

      int Y,U,V,R,G,B;
      Y = lYUVColor.rgbRed;
      U = lYUVColor.rgbGreen - 128;
      V = lYUVColor.rgbBlue - 128;
      
      R = (int)(Y + 1.403 \* V);
      G = (int)(Y - 0.344 \* U - 0.714 \* V);
      B = (int)(Y + 1.770 \* U);
      

      replaceing the declaration of Y, everything is ok.

      int U,V,R,G,B;
      float Y = lYUVColor.rgbRed;
      U = lYUVColor.rgbGreen - 128;
      V = lYUVColor.rgbBlue - 128;
      
      R = (int)(Y + 1.403 \* V);
      G = (int)(Y - 0.344 \* U - 0.714 \* V);
      B = (int)(Y + 1.770 \* U);
      

      where is the bug? in the compiler or in the code?

      H Offline
      H Offline
      Hesham Amin
      wrote on last edited by
      #2

      Hi,, I think the problem is in the code :( Y + 1.403 * V Y - 0.344 * U - 0.714 * V Y + 1.770 * U (do you write a jpeg decoder/encoder?) you use U (an int) and Y (an int) so te hole equation uses ints which means loss of accuracy (int truncates what comes after the period) so when you use Y (float) the compiler does not truncate them...

      D 1 Reply Last reply
      0
      • H Hesham Amin

        Hi,, I think the problem is in the code :( Y + 1.403 * V Y - 0.344 * U - 0.714 * V Y + 1.770 * U (do you write a jpeg decoder/encoder?) you use U (an int) and Y (an int) so te hole equation uses ints which means loss of accuracy (int truncates what comes after the period) so when you use Y (float) the compiler does not truncate them...

        D Offline
        D Offline
        Davide Pizzolato
        wrote on last edited by
        #3

        hspc wrote: do you write a jpeg decoder/encoder? it's for CxImage you'are right, but 1.403 is not an integer, so the * operator should give a floating point result, while in this case the result seems an integer. :confused: in fact, another way to fix the problem is writing the constants with the "f" suffix: 1.403f and the routine works

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups