Toshihiro Shimizu 890ddd
#include "tenv.h"
Toshihiro Shimizu 890ddd
#include "tsystem.h"
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
#include "ino_common.h"
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
/* copy and paste from
Toshihiro Shimizu 890ddd
 igs_ifx_common.h */
Shinya Kitaoka 120a6e
namespace igs {
Shinya Kitaoka 120a6e
namespace image {
Shinya Kitaoka 120a6e
namespace rgba {
Shinya Kitaoka 120a6e
enum num { blu = 0, gre, red, alp, siz };
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
//------------------------------------------------------------
Shinya Kitaoka 120a6e
namespace {
Toshihiro Shimizu 890ddd
// T is TPixel32 or TPixel64
Toshihiro Shimizu 890ddd
// U is unsigned char or unsigned short
Toshihiro Shimizu 890ddd
template <class class="" t,="" u=""></class>
Shinya Kitaoka 120a6e
void ras_to_arr_(const TRasterPT<t> ras, U *arr, const int channels) {</t>
Shinya Kitaoka 120a6e
  using namespace igs::image::rgba;
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  for (int yy = 0; yy < ras->getLy(); ++yy) {
Shinya Kitaoka 120a6e
    const T *ras_sl = ras->pixels(yy);
Shinya Kitaoka 120a6e
    for (int xx = 0; xx < ras->getLx(); ++xx, arr += channels) {
Shinya Kitaoka 120a6e
      if (red < channels) {
Shinya Kitaoka 120a6e
        arr[red] = ras_sl[xx].r;
Shinya Kitaoka 120a6e
      }
Shinya Kitaoka 120a6e
      if (gre < channels) {
Shinya Kitaoka 120a6e
        arr[gre] = ras_sl[xx].g;
Shinya Kitaoka 120a6e
      }
Shinya Kitaoka 120a6e
      if (blu < channels) {
Shinya Kitaoka 120a6e
        arr[blu] = ras_sl[xx].b;
Shinya Kitaoka 120a6e
      }
Shinya Kitaoka 120a6e
      if (alp < channels) {
Shinya Kitaoka 120a6e
        arr[alp] = ras_sl[xx].m;
Shinya Kitaoka 120a6e
      }
Shinya Kitaoka 120a6e
    }
Shinya Kitaoka 120a6e
  }
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
template <class class="" t="" u,=""></class>
Shinya Kitaoka 120a6e
void arr_to_ras_(const U *arr, const int channels, TRasterPT<t> ras,</t>
Shinya Kitaoka 120a6e
                 const int margin  // default is 0
Shinya Kitaoka 120a6e
                 ) {
Shinya Kitaoka 120a6e
  arr +=
Shinya Kitaoka 120a6e
      (ras->getLx() + margin + margin) * margin * channels + margin * channels;
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  using namespace igs::image::rgba;
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  for (int yy = 0; yy < ras->getLy();
Shinya Kitaoka 120a6e
       ++yy, arr += (ras->getLx() + margin + margin) * channels) {
Shinya Kitaoka 120a6e
    const U *arrx = arr;
Shinya Kitaoka 120a6e
    T *ras_sl     = ras->pixels(yy);
Shinya Kitaoka 120a6e
    for (int xx = 0; xx < ras->getLx(); ++xx, arrx += channels) {
Shinya Kitaoka 120a6e
      if (red < channels) {
Shinya Kitaoka 120a6e
        ras_sl[xx].r = arrx[red];
Shinya Kitaoka 120a6e
      }
Shinya Kitaoka 120a6e
      if (gre < channels) {
Shinya Kitaoka 120a6e
        ras_sl[xx].g = arrx[gre];
Shinya Kitaoka 120a6e
      }
Shinya Kitaoka 120a6e
      if (blu < channels) {
Shinya Kitaoka 120a6e
        ras_sl[xx].b = arrx[blu];
Shinya Kitaoka 120a6e
      }
Shinya Kitaoka 120a6e
      if (alp < channels) {
Shinya Kitaoka 120a6e
        ras_sl[xx].m = arrx[alp];
Shinya Kitaoka 120a6e
      }
Shinya Kitaoka 120a6e
    }
Shinya Kitaoka 120a6e
  }
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
//--------------------
Shinya Kitaoka 120a6e
void ino::ras_to_arr(const TRasterP in_ras, const int channels,
Shinya Kitaoka 120a6e
                     unsigned char *out_arr) {
Shinya Kitaoka 120a6e
  if ((TRaster32P)in_ras) {
Shinya Kitaoka 120a6e
    ras_to_arr_<tpixel32, char="" unsigned="">(in_ras, out_arr, channels);</tpixel32,>
Shinya Kitaoka 120a6e
  } else if ((TRaster64P)in_ras) {
Shinya Kitaoka 120a6e
    ras_to_arr_<tpixel64, short="" unsigned="">(</tpixel64,>
Shinya Kitaoka 120a6e
        in_ras, reinterpret_cast<unsigned *="" short="">(out_arr), channels);</unsigned>
Shinya Kitaoka 120a6e
  }
Toshihiro Shimizu 890ddd
}
Shinya Kitaoka 120a6e
void ino::arr_to_ras(const unsigned char *in_arr, const int channels,
Shinya Kitaoka 120a6e
                     TRasterP out_ras, const int margin) {
Shinya Kitaoka 120a6e
  if ((TRaster32P)out_ras) {
Shinya Kitaoka 120a6e
    arr_to_ras_<unsigned char,="" tpixel32="">(in_arr, channels, out_ras, margin);</unsigned>
Shinya Kitaoka 120a6e
  } else if ((TRaster64P)out_ras) {
Shinya Kitaoka 120a6e
    arr_to_ras_<unsigned short,="" tpixel64="">(</unsigned>
Shinya Kitaoka 120a6e
        reinterpret_cast<const *="" short="" unsigned="">(in_arr), channels, out_ras,</const>
Shinya Kitaoka 120a6e
        margin);
Shinya Kitaoka 120a6e
  }
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
//--------------------
Shinya Kitaoka 120a6e
void ino::ras_to_vec(const TRasterP in_ras, const int channels,
Shinya Kitaoka 120a6e
                     std::vector<unsigned char=""> &out_vec) {</unsigned>
Shinya Kitaoka 120a6e
  out_vec.resize(
Shinya Kitaoka 120a6e
      in_ras->getLy() * in_ras->getLx() * channels *
Shinya Kitaoka 120a6e
      (((TRaster64P)in_ras) ? sizeof(unsigned short) : sizeof(unsigned char)));
Shinya Kitaoka 120a6e
  ino::ras_to_arr(in_ras, channels, &out_vec.at(0));
Toshihiro Shimizu 890ddd
}
Shinya Kitaoka 120a6e
void ino::vec_to_ras(std::vector<unsigned char=""> &in_vec, const int channels,</unsigned>
Shinya Kitaoka 120a6e
                     TRasterP out_ras, const int margin  // default is 0
Shinya Kitaoka 120a6e
                     ) {
Shinya Kitaoka 120a6e
  ino::arr_to_ras(&in_vec.at(0), channels, out_ras, margin);
Shinya Kitaoka 120a6e
  in_vec.clear();
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
//--------------------
Shinya Kitaoka 120a6e
#if 0   //---
Toshihiro Shimizu 890ddd
void ino::Lx_to_wrap( TRasterP ras ) {
Toshihiro Shimizu 890ddd
	/*
Toshihiro Shimizu 890ddd
	ras->getLx()   : 描画の幅
Toshihiro Shimizu 890ddd
	ras->getWrap() : データの存在幅
Toshihiro Shimizu 890ddd
	描画幅よりデータの存在幅の方が大きい場合、
Toshihiro Shimizu 890ddd
	存在幅位置に置き直し、残りをゼロクリア
Toshihiro Shimizu 890ddd
	*/
Toshihiro Shimizu 890ddd
	if ( ras->getWrap() <= ras->getLx() ) { return; }
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	const int rowSize  = ras->getLx()   * ras->getPixelSize();
Toshihiro Shimizu 890ddd
	const int wrapSize = ras->getWrap() * ras->getPixelSize();
Toshihiro Shimizu 890ddd
	const int restSize = wrapSize - rowSize;
Toshihiro Shimizu 890ddd
	const UCHAR *rowImg  = ras->getRawData()+rowSize *(ras->getLy()-1);
Toshihiro Shimizu 890ddd
	      UCHAR *wrapImg = ras->getRawData()+wrapSize*(ras->getLy()-1);
Toshihiro Shimizu 890ddd
	for (int yy = 0; yy < ras->getLy(); ++yy) {
Toshihiro Shimizu 890ddd
		::memcpy(wrapImg, rowImg, rowSize);
Toshihiro Shimizu 890ddd
		::memset(wrapImg+rowSize, 0, restSize); /* 上下にはみ出すとここで落ちる */
Toshihiro Shimizu 890ddd
		rowImg  -= rowSize;
Toshihiro Shimizu 890ddd
		wrapImg -= wrapSize;
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
}
Shinya Kitaoka 120a6e
#endif  //---
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//------------------------------------------------------------
Shinya Kitaoka 120a6e
namespace {
Toshihiro Shimizu 890ddd
bool enable_sw_ = true;
Shinya Kitaoka 120a6e
bool check_sw_  = true;
Toshihiro Shimizu 890ddd
}
Shinya Kitaoka 120a6e
bool ino::log_enable_sw(void) {
Shinya Kitaoka 120a6e
  if (check_sw_) {
Shinya Kitaoka 120a6e
    TFileStatus file(
Shinya Kitaoka 120a6e
        // ToonzFolder::getProfileFolder()
Shinya Kitaoka 120a6e
        TEnv::getConfigDir() + "fx_ino_no_log.setup");
Shinya Kitaoka 120a6e
    if (file.doesExist()) {
Shinya Kitaoka 120a6e
      enable_sw_ = false;
Shinya Kitaoka 120a6e
    }
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
    check_sw_ = false;
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
  return enable_sw_;
Toshihiro Shimizu 890ddd
}