This code to a dll

A long time ago i found this code that allowed to give a x2 zoom on bitmaps with a filter like the ones from the 16bits emulators



Code:
#==============================================================================
# ** Bitmap
#------------------------------------------------------------------------------
# This class handles and draws the bitmaps
#==============================================================================

class Bitmap
#--------------------------------------------------------------------------
# * New method: x2
#--------------------------------------------------------------------------
def x2
bitmap = Bitmap.allocate
bitmap.send(:initialize, width * 2, height * 2)
width.times do |x|
	 height.times do |y|
	 px = get_pixel(x, y)
	 x2 = x * 2
	 y2 = y * 2
	 p1 = x == 0		 ? px : get_pixel(x - 1, y)
	 p2 = x == width - 1 ? px : get_pixel(x + 1, y)
	 p3 = y == 0		 ? px : get_pixel(x, y - 1)
	 p4 = y == height - 1 ? px : get_pixel(x, y + 1)
	 if p3 != p4 && p1 != p2
		 bitmap.set_pixel(x2 , y2,	 p1 == p3 ? p1 : px)
		 bitmap.set_pixel(x2 + 1, y2,	 p3 == p2 ? p2 : px)
		 bitmap.set_pixel(x2 , y2 + 1, p1 == p4 ? p1 : px)
		 bitmap.set_pixel(x2 + 1, y2 + 1, p4 == p2 ? p2 : px)
	 else
		 bitmap.fill_rect(x2, y2, 2, 2, px)
	 end
	 end
end
bitmap
end
end
zoomx2.PNG


the result is great but since ruby get pixel and set pixel is slow as hell, it's not something usable.

I know that it's possible to make a dll to use winapi to do this work faster, but since my C/C++ knowlegde is near nil i can't seem to make this work.
Does the dll function have to accept specific parameters? For example, an actual Bitmap object.
I found this thread that have some info on this subject: www.hbgames.org/forums/viewtopic.php?t=39324.0

But now it's not opening and i can't see what it's saying -.-'
I do have the Recolor C code from HBGames since it seems to be down at the moment.

Not sure how helpful this would be to you guys:

Spoiler
Code:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <windows.h>
#include <math.h>
#define EXPORTDLL __declspec(dllexport) //__stdcall

////////////////////////////////////////////////////////

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;

typedef struct {
 DWORD unk1;
 DWORD unk2;
 BITMAPINFOHEADER *infoheader;
 RGBQUAD *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__);}

////////////////////////////////////////////////////////

BOOL EXPORTDLL Bitmap_Recolor(long object, DWORD color1, DWORD color2)
{
     //DWORD tmp=0;
     RGSSBMINFO *bitmap=((RGSSBITMAP*)(object<<1))->bm->bminfo;
     DWORD rowsize;
     DWORD width,height;
     LPBYTE row;
     //byte blend[4];
     long xStart=0;
     long yStart=0;
     long x, y;
     int r1,g1,b1,a1; //Recolor to colors
     int r2,g2,b2,a2; //Recolor from colors
     int r3,g3,b3,a3; //Color of current pixel
     r1 = GetRValue(color1); g1 = GetGValue(color1); b1 = GetBValue(color1); a1 = color1>>24;
     r2 = GetRValue(color2); g2 = GetGValue(color2); b2 = GetBValue(color2); a2 = color2>>24;
     if(!bitmap)return FALSE;
     width=bitmap->infoheader->biWidth;
     height=bitmap->infoheader->biHeight;
     rowsize=width*4;
     if(width==xStart||height==yStart)return TRUE;
     row=bitmap->firstRow-yStart*rowsize+xStart*4;
     for (y=yStart; y<height; y++)
     {
           LPBYTE thisrow=row;
           for (x=xStart; x<width; x++)
           {
                 r3=thisrow[0];
                 g3=thisrow[1];
                 b3=thisrow[2];
                 a3=thisrow[3];
                 if ((r2 == r3) && (g2 == g3) && (b2 == b3))// && (a2 == a3))
                 {
                       thisrow[0]=r1;
                       thisrow[1]=g1;
                       thisrow[2]=b1;
                       thisrow[3]=a1;
                 }
                 thisrow+=4;
           }
           row-=rowsize;
     }
     return TRUE;
}
Hope this isn't a problem for the Author.

Its not exactly what you want, but its a start.

EDIT:

My pal P` (PK8) linked this:



Which leads to this:

http://www.santuariorpgmaker.com/forum/index.php?topic=10336.0

And for people interested in filters:

http://www.hiend3d.com/demos.html
Note that the C code (though you'll have to use the C++ compiler if you're using visual studio as that would require C99 and VS only supports C89) exports one function (Bitmap_Recolor) that expects what amounts to a pointer to the RGSS bitmap to be passed to it ("object"). The bitmap's object id stores this info, though it's unclear to me exactly how the information is formatted. There are also some missing function definitions (i.e., GetRValue, GetGValue, and GetBValue are undefined, though they shouldn't be hard to rewrite if needed).
With the help of a friend i could solve this. Thanks for everoye who helped.

Original thread: https://forums.rpgmakerweb.com/threads/this-code-to-a-dll.3168/