 define ['angular', 'xtk', 'file', 'dat'], (ng) ->
   image = ng.module 'qiprofile.image', ['qiprofile.file']
 
-  image.factory 'Image', ['$rootScope', 'File', ($rootScope, File) ->
+  image.factory 'Image', ['$rootScope', '$q', 'File', ($rootScope, $q, File) ->
     # The root scope {parent id: [Image objects]} cache.
     if not $rootScope.images
       $rootScope.images = {}

      #   read is completed
      load: ->
        # Set the loading flag.
        @state.loading = true
        
        # Read the file into an ArrayBuffer. The Coffeescript fat
        # arrow (=>) binds the this variable to the image object
        # rather than the $http request.
        File.read(filename, responseType: 'arraybuffer').then (data) =>
          # Unset the loading flag.
          @state.loading = false
          # Set the data property to the file content.
          @data = data
      
      # Renders the image in the given parent element.
      #

      # loaded, false otherwise.
      state:
        loading: false
        loaded: false

      # The image file content.
      data: null
      labelmapData: null
      colortableData: null

      # Transfers the image file content to the data property.
      # The image state loading flag is set to true while the
