code: def _populate_comptparms(self, img_array):
          
          # Only two precisions are possible.
          if img_array.dtype == np.uint8:
              comp_prec = 8
          else:
              comp_prec = 16
  
          numrows, numcols, num_comps = img_array.shape
          if version.openjpeg_version_tuple[0] == 1:
              comptparms = (opj.ImageComptParmType * num_comps)()
          else:
              comptparms = (opj2.ImageComptParmType * num_comps)()
          for j in range(num_comps):
              comptparms[j].dx = self._cparams.subsampling_dx
              comptparms[j].dy = self._cparams.subsampling_dy
              comptparms[j].w = numcols
              comptparms[j].h = numrows
              comptparms[j].x0 = self._cparams.image_offset_x0
              comptparms[j].y0 = self._cparams.image_offset_y0
              comptparms[j].prec = comp_prec
              comptparms[j].bpp = comp_prec
              comptparms[j].sgnd = 0
  
          self._comptparms = comptparms
docs: Instantiate and populate comptparms structure.
  
          This structure defines the image components.
  
          Parameters
          ----------
          img_array : ndarray
              Image data to be written to file.