#include <cstdlib>#include <ctime>#include <ctype.h>#include <math.h>#include <stddef.h>#include <stdio.h>#include <stdlib.h>#include <string.h>#include <windows.h>#include <time.h>#define M_PI 3.1415926535 double round(double d){ return floor(d + 0.5);} BOOL APIENTRY DllMain( HMODULE hModule, DWORD ul_reason_for_call, LPVOID lpReserved) { switch (ul_reason_for_call) { case DLL_PROCESS_ATTACH: case DLL_THREAD_ATTACH: case DLL_THREAD_DETACH: case DLL_PROCESS_DETACH: break; } return true;} typedef struct { DWORD flags; DWORD klass; void (*dmark) (void*); void (*dfree) (void*); double *data; //red is index 1, green is index 2, blue 3, alpha 0} RGSSCOLOR; typedef struct{ DWORD unk1; DWORD unk2; BITMAPINFOHEADER *infoheader; RGSSCOLOR *firstRow; RGBQUAD *lastRow;} RGSSBMINFO; typedef struct{ DWORD unk1; DWORD unk2; RGSSBMINFO *bminfo;} BITMAPSTRUCT; typedef struct{ DWORD flags; DWORD klass; void (*dmark) (void*); void (*dfree) (void*); BITMAPSTRUCT *bm;} RGSSBITMAP; #define ASSERT(x) if(!x){DebugOut("Failed: %s: %d", #x, __LINE__);} extern "C" _declspec (dllexport) BOOL clear_rect(long object, int x, int y, int w, int h){ RGSSBMINFO *bitmap = ((RGSSBITMAP*) (object<<1)) -> bm -> bminfo; DWORD rowsize; DWORD width, height; LPBYTE row; int i, e; //int red, green, blue; if(!bitmap) return false; width = bitmap -> infoheader -> biWidth; height = bitmap -> infoheader -> biHeight;if(x>(int)width) x = width;if(y>(int)height) y = height;if(x<0) x = 0;if(y<0) y = 0;if(w<0) return false;if(h<0) return false;if(x+w>(int)width) w = width - x;if(y+h>(int)height) h = height - y; rowsize = width * 4; row = (LPBYTE) (bitmap -> firstRow);row -= rowsize * y; for ( i = y; i < y + h; i++) { LPBYTE thisrow = row;thisrow += 4 * x; for ( e = x; e < x + w; e++) { //red = thisrow[2]; //green = thisrow[1]; //blue = thisrow[0];thisrow[0] = 0;thisrow[1] = 0;thisrow[2] = 0;thisrow[3] = 0; thisrow += 4; } row -= rowsize; } return true;} extern "C" _declspec (dllexport) BOOL fill_rect(long object, int x, int y, int w, int h, int r, int g, int b, int a){ RGSSBMINFO *bitmap = ((RGSSBITMAP*) (object<<1)) -> bm -> bminfo; DWORD rowsize; DWORD width, height; LPBYTE row; int i, e; //int red, green, blue; if(!bitmap) return false; width = bitmap -> infoheader -> biWidth; height = bitmap -> infoheader -> biHeight;if(x>(int)width) return false;if(y>(int)height) return false;if(x<0) {w += x;x = 0;}if(y<0) {h += y;y = 0;}if(w<0) return false;if(h<0) return false;if(x+w>(int)width) w = width - x;if(y+h>(int)height) h = height - y; rowsize = width * 4; row = (LPBYTE) (bitmap -> firstRow);row -= rowsize * y; for ( i = y; i < y + h; i++) { LPBYTE thisrow = row;thisrow += 4 * x; for ( e = x; e < x + w; e++) { thisrow[0] = b;thisrow[1] = g;thisrow[2] = r;thisrow[3] = a; thisrow += 4; } row -= rowsize; } return true;} BOOL fill_rect2(int width, int height, LPBYTE row, int x, int y, int w, int h, int r, int g, int b, int a){ int rowsize; int i, e; //int red, green, blue;if(x>width) return false;if(y>height) return false;if(x<0) {w += x;x = 0;}if(y<0) {h += y;y = 0;}if(w<0) return false;if(h<0) return false;if(x+w>width) w = width - x;if(y+h>height) h = height - y; rowsize = width * 4;//row -= rowsize * y; for ( i = y; i < y + h; i++) { LPBYTE thisrow = row;//thisrow += 4 * x; for ( e = x; e < x + w; e++) { thisrow[0] = b;thisrow[1] = g;thisrow[2] = r;thisrow[3] = a; thisrow += 4; } row -= rowsize; } return true;} extern "C" _declspec (dllexport) BOOL blt(long object, long source, int x, int y, int srcx, int srcy, int w, int h, int opacity){RGSSBMINFO *bitmap = ((RGSSBITMAP*) (object<<1)) -> bm -> bminfo;RGSSBMINFO *src = ((RGSSBITMAP*) (source<<1)) -> bm -> bminfo; DWORD rowsize, srcrowsize; DWORD width, height, srcwidth, srcheight; LPBYTE row, srcrow; int i, e, sa;int m2 = 255 * 255; if(!bitmap) return false;if(opacity == 0) return false; width = bitmap -> infoheader -> biWidth; height = bitmap -> infoheader -> biHeight; srcwidth = src -> infoheader -> biWidth; srcheight = src -> infoheader -> biHeight;if(srcx>(int)srcwidth) srcx = srcwidth;if(srcy>(int)srcheight) srcy = srcheight;if(srcx<0) srcx = 0;if(srcy<0) srcy = 0;if(srcwidth<0) return false;if(srcheight<0) return false;if(srcx+w>(int)srcwidth) w = srcwidth - srcx;if(srcy+h>(int)srcheight) h = srcheight - srcy;if(x>(int)width) x = width;if(y>(int)height) y = height;if(x<0) x = 0;if(y<0) y = 0;if(w<0) return false;if(h<0) return false;if(x+w>(int)width) w = width - x;if(y+h>(int)height) h = height - y; rowsize = width * 4; srcrowsize = srcwidth * 4; row = (LPBYTE) (bitmap -> firstRow);srcrow = (LPBYTE) (src -> firstRow);row -= rowsize * y;srcrow -= srcrowsize * srcy; for ( i = y; i < y + h; i++) { LPBYTE thisrow = row;LPBYTE thissrcrow = srcrow;thisrow += 4 * x;thissrcrow += 4 * srcx; for ( e = x; e < x + w; e++) {sa = thissrcrow[3] * opacity;if (sa == m2) {thisrow[0] = thissrcrow[0];thisrow[1] = thissrcrow[1];thisrow[2] = thissrcrow[2];thisrow[3] = 255;} else if (thisrow[3] == 0) {thisrow[0] = thissrcrow[0];thisrow[1] = thissrcrow[1];thisrow[2] = thissrcrow[2];thisrow[3] = sa / 255;} else if (sa != 0) {sa /= 255;if (sa == 0) continue;thisrow[0] = thissrcrow[0] * sa / 255 + thisrow[0] * (255 - sa) / 255;thisrow[1] = thissrcrow[1] * sa / 255 + thisrow[1] * (255 - sa) / 255;thisrow[2] = thissrcrow[2] * sa / 255 + thisrow[2] * (255 - sa) / 255;thisrow[3] = min(thisrow[3] + sa * sa / 255, 255);} thisrow += 4;thissrcrow += 4; } row -= rowsize;srcrow -= srcrowsize; } return true;} extern "C" _declspec (dllexport) BOOL simple_blt(long object, long source, int x, int y, int srcx, int srcy, int w, int h) {RGSSBMINFO *bitmap = ((RGSSBITMAP*) (object<<1)) -> bm -> bminfo;RGSSBMINFO *src = ((RGSSBITMAP*) (source<<1)) -> bm -> bminfo; DWORD rowsize, srcrowsize; DWORD width, height, srcwidth, srcheight; LPBYTE row, srcrow; int i, e; if(!bitmap) return false; width = bitmap -> infoheader -> biWidth; height = bitmap -> infoheader -> biHeight; srcwidth = src -> infoheader -> biWidth; srcheight = src -> infoheader -> biHeight;if(srcx>(int)srcwidth) srcx = srcwidth;if(srcy>(int)srcheight) srcy = srcheight;if(srcx<0) srcx = 0;if(srcy<0) srcy = 0;if(srcwidth<0) return false;if(srcheight<0) return false;if(srcx+w>(int)srcwidth) w = srcwidth - srcx;if(srcy+h>(int)srcheight) h = srcheight - srcy;if(x>(int)width) x = width;if(y>(int)height) y = height;if(x<0) x = 0;if(y<0) y = 0;if(w<0) return false;if(h<0) return false;if(x+w>(int)width) w = width - x;if(y+h>(int)height) h = height - y; rowsize = width * 4; srcrowsize = srcwidth * 4; row = (LPBYTE) (bitmap -> firstRow);srcrow = (LPBYTE) (src -> firstRow);row -= rowsize * y;srcrow -= srcrowsize * srcy; for ( i = y; i < y + h; i++) { LPBYTE thisrow = row;LPBYTE thissrcrow = srcrow;thisrow += 4 * x;thissrcrow += 4 * srcx; for ( e = x; e < x + w; e++) {thisrow[0] = thissrcrow[0];thisrow[1] = thissrcrow[1];thisrow[2] = thissrcrow[2];thisrow[3] = thissrcrow[3]; thisrow += 4;thissrcrow += 4; } row -= rowsize;srcrow -= srcrowsize; } return true;} extern "C" _declspec (dllexport) BOOL blend_blt(long object, long source, int x, int y, int srcx, int srcy, int w, int h, int blend_type, int opacity){//if (blend_type == 0) return blt(object, source, x, y, srcx, srcy, w, h, opacity);RGSSBMINFO *bitmap = ((RGSSBITMAP*) (object<<1)) -> bm -> bminfo;RGSSBMINFO *src = ((RGSSBITMAP*) (source<<1)) -> bm -> bminfo; DWORD rowsize, srcrowsize; DWORD width, height, srcwidth, srcheight; LPBYTE row, srcrow; int i, e, sa;int m2 = 255 * 255; if(!bitmap) return false;if(opacity == 0 && blend_type != 12) return false; width = bitmap -> infoheader -> biWidth; height = bitmap -> infoheader -> biHeight; srcwidth = src -> infoheader -> biWidth; srcheight = src -> infoheader -> biHeight;if(srcx>(int)srcwidth) srcx = srcwidth;if(srcy>(int)srcheight) srcy = srcheight;if(srcx<0) srcx = 0;if(srcy<0) srcy = 0;if(srcwidth<0) return false;if(srcheight<0) return false;if(srcx+w>(int)srcwidth) w = srcwidth - srcx;if(srcy+h>(int)srcheight) h = srcheight - srcy;if(x>(int)width) x = width;if(y>(int)height) y = height;if(x<0) x = 0;if(y<0) y = 0;if(w<0) return false;if(h<0) return false;if(x+w>(int)width) w = width - x;if(y+h>(int)height) h = height - y; rowsize = width * 4; srcrowsize = srcwidth * 4; row = (LPBYTE) (bitmap -> firstRow);srcrow = (LPBYTE) (src -> firstRow);row -= rowsize * y;srcrow -= srcrowsize * srcy;if (blend_type == 12) srand(time(NULL)); for ( i = y; i < y + h; i++) { LPBYTE thisrow = row;LPBYTE thissrcrow = srcrow;thisrow += 4 * x;thissrcrow += 4 * srcx; for ( e = x; e < x + w; e++) {int tmp;sa = thissrcrow[3] * opacity;switch (blend_type) {case 0:if (sa == m2) {thisrow[0] = thissrcrow[0];thisrow[1] = thissrcrow[1];thisrow[2] = thissrcrow[2];thisrow[3] = 255;} else if (thisrow[3] == 0) {thisrow[0] = thissrcrow[0];thisrow[1] = thissrcrow[1];thisrow[2] = thissrcrow[2];thisrow[3] = sa / 255;} else if (sa != 0) {sa /= 255;if (sa == 0) continue;thisrow[0] = ((int)thissrcrow[0] * sa + thisrow[0] * (255 - sa)) / 255;thisrow[1] = ((int)thissrcrow[1] * sa + thisrow[1] * (255 - sa)) / 255;thisrow[2] = ((int)thissrcrow[2] * sa + thisrow[2] * (255 - sa)) / 255;tmp = thisrow[3] + sa * sa / 255;if (tmp <= 255)thisrow[3] = tmp;elsethisrow[3] = 255;}break;case 1:if (sa == m2) {if (thisrow[0] + thissrcrow[0] <= 255)thisrow[0] += thissrcrow[0];elsethisrow[0] = 255;if (thisrow[1] + thissrcrow[1] <= 255)thisrow[1] += thissrcrow[1];elsethisrow[1] = 255;if (thisrow[2] + thissrcrow[2] <= 255)thisrow[2] += thissrcrow[2];elsethisrow[2] = 255;} else if (thisrow[3] == 0) {thisrow[0] = thissrcrow[0];thisrow[1] = thissrcrow[1];thisrow[2] = thissrcrow[2];thisrow[3] = sa / 255;} else if (sa != 0) {sa /= 255;if (sa == 0) continue;tmp = thisrow[0] + thissrcrow[0] * sa / 255;if (tmp <= 255)thisrow[0] = tmp;elsethisrow[0] = 255;tmp = thisrow[1] + thissrcrow[1] * sa / 255;if (tmp <= 255)thisrow[1] = tmp;elsethisrow[1] = 255;tmp = thisrow[2] + thissrcrow[2] * sa / 255;if (tmp <= 255)thisrow[2] = tmp;elsethisrow[2] = 255;tmp = thisrow[3] + sa * sa / 255;if (tmp <= 255)thisrow[3] = tmp;elsethisrow[3] = 255;//thisrow[0] = min(thisrow[0] + thissrcrow[0] * sa / 255, 255);//thisrow[1] = min(thisrow[1] + thissrcrow[1] * sa / 255, 255);//thisrow[2] = min(thisrow[2] + thissrcrow[2] * sa / 255, 255);//thisrow[3] = min(thisrow[3] + sa * sa / 255, 255);}break;case 2:if (sa == m2) {if (thisrow[0] - thissrcrow[0] >= 0)thisrow[0] -= thissrcrow[0];elsethisrow[0] = 0;if (thisrow[1] - thissrcrow[1] >= 0)thisrow[1] -= thissrcrow[1];elsethisrow[1] = 0;if (thisrow[2] - thissrcrow[2] >= 0)thisrow[2] -= thissrcrow[2];elsethisrow[2] = 0;} else if (thisrow[3] == 0) {thisrow[0] = 0;thisrow[1] = 0;thisrow[2] = 0;thisrow[3] = sa / 255;} else if (sa != 0) {sa /= 255;if (sa == 0) continue;tmp = thisrow[0] - thissrcrow[0] * sa / 255;if (tmp >= 0)thisrow[0] = tmp;elsethisrow[0] = 0;tmp = thisrow[1] - thissrcrow[1] * sa / 255;if (tmp >= 0)thisrow[1] = tmp;elsethisrow[1] = 0;tmp = thisrow[2] - thissrcrow[2] * sa / 255;if (tmp >= 0)thisrow[2] = tmp;elsethisrow[2] = 0;tmp = thisrow[3] + sa * sa / 255;if (tmp <= 255)thisrow[3] = tmp;elsethisrow[3] = 255;//thisrow[0] = min(thisrow[0] + thissrcrow[0] * sa / 255, 255);//thisrow[1] = min(thisrow[1] + thissrcrow[1] * sa / 255, 255);//thisrow[2] = min(thisrow[2] + thissrcrow[2] * sa / 255, 255);//thisrow[3] = min(thisrow[3] + sa * sa / 255, 255);}break;case 3:if (sa == m2) {thisrow[0] = thisrow[0] * thissrcrow[0] / 255;thisrow[1] = thisrow[1] * thissrcrow[1] / 255;thisrow[2] = thisrow[2] * thissrcrow[2] / 255;thisrow[3] = 255;} else if (sa != 0) {sa /= 255;if (sa == 0) continue;thisrow[0] = (thisrow[0] * (255 - sa) + thisrow[0] * thissrcrow[0] * sa / 255) / 255;thisrow[1] = (thisrow[1] * (255 - sa) + thisrow[1] * thissrcrow[1] * sa / 255) / 255;thisrow[2] = (thisrow[2] * (255 - sa) + thisrow[2] * thissrcrow[2] * sa / 255) / 255;tmp = thisrow[3] + sa * sa / 255;if (tmp <= 255)thisrow[3] = tmp;elsethisrow[3] = 255;}break;case 4:if (sa == m2) {thisrow[0] = 255 - (255 - thisrow[0]) * (255 - thissrcrow[0]) / 255;thisrow[1] = 255 - (255 - thisrow[1]) * (255 - thissrcrow[1]) / 255;thisrow[2] = 255 - (255 - thisrow[2]) * (255 - thissrcrow[2]) / 255;thisrow[3] = 255;} else if (sa != 0) {sa /= 255;if (sa == 0) continue;thisrow[0] = (thisrow[0] * (255 - sa) + sa * (255 - (255 - thisrow[0]) * (255 - thissrcrow[0]) / 255)) / 255;thisrow[1] = (thisrow[1] * (255 - sa) + sa * (255 - (255 - thisrow[1]) * (255 - thissrcrow[1]) / 255)) / 255;thisrow[2] = (thisrow[2] * (255 - sa) + sa * (255 - (255 - thisrow[2]) * (255 - thissrcrow[2]) / 255)) / 255;tmp = thisrow[3] + sa * sa / 255;if (tmp <= 255)thisrow[3] = tmp;elsethisrow[3] = 255;}break;case 5:if (sa == m2) {if (thisrow[0] > 127)thisrow[0] = 255 - (255 - thisrow[0]) * (255 - thissrcrow[0]) / 255;elsethisrow[0] = thisrow[0] * thissrcrow[0] / 255;if (thisrow[1] > 127)thisrow[1] = 255 - (255 - thisrow[1]) * (255 - thissrcrow[1]) / 255;elsethisrow[1] = thisrow[1] * thissrcrow[1] / 255;if (thisrow[2] > 127)thisrow[2] = 255 - (255 - thisrow[2]) * (255 - thissrcrow[2]) / 255;elsethisrow[2] = thisrow[2] * thissrcrow[2] / 255;thisrow[3] = 255;} else if (sa != 0) {sa /= 255;if (sa == 0) continue;if (thisrow[0] > 127)thisrow[0] = (thisrow[0] * (255 - sa) + sa * (255 - (255 - thisrow[0]) * (255 - thissrcrow[0]) / 255)) / 255;elsethisrow[0] = (thisrow[0] * (255 - sa) + thisrow[0] * thissrcrow[0] * sa / 255) / 255;if (thisrow[1] > 127)thisrow[1] = (thisrow[1] * (255 - sa) + sa * (255 - (255 - thisrow[1]) * (255 - thissrcrow[1]) / 255)) / 255;elsethisrow[1] = (thisrow[1] * (255 - sa) + thisrow[1] * thissrcrow[1] * sa / 255) / 255;if (thisrow[2] > 127)thisrow[2] = (thisrow[2] * (255 - sa) + sa * (255 - (255 - thisrow[2]) * (255 - thissrcrow[2]) / 255)) / 255;elsethisrow[2] = (thisrow[2] * (255 - sa) + thisrow[2] * thissrcrow[2] * sa / 255) / 255;tmp = thisrow[3] + sa * sa / 255;if (tmp <= 255)thisrow[3] = tmp;elsethisrow[3] = 255;}break;case 6:if (sa == m2) {thisrow[0] = (-thisrow[0] * (2 * (thisrow[0] - 255) * thissrcrow[0] - 255 * thisrow[0])) / (255 * 255);thisrow[1] = (-thisrow[1] * (2 * (thisrow[1] - 255) * thissrcrow[1] - 255 * thisrow[1])) / (255 * 255);thisrow[2] = (-thisrow[2] * (2 * (thisrow[2] - 255) * thissrcrow[2] - 255 * thisrow[2])) / (255 * 255);thisrow[3] = 255;} else if (sa != 0) {sa /= 255;if (sa == 0) continue;thisrow[0] = (thisrow[0] * (255 - sa) + sa * (-thisrow[0] * (2 * (thisrow[0] - 255) * thissrcrow[0] - 255 * thisrow[0])) / (255 * 255)) / 255;thisrow[1] = (thisrow[1] * (255 - sa) + sa * (-thisrow[1] * (2 * (thisrow[1] - 255) * thissrcrow[1] - 255 * thisrow[1])) / (255 * 255)) / 255;thisrow[2] = (thisrow[2] * (255 - sa) + sa * (-thisrow[2] * (2 * (thisrow[2] - 255) * thissrcrow[2] - 255 * thisrow[2])) / (255 * 255)) / 255;tmp = thisrow[3] + sa * sa / 255;if (tmp <= 255)thisrow[3] = tmp;elsethisrow[3] = 255;}break;case 7:if (sa == m2) {if (255 - thissrcrow[0] > thisrow[0])thisrow[0] = thisrow[0] * 255 / (255 - thissrcrow[0]);elsethisrow[0] = 255;if (255 - thissrcrow[1] > thisrow[1])thisrow[1] = thisrow[1] * 255 / (255 - thissrcrow[1]);elsethisrow[1] = 255;if (255 - thissrcrow[2] > thisrow[2])thisrow[2] = thisrow[2] * 255 / (255 - thissrcrow[2]);elsethisrow[2] = 255;thisrow[3] = 255;} else if (sa != 0) {sa /= 255;if (sa == 0) continue;if (thissrcrow[0] != 255) {tmp = (thisrow[0] * (255 - sa) + sa * thisrow[0] * 255 / (255 - thissrcrow[0])) / 255;if (tmp <= 255 && tmp >= 0)thisrow[0] = tmp;else if (tmp < 0)thisrow[0] = 0;elsethisrow[0] = 255;}if (thissrcrow[1] != 255) {tmp = (thisrow[1] * (255 - sa) + sa * thisrow[1] * 255 / (255 - thissrcrow[1])) / 255;if (tmp <= 255 && tmp >= 0)thisrow[1] = tmp;else if (tmp < 0)thisrow[1] = 0;elsethisrow[1] = 255;}if (thissrcrow[2] == 255) {tmp = (thisrow[2] * (255 - sa) + sa * thisrow[2] * 255 / (255 - thissrcrow[2])) / 255;if (tmp <= 255 && tmp >= 0)thisrow[2] = tmp;else if (tmp < 0)thisrow[2] = 0;elsethisrow[2] = 255;}tmp = thisrow[3] + sa * sa / 255;if (tmp <= 255)thisrow[3] = tmp;elsethisrow[3] = 255;}break;case 8:if (sa == m2) {if (thissrcrow[0] > 255 - thisrow[0])thisrow[0] = 255 - (255 - thisrow[0]) * 255 / (thissrcrow[0]);elsethisrow[0] = 0;if (thissrcrow[1] > 255 - thisrow[1])thisrow[1] = 255 - (255 - thisrow[1]) * 255 / (thissrcrow[1]);elsethisrow[1] = 0;if (thissrcrow[2] > 255 - thisrow[2])thisrow[2] = 255 - (255 - thisrow[2]) * 255 / (thissrcrow[2]);elsethisrow[2] = 0;thisrow[3] = 255;} else if (sa != 0) {sa /= 255;if (sa == 0) continue;if (thissrcrow[0] == 0) {thisrow[0] = 255 - thisrow[0];} else {tmp = (thisrow[0] * (255 - sa) + sa * (255 - (255 - thisrow[0]) * 255 / thissrcrow[0])) / 255;if (tmp <= 255 && tmp >= 0)thisrow[0] = tmp;else if (tmp < 0)thisrow[0] = 0;elsethisrow[0] = 255;}if (thissrcrow[1] == 0) {thisrow[1] = 255 - thisrow[1];} else {tmp = (thisrow[1] * (255 - sa) + sa * (255 - (255 - thisrow[1]) * 255 / thissrcrow[1])) / 255;if (tmp <= 255 && tmp >= 0)thisrow[1] = tmp;else if (tmp < 0)thisrow[1] = 0;elsethisrow[1] = 255;}if (thissrcrow[2] == 0) {thisrow[2] = 255 - thisrow[2];} else {tmp = (thisrow[2] * (255 - sa) + sa * (255 - (255 - thisrow[2]) * 255 / thissrcrow[2])) / 255;if (tmp <= 255 && tmp >= 0)thisrow[2] = tmp;else if (tmp < 0)thisrow[2] = 0;elsethisrow[2] = 255;}tmp = thisrow[3] + sa * sa / 255;if (tmp <= 255)thisrow[3] = tmp;elsethisrow[3] = 255;}break;case 9:if (sa == m2) {tmp = thisrow[0] + thissrcrow[0] - 255;if (tmp >= 0)thisrow[0] = tmp;elsethisrow[0] = 0;tmp = thisrow[1] + thissrcrow[1] - 255;if (tmp >= 0)thisrow[1] = tmp;elsethisrow[1] = 0;tmp = thisrow[2] + thissrcrow[2] - 255;if (tmp >= 0)thisrow[2] = tmp;elsethisrow[2] = 0;thisrow[3] = 255;} else if (thisrow[3] == 0) {thisrow[0] = 0;thisrow[1] = 0;thisrow[2] = 0;thisrow[3] = sa / 255;} else if (sa != 0) {sa /= 255;if (sa == 0) continue;tmp = (thisrow[0] * (255 - sa) + sa * (thisrow[0] + thissrcrow[0] - 255)) / 255;if (tmp >= 0)thisrow[0] = tmp;elsethisrow[0] = 0;tmp = (thisrow[1] * (255 - sa) + sa * (thisrow[1] + thissrcrow[1] - 255)) / 255;if (tmp >= 0)thisrow[1] = tmp;elsethisrow[1] = 0;tmp = (thisrow[2] * (255 - sa) + sa * (thisrow[2] + thissrcrow[2] - 255)) / 255;if (tmp >= 0)thisrow[2] = tmp;elsethisrow[2] = 0;tmp = thisrow[3] + sa * sa / 255;if (tmp <= 255)thisrow[3] = tmp;elsethisrow[3] = 255;}break;case 10:if (sa == m2) {if (thisrow[0] > thissrcrow[0])thisrow[0] = thissrcrow[0] * 255 / thisrow[0];elsethisrow[0] = 255;if (thisrow[1] > thissrcrow[1])thisrow[1] = thissrcrow[1] * 255 / thisrow[1];elsethisrow[1] = 255;if (thisrow[2] > thissrcrow[2])thisrow[2] = thissrcrow[2] * 255 / thisrow[2];elsethisrow[2] = 255;thisrow[3] = 255;} else if (sa != 0) {sa /= 255;if (sa == 0) continue;if (thisrow[0] == 0) {thisrow[0] = thissrcrow[0];} else {tmp = (thisrow[0] * (255 - sa) + sa * thissrcrow[0] * 255 / thisrow[0]) / 255;if (tmp <= 255 && tmp >= 0)thisrow[0] = tmp;else if (tmp < 0)thisrow[0] = 0;elsethisrow[0] = 255;}if (thisrow[1] == 0) {thisrow[1] = thissrcrow[1];} else {tmp = (thisrow[1] * (255 - sa) + sa * thissrcrow[1] * 255 / thisrow[1]) / 255;if (tmp <= 255 && tmp >= 0)thisrow[1] = tmp;else if (tmp < 0)thisrow[1] = 0;elsethisrow[1] = 255;}if (thisrow[2] == 0) {thisrow[2] = thissrcrow[2];} else {tmp = (thisrow[2] * (255 - sa) + sa * thissrcrow[2] * 255 / thisrow[2]) / 255;if (tmp <= 255 && tmp >= 0)thisrow[2] = tmp;else if (tmp < 0)thisrow[2] = 0;elsethisrow[2] = 255;tmp = thisrow[3] + sa * sa / 255;if (tmp <= 255)thisrow[3] = tmp;elsethisrow[3] = 255;}}break;case 11:sa /= 255;if (sa == 0) continue;thisrow[0] = fabs((float)(thisrow[0] - thissrcrow[0]));thisrow[1] = fabs((float)(thisrow[1] - thissrcrow[1]));thisrow[2] = fabs((float)(thisrow[2] - thissrcrow[2]));tmp = thisrow[3] + sa * sa / 255;if (tmp <= 255)thisrow[3] = tmp;elsethisrow[3] = 255;break;case 12:if (rand() % 258 < opacity + 1) {thisrow[0] = thissrcrow[0];thisrow[1] = thissrcrow[1];thisrow[2] = thissrcrow[2];thisrow[3] = thissrcrow[3];}break;} thisrow += 4;thissrcrow += 4; } row -= rowsize;srcrow -= srcrowsize; } return true;} extern "C" _declspec (dllexport) BOOL transfer_blt(long object, long source, int x, int y, int srcx, int srcy, int w, int h, int transfer_mode, int opacity){RGSSBMINFO *bitmap = ((RGSSBITMAP*) (object<<1)) -> bm -> bminfo;RGSSBMINFO *src = ((RGSSBITMAP*) (source<<1)) -> bm -> bminfo; DWORD rowsize, srcrowsize; DWORD width, height, srcwidth, srcheight; LPBYTE row, srcrow; int i, e, sa;int m2 = 255 * 255; if(!bitmap) return false;if(opacity == 0) return false; width = bitmap -> infoheader -> biWidth; height = bitmap -> infoheader -> biHeight; srcwidth = src -> infoheader -> biWidth; srcheight = src -> infoheader -> biHeight;if(srcx>(int)srcwidth) srcx = srcwidth;if(srcy>(int)srcheight) srcy = srcheight;if(srcx<0) srcx = 0;if(srcy<0) srcy = 0;if(srcwidth<0) return false;if(srcheight<0) return false;if(srcx+w>(int)srcwidth) w = srcwidth - srcx;if(srcy+h>(int)srcheight) h = srcheight - srcy;if(x>(int)width) x = width;if(y>(int)height) y = height;if(x<0) x = 0;if(y<0) y = 0;if(w<0) return false;if(h<0) return false;if(x+w>(int)width) w = width - x;if(y+h>(int)height) h = height - y; rowsize = width * 4; srcrowsize = srcwidth * 4; row = (LPBYTE) (bitmap -> firstRow);srcrow = (LPBYTE) (src -> firstRow);row -= rowsize * y;srcrow -= srcrowsize * srcy; for ( i = y; i < y + h; i++) { LPBYTE thisrow = row;LPBYTE thissrcrow = srcrow;thisrow += 4 * x;thissrcrow += 4 * srcx; for ( e = x; e < x + w; e++) {sa = thissrcrow[3] * opacity;switch (transfer_mode) {case 0:if (sa == m2) {thisrow[0] = thissrcrow[0];thisrow[1] = thissrcrow[1];thisrow[2] = thissrcrow[2];thisrow[3] = 255;} else if (thisrow[3] == 0) {thisrow[0] = thissrcrow[0];thisrow[1] = thissrcrow[1];thisrow[2] = thissrcrow[2];thisrow[3] = sa / 255;} else if (sa != 0) {sa /= 255;if (sa == 0) continue;thisrow[0] = thissrcrow[0] * sa / 255 + thisrow[0] * (255 - sa) / 255;thisrow[1] = thissrcrow[1] * sa / 255 + thisrow[1] * (255 - sa) / 255;thisrow[2] = thissrcrow[2] * sa / 255 + thisrow[2] * (255 - sa) / 255;thisrow[3] = min(thisrow[3] + sa * sa / 255, 255);}break;case 1:thisrow[0] = thissrcrow[0];thisrow[1] = thissrcrow[1];thisrow[2] = thissrcrow[2];thisrow[3] = thissrcrow[3] * opacity / 255;break;case 2:if (thisrow[3] == 0) {} else if (sa == m2) {thisrow[0] = thissrcrow[0];thisrow[1] = thissrcrow[1];thisrow[2] = thissrcrow[2];} else if (sa != 0) {sa /= 255;if (sa == 0) continue;thisrow[0] = (thissrcrow[0] * sa + thisrow[0] * (255 - sa)) / 255;thisrow[1] = (thissrcrow[1] * sa + thisrow[1] * (255 - sa)) / 255;thisrow[2] = (thissrcrow[2] * sa + thisrow[2] * (255 - sa)) / 255;}break;case 3:if (thisrow[3] == 255) {} else if (sa == m2 ) {thisrow[0] = (thissrcrow[0] * (255 - thisrow[3]) + thisrow[0] * thisrow[3]) / 255;thisrow[1] = (thissrcrow[1] * (255 - thisrow[3]) + thisrow[1] * thisrow[3]) / 255;thisrow[2] = (thissrcrow[2] * (255 - thisrow[3]) + thisrow[2] * thisrow[3]) / 255;thisrow[3] = 255;} else if (sa != 0) {sa /= 255;thisrow[0] = (thissrcrow[0] * (255 - thisrow[3]) * sa + thisrow[0] * thisrow[3] * (510 - sa)) / m2;thisrow[1] = (thissrcrow[1] * (255 - thisrow[3]) * sa + thisrow[1] * thisrow[3] * (510 - sa)) / m2;thisrow[2] = (thissrcrow[2] * (255 - thisrow[3]) * sa + thisrow[2] * thisrow[3] * (510 - sa)) / m2;thisrow[3] += (255 - thisrow[3]) * sa / 255;}break;} thisrow += 4;thissrcrow += 4; } row -= rowsize;srcrow -= srcrowsize; } return true;} extern "C" _declspec (dllexport) bool transition_in(long object, long transition, int frames, int duration, int rdur) {RGSSBMINFO *bitmap = ((RGSSBITMAP*) (object<<1)) -> bm -> bminfo;RGSSBMINFO *trans = ((RGSSBITMAP*) (transition<<1)) -> bm -> bminfo;int w, h, tw, th;DWORD rowsize, trsize;LPBYTE row, tr;int ofs;int i, e, ind;if(!bitmap) return false;w = bitmap -> infoheader -> biWidth;h = bitmap -> infoheader -> biHeight;tw = trans -> infoheader -> biWidth;th = trans -> infoheader -> biHeight;if (tw < w || th < h) return false;//rdur = duration / 2;ofs = (duration - rdur);rowsize = w * 4;trsize = tw * 4;row = (LPBYTE) bitmap -> firstRow;tr = (LPBYTE) trans -> firstRow;for ( i = 0; i < h; i++) { LPBYTE thisrow = row;LPBYTE thissrcrow = tr; for ( e = 0; e < w; e++) { ind = thissrcrow[2];if (frames - ind * ofs / 255 > 0 && frames - ind * ofs / 255 <= rdur) {thisrow[3] = thisrow[3] * (frames - ind * ofs / 255) / rdur;} else if (frames - ind * ofs / 255 <= 0) {thisrow[3] = 0;} thisrow += 4;thissrcrow += 4; } row -= rowsize;tr -= trsize; }return true;} extern "C" _declspec (dllexport) bool transition_out(long object, long transition, int frames, int duration, int rdur) {RGSSBMINFO *bitmap = ((RGSSBITMAP*) (object<<1)) -> bm -> bminfo;RGSSBMINFO *trans = ((RGSSBITMAP*) (transition<<1)) -> bm -> bminfo;int w, h, tw, th;DWORD rowsize, trsize;LPBYTE row, tr;int ofs;int i, e, ind;if(!bitmap) return false;w = bitmap -> infoheader -> biWidth;h = bitmap -> infoheader -> biHeight;tw = trans -> infoheader -> biWidth;th = trans -> infoheader -> biHeight;if (tw < w || th < h) return false;ofs = (duration - rdur);rowsize = w * 4;trsize = tw * 4;row = (LPBYTE) bitmap -> firstRow;tr = (LPBYTE) trans -> firstRow;for ( i = 0; i < h; i++) { LPBYTE thisrow = row;LPBYTE thissrcrow = tr; for ( e = 0; e < w; e++) { ind = thissrcrow[2];if (frames - ind * ofs / 255 > 0 && frames - ind * ofs / 255 <= rdur) {thisrow[3] = thisrow[3] - thisrow[3] * (frames - ind * ofs / 255) / rdur;} else if (frames - ind * ofs / 255 > rdur) {thisrow[3] = 0;} thisrow += 4;thissrcrow += 4; } row -= rowsize;tr -= trsize; }return true;} extern "C" _declspec (dllexport) bool draw_map(int* data, int* priority, int* sizes, long tileset, long* autotiles, long layer, int ox, int oy, int pri) {RGSSBMINFO *bitmap = ((RGSSBITMAP*) (layer<<1)) -> bm -> bminfo;int width, height;int ind, i, e, a;int tileid, xoff, yoff, z;if(!bitmap) return false;width = bitmap -> infoheader -> biWidth;height = bitmap -> infoheader -> biHeight;ind = 0;for(i = 0; i < width / 32; i++) {for(e = 0; e < height / 32; e++) {for(a = 0; a < sizes[2]; a++) {//ind = (i * sizes[1] * sizes[0] + e * sizes[0] + a);tileid = (int)data[ind];z = (int)priority[ind];ind++;if(z!=pri) continue;if(tileid >= 384) {tileid -= 384;xoff = tileid % 8;yoff = floor(tileid / 8.0);blt(layer, tileset, i * 32, e * 32, xoff * 32, yoff * 32, 32, 32, 255);}}}}return true;} extern "C" _declspec (dllexport) bool split_bitmap(long object1, long object2, int change_y, int change_x){if(change_y == 0 && change_x == 0) return false;RGSSBMINFO *bitmap1 = ((RGSSBITMAP*) (object1<<1)) -> bm -> bminfo;RGSSBMINFO *bitmap2 = ((RGSSBITMAP*) (object2<<1)) -> bm -> bminfo; DWORD width1, width2, height1, height2, size;int strtx, strty, xmod, ymod;int x;double ratio;if(!bitmap1 || !bitmap2) return false;width1 = bitmap1 -> infoheader -> biWidth;height1 = bitmap1 -> infoheader -> biHeight;width2 = bitmap2 -> infoheader -> biWidth;height2 = bitmap2 -> infoheader -> biHeight;if(width1 != width2 || height1 != height2) return false;size = min(width1, height1);xmod = (width1 - size) / 2;ymod = (height1 - size) / 2;xmod = (xmod == 0) ? -ymod / fabs((float)(change_y)) : xmod;ymod = (ymod == 0) ? -xmod / fabs((float)(change_x)) : ymod;x = 0;ratio = ((float) width1) / height1;if(fabs((float)(change_y * ratio)) >= fabs((float)(change_x)) && change_y > 0) {strtx = xmod + ((float) size) / 2 - ((float) change_x) / change_y * size / 2;strty = 0;while (strty < (int)height1) {blt(object2, object1, strtx, strty, strtx, strty, width1 - strtx, change_y, 255);clear_rect(object1, strtx, strty, width1 - strtx, change_y);strty += change_y;strtx += change_x;x++;}} else if(fabs((float)(change_y * ratio)) >= fabs((float)(change_x))) {strtx = xmod + ((float) size) / 2 - ((float) change_x) / (-change_y) * size / 2;strty = height1 + change_y;while (strty > 0) {blt(object2, object1, strtx, strty, strtx, strty, width1 - strtx, -change_y, 255);clear_rect(object1, strtx, strty, width1 - strtx, -change_y);strty += change_y;strtx += change_x;x++;}} else if(change_x > 0) {strtx = 0;strty = ymod + ((float) size) / 2 - ((float) change_y) / change_x * size / 2;while (strtx < (int)width1) {blt(object2, object1, strtx, strty, strtx, strty, change_x, height1 - strty, 255);clear_rect(object1, strtx, strty, change_x, height1 - strty);strty += change_y;strtx += change_x;x++;}} else {strtx = width1 + change_x;strty = ymod + ((float) size) / 2 - ((float) change_y) / (-change_x) * size / 2;while (strtx > 0) {blt(object2, object1, strtx, strty, strtx, strty, -change_x, height1 - strty, 255);clear_rect(object1, strtx, strty, -change_x, height1 - strty);strty += change_y;strtx += change_x;x++;}} return true;} extern "C" _declspec (dllexport) BOOL tint(long object, int amount, int r, int g, int { RGSSBMINFO *bitmap = ((RGSSBITMAP*) (object<<1)) -> bm -> bminfo; DWORD rowsize; DWORD width, height; LPBYTE row; int i, e; //int red, green, blue; if(!bitmap) return false; width = bitmap -> infoheader -> biWidth; height = bitmap -> infoheader -> biHeight; rowsize = width * 4; row = (LPBYTE) (bitmap -> firstRow); for ( i = 0; i < (int)height; i++) { LPBYTE thisrow = row; for ( e = 0; e < (int)width; e++) {thisrow[0] = (((float) amount) * b + ((float) (100 - amount)) * thisrow[0]) / 100;thisrow[1] = (((float) amount) * g + ((float) (100 - amount)) * thisrow[1]) / 100;thisrow[2] = (((float) amount) * r + ((float) (100 - amount)) * thisrow[2]) / 100; thisrow += 4; } row -= rowsize; } return true;} extern "C" _declspec (dllexport) BOOL colorize(long object, int amount, int r, int g, int { RGSSBMINFO *bitmap = ((RGSSBITMAP*) (object<<1)) -> bm -> bminfo; DWORD rowsize; DWORD width, height; LPBYTE row; int i, e;int avg; //int red, green, blue; if(!bitmap) return false; width = bitmap -> infoheader -> biWidth; height = bitmap -> infoheader -> biHeight; rowsize = width * 4; row = (LPBYTE) (bitmap -> firstRow); for ( i = 0; i < (int)height; i++) { LPBYTE thisrow = row; for ( e = 0; e < (int)width; e++) { avg = (thisrow[0] + thisrow[1] + thisrow[2]) / 3;thisrow[0] = (((float) amount) * b + ((float) (100 - amount)) * avg) / 100;thisrow[1] = (((float) amount) * g + ((float) (100 - amount)) * avg) / 100;thisrow[2] = (((float) amount) * r + ((float) (100 - amount)) * avg) / 100; thisrow += 4; } row -= rowsize; } return true;} extern "C" _declspec (dllexport) BOOL grayscale(long object, int amount){ RGSSBMINFO *bitmap = ((RGSSBITMAP*) (object<<1)) -> bm -> bminfo; DWORD rowsize; DWORD width, height; LPBYTE row; int i, e;int avg; if(!bitmap) return false;if(amount == 0) return true; width = bitmap -> infoheader -> biWidth; height = bitmap -> infoheader -> biHeight; rowsize = width * 4; row = (LPBYTE) (bitmap -> firstRow); for ( i = 0; i < (int)height; i++) { LPBYTE thisrow = row; for ( e = 0; e < (int)width; e++) { avg = (thisrow[0] + thisrow[1] + thisrow[2]) / 3;if (amount < 100) {thisrow[0] = (((float) (100 - amount)) * thisrow[0] + ((float) amount) * avg) / 100;thisrow[1] = (((float) (100 - amount)) * thisrow[1] + ((float) amount) * avg) / 100;thisrow[2] = (((float) (100 - amount)) * thisrow[2] + ((float) amount) * avg) / 100;} else {thisrow[0] = avg;thisrow[1] = avg;thisrow[2] = avg;} thisrow += 4; } row -= rowsize; } return true;} extern "C" _declspec (dllexport) BOOL ripple(long object, long source, int amplitude, int wavelength, int dir){//if(wavelength == 0) return false; RGSSBMINFO *bitmap = ((RGSSBITMAP*) (object<<1)) -> bm -> bminfo; DWORD width, height; int i;int shift; //int red, green, blue; if(!bitmap) return false; width = bitmap -> infoheader -> biWidth; height = bitmap -> infoheader -> biHeight;shift = 0;clear_rect(object, 0, 0, width, height);if (dir == 0) {for ( i = 0; i < (int)height; i++) {shift = sin((float) i / amplitude) * wavelength;if (wavelength > 0) {blt(object, source, shift + wavelength, i, 0, i, width, 1, 255);} else {blt(object, source, shift - wavelength, i, 0, i, width, 1, 255);}}} else {for ( i = 0; i < (int)width; i++) {shift = sin((float) i / amplitude) * wavelength;if (wavelength > 0) {blt(object, source, i, shift + wavelength, i, 0, 1, height, 255);} else {blt(object, source, i, shift - wavelength, i, 0, 1, height, 255);}}} return true;} extern _declspec (dllexport) int get_pixel(long object, int x, int y, int index) { RGSSBMINFO *bitmap = ((RGSSBITMAP*) (object<<1)) -> bm -> bminfo; DWORD rowsize; DWORD width, height; LPBYTE row; if(!bitmap) return false; width = bitmap -> infoheader -> biWidth; height = bitmap -> infoheader -> biHeight;if(y > (int)height - 1 || x > (int)width - 1 || y < 0 || x < 0) return false; rowsize = width * 4; row = (LPBYTE) (bitmap -> firstRow);row -= rowsize * y;row += x * 4;return row[index];} extern "C" _declspec (dllexport) int ripple_circ(long object, int cx, int cy, int o, int w, int change, int amnt) {RGSSBMINFO *bitmap = ((RGSSBITMAP*) (object<<1)) -> bm -> bminfo; DWORD rowsize; DWORD width, height; LPBYTE row; int i, e, d, sx, sy, ex, ey;float ratio; if(!bitmap) return false; width = bitmap -> infoheader -> biWidth; height = bitmap -> infoheader -> biHeight; rowsize = width * 4; row = (LPBYTE) (bitmap -> firstRow);ratio = 0.0;sx = max(cx - amnt, 0);sy = max(cy - amnt, 0);ex = min(cx + amnt, width);ey = min(cy + amnt, height);double* sins = new double[w];for (i = 0;i < w;i++) {sins[i] = change * sin(M_PI * 3 / 2 + ((float)((i + o) % w)) * M_PI * 2 / w) / 100;}row -= rowsize * sy;row += 4 * sx; for ( i = sy; i < (int)ey; i++) { LPBYTE thisrow = row; for ( e = sx; e < (int)ex; e++) {d = (int)sqrt((pow((float)e - cx, 2)) + (pow((float)i - cy, 2)));if (d > amnt) {thisrow += 4;continue;}ratio = 1 + sins[d % w];thisrow[0] = max(min(thisrow[0] * ratio, 255), 0);thisrow[1] = max(min(thisrow[1] * ratio, 255), 0);thisrow[2] = max(min(thisrow[2] * ratio, 255), 0); thisrow += 4; } row -= rowsize; }free(sins); return true;} extern "C" _declspec (dllexport) BOOL negative(long object){ RGSSBMINFO *bitmap = ((RGSSBITMAP*) (object<<1)) -> bm -> bminfo; DWORD rowsize; DWORD width, height; LPBYTE row; int i, e; if(!bitmap) return false; width = bitmap -> infoheader -> biWidth; height = bitmap -> infoheader -> biHeight; rowsize = width * 4; row = (LPBYTE) (bitmap -> firstRow); for ( i = 0; i < (int)height; i++) { LPBYTE thisrow = row; for ( e = 0; e < (int)width; e++) {thisrow[0] = (255 - thisrow[0]);thisrow[1] = (255 - thisrow[1]);thisrow[2] = (255 - thisrow[2]); thisrow += 4; } row -= rowsize; } return true;} extern "C" _declspec (dllexport) BOOL draw_circle(long object, int cx, int cy, int rad, int thick, int start_angle, int end_angle, int r, int g, int b, int a) {int error, x, y;int radb, errorb, xb, yb;int t;int ang;start_angle %= 360;while (start_angle < 0) {start_angle += 360;}end_angle %= 360;while (end_angle < 0) {end_angle += 360;}if (end_angle == 0 && start_angle == 0) {end_angle = 360;} rad -= 1; error = -rad; x = rad;y = 0;radb = rad - 1;errorb = -radb;xb = radb;yb = 0;if (rad == 0) {fill_rect(object, cx, cy, 1, 1, r, g, b, a);return true;} while (x >= y) {t = x - xb;ang = 61 * y / rad;if ((end_angle > start_angle && end_angle >= 270 - ang && start_angle <= 270 - ang) || (end_angle < start_angle && (end_angle >= 270 - ang || start_angle <= 270 - ang))) {fill_rect(object, cx + x + 1 - t, cy + y, t, 1, r, g, b, a);}if (x != 0 && ((end_angle > start_angle && end_angle >= 90 + ang && start_angle <= 90 + ang) || (end_angle < start_angle && (end_angle >= 90 + ang || start_angle <= 90 + ang)))) {fill_rect(object, cx - x, cy + y, t, 1, r, g, b, a);}if (y != 0 && ((end_angle > start_angle && end_angle >= 270 + ang && start_angle <= 270 + ang) || (end_angle < start_angle && (end_angle >= 270 + ang || start_angle <= 270 + ang)))) {fill_rect(object, cx + x + 1 - t, cy - y, t, 1, r, g, b, a);}if (x != 0 && y != 0 && ((end_angle > start_angle && end_angle >= 90 - ang && start_angle <= 90 - ang) || (end_angle < start_angle && (end_angle >= 90 - ang || start_angle <= 90 - ang)))) {fill_rect(object, cx - x, cy - y, t, 1, r, g, b, a);}if (x != y) {if ((end_angle > start_angle && end_angle >= 180 + ang && start_angle <= 180 + ang) || (end_angle < start_angle && (end_angle >= 180 + ang || start_angle <= 180 + ang))) {fill_rect(object, cx + y, cy + x + 1 - t, 1, t, r, g, b, a);}if ((end_angle > start_angle && end_angle >= 180 - ang && start_angle <= 180 - ang) || (end_angle < start_angle && (end_angle >= 180 - ang || start_angle <= 180 - ang))) {fill_rect(object, cx - y, cy + x + 1 - t, 1, t, r, g, b, a);}if ((end_angle > start_angle && end_angle >= 360 - ang && start_angle <= 360 - ang) || (end_angle < start_angle && (end_angle >= 360 - ang || start_angle <= 360 - ang))) {fill_rect(object, cx + y, cy - x, 1, t, r, g, b, a);}if ((end_angle > start_angle && end_angle >= ang && start_angle <= ang) || (end_angle < start_angle && (end_angle >= ang || start_angle <= ang))) {fill_rect(object, cx - y, cy - x, 1, t, r, g, b, a);}}error += y;errorb += yb;y += 1;yb += 1;error += y;errorb += yb;if (error >= 0) {error -= x;x -= 1;error -= x;}if (errorb >= 0) {errorb -= xb;xb -= 1;errorb -= xb;} }if (thick > 1) draw_circle(object, cx, cy, rad, thick - 1, start_angle, end_angle, r, g, b, a);return true;} extern "C" _declspec (dllexport) int draw_ellipse(long object, int cx, int cy, int rx, int ry, int thick, int start_angle, int end_angle, int r, int g, int b, int a) {int rxb = rx - 1, ryb = ry - 1;int rx2 = rx * rx, rxb2 = rxb * rxb; int ry2 = ry * ry, ryb2 = ryb * ryb; int tworx2 = 2 * rx2, tworxb2 = 2 * rxb2; int twory2 = 2 * rx2, tworyb2 = 2 * ryb2; int p, pb; int x = 0, xb = 0; int y = ry, yb = ryb; int px = 0, pxb = 0; int py = tworx2 * y, pyb = tworxb2 * yb;int t;int ne1, ne2;//int ang; /* Plot the initial point in each quadrant. */ fill_rect(object, cx + x, cy + y, 1, 1, r, g, b, a); fill_rect(object, cx - x, cy + y, 1, 1, r, g, b, a); fill_rect(object, cx + x, cy - y, 1, 1, r, g, b, a); fill_rect(object, cx - x, cy - y, 1, 1, r, g, b, a); /* Region 1 */ p = round(ry2 - (rx2 * ry) + (0.25 * rx2));pb = round(ryb2 - (rxb2 * ryb) + (0.25 * rxb2));ne1 = 0;ne2 = 0; while (px < py) {bool extra = false;if (pxb >= pyb) extra = true; x++;xb++; px += twory2;pxb += tworyb2;if (extra) ne1++; if (p < 0)p += ry2 + px; else {y--;py -= tworx2;p += ry2 + px - py; }if (pb < 0)pb += ryb2 + pxb;else {yb--;pyb -= tworxb2;pb += ryb2 + pxb - pyb;if (extra) ne2++;}t = y - yb; fill_rect(object, cx + x, cy + y + 1 - t, 1, t, r, g, b, a);fill_rect(object, cx - x, cy + y + 1 - t, 1, t, r, g, b, a);fill_rect(object, cx + x, cy - y, 1, t, r, g, b, a);fill_rect(object, cx - x, cy - y, 1, t, r, g, b, a); } xb -= ne1;pxb -= tworyb2 * ne1;yb += ne2;pyb += tworxb2 * ne2; /* Region 2 */ p = round(ry2 * (x+0.5) * (x+0.5) + rx2 * (y-1) * (y-1) - rx2 * ry2);pb = round(ryb2 * (xb+0.5) * (xb+0.5) + rxb2 * (yb-1) * (yb-1) - rxb2 * ryb2); while (y > 0) { y--;yb--; py -= tworx2;pyb -= tworxb2; if (p > 0)p += rx2 - py; else {x++;px += twory2;p += rx2 - py + px; } if (pb > 0)pb += rxb2 - pyb; else {xb++;pxb += tworyb2;pb += rxb2 - pyb + pxb; }t = x - xb; fill_rect(object, cx + x + 1 - t, cy + y, t, 1, r, g, b, a);fill_rect(object, cx - x, cy + y, t, 1, r, g, b, a);fill_rect(object, cx + x + 1 - t, cy - y, t, 1, r, g, b, a);fill_rect(object, cx - x, cy - y, t, 1, r, g, b, a); } if (thick > 1) {draw_ellipse(object, cx, cy, rxb, ryb, thick - 1, start_angle, end_angle, r, g, b, a);} return true;} void get_radial_average2(int width, int height, LPBYTE row, int x, int y, int cx, int cy, float scale, int amnt, int* col, int* avg, int* tp, int mr, int wc) {int rscale;int curx, cury, error, ystep, xstep;int x1, y1, deltax, deltay;bool steep;if (wc > 0) {long rr = 2.0 * sqrt((double)x * x * height * height + (double)y * y * width * width);//rr = scale * rr;//rr -= rr % mr;rscale = scale * rr / mr;} else {rscale = scale;}LPBYTE thisrow;int rowsize = width * 4;avg[0] = 0;avg[1] = 0;avg[2] = 0;avg[3] = 0;avg[4] = 0;//int ex, ey;//ex = round(x * rscale + cx);//ey = round(y * rscale + cy);if (rscale != 0) {deltax = -x;deltay = -y;x1 = x + cx;y1 = y + cy;steep = fabs((float)(deltay)) > fabs((float)(deltax));if (steep) {int tmp;tmp = x1;x1 = y1;y1 = tmp;tmp = deltax;deltax = deltay;deltay = tmp;}ystep = deltay / fabs((float)(deltay));xstep = deltax / fabs((float)(deltax));deltay = fabs((float)(deltay));deltax = fabs((float)(deltax));error = deltax / 2; curx = x1;cury = y1;for (int i = 0;i < rscale;i++) {if (steep) {if (curx < height && curx >= 0 && cury < width && cury >= 0) {thisrow = row;thisrow -= curx * rowsize;thisrow += cury * 4;avg[0] += thisrow[2];avg[1] += thisrow[1];avg[2] += thisrow[0];avg[3] += thisrow[3];avg[4]++;} else {break;}} else {if (cury < height && cury >= 0 && curx < width && curx >= 0) {thisrow = row;thisrow -= cury * rowsize;thisrow += curx * 4;avg[0] += thisrow[2];avg[1] += thisrow[1];avg[2] += thisrow[0];avg[3] += thisrow[3];avg[4]++;} else {break;}}error -= deltay;if (error < 0) {cury += ystep;error += deltax;if ((steep && cury == width / 2 + ystep) || (!steep && cury == height / 2 + ystep)) break;}curx += xstep;if ((!steep && curx == width / 2 + xstep) || (steep && curx == height / 2 + xstep)) break;}}thisrow = row;thisrow -= (y + cy) * rowsize;thisrow += (x + cx) * 4;if (avg[4] == 0) {col[0] = thisrow[2];col[1] = thisrow[1];col[2] = thisrow[0];col[3] = thisrow[3];return;}col[0] = avg[0] / avg[4];col[1] = avg[1] / avg[4];col[2] = avg[2] / avg[4];col[3] = avg[3] / avg[4];//col[0] = col[0] * amnt / 100 + thisrow[2] * (100 - amnt) / 100;//col[1] = col[1] * amnt / 100 + thisrow[1] * (100 - amnt) / 100;//col[2] = col[2] * amnt / 100 + thisrow[0] * (100 - amnt) / 100;//col[3] = col[3] * amnt / 100 + thisrow[3] * (100 - amnt) / 100;} extern "C" _declspec (dllexport) bool radial_blur(long object, long source, int scale, int amnt, int wc) {RGSSBMINFO *bitmap = ((RGSSBITMAP*) (object<<1)) -> bm -> bminfo;RGSSBMINFO *src = ((RGSSBITMAP*) (source << 1)) -> bm -> bminfo;int cx, cy, i, e;int* col = new int[4];int* avg = new int[5];int* tp = new int[4];int rowsize;int mr; int width, height, sw, sh; LPBYTE row, sr; if(!bitmap) return false; width = bitmap -> infoheader -> biWidth; height = bitmap -> infoheader -> biHeight;sw = src -> infoheader -> biWidth;sh = src -> infoheader -> biHeight;if(width != sw || height != sh) return false; rowsize = width * 4; sr = (LPBYTE) (src -> firstRow); row = (LPBYTE) (bitmap -> firstRow);cx = width / 2;cy = height / 2;mr = height * width;// * sqrt(cx * cx + cy * cy);for ( i = 0; i < height; i++) { LPBYTE thisrow = row; for ( e = 0; e < width; e++) { get_radial_average2(sw, sh, sr, e - cx, i - cy, cx, cy, scale, amnt, col, avg, tp, mr, wc);thisrow[2] = (int) col[0];thisrow[1] = (int) col[1];thisrow[0] = (int) col[2];thisrow[3] = (int) col[3]; thisrow += 4; } row -= rowsize; } return true;} extern "C" _declspec (dllexport) bool table_lookup(long object, int* table, int ua) {RGSSBMINFO *bitmap = ((RGSSBITMAP*) (object<<1)) -> bm -> bminfo; DWORD rowsize; DWORD width, height; LPBYTE row; int i, e; if(!bitmap) return false; width = bitmap -> infoheader -> biWidth; height = bitmap -> infoheader -> biHeight; rowsize = width * 4; row = (LPBYTE) (bitmap -> firstRow); for ( i = 0; i < (int)height; i++) { LPBYTE thisrow = row; for ( e = 0; e < (int)width; e++) {thisrow[0] = max(min(table[thisrow[0]], 255), 0);thisrow[1] = max(min(table[thisrow[1]], 255), 0);thisrow[2] = max(min(table[thisrow[2]], 255), 0);if (ua > 0) thisrow[3] = max(min(table[thisrow[3]], 255), 0); thisrow += 4; } row -= rowsize; } return true;} void get_rect_average(int width, int height, LPBYTE row, int x, int y, int w, int h, int* avg) { int i, e;int rowsize;LPBYTE row2;if(x>width) x = width;if(y>height) y = height;if(x<0) x = 0;if(y<0) y = 0;if(x+w>width) w = width - x;if(y+h>height) h = height - y;if(w<0) return;if(h<0) return; rowsize = width * 4;row2 = row;//row2 -= rowsize * y; for ( i = y; i < y + h; i++) { LPBYTE thisrow = row2;//thisrow += 4 * x; for ( e = x; e < x + w; e++) { avg[0] += thisrow[2]; avg[1] += thisrow[1]; avg[2] += thisrow[0]; avg[3] += thisrow[3];avg[4]++; thisrow += 4; } row2 -= rowsize; }} extern "C" _declspec (dllexport) bool pixelize(long object, int sizex, int sizey) {int* avg = new int[5];RGSSBMINFO *bitmap = ((RGSSBITMAP*) (object<<1)) -> bm -> bminfo;int width, height;LPBYTE row, thisrow;int rowsize;int i, e, nw, nh;//, x, y;if(!bitmap) return false;width = bitmap -> infoheader -> biWidth;height = bitmap -> infoheader -> biHeight;rowsize = width * 4;nw = ceil((float) width / sizex);nh = ceil((float) height / sizey);row = (LPBYTE) (bitmap -> firstRow);//row = mr;for ( e = 0; e < nh; e++) {thisrow = row;for ( i = 0; i < nw; i++) {avg[0] = 0;avg[1] = 0;avg[2] = 0;avg[3] = 0;avg[4] = 0;get_rect_average(width, height, thisrow, i * sizex, e * sizey, sizex, sizey, avg);avg[0] /= avg[4];avg[1] /= avg[4];avg[2] /= avg[4];avg[3] /= avg[4];fill_rect2(width, height, thisrow, i * sizex, e * sizey, sizex, sizey, avg[0], avg[1], avg[2], avg[3]);thisrow += 4 * sizex;/*row = mr;row -= rowsize * e * sizey;for (y = 0;y < min(sizey, height - e * sizey);y++) {thisrow = row;thisrow += i * sizex * 4;for (x = 0;x < min(sizex, width - i * sizex);x++) {thisrow[0] = avg[2];thisrow[1] = avg[1];thisrow[2] = avg[0];thisrow[3] = avg[3];thisrow += 4;}row -= rowsize;}*///thisrow[0] = max(min(table[thisrow[0]], 255), 0);//thisrow[1] = max(min(table[thisrow[1]], 255), 0);//thisrow[2] = max(min(table[thisrow[2]], 255), 0);//if (ua > 0) thisrow[3] = max(min(table[thisrow[3]], 255), 0); }row -= rowsize * sizey; } return true;} extern "C" _declspec (dllexport) void get_pixels(long object, int* pixels) {//int* pixels;RGSSBMINFO *bitmap = ((RGSSBITMAP*) (object<<1)) -> bm -> bminfo; int rowsize; int width, height; LPBYTE row; int i, e; //int red, green, blue; if(!bitmap) return; width = bitmap -> infoheader -> biWidth; height = bitmap -> infoheader -> biHeight;//pixels = new int[width * height * 4]; rowsize = width * 4; row = (LPBYTE) (bitmap -> firstRow); for ( i = 0; i < height; i++) { LPBYTE thisrow = row; for ( e = 0; e < width; e++) {pixels[e * height * 4 + i * 4] = thisrow[2];pixels[e * height * 4 + i * 4 + 1] = thisrow[1];pixels[e * height * 4 + i * 4 + 2] = thisrow[0];pixels[e * height * 4 + i * 4 + 3] = thisrow[3]; thisrow += 4; } row -= rowsize; }}