anchor.diff:          get_png_content/1,
           deflate_stream/1,
           inflate_stream/1]).
  -
  +-compile(export_all).
   -include("../include/eg.hrl").
   
   %% ============================================================================
  
positive.code:           3 ->
                [Params, MoreParams, list_to_binary(Palette), list_to_binary(Image) , list_to_binary(Alpha_channel)];
            4 ->
                {ImageScan, AlphaCodes} = extractAlphaAndData(list_to_binary(Image)),
                [Params, MoreParams, list_to_binary(Palette), ImageScan , AlphaCodes];
            6 ->        
                {ImageScan, AlphaCodes} = extractAlphaAndData(list_to_binary(Image)),
                [Params, MoreParams, list_to_binary(Palette), ImageScan , AlphaCodes]
            end;
          
  process_png( <<Length:32/integer, _ID:32, _:Length/binary-unit:8, _CRC:32, Rest/binary >>, 
                Params, MoreParams, Palette, Image, Alpha_channel) ->
          process_png( Rest, Params, MoreParams, Palette, Image , Alpha_channel).   
          
  extractAlphaAndData(Image) ->
    {ok,Decompressed} = deflate_stream(Image),
    {Decompressed,<< >>}.     
   
  breakout({PixelSize, AlphaSize}, Stream, Pixels, Alpha_channel) ->
    <<Pixel:PixelSize, Alpha:AlphaSize, Rest/binary>> = Stream,
    breakout({PixelSize, AlphaSize},  Rest, Pixels ++ binary_to_list(Pixel), Alpha_channel ++ binary_to_list(Alpha));
  breakout(Sizes, << >>,Pixels, Alpha_channel) ->
    {list_to_binary(Pixels), list_to_binary(Alpha_channel)}.
    
  %% Apply the PDF filter to the bytes of the image 
  filter(X,A,B,C,D, Method) ->
    NewX = case Method of
      0 -> X;
      1 -> X - A div 256;
      2 -> X - B div 256;
      3 -> (X - floor( (A + B)/2) ) div 256;
      4 -> (X - paethPredictor(A,B,C)) div 256
    end,
    NewX.
  
  %% calculate the specialized filter invented by Mr. Paeth
    
  
negative.code:   Decompressed = zlib:inflate(Z, Data),
    ok = zlib:inflateEnd(Z),
    zlib:close(Z),
    F = fun(A, B) -> <<A/binary, B/binary>> end,
    MergedBinaries = lists:foldr(F, <<>>, Decompressed),
    {ok,MergedBinaries}.
    
  %% @doc Compress a bit stream using the zlib/deflate algorithm
  %% 
  