You are an expert in writing code in many different languages. Your goal is to perform code completion for the following code, keeping in mind the rest of the code and the file meta data.
    Metadata details:
    filename: packpng.m
    path of file: ./repos/gptoolbox/imageprocessing
    
    the code of the file until where you have to start completion: function rgba = packpng(G,filename,depth)
  % PACKPNG pack a grayscale double image into a depth bit RGBA PNG image
  %

    
function rgba = packpng(G,filename,depth)
  % PACKPNG pack a grayscale double image into a depth bit RGBA PNG image
  %
  % rgba = packpng(G,filename,depth)
  %
  % Inputs:
  %   G  h by w image of doubles in [0,1]
  %   filename  path to png file
  %   depth  number of bits to use: 8 or 16
  % Outputs:
  %  rgba  RGBA png image
  %

  % clamp to [0,1]
  if any(G(:)<0)
    warning('Clamping values as small as %g to 0\n',min(G(:)));
    G(G<0) = 0;
  end