Results 1 to 3 of 3

Thread: Making a GetIntermediatePixel() function

  1. #1

    Making a GetIntermediatePixel() function

    You might know the classic GetPixel() function, now I want to make a function that retrieves the intermediate color from a floating-point coordinate. This is what I'm doing:

    Code:
    function im_cImage.GetInterPixel(
      X, Y: Single
      ): cr_rARGB;
    
      var
        X0, Y0, X1, Y1: Integer;
        FX, FY: Single;
        C10, C01, C11: cr_rARGB;
    
    begin
      X0 := Trunc(X);
      Y0 := Trunc(Y);
      FX := X-X0;
      FY := Y-Y0;
    
      if FX < 0.5 then
      begin
        X1 &#58;= X0;
        X0 &#58;= X1-1;
        FX &#58;= FX+0.5;
      end else
      begin
        X1 &#58;= X0+1;
        FX &#58;= FX-0.5;
      end;
    
      if FY < 0.5 then
      begin
        Y1 &#58;= Y0;
        Y0 &#58;= Y1-1;
        FY &#58;= FY+0.5;
      end else
      begin
        Y1 &#58;= Y0+1;
        FY &#58;= FY-0.5;
      end;
    
      C10 &#58;= cr_Interpolate&#40;GetPixel&#40;X0, Y0&#41;, GetPixel&#40;X1, Y0&#41;, FX&#41;;
      C01 &#58;= cr_Interpolate&#40;GetPixel&#40;X0, Y0&#41;, GetPixel&#40;X0, Y1&#41;, FY&#41;;
      C11 &#58;= cr_Interpolate&#40;GetPixel&#40;X0, Y0&#41;, GetPixel&#40;X1, Y1&#41;,
        cm_Distance&#40;0, 0, FX, FY&#41;&#41;;
    
      // ... what should I do next? ...
    end;
    When I first started had the idea of blending those 3 colors (C10, C01 and C11), but now I'm not sure if those should be interpolated (and how), to get the right color. Any ideas? :?

  2. #2

    Making a GetIntermediatePixel() function

    Isn't there 4 pixels around given floating point position?

    Next step is sum up all colors multiplied with their power 0..1 (looks this means the FX,FY in your code) depending on how far they are from observation point, then because of 2 rows add up to double, divide by 2.

  3. #3

    Making a GetIntermediatePixel() function

    Yes, I'm using the four colors around the floating coordinate.

    That sum is the blending of the interpolated colors... maybe my idea was right from the beginning

Bookmarks

Posting Permissions

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