// blend1.cpp : DLL アプリケーションのエントリ ポイントを定義します。 // #include "stdafx.h" #include #include #ifdef _MANAGED #pragma managed(push, off) #endif extern "C" { typedef unsigned char n_byte; int __stdcall get_blend_func_count(); char* __stdcall get_blend_func_key(int no); char* __stdcall get_blend_func_name(int no); void __stdcall blend(unsigned char* dst,const unsigned char* col,const unsigned char* alpha,int col_step ,int alpha_step,int num_channel,int num_pixel,int no); //追加する合成方法の数を返す。 int __stdcall get_blend_func_count() { return 1; } //psdファイルに保存するときのkeyを返す。 /* 'norm' = normal 'dark' = darken 'lite' = lighten 'hue ' = hue 'sat ' = saturation 'colr' = color 'lum ' = luminosity 'mul ' = multiply 'scrn' = screen 'diss' = dissolve 'over' = overlay 'hLit' = hard light 'sLit' = soft light 'diff' = difference 'smud' = exlusion 'div ' = color dodge 'idiv' = color burn */ char* __stdcall get_blend_func_key(int no) { if (no == 0) { return "sand"; } return 0; } //合成方法の名前を返す。 char* __stdcall get_blend_func_name(int no) { if (no == 0) { return "砂トーン"; } return ""; } //合成を行う関数。 //num_channel チャンネル数。グレーモードの場合は1、カラーモードの場合は3 void __stdcall blend(unsigned char* dst,const unsigned char* col,const unsigned char* alpha,int col_step,int alpha_step ,int num_channel,int num_pixel,int no) { if (no == 0) {//ディザ拡散 if (num_channel == 1) { const unsigned char* col_end = col + num_pixel * col_step; while (col < col_end) { unsigned int a1 = *alpha; if (a1 != 0){//α値の完全に透明部分は描かない int sand_rand = rand() % 101; int kido = (77 * *col + 150 * *col + 29 * *col) / 256;//輝度計算 double deep = (int)(100 - kido / 2.55) * (*alpha/255.0) ; if (sand_rand <= deep && deep != 0){ *dst = 0 ; } else { *dst = (unsigned char)*dst; } } alpha += alpha_step; col += col_step; dst += col_step; } } else if (num_channel == 3) { const unsigned char* col_end = col + num_pixel * col_step; // srand(0); // rand関数を初期化する。0を入れてるのは適当 while (col < col_end) { unsigned int a1 = *alpha; if (a1 != 0){//α値の完全に透明部分は描かない int sand_rand = rand() % 101 ; int kido = (77 * *(col + 2) + 150 * *(col + 1) + 29 * *col) / 256;//輝度計算 double deep = (int)(100 - kido / 2.55) * (*alpha/255.0) ; if (sand_rand <= deep && deep != 0){ *dst = 0 ; *(dst + 1) = 0 ; *(dst + 2) = 0 ; } else { *dst = (unsigned char)*dst; *(dst + 1) = (unsigned char)*(dst + 1) ; *(dst + 2) = (unsigned char)*(dst + 2) ; } } alpha += alpha_step; col += col_step; dst += col_step; } } } } //下のレイヤーと結合で使用される void __stdcall merge(n_byte* dst,const n_byte* col,const n_byte* base_col,const n_byte* alpha,const n_byte* base_alpha ,int col_step,int alpha_step,int base_alpha_step,int num_channel,int num_pixel,int no) { if (no == 0) { if (num_channel == 1) { const unsigned char* col_end = col + num_pixel * col_step; while (col < col_end) { unsigned int a0 = *base_alpha; unsigned int a1 = *alpha; if (a1 != 0){ int sand_rand = rand() % 101 ; int kido = (77 * *col + 150 * *col + 29 * *col) / 256;//輝度計算 double deep = (int)(100 - kido / 2.55) * (a1/255.0) ; if (sand_rand <= deep && deep != 0){ *dst = 0 ; *(dst + 1) = 255 ; } else { *dst = (unsigned char)*base_col; *(dst + 1) = *base_alpha; } } else { *dst = *base_col; *(dst + 1) = *base_alpha; } dst += 2; col += col_step; base_col += col_step; alpha += alpha_step; base_alpha += alpha_step; } } else if (num_channel == 3) { const unsigned char* col_end = col + num_pixel * col_step; while (col < col_end) { unsigned int a0 = *base_alpha; unsigned int a1 = *alpha; if (a1 != 0){ int sand_rand = rand() % 101 ; int kido = (77 * *(col + 2) + 150 * *(col + 1) + 29 * *col) / 256;//輝度計算 double deep = (int)(100 - kido / 2.55) * (a1/255.0) ; if (sand_rand <= deep && deep != 0){ *dst = 0 ; *(dst + 1) = 0 ; *(dst + 2) = 0 ; *(dst + 3) = 255; } else { *dst = (unsigned char)*base_col; *(dst + 1) = (unsigned char)*(base_col + 1) ; *(dst + 2) = (unsigned char)*(base_col + 2) ; *(dst + 3) = *base_alpha; } } else {//現在のレイヤーが透明ならば *dst = *base_col; *(dst + 1) = *(base_col + 1); *(dst + 2) = *(base_col + 2); *(dst + 3) = *base_alpha; } dst += 4; col += col_step; base_col += col_step; alpha += alpha_step; base_alpha += base_alpha_step; } } } } } BOOL APIENTRY DllMain( HMODULE hModule, DWORD ul_reason_for_call, LPVOID lpReserved ) { return TRUE; } #ifdef _MANAGED #pragma managed(pop) #endif