Created
February 22, 2017 21:15
-
-
Save anonymous/9ecb951e19de2d332a1489f2cf09f469 to your computer and use it in GitHub Desktop.
Bitmap RGSS C
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | |
/* | |
RECORDATORIOS: | |
MOSTRAR MENSAJE CON TEXO: | |
char buffer[length]; | |
sprintf(buffer, "formatos", variables); | |
MessageBox ( NULL, buffer, "Titulo", MB_OK ); | |
TCHAR szBuffer[32]; | |
sprintf( szBuffer, "%f", angle[0]); | |
MessageBox(0,szBuffer,"title",1); | |
*/ | |
// -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | |
#include <cstdlib> | |
//#include <ctime> | |
#include <ctype.h> | |
//#define _USE_MATH_DEFINES | |
#include <math.h> | |
//#include <stddef.h> | |
//#include <stdio.h> | |
//#include <stdlib.h> | |
//#include <string> | |
//#include <string.h> | |
#include <windows.h> | |
#include <time.h> | |
// -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | |
#define RGSSApi extern "C" __declspec(dllexport) | |
#define ChannelBlend_Normal(A,B) ((int)(A)) | |
#define ChannelBlend_Lighten(A,B) ((int)((B > A) ? B:A)) | |
#define ChannelBlend_Darken(A,B) ((int)((B > A) ? A:B)) | |
#define ChannelBlend_Multiply(A,B) ((int)((A * B) / 255)) | |
#define ChannelBlend_Average(A,B) ((int)((A + B) / 2)) | |
#define ChannelBlend_Add(A,B) ((int)(min(255, (A + B)))) | |
#define ChannelBlend_Subtract(A,B) ((int)((A + B < 255) ? 0:(A + B - 255))) | |
#define ChannelBlend_Difference(A,B) ((int)(abs(A - B))) | |
#define ChannelBlend_Negation(A,B) ((int)(255 - abs(255 - A - B))) | |
#define ChannelBlend_Screen(A,B) ((int)(255 - (((255 - A) * (255 - B)) >> 8))) | |
#define ChannelBlend_Exclusion(A,B) ((int)(A + B - 2 * A * B / 255)) | |
#define ChannelBlend_Overlay(A,B) ((int)((B < 128) ? (2 * A * B / 255):(255 - 2 * (255 - A) * (255 - B) / 255))) | |
#define ChannelBlend_SoftLight(A,B) ((int)((B < 128)?(2*((A>>1)+64))*((float)B/255):(255-(2*(255-((A>>1)+64))*(float)(255-B)/255)))) | |
#define ChannelBlend_HardLight(A,B) (ChannelBlend_Overlay(B,A)) | |
#define ChannelBlend_ColorDodge(A,B) ((int)((B == 255) ? B:min(255, ((A << 8 ) / (255 - B))))) | |
#define ChannelBlend_ColorBurn(A,B) ((int)((B == 0) ? B:max(0, (255 - ((255 - A) << 8 ) / B)))) | |
#define ChannelBlend_LinearDodge(A,B)(ChannelBlend_Add(A,B)) | |
#define ChannelBlend_LinearBurn(A,B) (ChannelBlend_Subtract(A,B)) | |
#define ChannelBlend_LinearLight(A,B)((int)(B < 128)?ChannelBlend_LinearBurn(A,(2 * B)):ChannelBlend_LinearDodge(A,(2 * (B - 128)))) | |
#define ChannelBlend_VividLight(A,B) ((int)(B < 128)?ChannelBlend_ColorBurn(A,(2 * B)):ChannelBlend_ColorDodge(A,(2 * (B - 128)))) | |
#define ChannelBlend_PinLight(A,B) ((int)(B < 128)?ChannelBlend_Darken(A,(2 * B)):ChannelBlend_Lighten(A,(2 * (B - 128)))) | |
#define ChannelBlend_HardMix(A,B) ((int)((ChannelBlend_VividLight(A,B) < 128) ? 0:255)) | |
#define ChannelBlend_Reflect(A,B) ((int)((B == 255) ? B:min(255, (A * A / (255 - B))))) | |
#define ChannelBlend_Glow(A,B) (ChannelBlend_Reflect(B,A)) | |
#define ChannelBlend_Phoenix(A,B) ((int)(min(A,B) - max(A,B) + 255)) | |
#define ChannelBlend_Alpha(A,B,O) ((int)(O * A + (1 - O) * B)) | |
#define ChannelBlend_AlphaF(A,B,F,O) (ChannelBlend_Alpha(F(A,B),A,O)) | |
// -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | |
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; | |
} | |
// -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | |
// Rect RGSS (rect.__id__ = object) | |
// RECTSTRUCT * rect = ((RGSSRECT*)(object<<1))->rectvars; | |
// -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | |
typedef struct { | |
DWORD unka; | |
DWORD unkb; | |
DWORD x; // x rect | |
DWORD y; // y rect | |
DWORD width; // width rect | |
DWORD height; // height rect | |
}RECTSTRUCT; | |
typedef struct { | |
DWORD flags; | |
DWORD klass; | |
void (*dmark) (void*); | |
void (*dfree) (void*); | |
RECTSTRUCT * rectvars; | |
} RGSSRECT; | |
// -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | |
// Color RGSS (method 1) (color.__id__ = object) | |
// RGSSCOLOR *color = ((RGSSCOLOR*)(object << 1)); | |
// color->data[1] = red, color->data[2] = green, color->data[3] = blue, color->data[4] = alpha | |
// -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | |
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 4 | |
} RGSSCOLOR; | |
// -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | |
// Bitmap RGSS (method 1) (bitmap.__id__ = object) | |
// RGSSBMINFO *bitmap = ((RGSSBITMAP*)(object << 1))->bm->bminfo; | |
// -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | |
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; | |
// -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | |
// Color RGSS (method 2) | |
// RGSSRGBA *color = ((RGSSRGBA*)(object << 1)); | |
// color->red = red, color->green = green, color->blue = blue, color->alpha = alpha | |
// -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | |
typedef union { | |
unsigned int pixel; | |
struct { | |
unsigned char blue; | |
unsigned char green; | |
unsigned char red; | |
unsigned char alpha; | |
}; | |
} RGSSRGBA; | |
// -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | |
// Bitmap RGSS (method 2) | |
// -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | |
typedef struct{ | |
DWORD unk1; | |
DWORD unk2; | |
BITMAPINFOHEADER *infoheader; | |
RGSSRGBA *firstRow; | |
RGSSRGBA *lastRow; | |
} RGSSBMINFO2; | |
typedef struct{ | |
DWORD unk1; | |
DWORD unk2; | |
RGSSBMINFO2 *bminfo; | |
} BITMAPSTRUCT2; | |
typedef struct{ | |
DWORD flags; | |
DWORD klass; | |
void (*dmark) (void*); | |
void (*dfree) (void*); | |
BITMAPSTRUCT2 *bm; | |
} RGSSBITMAP2; | |
// -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | |
// Table RGSS (table.__id__ = object) | |
// TABLESTRUCT * table = ((TABLEDATA*)(object<<1))->tablevars; | |
// -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | |
typedef struct { | |
DWORD unka; //0 | |
DWORD unkb; //0 | |
DWORD dimensions; // # of parameters | |
DWORD xsize; // xsize | |
DWORD ysize; // ysize (returns 1 if not specified) | |
DWORD zsize; // zsize (returns 1 if not specified) | |
DWORD total_elements; // xsize * ysize * zsize | |
INT16 * data; // 1-D Array, where [x,y,z] can be found at index [x+(y*xsize)+(z*xsize*ysize)] | |
}TABLESTRUCT; | |
typedef struct { | |
DWORD unk1; | |
DWORD classname; // I think? | |
DWORD unk3; | |
DWORD unk4; | |
TABLESTRUCT * tablevars; | |
}TABLEDATA; | |
// -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | |
// -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | |
//#define ASSERT(x) if(!x){DebugOut("Failed: %s: %d", #x, __LINE__);} | |
// -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | |
// -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | |
int min(int a, int b){ | |
if (a>b) | |
return b; | |
else | |
return a; | |
} | |
// -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | |
int max(int a, int b){ | |
if (a>b) | |
return a; | |
else | |
return b; | |
} | |
RGSSApi int* get_colors(long object) | |
{ | |
RGSSBMINFO2 *bitmap = ((RGSSBITMAP2*)(object << 1))->bm->bminfo; | |
long width, height, x, y, x2, y2; | |
RGSSRGBA *row; | |
RGSSRGBA *lastrow; | |
int *colors; | |
width = bitmap->infoheader->biWidth; | |
height = bitmap->infoheader->biHeight; | |
row = bitmap->lastRow; | |
colors = new int(width*height*4); | |
//lastrow=new RGSSRGBA[width*height*4]; | |
//memcpy(lastrow,row,width*height*4); | |
for (y = 0; y < height; y++) { | |
y2 = y * width * 4; | |
for (x = 0; x < width; x++) { | |
x2 = x * 4; | |
colors[y2 + x2 + 0] = row->red; | |
colors[y2 + x2 + 1] = row->green; | |
colors[y2 + x2 + 2] = row->blue; | |
colors[y2 + x2 + 3] = row->alpha; | |
row++; | |
} | |
} | |
return colors; | |
} | |
// -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | |
RGSSApi 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; | |
} | |
// -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | |
RGSSApi 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; | |
} | |
// -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | |
RGSSApi 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; | |
} | |
// -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | |
RGSSApi BOOL replace_image_data(long object,long *object2) { | |
RGSSBMINFO *bitmap = ((RGSSBITMAP*)(object << 1))->bm->bminfo; | |
DWORD rowsize, width, height; | |
long index,x,y; | |
LPBYTE row; | |
if (!bitmap) return false; | |
width = bitmap->infoheader->biWidth; | |
height = bitmap->infoheader->biHeight; | |
row = (LPBYTE)bitmap->firstRow; | |
rowsize = width * 4; | |
for (y = 0; y < height; y++) { | |
LPBYTE thisrow = row; | |
for (x = 0; x < width; x++) { | |
index = ((y * width) + x) * 4; | |
thisrow[0] = object2[index]; | |
thisrow[1] = object2[index+1]; | |
thisrow[2] = object2[index+2]; | |
thisrow[3] = object2[index+3]; | |
thisrow += 4; | |
} | |
row -= rowsize; | |
} | |
} | |
// -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | |
RGSSApi 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; | |
} | |
// -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | |
int Blend(int type, int a, int b){ | |
switch (type) { | |
case 1: | |
return ChannelBlend_Lighten(a,b); | |
case 2: | |
return ChannelBlend_Darken(a,b); | |
case 3: | |
return ChannelBlend_Multiply(a,b); | |
case 4: | |
return ChannelBlend_Average(a,b); | |
case 5: | |
return ChannelBlend_Add(a,b); | |
case 6: | |
return ChannelBlend_Subtract(a,b); | |
case 7: | |
return ChannelBlend_Difference(a,b); | |
case 8: | |
return ChannelBlend_Negation(a,b); | |
case 9: | |
return ChannelBlend_Screen(a,b); | |
case 10: | |
return ChannelBlend_Exclusion(a,b); | |
case 11: | |
return ChannelBlend_Overlay(a,b); | |
case 12: | |
return ChannelBlend_SoftLight(a,b); | |
case 13: | |
return ChannelBlend_HardLight(a,b); | |
case 14: | |
return ChannelBlend_ColorDodge(a,b); | |
case 15: | |
return ChannelBlend_ColorBurn(a,b); | |
case 16: | |
return ChannelBlend_LinearDodge(a,b); | |
case 17: | |
return ChannelBlend_LinearBurn(a,b); | |
case 18: | |
return ChannelBlend_LinearLight(a,b); | |
case 19: | |
return ChannelBlend_VividLight(a,b); | |
case 20: | |
return ChannelBlend_PinLight(a,b); | |
case 21: | |
return ChannelBlend_HardMix(a,b); | |
case 22: | |
return ChannelBlend_Reflect(a,b); | |
case 23: | |
return ChannelBlend_Glow(a,b); | |
case 24: | |
return ChannelBlend_Phoenix(a,b); | |
case 25: | |
return ChannelBlend_Alpha(a,b,255); | |
case 26: | |
return b; | |
} | |
} | |
// -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | |
RGSSApi BOOL get_pixel(long object, long x, long y,long color_dest){ | |
RGSSBMINFO *bitmap = ((RGSSBITMAP*)(object << 1))->bm->bminfo; | |
RGSSCOLOR *color = ((RGSSCOLOR*)(color_dest << 1)); | |
if (!bitmap or !color) return false; | |
DWORD width = bitmap->infoheader->biWidth; | |
DWORD height = bitmap->infoheader->biHeight; | |
if (x < 0 or x > width or y < 0 or y > height) return false; | |
DWORD rowsize = width * 4; | |
LPBYTE thisrow = (LPBYTE)(bitmap->firstRow); | |
thisrow += (x * 4); | |
thisrow -= (rowsize * y); | |
color->data[1] = thisrow[2]; // red | |
color->data[2] = thisrow[1]; // green | |
color->data[3] = thisrow[0]; // blue | |
color->data[4] = thisrow[3]; // alpha | |
return true; | |
} | |
// -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | |
RGSSApi BOOL set_pixel(long object, long x, long y,long color_dest){ | |
RGSSBMINFO *bitmap = ((RGSSBITMAP*)(object << 1))->bm->bminfo; | |
RGSSCOLOR *color = ((RGSSCOLOR*)(color_dest << 1)); | |
if (!bitmap or !color) return false; | |
DWORD width = bitmap->infoheader->biWidth; | |
DWORD height = bitmap->infoheader->biHeight; | |
if (x < 0 or x > width or y < 0 or y > height) return false; | |
DWORD rowsize = width * 4; | |
LPBYTE thisrow = (LPBYTE)(bitmap->firstRow); | |
thisrow += (x * 4); | |
thisrow -= (rowsize * y); | |
thisrow[2] = color->data[1]; // red | |
thisrow[1] = color->data[2]; // green | |
thisrow[0] = color->data[3]; // blue | |
thisrow[3] = color->data[4]; // alpha | |
return true; | |
} | |
// -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | |
RGSSApi BOOL draw_light2(long object, long lights_size, long *lights, long *rects,int *blend_type, int background_color){ | |
RGSSBMINFO *bitmap = ((RGSSBITMAP*)(object << 1))->bm->bminfo; | |
RGSSCOLOR *color = ((RGSSCOLOR*)(background_color << 1)); | |
DWORD rowsize, srcrowsize, width, height, srcwidth, srcheight; | |
LPBYTE row, srcrow; | |
int x,y,i,blend; | |
if (!bitmap) return false; | |
width = bitmap->infoheader->biWidth; | |
height = bitmap->infoheader->biHeight; | |
rowsize = width * 4; | |
for (i = 0; i < lights_size; i++) { | |
RGSSBMINFO *src = ((RGSSBITMAP*)(lights[i] << 1))->bm->bminfo; | |
RECTSTRUCT *rect = ((RGSSRECT*)(rects[i]<<1))->rectvars; | |
blend = blend_type[i]; | |
srcrow = (LPBYTE)(src->firstRow); | |
srcwidth = src->infoheader->biWidth; | |
srcheight = src->infoheader->biHeight; | |
srcrowsize = srcwidth * 4; | |
for (y = 0; y < srcheight; y++) { | |
LPBYTE thissrcrow = srcrow; | |
for (x = 0; x < srcwidth; x++) { | |
if (((x + rect->x >= 0 and x + rect->x < width) or (x + rect->x < 0 and x + rect->x + srcwidth > 0)) and | |
((y + rect->y >= 0 and y + rect->y < height) or (y + rect->y < 0 and y + rect->y + srcheight > 0))) | |
{ | |
LPBYTE thisrow = (LPBYTE)(bitmap->firstRow); | |
thisrow += (x + rect->x) * 4; | |
thisrow -= rowsize * (y + rect->y); | |
// --------------------------------------------------------------------------------------------------- | |
// Blend code | |
// --------------------------------------------------------------------------------------------------- | |
if (blend == 0) { | |
if (255 - thissrcrow[3] < thisrow[3]) { | |
thisrow[3] = 255 - thissrcrow[3]; | |
thisrow[0] = Blend(3,thisrow[0],thissrcrow[0]); | |
thisrow[1] = Blend(3,thisrow[1],thissrcrow[1]); | |
thisrow[2] = Blend(3,thisrow[2],thissrcrow[2]); | |
} | |
} | |
else { | |
if (thissrcrow[3] > 5) { | |
thisrow[0] = Blend(blend,thisrow[0],thissrcrow[0]); | |
thisrow[1] = Blend(blend,thisrow[1],thissrcrow[1]); | |
thisrow[2] = Blend(blend,thisrow[2],thissrcrow[2]); | |
if (blend == 26) thisrow[3] = thissrcrow[3]; | |
else if (255 - thissrcrow[3] < thisrow[3]) thisrow[3] = 255 - thissrcrow[3]; | |
} | |
} | |
// --------------------------------------------------------------------------------------------------- | |
} | |
thissrcrow += 4; | |
} | |
srcrow -= srcrowsize; | |
} | |
} | |
} | |
// -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | |
RGSSApi BOOL draw_light(long object, long source, long src_rect,int color, int bg_color){ | |
RECTSTRUCT * rect = ((RGSSRECT*)(src_rect<<1))->rectvars; | |
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 x, y, alpha; | |
if (!bitmap) return false; | |
width = bitmap->infoheader->biWidth; | |
height = bitmap->infoheader->biHeight; | |
srcwidth = src->infoheader->biWidth; | |
srcheight = src->infoheader->biHeight; | |
rowsize = width * 4; | |
srcrowsize = srcwidth * 4; | |
srcrow = (LPBYTE)(src->firstRow); | |
for (y = 0; y < srcheight; y++) { | |
LPBYTE thisrow = row; | |
LPBYTE thissrcrow = srcrow; | |
for (x = 0; x < srcwidth; x++) { | |
if (x + rect->x >= 0 and x + rect->x < width and y + rect->y >= 0 and y + rect->y < height) | |
{ | |
if (thissrcrow[3] > 0) | |
{ | |
LPBYTE thisrow = (LPBYTE)(bitmap->firstRow);; | |
thisrow -= rowsize * (y + rect->y); | |
thisrow += (x + rect->x) * 4; | |
alpha = 255 - thissrcrow[3]; | |
if (alpha < 0) alpha = 0; | |
thisrow[3] = alpha; | |
if (alpha > 20) | |
{ | |
if (color == 1){ | |
thisrow[0] = ChannelBlend_SoftLight(thisrow[0],thissrcrow[0]); | |
thisrow[1] = ChannelBlend_SoftLight(thisrow[1],thissrcrow[1]); | |
thisrow[2] = ChannelBlend_SoftLight(thisrow[2],thissrcrow[2]); | |
//thisrow[3] = thissrcrow[3]; | |
} | |
} | |
} | |
} | |
thissrcrow += 4; | |
} | |
srcrow -= srcrowsize; | |
} | |
} | |
// -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | |
RGSSApi 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; | |
if (y < 0) continue; | |
for (e = x; e < x + w; e++) { | |
if (e < 0) continue; | |
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; | |
else | |
thisrow[3] = 255; | |
} | |
break; | |
case 1: | |
if (sa == m2) { | |
if (thisrow[0] + thissrcrow[0] <= 255) | |
thisrow[0] += thissrcrow[0]; | |
else | |
thisrow[0] = 255; | |
if (thisrow[1] + thissrcrow[1] <= 255) | |
thisrow[1] += thissrcrow[1]; | |
else | |
thisrow[1] = 255; | |
if (thisrow[2] + thissrcrow[2] <= 255) | |
thisrow[2] += thissrcrow[2]; | |
else | |
thisrow[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; | |
else | |
thisrow[0] = 255; | |
tmp = thisrow[1] + thissrcrow[1] * sa / 255; | |
if (tmp <= 255) | |
thisrow[1] = tmp; | |
else | |
thisrow[1] = 255; | |
tmp = thisrow[2] + thissrcrow[2] * sa / 255; | |
if (tmp <= 255) | |
thisrow[2] = tmp; | |
else | |
thisrow[2] = 255; | |
tmp = thisrow[3] + sa * sa / 255; | |
if (tmp <= 255) | |
thisrow[3] = tmp; | |
else | |
thisrow[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 21: | |
if (sa == m2) { | |
if (thisrow[0] + thissrcrow[0] <= 255) | |
thisrow[0] += thissrcrow[0]; | |
else | |
thisrow[0] = 255; | |
if (thisrow[1] + thissrcrow[1] <= 255) | |
thisrow[1] += thissrcrow[1]; | |
else | |
thisrow[1] = 255; | |
if (thisrow[2] + thissrcrow[2] <= 255) | |
thisrow[2] += thissrcrow[2]; | |
else | |
thisrow[2] = 255; | |
thisrow[3] = 255-thissrcrow[3]; | |
} | |
else if (thisrow[3] == 0) { | |
thisrow[0] = thissrcrow[0]; | |
thisrow[1] = thissrcrow[1]; | |
thisrow[2] = thissrcrow[2]; | |
thisrow[3] = 255-thissrcrow[3]; | |
//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; | |
else | |
thisrow[0] = 255; | |
tmp = thisrow[1] + thissrcrow[1] * sa / 255; | |
if (tmp <= 255) | |
thisrow[1] = tmp; | |
else | |
thisrow[1] = 255; | |
tmp = thisrow[2] + thissrcrow[2] * sa / 255; | |
if (tmp <= 255) | |
thisrow[2] = tmp; | |
else | |
thisrow[2] = 255; | |
//tmp = thisrow[3] + sa * sa / 255; | |
//if (tmp <= 255) | |
//thisrow[3] = tmp; | |
//else | |
//thisrow[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); | |
thisrow[3] = 255 - thissrcrow[3]; | |
} | |
break; | |
case 2: | |
if (sa == m2) { | |
if (thisrow[0] - thissrcrow[0] >= 0) | |
thisrow[0] -= thissrcrow[0]; | |
else | |
thisrow[0] = 0; | |
if (thisrow[1] - thissrcrow[1] >= 0) | |
thisrow[1] -= thissrcrow[1]; | |
else | |
thisrow[1] = 0; | |
if (thisrow[2] - thissrcrow[2] >= 0) | |
thisrow[2] -= thissrcrow[2]; | |
else | |
thisrow[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; | |
else | |
thisrow[0] = 0; | |
tmp = thisrow[1] - thissrcrow[1] * sa / 255; | |
if (tmp >= 0) | |
thisrow[1] = tmp; | |
else | |
thisrow[1] = 0; | |
tmp = thisrow[2] - thissrcrow[2] * sa / 255; | |
if (tmp >= 0) | |
thisrow[2] = tmp; | |
else | |
thisrow[2] = 0; | |
tmp = thisrow[3] + sa * sa / 255; | |
if (tmp <= 255) | |
thisrow[3] = tmp; | |
else | |
thisrow[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; | |
else | |
thisrow[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; | |
else | |
thisrow[3] = 255; | |
} | |
break; | |
case 5: | |
if (sa == m2) { | |
if (thisrow[0] > 127) | |
thisrow[0] = 255 - (255 - thisrow[0]) * (255 - thissrcrow[0]) / 255; | |
else | |
thisrow[0] = thisrow[0] * thissrcrow[0] / 255; | |
if (thisrow[1] > 127) | |
thisrow[1] = 255 - (255 - thisrow[1]) * (255 - thissrcrow[1]) / 255; | |
else | |
thisrow[1] = thisrow[1] * thissrcrow[1] / 255; | |
if (thisrow[2] > 127) | |
thisrow[2] = 255 - (255 - thisrow[2]) * (255 - thissrcrow[2]) / 255; | |
else | |
thisrow[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; | |
else | |
thisrow[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; | |
else | |
thisrow[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; | |
else | |
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; | |
else | |
thisrow[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; | |
else | |
thisrow[3] = 255; | |
} | |
break; | |
case 7: | |
if (sa == m2) { | |
if (255 - thissrcrow[0] > thisrow[0]) | |
thisrow[0] = thisrow[0] * 255 / (255 - thissrcrow[0]); | |
else | |
thisrow[0] = 255; | |
if (255 - thissrcrow[1] > thisrow[1]) | |
thisrow[1] = thisrow[1] * 255 / (255 - thissrcrow[1]); | |
else | |
thisrow[1] = 255; | |
if (255 - thissrcrow[2] > thisrow[2]) | |
thisrow[2] = thisrow[2] * 255 / (255 - thissrcrow[2]); | |
else | |
thisrow[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; | |
else | |
thisrow[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; | |
else | |
thisrow[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; | |
else | |
thisrow[2] = 255; | |
} | |
tmp = thisrow[3] + sa * sa / 255; | |
if (tmp <= 255) | |
thisrow[3] = tmp; | |
else | |
thisrow[3] = 255; | |
} | |
break; | |
case 8: | |
if (sa == m2) { | |
if (thissrcrow[0] > 255 - thisrow[0]) | |
thisrow[0] = 255 - (255 - thisrow[0]) * 255 / (thissrcrow[0]); | |
else | |
thisrow[0] = 0; | |
if (thissrcrow[1] > 255 - thisrow[1]) | |
thisrow[1] = 255 - (255 - thisrow[1]) * 255 / (thissrcrow[1]); | |
else | |
thisrow[1] = 0; | |
if (thissrcrow[2] > 255 - thisrow[2]) | |
thisrow[2] = 255 - (255 - thisrow[2]) * 255 / (thissrcrow[2]); | |
else | |
thisrow[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; | |
else | |
thisrow[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; | |
else | |
thisrow[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; | |
else | |
thisrow[2] = 255; | |
} | |
tmp = thisrow[3] + sa * sa / 255; | |
if (tmp <= 255) | |
thisrow[3] = tmp; | |
else | |
thisrow[3] = 255; | |
} | |
break; | |
case 9: | |
if (sa == m2) { | |
tmp = thisrow[0] + thissrcrow[0] - 255; | |
if (tmp >= 0) | |
thisrow[0] = tmp; | |
else | |
thisrow[0] = 0; | |
tmp = thisrow[1] + thissrcrow[1] - 255; | |
if (tmp >= 0) | |
thisrow[1] = tmp; | |
else | |
thisrow[1] = 0; | |
tmp = thisrow[2] + thissrcrow[2] - 255; | |
if (tmp >= 0) | |
thisrow[2] = tmp; | |
else | |
thisrow[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; | |
else | |
thisrow[0] = 0; | |
tmp = (thisrow[1] * (255 - sa) + sa * (thisrow[1] + thissrcrow[1] - 255)) / 255; | |
if (tmp >= 0) | |
thisrow[1] = tmp; | |
else | |
thisrow[1] = 0; | |
tmp = (thisrow[2] * (255 - sa) + sa * (thisrow[2] + thissrcrow[2] - 255)) / 255; | |
if (tmp >= 0) | |
thisrow[2] = tmp; | |
else | |
thisrow[2] = 0; | |
tmp = thisrow[3] + sa * sa / 255; | |
if (tmp <= 255) | |
thisrow[3] = tmp; | |
else | |
thisrow[3] = 255; | |
} | |
break; | |
case 10: | |
if (sa == m2) { | |
if (thisrow[0] > thissrcrow[0]) | |
thisrow[0] = thissrcrow[0] * 255 / thisrow[0]; | |
else | |
thisrow[0] = 255; | |
if (thisrow[1] > thissrcrow[1]) | |
thisrow[1] = thissrcrow[1] * 255 / thisrow[1]; | |
else | |
thisrow[1] = 255; | |
if (thisrow[2] > thissrcrow[2]) | |
thisrow[2] = thissrcrow[2] * 255 / thisrow[2]; | |
else | |
thisrow[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; | |
else | |
thisrow[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; | |
else | |
thisrow[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; | |
else | |
thisrow[2] = 255; | |
tmp = thisrow[3] + sa * sa / 255; | |
if (tmp <= 255) | |
thisrow[3] = tmp; | |
else | |
thisrow[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; | |
else | |
thisrow[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; | |
} | |
// -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | |
RGSSApi 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; | |
} | |
// -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | |
RGSSApi 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; | |
} | |
// -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | |
RGSSApi 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; | |
} | |
// -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | |
RGSSApi 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; | |
} | |
// -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | |
RGSSApi 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; | |
} | |
// -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | |
RGSSApi BOOL tint(long object, int amount, int r, int g, int b){ | |
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; | |
} | |
// -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | |
RGSSApi BOOL colorize(long object, int amount, int r, int g, int b){ | |
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; | |
} | |
// -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | |
RGSSApi 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; | |
} | |
// -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | |
RGSSApi 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; | |
} | |
// -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | |
RGSSApi 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; | |
} | |
// -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | |
RGSSApi 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; | |
} | |
// -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | |
RGSSApi 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; | |
} | |
// -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | |
RGSSApi 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; | |
} | |
// -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | |
RGSSApi 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; | |
} | |
// -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | |
RGSSApi 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; | |
} | |
} | |
// -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | |
RGSSApi 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; | |
} | |
// -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | |
RGSSApi 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; | |
} | |
} | |
// -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | |
float det(float a, float b, float c, float d){ | |
return a*d-b*c; | |
} | |
void intersectLines(int *xx2, int *yy2, float x1, float y1, float x2, float y2, float x3, float y3, float x4, float y4) { | |
float d = det(x1-x2,y1-y2,x3-x4,y3-y4) + 0.000001; | |
*xx2 = ceil(det(det(x1,y1,x2,y2),x1-x2,det(x3,y3,x4,y4),x3-x4)/d+0.4); | |
*yy2 = ceil(det(det(x1,y1,x2,y2),y1-y2,det(x3,y3,x4,y4),y3-y4)/d+0.4); | |
} | |
void transferPoint(float x0, float y0, float x1, float y1, float x2, float y2, float x3, float y3, int x, int y, int w, int h, int *xx2, int *yy2) { | |
intersectLines(xx2, yy2, | |
((h-y)*x0 + (y)*x3)/h, ((h-y)*y0 + y*y3)/h, | |
((h-y)*x1 + (y)*x2)/h, ((h-y)*y1 + y*y2)/h, | |
((w-x)*x0 + (x)*x1)/w, ((w-x)*y0 + x*y1)/w, | |
((w-x)*x3 + (x)*x2)/w, ((w-x)*y3 + x*y2)/w); | |
} | |
// points = packed [esquina superior izquierda, esquina superior derecha, esquina inferior derecha, esquina inferior izquierda] | |
RGSSApi BOOL transform(long object, long object2, float *points) { | |
RGSSBMINFO *bitmap = ((RGSSBITMAP*)(object << 1))->bm->bminfo; | |
RGSSBMINFO *bitmap2 = ((RGSSBITMAP*)(object2 << 1))->bm->bminfo; | |
int width, height, width2, height2; | |
LPBYTE row, row2, thisrow; | |
int rowsize; | |
int x, y, x2, y2, x3, y3, red, green, blue, alpha; | |
if (!bitmap) return false; | |
width = bitmap2->infoheader->biWidth; | |
height = bitmap2->infoheader->biHeight; | |
width2 = bitmap->infoheader->biWidth; | |
height2 = bitmap->infoheader->biHeight; | |
rowsize = width * 4; | |
clear_rect(object, 0, 0, width, height); | |
x3 = 0; y3 = 0; | |
for (y = 0; y < height; y++) { | |
for (x = 0; x < width; x++) { | |
row = (LPBYTE)(bitmap2->firstRow); | |
row -= rowsize * y; | |
row += 4 * x; | |
alpha = row[3]; | |
red = row[2]; | |
green = row[1]; | |
blue = row[0]; | |
transferPoint(points[0],points[1],points[2],points[3],points[4],points[5],points[6],points[7],x,y,width,height,&x2,&y2); | |
if (x3 != x2 || y3 != y2){ | |
if (x2 >= 0 && y2 >= 0 and x2 < width2 and y2 < height2) | |
//fill_rect(object, x3, y3, max(x2-x+1,1), max(y2-y+1,1), red, green, blue, alpha); | |
//fill_rect(object, x3, y3, max(x2-x+1,1), min(y2-y+1,4), red, green, blue, alpha); | |
if (width == width2 && height == height2) | |
fill_rect(object, x3, y3, 2, 1, red, green, blue, alpha); | |
else | |
fill_rect(object, x3, y3, max(x2-x+1,1), min(y2-y+1,4), red, green, blue, alpha); | |
} | |
x3 = x2; y3 = y2; | |
} | |
} | |
return true; | |
} | |
// Rota una imagen en el eje X | |
RGSSApi BOOL rotate_x(long source_bitmap, long dest_bitmap, double *angle, long invert_x, long invert_y, long invert_animation, double *z, double *div_z, int *rect) { | |
RGSSBMINFO *bitmap = ((RGSSBITMAP*)(source_bitmap << 1))->bm->bminfo; | |
RGSSBMINFO *bitmap2 = ((RGSSBITMAP*)(dest_bitmap << 1))->bm->bminfo; | |
int width, height, width2, height2, x0, y0, x, y, x2, y2, red, green, blue, alpha, rowsize; | |
double sinf, cosf, z2; | |
LPBYTE row, row2, thisrow; | |
if (!bitmap) return false; | |
sinf = sin(angle[0]); | |
cosf = cos(angle[0]); | |
if (invert_animation == 0){ | |
sinf = sinf * (-1); | |
cosf = cosf * (-1); | |
} | |
width = bitmap->infoheader->biWidth; | |
height = bitmap->infoheader->biHeight; | |
width2 = bitmap2->infoheader->biWidth; | |
height2 = bitmap2->infoheader->biHeight; | |
rowsize = width * 4; | |
x0 = width2 / 2; | |
y0 = height2 / 2; | |
for (y = 0; y < height; y++) { | |
for (x = 0; x < width; x++) { | |
if (invert_x == 1){ | |
x2 = width - x-1; | |
}else{ | |
x2 = x; | |
} | |
if (invert_y == 1){ | |
y2 = height - y-1; | |
}else{ | |
y2 = y; | |
} | |
row = (LPBYTE)(bitmap->firstRow); | |
row -= rowsize * y2; | |
row += 4 * x2; | |
alpha = row[3]; | |
red = row[2]; | |
green = row[1]; | |
blue = row[0]; | |
z2 = y * sinf - z[0] * cosf; | |
y2 = y0 + y * cosf - z[0] * sinf; | |
x2 = x0 + x + z2 / div_z[0]; | |
if (x2 < rect[0]) rect[0] = x2; | |
if (x2 > rect[1]) rect[1] = x2; | |
if (y2 < rect[2]) rect[2] = y2; | |
if (y2 > rect[3]) rect[3] = y2; | |
if (x2 >= 0 && y2 >= 0 and x2 <= width2 and y2 <= height2){ | |
fill_rect(dest_bitmap, x2, y2, 2, 1, red, green, blue, alpha); | |
} | |
} | |
} | |
} | |
// Rota una imagen en el eje Y | |
RGSSApi BOOL rotate_y(long source_bitmap, long dest_bitmap, double *angle, long invert_x, long invert_y, long invert_animation, double *z, double *div_z, int *rect) { | |
RGSSBMINFO *bitmap = ((RGSSBITMAP*)(source_bitmap << 1))->bm->bminfo; | |
RGSSBMINFO *bitmap2 = ((RGSSBITMAP*)(dest_bitmap << 1))->bm->bminfo; | |
int width, height, width2, height2, x0, y0, x, y, x2, y2, red, green, blue, alpha, rowsize; | |
double sinf, cosf, z2; | |
LPBYTE row, row2, thisrow; | |
if (!bitmap) return false; | |
sinf = sin(angle[0]); | |
cosf = cos(angle[0]); | |
if (invert_animation == 0){ | |
sinf = sinf * (-1); | |
cosf = cosf * (-1); | |
} | |
width = bitmap->infoheader->biWidth; | |
height = bitmap->infoheader->biHeight; | |
width2 = bitmap2->infoheader->biWidth; | |
height2 = bitmap2->infoheader->biHeight; | |
rowsize = width * 4; | |
x0 = width2 / 2; | |
y0 = height2 / 2; | |
for (y = 0; y < height; y++) { | |
for (x = 0; x < width; x++) { | |
if (invert_x == 1){ | |
x2 = width - x-1; | |
}else{ | |
x2 = x; | |
} | |
if (invert_y == 1){ | |
y2 = height - y-1; | |
}else{ | |
y2 = y; | |
} | |
row = (LPBYTE)(bitmap->firstRow); | |
row -= rowsize * y2; | |
row += 4 * x2; | |
alpha = row[3]; | |
red = row[2]; | |
green = row[1]; | |
blue = row[0]; | |
z2 = x * sinf - z[0] * cosf; | |
x2 = x0 + x * cosf + z[0] * sinf; | |
y2 = y0 + y + z2 / div_z[0]; | |
if (x2 < rect[0]) rect[0] = x2; | |
if (x2 > rect[1]) rect[1] = x2; | |
if (y2 < rect[2]) rect[2] = y2; | |
if (y2 > rect[3]) rect[3] = y2; | |
if (x2 >= 0 && y2 >= 0 and x2 < width2 and y2 < height2){ | |
fill_rect(dest_bitmap, x2, y2, 2, 1, red, green, blue, alpha); | |
} | |
} | |
} | |
} | |
// Rota una imagen en el eje Z | |
RGSSApi BOOL rotate_z(long source_bitmap, long dest_bitmap, double *angle, long invert_x, long invert_y, long invert_animation, double *z, double *div_z, int *rect) { | |
RGSSBMINFO *bitmap = ((RGSSBITMAP*)(source_bitmap << 1))->bm->bminfo; | |
RGSSBMINFO *bitmap2 = ((RGSSBITMAP*)(dest_bitmap << 1))->bm->bminfo; | |
int width, height, width2, height2, x0, y0, x, y, x2, y2, red, green, blue, alpha, rowsize; | |
double sinf, cosf, z2; | |
LPBYTE row, row2, thisrow; | |
if (!bitmap) return false; | |
sinf = sin(angle[0]); | |
cosf = cos(angle[0]); | |
if (invert_animation == 0){ | |
sinf = sinf * (-1); | |
cosf = cosf * (-1); | |
} | |
width = bitmap->infoheader->biWidth; | |
height = bitmap->infoheader->biHeight; | |
width2 = bitmap2->infoheader->biWidth; | |
height2 = bitmap2->infoheader->biHeight; | |
rowsize = width * 4; | |
x0 = width2 / 2; | |
y0 = height2 / 2; | |
for (y = 0; y < height; y++) { | |
for (x = 0; x < width; x++) { | |
if (invert_x == 1){ | |
x2 = width - x-1; | |
}else{ | |
x2 = x; | |
} | |
if (invert_y == 1){ | |
y2 = height - y-1; | |
}else{ | |
y2 = y; | |
} | |
row = (LPBYTE)(bitmap->firstRow); | |
row -= rowsize * y2; | |
row += 4 * x2; | |
alpha = row[3]; | |
red = row[2]; | |
green = row[1]; | |
blue = row[0]; | |
z2 = z[0] * cosf - x * sinf; | |
x2 = x0 + x * cosf - y * sinf + z2 / div_z[0]; | |
y2 = y0 + x * sinf + y * cosf - z2 / div_z[0]; | |
if (x2 < rect[0]) rect[0] = x2; | |
if (x2 > rect[1]) rect[1] = x2; | |
if (y2 < rect[2]) rect[2] = y2; | |
if (y2 > rect[3]) rect[3] = y2; | |
if (x2 >= 0 && y2 >= 0 and x2 < width2 and y2 < height2){ | |
fill_rect(dest_bitmap, x2, y2, 3, 3, red, green, blue, alpha); | |
} | |
} | |
} | |
} | |
// -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | |
// Con este filtro se consiguen varias cosas: | |
// blur -> Filter33(bitmap.__id__,3,3,[0,1,0,1,1,1,0,1,0,5].pack("i*"),1,0) | |
// blur more -> Filter33(bitmap.__id__,3,3,[1,1,1,1,1,1,1,1,1,9].pack("i*"),1,0) | |
// sharpen -> Filter33(bitmap.__id__,3,3,[0,-1,0,-1,5,-1,0,-1,0,1].pack("i*"),1,0) | |
// sharpen more -> Filter33(bitmap.__id__,3,3,[-1,-1,-1,-1,9,-1,-1,-1,-1,1].pack("i*"),1,0) | |
// detect edges -> Filter33(bitmap.__id__,3,3,[0,-1,0,-1,4,-1,0,-1,0,1].pack("i*"),1,0) | |
// emboss -> Filter33(bitmap.__id__,3,3,[-2,-1,0,-1,1,1,0,1,2,1].pack("i*"),1,0) | |
// glow -> Filter33(bitmap.__id__,5,4,[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0].pack("i*"),1,1) | |
// -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | |
RGSSApi bool Filter33(long object, int kWidth, int kHeight, int* kernel, int scale, bool newEffects) | |
{ | |
#pragma warning (disable:4312) | |
RGSSBMINFO2 *bitmap = ((RGSSBITMAP2*)(object << 1))->bm->bminfo; | |
#pragma warning (default:4312) | |
long width, height; | |
RGSSRGBA *row; | |
RGSSRGBA *rowcopy; | |
long x, y; | |
float red, green, blue; | |
int xm, xp, ym, yp; | |
kWidth += kWidth % 2 - 1; | |
kHeight += kHeight % 2 - 1; | |
if (!bitmap) | |
return false; | |
width = bitmap->infoheader->biWidth; | |
height = bitmap->infoheader->biHeight; | |
rowcopy = new RGSSRGBA[width*height]; | |
row = bitmap->lastRow; | |
RGSSRGBA *rowcopyOffset = rowcopy; | |
memcpy(rowcopy, row, width*height * 4); | |
if (scale == 0) | |
scale = 1; | |
for (y = 0; y < height; y++) | |
{ | |
for (x = 0; x < width; x++) | |
{ | |
if (newEffects){ | |
kernel[3] = row->red; | |
kernel[9] = row->green; | |
kernel[14] = row->blue; | |
scale = row->red + row->green + row->blue + 1; | |
}else{ | |
red = 0; | |
green = 0; | |
blue = 0; | |
} | |
xm = -min((kWidth - 1) / 2, x); | |
ym = -min((kHeight - 1) / 2, y); | |
xp = min((kWidth - 1) / 2, width - x - 1); | |
yp = min((kHeight - 1) / 2, height - y - 1); | |
for (int i = 0; i < kWidth; i++) { | |
for (int e = 0; e < kHeight; e++) { | |
red += (rowcopyOffset + min(xp, max(xm, i - kWidth / 2)) + width * min(yp, max(ym, e - kHeight / 2)))->red * kernel[i + e * kWidth]; | |
green += (rowcopyOffset + min(xp, max(xm, i - kWidth / 2)) + width * min(yp, max(ym, e - kHeight / 2)))->green * kernel[i + e * kWidth]; | |
blue += (rowcopyOffset + min(xp, max(xm, i - kWidth / 2)) + width * min(yp, max(ym, e - kHeight / 2)))->blue * kernel[i + e * kWidth]; | |
} | |
} | |
red /= scale; | |
green /= scale; | |
blue /= scale; | |
row->red = (unsigned char)min(255, max(0, red)); | |
row->green = (unsigned char)min(255, max(0, green)); | |
row->blue = (unsigned char)min(255, max(0, blue)); | |
row++; | |
rowcopyOffset++; | |
} | |
} | |
delete[]rowcopy; | |
return true; | |
} | |
// -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | |
RGSSApi BOOL multiply(long object, int r, int g, int b){ | |
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] = thisrow[0] * b / 256; | |
thisrow[1] = thisrow[1] * g / 256; | |
thisrow[2] = thisrow[2] * r / 256; | |
thisrow += 4; | |
} | |
row -= rowsize; | |
} | |
return true; | |
} | |
// -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment