Features::get_item_features( int $target_item_id, int $tile_depth ): AvifinfoStatus

In this article

This function’s access is marked private. This means it is not intended for use by plugin or theme developers, only in other core functions. It is listed here for completeness.

Binds the width, height, bit depth and number of channels from stored internal features.

Parameters

$target_item_idintrequired
Id of the item whose features will be bound.
$tile_depthintrequired
Maximum recursion to search within tile-parent relations.

Return

AvifinfoStatus FOUND on success or NOT_FOUND on failure.

Source

private function get_item_features( $target_item_id, $tile_depth ) {
  foreach ( $this->props as $prop ) {
    if ( $prop->item_id != $target_item_id ) {
      continue;
    }

    // Retrieve the width and height of the primary item if not already done.
    if ( $target_item_id == $this->primary_item_id &&
         ( $this->primary_item_features['width'] == UNDEFINED ||
           $this->primary_item_features['height'] == UNDEFINED ) ) {
      foreach ( $this->dim_props as $dim_prop ) {
        if ( $dim_prop->property_index != $prop->property_index ) {
          continue;
        }
        $this->primary_item_features['width']  = $dim_prop->width;
        $this->primary_item_features['height'] = $dim_prop->height;
        if ( $this->primary_item_features['bit_depth'] != UNDEFINED &&
             $this->primary_item_features['num_channels'] != UNDEFINED ) {
          return FOUND;
        }
        break;
      }
    }
    // Retrieve the bit depth and number of channels of the target item if not
    // already done.
    if ( $this->primary_item_features['bit_depth'] == UNDEFINED ||
         $this->primary_item_features['num_channels'] == UNDEFINED ) {
      foreach ( $this->chan_props as $chan_prop ) {
        if ( $chan_prop->property_index != $prop->property_index ) {
          continue;
        }
        $this->primary_item_features['bit_depth']    = $chan_prop->bit_depth;
        $this->primary_item_features['num_channels'] = $chan_prop->num_channels;
        if ( $this->primary_item_features['width'] != UNDEFINED &&
            $this->primary_item_features['height'] != UNDEFINED ) {
          return FOUND;
        }
        break;
      }
    }
  }

  // Check for the bit_depth and num_channels in a tile if not yet found.
  if ( $tile_depth < 3 ) {
    foreach ( $this->tiles as $tile ) {
      if ( $tile->parent_item_id != $target_item_id ) {
        continue;
      }
      $status = $this->get_item_features( $tile->tile_item_id, $tile_depth + 1 );
      if ( $status != NOT_FOUND ) {
        return $status;
      }
    }
  }
  return NOT_FOUND;
}

User Contributed Notes

You must log in before being able to contribute a note or feedback.