Shinya Kitaoka 810553
#pragma once
Shinya Kitaoka 810553
Toshihiro Shimizu 890ddd
#ifndef igs_ifx_common_h
Toshihiro Shimizu 890ddd
#define igs_ifx_common_h
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
#ifndef IGS_IFX_COMMON_EXPORT
Toshihiro Shimizu 890ddd
#define IGS_IFX_COMMON_EXPORT
Toshihiro Shimizu 890ddd
#endif
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
#define RGBA_ORDER_OF_TOONZ6
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
namespace igs {
Shinya Kitaoka 120a6e
namespace image {
Toshihiro Shimizu 890ddd
#if defined RGBA_ORDER_OF_TOONZ6
Toshihiro Shimizu 890ddd
// Toonz6, or GDI, TGA order
Toshihiro Shimizu 890ddd
/*	Exsample:
Shinya Kitaoka 120a6e
        igs::image::rgba::num order = igs::image::rgba::red;
Shinya Kitaoka 120a6e
        igs::image::rgb::num order = igs::image::rgba::red;
Toshihiro Shimizu 890ddd
  */
Shinya Kitaoka 120a6e
namespace rgba {
Shinya Kitaoka 120a6e
enum num { blu = 0, gre, red, alp, siz };
Toshihiro Shimizu 890ddd
}
Shinya Kitaoka 120a6e
namespace rgb {
Shinya Kitaoka 120a6e
enum num { blu = 0, gre, red, siz };
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
#elif defined RGBA_ORDER_OF_OPENGL
Toshihiro Shimizu 890ddd
// OpenGL order
Shinya Kitaoka 120a6e
namespace rgba {
Shinya Kitaoka 120a6e
enum num { red = 0, gre, blu, alp, siz };
Toshihiro Shimizu 890ddd
}
Shinya Kitaoka 120a6e
namespace rgb {
Shinya Kitaoka 120a6e
enum num { red = 0, gre, blu, siz };
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
#else
Shinya Kitaoka 120a6e
Must be define / DRGBA_ORDER_OF_TOONZ6 or
Shinya Kitaoka 120a6e
    / DRGBA_ORDER_OF_OPENGL
Toshihiro Shimizu 890ddd
#endif
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
// Direct 3D, Apple Packed Pixel order
Toshihiro Shimizu 890ddd
// namespace rgba {enum num { alp=0, red, gre, blu, siz }; }
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
// Direct 3D 10
Toshihiro Shimizu 890ddd
// namespace rgba {enum num { alp=0, blu, gre, red, siz }; }
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
template <class t=""></class>
Shinya Kitaoka 120a6e
void copy_except_margin(const T *in, const int margin, T *out, const int hh,
Shinya Kitaoka 120a6e
                        const int ww, const int cc) {
Shinya Kitaoka 120a6e
  const T *p_in = in + margin * (ww + margin * 2) * cc + margin * cc;
Shinya Kitaoka 120a6e
  T *pout       = out;
Shinya Kitaoka 120a6e
  for (int yy = margin; yy < hh + margin; ++yy, p_in += 2 * margin * cc) {
Shinya Kitaoka 120a6e
    for (int xx = margin; xx < ww + margin; ++xx, p_in += cc, pout += cc) {
Shinya Kitaoka 120a6e
      for (int zz = 0; zz < cc; ++zz) {
Shinya Kitaoka 120a6e
        pout[zz] = p_in[zz];
Shinya Kitaoka 120a6e
      }
Shinya Kitaoka 120a6e
    }
Shinya Kitaoka 120a6e
  }
Toshihiro Shimizu 890ddd
}
shun-iwasawa 443318
}  // namespace image
Shinya Kitaoka 120a6e
namespace color {
Toshihiro Shimizu 890ddd
template <class t=""></class>
Shinya Kitaoka 120a6e
double ref_value(const T *ref, const int cc, const int ref_max,
Shinya Kitaoka 120a6e
                 const int ref_mode) {
Shinya Kitaoka 120a6e
  if (igs::image::rgba::siz == cc) {
Shinya Kitaoka 120a6e
    using namespace igs::image::rgba;
Shinya Kitaoka 120a6e
    switch (ref_mode) {
Shinya Kitaoka 120a6e
    case 0:
shun-iwasawa 443318
      return static_cast<double>(ref[red]) / static_cast<double>(ref_max);</double></double>
Shinya Kitaoka 120a6e
      break;
Shinya Kitaoka 120a6e
    case 1:
shun-iwasawa 443318
      return static_cast<double>(ref[gre]) / static_cast<double>(ref_max);</double></double>
Shinya Kitaoka 120a6e
      break;
Shinya Kitaoka 120a6e
    case 2:
shun-iwasawa 443318
      return static_cast<double>(ref[blu]) / static_cast<double>(ref_max);</double></double>
Shinya Kitaoka 120a6e
      break;
Shinya Kitaoka 120a6e
    case 3:
shun-iwasawa 443318
      return static_cast<double>(ref[alp]) / static_cast<double>(ref_max);</double></double>
Shinya Kitaoka 120a6e
      break;
Shinya Kitaoka 120a6e
    case 4:
Shinya Kitaoka 120a6e
      return /* 輝度(Luminance)(CCIR Rec.601) */
shun-iwasawa 443318
          0.298912 * static_cast<double>(ref[red]) /</double>
shun-iwasawa 443318
              static_cast<double>(ref_max) +</double>
shun-iwasawa 443318
          0.586611 * static_cast<double>(ref[gre]) /</double>
shun-iwasawa 443318
              static_cast<double>(ref_max) +</double>
shun-iwasawa 443318
          0.114478 * static_cast<double>(ref[blu]) /</double>
shun-iwasawa 443318
              static_cast<double>(ref_max);</double>
Shinya Kitaoka 120a6e
      break;
Shinya Kitaoka 120a6e
    }
Shinya Kitaoka 120a6e
  } else if (igs::image::rgb::siz == cc) {
Shinya Kitaoka 120a6e
    using namespace igs::image::rgb;
Shinya Kitaoka 120a6e
    switch (ref_mode) {
Shinya Kitaoka 120a6e
    case 0:
shun-iwasawa 443318
      return static_cast<double>(ref[red]) / static_cast<double>(ref_max);</double></double>
Shinya Kitaoka 120a6e
      break;
Shinya Kitaoka 120a6e
    case 1:
shun-iwasawa 443318
      return static_cast<double>(ref[gre]) / static_cast<double>(ref_max);</double></double>
Shinya Kitaoka 120a6e
      break;
Shinya Kitaoka 120a6e
    case 2:
shun-iwasawa 443318
      return static_cast<double>(ref[blu]) / static_cast<double>(ref_max);</double></double>
Shinya Kitaoka 120a6e
      break;
Shinya Kitaoka 120a6e
    case 3:
Shinya Kitaoka 120a6e
      return /* 輝度(Luminance)(CCIR Rec.601) */
shun-iwasawa 443318
          0.298912 * static_cast<double>(ref[red]) /</double>
shun-iwasawa 443318
              static_cast<double>(ref_max) +</double>
shun-iwasawa 443318
          0.586611 * static_cast<double>(ref[gre]) /</double>
shun-iwasawa 443318
              static_cast<double>(ref_max) +</double>
shun-iwasawa 443318
          0.114478 * static_cast<double>(ref[blu]) /</double>
shun-iwasawa 443318
              static_cast<double>(ref_max);</double>
Shinya Kitaoka 120a6e
      break;
Shinya Kitaoka 120a6e
    }
Shinya Kitaoka 120a6e
  } else if (1 == cc) {
shun-iwasawa 443318
    return static_cast<double>(ref[0]) / static_cast<double>(ref_max);</double></double>
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
  return 1.0;
Toshihiro Shimizu 890ddd
}
shun-iwasawa 443318
}  // namespace color
shun-iwasawa 443318
}  // namespace igs
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
#endif /* !igs_ifx_common_h */