Toshihiro Shimizu 890ddd
#include "plugin_tile_interface.h"
Toshihiro Shimizu 890ddd
#include "ttile.h"
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
int tile_interface_get_raw_address_unsafe(toonz_tile_handle_t handle,
Shinya Kitaoka 120a6e
                                          void **address) {
Shinya Kitaoka 120a6e
  if (!handle || !address) return -1;  // inval
Shinya Kitaoka 120a6e
  TTile *tile = reinterpret_cast<ttile *="">(handle);</ttile>
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  tile->getRaster()->lock();
Shinya Kitaoka 120a6e
  *address = tile->getRaster()->getRawData();
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  return 0;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
int tile_interface_safen(toonz_tile_handle_t handle) {
Shinya Kitaoka 120a6e
  if (!handle) {
Shinya Kitaoka 120a6e
    return -1;  // inval
Shinya Kitaoka 120a6e
  }
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  TTile *tile = reinterpret_cast<ttile *="">(handle);</ttile>
Shinya Kitaoka 120a6e
  tile->getRaster()->unlock();
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  return 0;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
int tile_interface_get_raw_stride(toonz_tile_handle_t handle, int *stride) {
Shinya Kitaoka 120a6e
  if (!handle || !stride) return -1;  // inval
Shinya Kitaoka 120a6e
  TTile *tile = reinterpret_cast<ttile *="">(handle);</ttile>
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  //	return stride in byte, not in pixel
Shinya Kitaoka 120a6e
  *stride = tile->getRaster()->getWrap() * tile->getRaster()->getPixelSize();
Shinya Kitaoka 120a6e
  return 0;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
int tile_interface_get_element_type(toonz_tile_handle_t handle, int *element) {
Shinya Kitaoka 120a6e
  if (!handle || !element) return -1;  // inval
Shinya Kitaoka 120a6e
  TTile *tile     = reinterpret_cast<ttile *="">(handle);</ttile>
Shinya Kitaoka 120a6e
  TRasterP raster = tile->getRaster();
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  if (false)
Shinya Kitaoka 120a6e
    ;
Shinya Kitaoka 120a6e
  else if (TRaster32P(raster))
Shinya Kitaoka 120a6e
    *element = TOONZ_TILE_TYPE_32P;
Shinya Kitaoka 120a6e
  else if (TRaster64P(raster))
Shinya Kitaoka 120a6e
    *element = TOONZ_TILE_TYPE_64P;
Shinya Kitaoka 120a6e
  else if (TRasterGR8P(raster))
Shinya Kitaoka 120a6e
    *element = TOONZ_TILE_TYPE_GR8P;
Shinya Kitaoka 120a6e
  else if (TRasterGR16P(raster))
Shinya Kitaoka 120a6e
    *element = TOONZ_TILE_TYPE_GR16P;
Shinya Kitaoka 120a6e
  else if (TRasterGRDP(raster))
Shinya Kitaoka 120a6e
    *element = TOONZ_TILE_TYPE_GRDP;
Shinya Kitaoka 120a6e
  else if (TRasterYUV422P(raster))
Shinya Kitaoka 120a6e
    *element = TOONZ_TILE_TYPE_YUV422P;
Shinya Kitaoka 120a6e
  else {
Shinya Kitaoka 120a6e
    *element = TOONZ_TILE_TYPE_NONE;
Shinya Kitaoka 120a6e
    return -1;
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  return 0;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
int tile_interface_copy_rect(toonz_tile_handle_t handle, int left, int top,
Shinya Kitaoka 120a6e
                             int width, int height, void *dst, int dststride) {
Shinya Kitaoka 120a6e
  if (!handle || !dst || !dststride) return -1;  // inval
Shinya Kitaoka 120a6e
  if (!width || !height) return 0;               // do nothing
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  TTile *tile     = reinterpret_cast<ttile *="">(handle);</ttile>
Shinya Kitaoka 120a6e
  TRasterP raster = tile->getRaster();
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  if (!(0 <= left && left + width <= raster->getLx() && 0 <= top &&
Shinya Kitaoka 120a6e
        top + height <= raster->getLy())) {
Shinya Kitaoka 120a6e
    return -1;
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  for (int y = 0; y < height; y++) {
Shinya Kitaoka 120a6e
    memcpy((UCHAR *)dst + y * dststride, raster->getRawData(left, top + y),
Shinya Kitaoka 120a6e
           width * raster->getPixelSize());
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  return 0;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
int tile_interface_create_from(toonz_tile_handle_t handle,
Shinya Kitaoka 120a6e
                               toonz_tile_handle_t *newhandle) {
Shinya Kitaoka 120a6e
  if (!handle || !newhandle) return -1;  // inval
Shinya Kitaoka 120a6e
  TTile *tile    = reinterpret_cast<ttile *="">(handle);</ttile>
Shinya Kitaoka 120a6e
  TTile *newtile = new TTile(tile->getRaster());
Shinya Kitaoka 120a6e
  *newhandle     = reinterpret_cast<toonz_tile_handle_t *="">(newtile);</toonz_tile_handle_t>
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  return 0;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
int tile_interface_create(toonz_tile_handle_t *newhandle) {
Shinya Kitaoka 120a6e
  if (!newhandle) return -1;  // inval
Shinya Kitaoka 120a6e
  *newhandle = reinterpret_cast<toonz_tile_handle_t *="">(new TTile());</toonz_tile_handle_t>
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  return 0;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
int tile_interface_destroy(toonz_tile_handle_t handle) {
Shinya Kitaoka 120a6e
  if (!handle) return -1;  // inval
Shinya Kitaoka 120a6e
  TTile *tile = reinterpret_cast<ttile *="">(handle);</ttile>
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  delete tile;
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  return 0;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
int tile_interface_get_rectangle(toonz_tile_handle_t handle,
Shinya Kitaoka 120a6e
                                 toonz_rect_t *rect) {
Shinya Kitaoka 120a6e
  if (!handle || !rect) {
Shinya Kitaoka 120a6e
    return -1;  // inval
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  TTile *tile = reinterpret_cast<ttile *="">(handle);</ttile>
Shinya Kitaoka 120a6e
  rect->x0    = tile->m_pos.x;
Shinya Kitaoka 120a6e
  rect->y0    = tile->m_pos.y;
Shinya Kitaoka 120a6e
  rect->x1    = tile->m_pos.x + tile->getRaster()->getLx();
Shinya Kitaoka 120a6e
  rect->y1    = tile->m_pos.y + tile->getRaster()->getLy();
Shinya Kitaoka 120a6e
  return 0;
Toshihiro Shimizu 890ddd
}