diff --git a/ColorizingDMD.cpp b/ColorizingDMD.cpp index 847688a..9d1e2a1 100644 --- a/ColorizingDMD.cpp +++ b/ColorizingDMD.cpp @@ -39,6 +39,7 @@ using namespace cv; #include #include "serumdll.h" #include "ZeDMD.h" +#include #pragma endregion Includes @@ -46,7 +47,7 @@ using namespace cv; #define MAJOR_VERSION 3 #define MINOR_VERSION 0 -#define PATCH_VERSION 10 +#define PATCH_VERSION 17 static TCHAR szWindowClass[] = _T("ColorizingDMD"); static TCHAR szWindowClass2[] = _T("ChildWin"); @@ -137,10 +138,6 @@ int crop_iOsizeW = 0, crop_iOsizeH = 0; int crop_fOsizeW = 0, crop_fOsizeH = 0; int crop_ioffsetx = 0, crop_ioffsety = 0, crop_foffsetx = 0, crop_foffsety = 0; int crop_width = 0, crop_height = 0; -/*int crop_scroll_mode = 0; -bool crop_scroll_invert = false; -int crop_scroll_extend = 0; -*/ int image_posx = 0, image_posy = 0; int image_sizeW = 10, image_sizeH = 10; bool image_mouseLpressed = false, image_mouseRpressed = false; @@ -5522,7 +5519,7 @@ void drawcircle2(int xc, int yc, int r, UINT8* surface, UINT8 color, BOOL filled void drawrectangle(int xd, int yd, int xf, int yf, UINT8* surface, UINT8 color, BOOL isfilled, bool coloronly, UINT16* frame) { UINT fw, fh; - if (nEditExtraResolutionF) + if (nEditExtraResolutionF && Edit_Mode==1) { fw = MycRom.fWidthX; fh = MycRom.fHeightX; @@ -7349,9 +7346,6 @@ bool CreateGIF(char* GIFname, UINT8* pimages, UINT8* pimagesX, UINT16* protation isrotactiveX[tj] = pimagesX && pacrotX[tj * MAX_LENGTH_COLOR_ROTATION] > 0; if (isrotactiveX[tj]) nrotX++; } - /*UINT16 lesrot[MAX_COLOR_ROTATIONN * MAX_LENGTH_COLOR_ROTATION]; - UINT16 lesrotX[MAX_COLOR_ROTATIONN * MAX_LENGTH_COLOR_ROTATION]; - */ if (poimages) { for (UINT tj = 0; tj < MycRom.fHeight * MUL_SIZE_GIF; tj++) @@ -7707,16 +7701,18 @@ void SaveAnimatedGif(void) } bool isTesterfr32, isTesterfr64; - UINT16* ptesternewfr32, * ptesternewfr64; UINT8* ptesterbuffer32, * ptesterbuffer64; #define MUL_TESTER_PIXEL_SIZE 5 +HWND hTester; +char TesterExtraStr[64] = { 0 }; +char TesterpreExtraStr[64] = { 0 }; - - -LRESULT CALLBACK FrameWndProc(HWND hwDlg, UINT message, WPARAM wParam, LPARAM lParam) { - switch (message) { +LRESULT CALLBACK FrameWndProc(HWND hwDlg, UINT message, WPARAM wParam, LPARAM lParam) +{ + switch (message) + { case WM_CLOSE: return 0; @@ -7737,8 +7733,10 @@ LRESULT CALLBACK FrameWndProc(HWND hwDlg, UINT message, WPARAM wParam, LPARAM lP fw = MycRom.fWidthX; fh = MycRom.fHeightX; } - imageWidth = MUL_TESTER_PIXEL_SIZE * fw; - imageHeight = MUL_TESTER_PIXEL_SIZE * fh; + int Mul_Tester_Pixel = MUL_TESTER_PIXEL_SIZE; + if (hwDlg == hFrame32) Mul_Tester_Pixel *= 2; + imageWidth = Mul_Tester_Pixel * fw; + imageHeight = Mul_Tester_Pixel * fh; RECT clientRect; GetClientRect(hwDlg, &clientRect); int clientWidth = clientRect.right - clientRect.left; @@ -7746,7 +7744,31 @@ LRESULT CALLBACK FrameWndProc(HWND hwDlg, UINT message, WPARAM wParam, LPARAM lP UINT8* ptnf; if (hwDlg == hFrame32) ptnf = ptesterbuffer32; else ptnf = ptesterbuffer64; memset(ptnf, 0, imageWidth * imageHeight * 4); - if ((hwDlg == hFrame32 && ptesternewfr32 && isTesterfr32) || (hwDlg == hFrame64 && ptesternewfr64 && isTesterfr64)) + + if (hwDlg == hFrame32 && ptesternewfr32 && !isTesterfr32) + { + SetWindowTextA(hwDlg, "Frame 64P downscaled"); + DownscaleRGB565Frame(ptesternewfr64, ptesternewfr32, MycRom.fWidth); + InvalidateRect(GetDlgItem(hTester, IDC_ISEXTRA), NULL, FALSE); + } + else if (hwDlg == hFrame64 && ptesternewfr64 && !isTesterfr64) + { + SetWindowTextA(hwDlg, "Frame 32P upscaled"); + UpscaleRGB565Frame(ptesternewfr32, ptesternewfr64, MycRom.fWidth); + InvalidateRect(GetDlgItem(hTester, IDC_ISEXTRA), NULL, FALSE); + } + else if (hwDlg == hFrame32) + { + SetWindowTextA(hwDlg, "Frame 32P"); + InvalidateRect(GetDlgItem(hTester, IDC_ISEXTRA), NULL, FALSE); + } + else if (hwDlg == hFrame64) + { + SetWindowTextA(hwDlg, "Frame 64P"); + InvalidateRect(GetDlgItem(hTester, IDC_ISEXTRA), NULL, FALSE); + } + + if ((hwDlg == hFrame32 && ptesternewfr32) || (hwDlg == hFrame64 && ptesternewfr64)) { for (UINT tj = 0; tj < fh; tj++) { @@ -7759,20 +7781,22 @@ LRESULT CALLBACK FrameWndProc(HWND hwDlg, UINT message, WPARAM wParam, LPARAM lP pixcol[0] = pixcol[2]; pixcol[2] = pixcol[3]; pixcol[3] = 255; - for (int tl = 0; tl < MUL_TESTER_PIXEL_SIZE; tl++) + for (int tl = 0; tl < Mul_Tester_Pixel; tl++) { - for (int tk = 0; tk < MUL_TESTER_PIXEL_SIZE; tk++) + for (int tk = 0; tk < Mul_Tester_Pixel; tk++) { - if ((tl > 0 && tk > 0 && tl < MUL_TESTER_PIXEL_SIZE - 2 && tk < MUL_TESTER_PIXEL_SIZE - 2) || - ((tl == 0 || tl == MUL_TESTER_PIXEL_SIZE - 2) && tk > 0 && tk < MUL_TESTER_PIXEL_SIZE - 2) || - ((tk == 0 || tk == MUL_TESTER_PIXEL_SIZE - 2) && tl > 0 && tl < MUL_TESTER_PIXEL_SIZE - 2)) + if ((tl > 0 && tk > 0 && tl < Mul_Tester_Pixel - 2 && tk < Mul_Tester_Pixel - 2) || + ((tl == 0 || tl == Mul_Tester_Pixel - 2) && tk > 0 && tk < Mul_Tester_Pixel - 2) || + ((tk == 0 || tk == Mul_Tester_Pixel - 2) && tl > 0 && tl < Mul_Tester_Pixel - 2)) { - memcpy(&ptnf[((tj * MUL_TESTER_PIXEL_SIZE + tl) * fw * MUL_TESTER_PIXEL_SIZE + ti * MUL_TESTER_PIXEL_SIZE + tk) * 4], pixcol, 4); + memcpy(&ptnf[((tj * Mul_Tester_Pixel + tl) * fw * Mul_Tester_Pixel + ti * Mul_Tester_Pixel + tk) * 4], pixcol, 4); } } } } } + + } bitmapInfo.bmiHeader.biSize = sizeof(BITMAPINFOHEADER); @@ -7863,6 +7887,13 @@ void SendFrameToTester2(unsigned int nofr, UINT8* pframes) ColorizeAFrame(&pframes[nofr * MycRom.fWidth * MycRom.fHeight], &ptesternewfr32, &ptesternewfr64, &testerframeID, &isTesterfr32, &isTesterfr64); SendToZeDMD(); + RECT rect; + GetClientRect(hTester, &rect); + rect.top = 100; + InvalidateRect(hTester, &rect, TRUE); + InvalidateRect(GetDlgItem(hTester, IDC_ISEXTRA), NULL, FALSE); + InvalidateRect(GetDlgItem(hTester, IDC_ISEXTRA), NULL, FALSE); + InvalidateRect(GetDlgItem(hTester, IDC_ISEXTRAE), NULL, FALSE); InvalidateRect(hFrame32, NULL, FALSE); InvalidateRect(hFrame64, NULL, FALSE); @@ -7897,12 +7928,12 @@ bool CreateFrameWindows(HWND hParent) RECT rc; if (MycRom.fHeight == 32) { - rc = { 0, 0, (LONG)MycRom.fWidth * MUL_TESTER_PIXEL_SIZE, (LONG)MycRom.fHeight * MUL_TESTER_PIXEL_SIZE }; + rc = { 0, 0, (LONG)MycRom.fWidth * 2*MUL_TESTER_PIXEL_SIZE, (LONG)MycRom.fHeight * 2*MUL_TESTER_PIXEL_SIZE }; AdjustWindowRect(&rc, WS_OVERLAPPEDWINDOW & ~WS_THICKFRAME & ~WS_MAXIMIZEBOX, FALSE); } else { - rc = { 0, 0, (LONG)MycRom.fWidthX * MUL_TESTER_PIXEL_SIZE, (LONG)MycRom.fHeightX * MUL_TESTER_PIXEL_SIZE }; + rc = { 0, 0, (LONG)MycRom.fWidthX * 2*MUL_TESTER_PIXEL_SIZE, (LONG)MycRom.fHeightX * 2*MUL_TESTER_PIXEL_SIZE }; AdjustWindowRect(&rc, WS_OVERLAPPEDWINDOW & ~WS_THICKFRAME & ~WS_MAXIMIZEBOX, FALSE); } @@ -7940,13 +7971,13 @@ bool CreateFrameWindows(HWND hParent) ptesterbuffer64 = ptesterbuffer32 = NULL; if (MycRom.fHeight == 32) { - ptesterbuffer32 = (UINT8*)malloc(4 * MycRom.fWidth * MUL_TESTER_PIXEL_SIZE * MycRom.fHeight * MUL_TESTER_PIXEL_SIZE); + ptesterbuffer32 = (UINT8*)malloc(4 * MycRom.fWidth * 2*MUL_TESTER_PIXEL_SIZE * MycRom.fHeight * 2*MUL_TESTER_PIXEL_SIZE); ptesterbuffer64 = (UINT8*)malloc(4 * MycRom.fWidthX * MUL_TESTER_PIXEL_SIZE * MycRom.fHeightX * MUL_TESTER_PIXEL_SIZE); } else { ptesterbuffer64 = (UINT8*)malloc(4 * MycRom.fWidth * MUL_TESTER_PIXEL_SIZE * MycRom.fHeight * MUL_TESTER_PIXEL_SIZE); - ptesterbuffer32 = (UINT8*)malloc(4 * MycRom.fWidthX * MUL_TESTER_PIXEL_SIZE * MycRom.fHeightX * MUL_TESTER_PIXEL_SIZE); + ptesterbuffer32 = (UINT8*)malloc(4 * MycRom.fWidthX * 2*MUL_TESTER_PIXEL_SIZE * MycRom.fHeightX * 2*MUL_TESTER_PIXEL_SIZE); } if (!ptesterbuffer32 || !ptesterbuffer64) { @@ -7982,6 +8013,11 @@ LRESULT CALLBACK Tester_Proc(HWND hwDlg, UINT Msg, WPARAM wParam, LPARAM lParam) { HWND hChFr = GetDlgItem(hwDlg, IDC_CHOOSEFRAME); char cFrameID[64]; + if (strcmp(TesterExtraStr, TesterpreExtraStr) != 0) + { + SetDlgItemTextA(hwDlg, IDC_ISEXTRAE, TesterExtraStr); + strcpy_s(TesterpreExtraStr, 64, TesterExtraStr); + } switch (Msg) { case WM_INITDIALOG: @@ -7992,13 +8028,14 @@ LRESULT CALLBACK Tester_Proc(HWND hwDlg, UINT Msg, WPARAM wParam, LPARAM lParam) DestroyWindow(hwDlg); return TRUE; } + strcpy_s(TesterExtraStr, 64, ""); + hTester = hwDlg; SetDlgItemTextA(hwDlg, IDC_INFO, "Navigate through the selected frames:"); SetTesterRangeAndTicKs(hChFr, nSelFrames); char tbuf[128]; GetIDFrameText(testerframeID, cFrameID); sprintf_s(tbuf, 128, "Frame Tester Current frame: %i / Total: %i %s", 0, nSelFrames, cFrameID); SetWindowTextA(hwDlg, tbuf); - InvalidateRect(hwDlg, NULL, FALSE); TesterSelectionMode = true; Testerplayspeed = 1; TesterPlay = 0; @@ -8103,8 +8140,8 @@ LRESULT CALLBACK Tester_Proc(HWND hwDlg, UINT Msg, WPARAM wParam, LPARAM lParam) } } SendMessage(hChFr, TBM_SETPOS, TRUE, frpos); - SetTimer(hwDlg, 1, 16, NULL); SendMessage(hwDlg, WM_HSCROLL, 0, 0); + SetTimer(hwDlg, 1, 16, NULL); } if (ColorRotateAFrame(&ptesternewfr32, NULL, &ptesternewfr64, NULL)) { @@ -8119,8 +8156,8 @@ LRESULT CALLBACK Tester_Proc(HWND hwDlg, UINT Msg, WPARAM wParam, LPARAM lParam) PAINTSTRUCT ps; BITMAPINFO bitmapInfo = { 0 }; - int imageWidth = 512; - int imageHeight = 128; + int imageWidth = 512; + int imageHeight = 128; RECT clientRect; GetClientRect(hwDlg, &clientRect); @@ -8153,7 +8190,33 @@ LRESULT CALLBACK Tester_Proc(HWND hwDlg, UINT Msg, WPARAM wParam, LPARAM lParam) DeleteDC(memDC); EndPaint(hwDlg, &ps); - return 0; + return TRUE; + } + case WM_DRAWITEM: + { + + LPDRAWITEMSTRUCT pDIS = (LPDRAWITEMSTRUCT)lParam; + if (pDIS->CtlID != IDC_ISEXTRA) return FALSE; + RECT rcColors; + GetWindowRect(GetDlgItem(hwDlg, IDC_ISEXTRA), &rcColors); + rcColors.right -= rcColors.left; + rcColors.bottom -= rcColors.top; + rcColors.left = 0; + rcColors.top = 0; + HBRUSH hbr; + if (!isTesterfr32 || !isTesterfr64) + { + hbr = CreateSolidBrush(RGB(255, 0, 0)); + strcpy_s(TesterExtraStr, 64, "No Extra Res."); + } + else + { + hbr = CreateSolidBrush(RGB(0, 255, 0)); + strcpy_s(TesterExtraStr, 64, "Extra Res. Avail."); + } + FillRect(pDIS->hDC, &rcColors, hbr); + DeleteObject(hbr); + return TRUE; } case WM_COMMAND: { @@ -8349,30 +8412,6 @@ LRESULT CALLBACK Tester_Proc(HWND hwDlg, UINT Msg, WPARAM wParam, LPARAM lParam) } } } - /*case WM_CLOSE: - { - KillTimer(hwDlg, 1); - WINDOWPLACEMENT wp; - wp.length = sizeof(WINDOWPLACEMENT); - GetWindowPlacement(hwDlg, &wp); - Tester_Posx = wp.rcNormalPosition.left; - Tester_Posy = wp.rcNormalPosition.top; - SaveWindowPosition(); - - - if (pTesterFrames) - { - free(pTesterFrames); - pTesterFrames = NULL; - } - if (pTesterTimecodes) - { - free(pTesterTimecodes); - pTesterTimecodes = NULL; - } - return 0; - } - */ case WM_HSCROLL: { char tbuf[128]; @@ -8380,14 +8419,12 @@ LRESULT CALLBACK Tester_Proc(HWND hwDlg, UINT Msg, WPARAM wParam, LPARAM lParam) if (TesterSelectionMode) { SendFrameToTester2(SelFrames[frpos], MycRP.oFrames); - InvalidateRect(hwDlg, NULL, FALSE); GetIDFrameText(testerframeID, cFrameID); sprintf_s(tbuf, 128, "Frame Tester Current frame: %i / Total: %i %s", frpos, nSelFrames, cFrameID); } else { SendFrameToTester2(frpos, pTesterFrames); - InvalidateRect(hwDlg, NULL, FALSE); GetIDFrameText(testerframeID, cFrameID); sprintf_s(tbuf, 128, "Frame Tester Current frame: %i / Total: %i %s", frpos, nTesterFrames, cFrameID); } @@ -8448,16 +8485,6 @@ void TestSelectedFrames(void) } } Save_cRom(false, true, tbuf); - /*char tbuf2[MAX_PATH]; - strcat_s(tbuf, MAX_PATH, MycRom.name); - strcat_s(tbuf, MAX_PATH, ".cRZ"); - sprintf_s(tbuf2, MAX_PATH, "%s%s.cRZ", Dir_Serum, MycRom.name); - if (!CopyFileA(tbuf2, tbuf, FALSE)) - { - MessageBoxA(hWnd, "Can't copy the cRZ file in the altcolor\\rom_name directory", "Failed", MB_OK); - return; - } - */ if (!InitLibSerum(Dir_VP, MycRom.name)) { @@ -10756,14 +10783,6 @@ bool CopyTXTFrames2Frame(UINT nFrames, sFrames* pFrames) MycRom.nSprites = 0; MycRom.nBackgrounds= 0; - /*MycRom.cPal = (UINT8*)malloc(nF * sizepalette); - if (!MycRom.cPal) - { - Free_cRom(); - cprintf(true, "Unable to allocate memory for colorized palettes"); - return false; - } - */ MycRom.cFrames = (UINT16*)malloc(nF * MycRom.fWidth * MycRom.fHeight * sizeof(UINT16)); if (!MycRom.cFrames) { @@ -10912,17 +10931,6 @@ bool CopyTXTFrames2Frame(UINT nFrames, sFrames* pFrames) char* psFr = pFrames[tk].ptr; UINT8* pdoFr = &MycRP.oFrames[MycRom.fWidth * MycRom.fHeight * MycRom.nFrames]; UINT16* pdcFr = &MycRom.cFrames[MycRom.fWidth * MycRom.fHeight * MycRom.nFrames]; -/* if (tk < nFrames - 1) - { - UINT32 time1 = pFrames[tk].timecode; - UINT32 time2 = pFrames[tk + 1].timecode; - if (time2 < time1) MycRP.FrameDuration[MycRom.nFrames] = 0; - else if (time2 - time1 > 30000) MycRP.FrameDuration[MycRom.nFrames] = 0; - else MycRP.FrameDuration[MycRom.nFrames] = time2 - time1; - if (filter_time && (filter_length > MycRP.FrameDuration[MycRom.nFrames])) pFrames[tk].active = FALSE; - } - else MycRP.FrameDuration[MycRom.nFrames] = 0; - */ memset(MycRP.Palette, 0, sizeof(UINT16) * N_PALETTES * 64); memset(MycRP.PalNames, 0, N_PALETTES * 64); Init_cFrame_Palette2(); @@ -10990,14 +10998,6 @@ bool AddTXTFrames2Frame(UINT nFrames, sFrames* pFrames) memset(&MycRom.isExtraFrame[MycRom.nFrames], 0, nF * sizeof(UINT8)); - /*MycRom.cPal = (UINT8*)realloc(MycRom.cPal, (nF + MycRom.nFrames) * sizepalette); - if (!MycRom.cPal) - { - Free_cRom(); - cprintf(true, "Unable to reallocate memory for colorized palettes"); - return false; - } - */ MycRom.cFrames = (UINT16*)realloc(MycRom.cFrames, (nF + MycRom.nFrames) * MycRom.fWidth * MycRom.fHeight * sizeof(UINT16)); if (!MycRom.cFrames) { @@ -11133,16 +11133,6 @@ bool AddTXTFrames2Frame(UINT nFrames, sFrames* pFrames) UINT8* psFr = (UINT8*)pFrames[tk].ptr; UINT8* pdoFr = &MycRP.oFrames[MycRom.fWidth * MycRom.fHeight * MycRom.nFrames]; UINT16* pdcFr = &MycRom.cFrames[MycRom.fWidth * MycRom.fHeight * MycRom.nFrames]; -/* if (tk < nFrames - 1) - { - UINT32 time1 = pFrames[tk].timecode; - UINT32 time2 = pFrames[tk + 1].timecode; - if (time2 < time1) MycRP.FrameDuration[MycRom.nFrames] = 0; - else if (time2 - time1 > 30000) MycRP.FrameDuration[MycRom.nFrames] = 0; - else MycRP.FrameDuration[MycRom.nFrames] = time2 - time1; - } - else MycRP.FrameDuration[MycRom.nFrames] = 0; - */ Init_cFrame_Palette2(); for (unsigned int tj = 0; tj < MycRom.fHeight * MycRom.fWidth; tj++) { @@ -11519,9 +11509,6 @@ void SortSections(void) void MoveSection(int nosec, int decalage) { if (nosec == LB_ERR) return; -/* UINT32 Section_Firsts[MAX_SECTIONS]; - char Section_Names[MAX_SECTIONS * SIZE_SECTION_NAMES]; -*/ UINT32 sfirst; char sName[SIZE_SECTION_NAMES]; sfirst = MycRP.Section_Firsts[nosec + decalage]; @@ -12212,19 +12199,6 @@ LRESULT CALLBACK WndProc(HWND hWin, UINT message, WPARAM wParam, LPARAM lParam) if (tj > ymax) ymax = tj; } } - /*int tx, ty; - glfwGetWindowPos(glfwframe, &tx, &ty); - if (Zoom_Pushed && ((nEditExtraResolutionF && MycRom.fHeightX == 64) || (!nEditExtraResolutionF && MycRom.fHeight == 64))) - { - paste_centerx = (int)(tx + 2 * frame_zoom * (xmax + xmin) / 2); - paste_centery = (int)(ty + 2 * frame_zoom * (ymax + ymin) / 2); - } - else - { - paste_centerx = (int)(tx + frame_zoom * (xmax + xmin) / 2); - paste_centery = (int)(ty + frame_zoom * (ymax + ymin) / 2); - } - */ } break; } @@ -12441,14 +12415,6 @@ void activateColSet(int noSet) MycRP.activeColSet[noSet + MycRP.preColSet] = true; EnableWindow(GetDlgItem(hColSet, noSet + IDC_NOMCOLSET1), TRUE); } -/*void activateColRot(int noSet) -{ - MycRom.ColorRotations[acFrame * 3 * MAX_COLOR_ROTATION + noSet * 3 + preColRot] = Ini_Gradient_Color; - MycRom.ColorRotations[acFrame * 3 * MAX_COLOR_ROTATION + noSet * 3 + preColRot + 1] = Fin_Gradient_Color; - MycRom.ColorRotations[acFrame * 3 * MAX_COLOR_ROTATION + noSet * 3 + preColRot + 2] = 50; - EnableWindow(GetDlgItem(hColSet, noSet + IDC_NOMCOLSET1), TRUE); -} -*/ @@ -12802,31 +12768,6 @@ INT_PTR AskName_Proc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam) return FALSE; } -/*LRESULT CALLBACK CBList_Proc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam, UINT_PTR uIdSubclass, DWORD_PTR dwRefData) -{ - switch (message) - { - case WM_RBUTTONDOWN: - { - if (MycRom.name[0] == 0) return TRUE; - POINT tp; - GetCursorPos(&tp); - ScreenToClient(hDlg, &tp); - int noItem=(int)SendMessage(hDlg, LB_ITEMFROMPOINT, 0, MAKELPARAM(tp.x, tp.y)); - if (noItem == 0) return TRUE; - strcpy_s(askname_res, 64, &MycRP.Mask_Names[SIZE_MASK_NAME * (noItem - 1)]); - if (DialogBox(hInst, MAKEINTRESOURCE(IDD_ASKNAME), hDlg, (DLGPROC)AskName_Proc) == IDOK) - { - strcpy_s(&MycRP.Mask_Names[SIZE_MASK_NAME * (noItem - 1)], SIZE_MASK_NAME-1, askname_res); - UpdateMaskList(); - } - return TRUE; - } - } - return DefSubclassProc(hDlg,message,wParam,lParam); -} -*/ - HBRUSH CreateGradientBrush(UINT icol, UINT fcol, HDC hDC,LPRECT prect) { HBRUSH Brush = NULL; @@ -13201,6 +13142,7 @@ void ShadowSelection(WORD wdir) UINT16* pcfr; UINT8* pdynm; UINT fw, fh; + UpdateFSneeded = true; if (nEditExtraResolutionF) { fw = MycRom.fWidthX; @@ -13343,10 +13285,6 @@ INT_PTR CALLBACK Toolbar_Proc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lPa { case WM_INITDIALOG: { - /*HWND hwndChild = GetWindow(hDlg, GW_CHILD); - while (hwndChild != NULL) - { - */ SetWindowSubclass(GetDlgItem(hDlg, IDC_NEW), ButtonSubclassProc, 0, 0); SetWindowSubclass(GetDlgItem(hDlg, IDC_ADDTXT), ButtonSubclassProc, 0, 0); SetWindowSubclass(GetDlgItem(hDlg, IDC_OPEN), ButtonSubclassProc, 0, 0); @@ -13922,6 +13860,7 @@ INT_PTR CALLBACK Toolbar_Proc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lPa if (!nEditExtraResolutionF) memcpy(&MycRom.Dyna4Cols[SelFrames[ti] * MAX_DYNA_SETS_PER_FRAMEN * MycRom.noColors], &MycRom.Dyna4Cols[acFrame * MAX_DYNA_SETS_PER_FRAMEN * MycRom.noColors], MAX_DYNA_SETS_PER_FRAMEN * MycRom.noColors * sizeof(UINT16)); else memcpy(&MycRom.Dyna4ColsX[SelFrames[ti] * MAX_DYNA_SETS_PER_FRAMEN * MycRom.noColors], &MycRom.Dyna4ColsX[acFrame * MAX_DYNA_SETS_PER_FRAMEN * MycRom.noColors], MAX_DYNA_SETS_PER_FRAMEN* MycRom.noColors * sizeof(UINT16)); } + UpdateFSneeded = true; return TRUE; } case IDC_COLPICK: @@ -14365,19 +14304,6 @@ INT_PTR CALLBACK Toolbar_Proc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lPa if (tj > ymax) ymax = tj; } } - /*int tx, ty; - glfwGetWindowPos(glfwframe, &tx, &ty); - if (Zoom_Pushed && ((nEditExtraResolutionF && MycRom.fHeightX == 64) || (!nEditExtraResolutionF && MycRom.fHeight == 64))) - { - paste_centerx = (int)(tx + 2 * frame_zoom * (xmax + xmin) / 2); - paste_centery = (int)(ty + 2 * frame_zoom * (ymax + ymin) / 2); - } - else - { - paste_centerx = (int)(tx + frame_zoom * (xmax + xmin) / 2); - paste_centery = (int)(ty + frame_zoom * (ymax + ymin) / 2); - } - */ return TRUE; } case IDC_ADDSECTION: @@ -14470,6 +14396,7 @@ INT_PTR CALLBACK Toolbar_Proc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lPa } } for (UINT ti = IDC_DYNACOL1; ti <= IDC_DYNACOL16; ti++) InvalidateRect(GetDlgItem(hwTB, ti), NULL, TRUE); + UpdateFSneeded = true; return TRUE; } case IDC_INVERTSEL: @@ -14865,7 +14792,7 @@ INT_PTR CALLBACK Toolbar_Proc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lPa { if (SelFrames[ti] == acFrame) continue; if (nEditExtraResolutionF && MycRom.isExtraFrame[SelFrames[ti]] == 0) continue; - memcpy(&pdync[SelFrames[ti] * MAX_DYNA_SETS_PER_FRAMEN * MycRom.noColors], &pdync[acFrame * MAX_DYNA_SETS_PER_FRAMEN * MycRom.noColors], MAX_DYNA_SETS_PER_FRAMEN* MycRom.noColors); + memcpy(&pdync[SelFrames[ti] * MAX_DYNA_SETS_PER_FRAMEN * MycRom.noColors], &pdync[acFrame * MAX_DYNA_SETS_PER_FRAMEN * MycRom.noColors], MAX_DYNA_SETS_PER_FRAMEN* MycRom.noColors * sizeof(UINT16)); memcpy(&pdynm[SelFrames[ti] * fwmfh], &pdynm[acFrame * fwmfh], fwmfh); } UpdateFSneeded = true; @@ -15579,26 +15506,6 @@ INT_PTR CALLBACK Toolbar_Proc2(HWND hDlg, UINT message, WPARAM wParam, LPARAM lP if ((int)acFrame < PreFrameInStrip) PreFrameInStrip = acFrame; UpdateFSneeded = true; UpdateNewacFrame(); - /* - - if (MycRP.SpriteRect[4 * acSprite] < 0xffff) - { - memset(Copy_Mask, 0, MycRom.fWidth * MycRom.fHeight); - for (UINT tj = MycRP.SpriteRect[4 * acSprite + 1]; tj <= MycRP.SpriteRect[4 * acSprite + 3]; tj++) - { - for (UINT ti = MycRP.SpriteRect[4 * acSprite]; ti <= MycRP.SpriteRect[4 * acSprite + 2]; ti++) - { - UINT i = ti, j = tj; - if (MycRP.SpriteRectMirror[2 * acSprite] == TRUE) i = MycRP.SpriteRect[4 * acSprite + 2] - (ti - MycRP.SpriteRect[4 * acSprite]); - if (MycRP.SpriteRectMirror[2 * acSprite + 1] == TRUE) j = MycRP.SpriteRect[4 * acSprite + 3] - (tj - MycRP.SpriteRect[4 * acSprite + 1]); - if ((MycRom.SpriteDescriptions[acSprite * MAX_SPRITE_SIZE * MAX_SPRITE_SIZE + (tj - MycRP.SpriteRect[4 * acSprite + 1]) * MAX_SPRITE_SIZE + ti - MycRP.SpriteRect[4 * acSprite]] & 0x8000) == 0) - { - Copy_Mask[i + j * MycRom.fWidth] = 1; - } - } - } - } - */ return TRUE; } case IDC_SPRITELIST2: @@ -16293,35 +16200,6 @@ void CopyImageTo1Selection(cv::Mat tmp32, cv::Mat tmp64, UINT nofr) } } } -/*void CopyImageTo1Selection(cv::Mat mat, UINT nofr) -{ - UINT fw, fh; - UINT16* pfr; - if (ExtraResFClicked && MycRom.isExtraFrame[nofr] > 0) - { - fw = MycRom.fWidthX; - fh = MycRom.fHeightX; - pfr = &MycRom.cFramesX[nofr * fw * fh]; - } - else - { - fw = MycRom.fWidth; - fh = MycRom.fHeight; - pfr = &MycRom.cFrames[nofr * fw * fh]; - } - for (UINT tj = 0; tj < HiSelection; tj++) - { - for (UINT ti = 0; ti < WiSelection; ti++) - { - if (Copy_Mask[(tj + YiSelection) * fw + ti + XiSelection] > 0) - { - cv::Vec3b color = mat.at(tj, ti); - pfr[(tj + YiSelection) * fw + ti + XiSelection] = rgb888_to_rgb565(color[2], color[1], color[0]); - } - } - } -} -*/ @@ -16630,25 +16508,6 @@ void ScrollCopy(HWND hDlg) UINT tSelFrames[MAX_SEL_FRAMES]; for (UINT ti = 0; ti < nSelFrames; ti++) tSelFrames[ti] = SelFrames[ti]; BubbleSort(tSelFrames, nSelFrames); - /*UINT preframe = acFrame, derframe = acFrame; - bool frfound = true; - while (frfound) - { - frfound = false; - for (UINT ti = 0; ti < nSelFrames; ti++) - { - if (derframe < MycRom.nFrames - 1) - { - if (SelFrames[ti] == derframe + 1) - { - derframe++; - frfound = true; - } - } - } - } - UINT nfr = derframe - preframe + 1; - */ UINT8* image = NULL; float ratio = (float)width_image / (float)image_sizeW; @@ -17541,18 +17400,6 @@ LRESULT CALLBACK BGProc(HWND hWin, UINT message, WPARAM wParam, LPARAM lParam) { switch (message) { - /*case WM_COMMAND: - { - int wmId = LOWORD(wParam); - - switch (wmId) - { - default: - return DefWindowProc(hWin, message, wParam, lParam); - } - break; - } - */ case WM_MOUSEWHEEL: { if (MycRom.name[0] == 0) return TRUE; @@ -19446,7 +19293,7 @@ void mouse_move_callback(GLFWwindow* window, double xpos, double ypos) GetCursorPos(&tpt); int xspos, yspos; glfwGetWindowPos(glfwframe, &xspos, &yspos); - if (Zoom_Pushed && ((nEditExtraResolutionF && MycRom.fHeightX == 64) || (!nEditExtraResolutionF && MycRom.fHeight == 64))) + if (Edit_Mode == 1 && Zoom_Pushed && ((nEditExtraResolutionF && MycRom.fHeightX == 64) || (!nEditExtraResolutionF && MycRom.fHeight == 64))) { paste_offsetx = (int)((tpt.x - xspos) / (2 * frame_zoom) - Paste_Width / 2); paste_offsety = (int)((tpt.y - yspos) / (2 * frame_zoom) - Paste_Height / 2); @@ -19459,7 +19306,7 @@ void mouse_move_callback(GLFWwindow* window, double xpos, double ypos) } else if ((window == glfwframe) && (Color_Pipette == 0)) { - if (Zoom_Pushed && ((nEditExtraResolutionF && MycRom.fHeightX == 64) || (!nEditExtraResolutionF && MycRom.fHeight == 64))) + if (Edit_Mode == 1 && Zoom_Pushed && ((nEditExtraResolutionF && MycRom.fHeightX == 64) || (!nEditExtraResolutionF && MycRom.fHeight == 64))) { MouseFinPosx = (int)(xpos / (2 * frame_zoom) + offset_frame_x); MouseFinPosy = (int)(ypos / (2 * frame_zoom) + offset_frame_y); @@ -19586,9 +19433,9 @@ void mouse_button_callback(GLFWwindow* window, int button, int action, int mods) int xipos = (int)xpos, yipos = (int)ypos; if (window == glfwframe) { - if (ExtraResFClicked && MycRom.isExtraFrame[acFrame] == 0) return; + if (Edit_Mode == 1 && ExtraResFClicked && MycRom.isExtraFrame[acFrame] == 0) return; int xgrid, ygrid; - if (Zoom_Pushed && ((nEditExtraResolutionF && MycRom.fHeightX == 64) || (!nEditExtraResolutionF && MycRom.fHeight == 64))) + if (Edit_Mode == 1 && Zoom_Pushed && ((nEditExtraResolutionF && MycRom.fHeightX == 64) || (!nEditExtraResolutionF && MycRom.fHeight == 64))) { xgrid = (int)(xipos / (2 * frame_zoom) + offset_frame_x); ygrid = (int)(yipos / (2 * frame_zoom) + offset_frame_y); @@ -19984,23 +19831,26 @@ void mouse_button_callback(GLFWwindow* window, int button, int action, int mods) for (UINT tj = 0; tj < nSelFrames; tj++) { if (nEditExtraResolutionF && MycRom.isExtraFrame[SelFrames[tj]] == 0) continue; - for (UINT ti = 0; ti < fw * fh; ti++) + for (UINT ti = 0; ti < fh; ti++) { - if (pfr[SelFrames[tj] * fw * fh + ti] == col_to_find) + for (UINT tk = 0; tk < fw; tk++) { - if (MycRP.DrawColMode == 1) + if (pfr[SelFrames[tj] * fw * fh + ti*fw+tk] == col_to_find) { - if (!nEditExtraResolutionF) - pfr[SelFrames[tj] * fw * fh + ti] = MycRP.acEditColorsS[MycRP.oFrames[SelFrames[tj] * MycRom.fHeight * MycRom.fWidth + ti]]; - else + if (MycRP.DrawColMode == 1) { - if (fh == 64) - pfr[SelFrames[tj] * fw * fh + ti] = MycRP.acEditColorsS[MycRP.oFrames[SelFrames[tj] * MycRom.fHeight * MycRom.fWidth + ti / 2]]; + if (!nEditExtraResolutionF) + pfr[SelFrames[tj] * fw * fh + ti * fw + tk] = MycRP.acEditColorsS[MycRP.oFrames[SelFrames[tj] * MycRom.fHeight * MycRom.fWidth + ti * fw + tk]]; else - pfr[SelFrames[tj] * fw * fh + ti] = MycRP.acEditColorsS[MycRP.oFrames[SelFrames[tj] * MycRom.fHeight * MycRom.fWidth + ti * 2]]; + { + if (fh == 64) + pfr[SelFrames[tj] * fw * fh + ti * fw + tk] = MycRP.acEditColorsS[MycRP.oFrames[SelFrames[tj] * MycRom.fHeight * MycRom.fWidth + ti/2 * MycRom.fWidth + tk/2]]; + else + pfr[SelFrames[tj] * fw * fh + ti * fw + tk] = MycRP.acEditColorsS[MycRP.oFrames[SelFrames[tj] * MycRom.fHeight * MycRom.fWidth + ti*2 * MycRom.fWidth + tk*2]]; + } } + else pfr[SelFrames[tj] * fw * fh + ti * fw + tk] = MycRP.acEditColorsS[noColSel]; } - else pfr[SelFrames[tj] * fw * fh + ti] = MycRP.acEditColorsS[noColSel]; } } } @@ -20903,14 +20753,6 @@ bool CreateToolbar(void) } ComboBox_SetItemHeight(GetDlgItem(hwTB, IDC_MASKLIST), 0, 90); SetCommonButton(Common_Pushed); - /*oldMaskListFunc = (WNDPROC)GetWindowLongPtr(GetDlgItem(hwTB, IDC_MASKLIST), GWLP_WNDPROC); - SetWindowSubclass(GetDlgItem(hwTB, IDC_MASKLIST), (SUBCLASSPROC)SubclassMaskListProc, 0, 0); - oldSectionListoFunc = (WNDPROC)GetWindowLongPtr(GetDlgItem(hwTB, IDC_SECTIONLIST), GWLP_WNDPROC); - SetWindowSubclass(GetDlgItem(hwTB, IDC_SECTIONLIST), (SUBCLASSPROC)SubclassSecListoProc, 1, 0); - oldMask2ListFunc = (WNDPROC)GetWindowLongPtr(GetDlgItem(hwTB, IDC_MASKLIST2), GWLP_WNDPROC); - SetWindowSubclass(GetDlgItem(hwTB, IDC_MASKLIST2), (SUBCLASSPROC)SubclassMask2ListProc, 4, 0); - functoremove = 1; - */ } else { @@ -21010,12 +20852,6 @@ bool CreateToolbar(void) SendMessageA(GetDlgItem(hwTB, IDC_FILTERTYPE), CB_ADDSTRING, 0, (LPARAM)"Lanczos4"); FrameResizeFilter = 0; SendMessageA(GetDlgItem(hwTB, IDC_FILTERTYPE), CB_SETCURSEL, 0, 0); - /*oldSectionListcFunc = (WNDPROC)GetWindowLongPtr(GetDlgItem(hwTB, IDC_SECTIONLIST), GWLP_WNDPROC); - SetWindowSubclass(GetDlgItem(hwTB, IDC_SECTIONLIST), (SUBCLASSPROC)SubclassSecListcProc, 2, 0); - oldSpriteList2Func = (WNDPROC)GetWindowLongPtr(GetDlgItem(hwTB, IDC_SPRITELIST2), GWLP_WNDPROC); - SetWindowSubclass(GetDlgItem(hwTB, IDC_SPRITELIST2), (SUBCLASSPROC)SubclassSpriteList2Proc, 3, 0); - functoremove = 2; - */ } if (UndoAvailableN > 0) EnableWindow(GetDlgItem(hwTB, IDC_UNDO), TRUE); else EnableWindow(GetDlgItem(hwTB, IDC_UNDO), FALSE); if (RedoAvailableN > 0) EnableWindow(GetDlgItem(hwTB, IDC_REDO), TRUE); else EnableWindow(GetDlgItem(hwTB, IDC_REDO), FALSE); @@ -21033,9 +20869,6 @@ bool CreateToolbar2(void) { if (hwTB2) { - /*RemoveWindowSubclass(hwTB2, (SUBCLASSPROC)SubclassSpriteListProc, 5); - RemoveWindowSubclass(hwTB2, (SUBCLASSPROC)SubclassSpriteDetListProc, 6); - */ DestroyWindow(hwTB2); } hwTB2 = CreateDialog(hInst, MAKEINTRESOURCE(IDD_SPRDLG), hSprites, Toolbar_Proc2); @@ -21081,11 +20914,6 @@ bool CreateToolbar2(void) SetWindowPos(GetDlgItem(hwTB2, IDC_STRY19), 0, 0, 0, 5, 100, SWP_NOMOVE | SWP_NOZORDER); if (UndoAvailableN > 0) EnableWindow(GetDlgItem(hwTB2, IDC_UNDO), TRUE); else EnableWindow(GetDlgItem(hwTB2, IDC_UNDO), FALSE); if (RedoAvailableN > 0) EnableWindow(GetDlgItem(hwTB2, IDC_REDO), TRUE); else EnableWindow(GetDlgItem(hwTB2, IDC_REDO), FALSE); - /*oldSpriteListFunc = (WNDPROC)GetWindowLongPtr(GetDlgItem(hwTB2, IDC_SPRITELIST), GWLP_WNDPROC); - SetWindowSubclass(GetDlgItem(hwTB2, IDC_SPRITELIST), (SUBCLASSPROC)SubclassSpriteListProc, 5, 0); - oldSpriteDetListFunc = (WNDPROC)GetWindowLongPtr(GetDlgItem(hwTB2, IDC_DETSPR), GWLP_WNDPROC); - SetWindowSubclass(GetDlgItem(hwTB2, IDC_DETSPR), (SUBCLASSPROC)SubclassSpriteDetListProc, 6, 0); - */ SetZoomSpriteButton(Zoom_Pushed_Sprite); SetExtraResFBox(); char tbuf[8]; @@ -21115,9 +20943,6 @@ bool CreateToolbar3(void) { if (hwTB3) { - /*RemoveWindowSubclass(hwTB2, (SUBCLASSPROC)SubclassSpriteListProc, 5); - RemoveWindowSubclass(hwTB2, (SUBCLASSPROC)SubclassSpriteDetListProc, 6); - */ DestroyWindow(hwTB3); } hwTB3 = CreateDialog(hInst, MAKEINTRESOURCE(IDD_IMGDLG), hImages, Toolbar_Proc3); @@ -21155,15 +20980,6 @@ bool CreateToolbar3(void) SendMessageA(GetDlgItem(hwTB3, IDC_FILTERTYPE), CB_SETCURSEL, 0, 0); - /*char tbuf[8]; - SendMessage(GetDlgItem(hwTB2, IDC_DETSPR), CB_RESETCONTENT, 0, 0); - for (int ti = 0; ti < MAX_SPRITE_DETECT_AREAS; ti++) - { - _itoa_s(ti + 1, tbuf, 8, 10); - SendMessageA(GetDlgItem(hwTB2, IDC_DETSPR), CB_ADDSTRING, 0, (LPARAM)tbuf); - } - SendMessage(GetDlgItem(hwTB2, IDC_DETSPR), CB_SETCURSEL, 0, 1); - */ diff --git a/ColorizingDMD.rc b/ColorizingDMD.rc index 08f8165..c96c55f 100644 Binary files a/ColorizingDMD.rc and b/ColorizingDMD.rc differ diff --git a/ColorizingDMD.vcxproj b/ColorizingDMD.vcxproj index 8922fe2..14d12fa 100644 --- a/ColorizingDMD.vcxproj +++ b/ColorizingDMD.vcxproj @@ -126,7 +126,7 @@ Windows true - $(CoreLibraryDependencies);%(AdditionalDependenies);gdiplus.lib;Comctl32.lib;Shlwapi.lib;Winmm.lib;opengl32.lib;glfw3.lib;glew32.lib;LiteZip.lib;opencv_aruco451d.lib;opencv_bgsegm451d.lib;opencv_bioinspired451d.lib;opencv_calib3d451d.lib;opencv_ccalib451d.lib;opencv_core451d.lib;opencv_datasets451d.lib;opencv_dnn451d.lib;opencv_dnn_objdetect451d.lib;opencv_dnn_superres451d.lib;opencv_dpm451d.lib;opencv_face451d.lib;opencv_features2d451d.lib;opencv_flann451d.lib;opencv_fuzzy451d.lib;opencv_gapi451d.lib;opencv_hdf451d.lib;opencv_hfs451d.lib;opencv_highgui451d.lib;opencv_imgcodecs451d.lib;opencv_imgproc451d.lib;opencv_img_hash451d.lib;opencv_intensity_transform451d.lib;opencv_line_descriptor451d.lib;opencv_mcc451d.lib;opencv_ml451d.lib;opencv_objdetect451d.lib;opencv_optflow451d.lib;opencv_phase_unwrapping451d.lib;opencv_photo451d.lib;opencv_plot451d.lib;opencv_quality451d.lib;opencv_rapid451d.lib;opencv_reg451d.lib;opencv_rgbd451d.lib;opencv_shape451d.lib;opencv_stereo451d.lib;opencv_stitching451d.lib;opencv_structured_light451d.lib;opencv_superres451d.lib;opencv_surface_matching451d.lib;opencv_text451d.lib;opencv_tracking451d.lib;opencv_video451d.lib;opencv_videoio451d.lib;opencv_videostab451d.lib;opencv_xfeatures2d451d.lib;opencv_ximgproc451d.lib;opencv_xobjdetect451d.lib;opencv_xphoto451d.lib; libserialport64.lib;libserialport64.lib; zedmd64.lib; + $(CoreLibraryDependencies);%(AdditionalDependenies);gdiplus.lib;Comctl32.lib;Shlwapi.lib;Winmm.lib;opengl32.lib;glfw3.lib;glew32.lib;LiteZip.lib;opencv_aruco451d.lib;opencv_bgsegm451d.lib;opencv_bioinspired451d.lib;opencv_calib3d451d.lib;opencv_ccalib451d.lib;opencv_core451d.lib;opencv_datasets451d.lib;opencv_dnn451d.lib;opencv_dnn_objdetect451d.lib;opencv_dnn_superres451d.lib;opencv_dpm451d.lib;opencv_face451d.lib;opencv_features2d451d.lib;opencv_flann451d.lib;opencv_fuzzy451d.lib;opencv_gapi451d.lib;opencv_hdf451d.lib;opencv_hfs451d.lib;opencv_highgui451d.lib;opencv_imgcodecs451d.lib;opencv_imgproc451d.lib;opencv_img_hash451d.lib;opencv_intensity_transform451d.lib;opencv_line_descriptor451d.lib;opencv_mcc451d.lib;opencv_ml451d.lib;opencv_objdetect451d.lib;opencv_optflow451d.lib;opencv_phase_unwrapping451d.lib;opencv_photo451d.lib;opencv_plot451d.lib;opencv_quality451d.lib;opencv_rapid451d.lib;opencv_reg451d.lib;opencv_rgbd451d.lib;opencv_shape451d.lib;opencv_stereo451d.lib;opencv_stitching451d.lib;opencv_structured_light451d.lib;opencv_superres451d.lib;opencv_surface_matching451d.lib;opencv_text451d.lib;opencv_tracking451d.lib;opencv_video451d.lib;opencv_videoio451d.lib;opencv_videostab451d.lib;opencv_xfeatures2d451d.lib;opencv_ximgproc451d.lib;opencv_xobjdetect451d.lib;opencv_xphoto451d.lib;libserialport64.lib;zedmd64.lib;Dwmapi.lib 3000000 @@ -148,7 +148,7 @@ true true true - $(CoreLibraryDependencies);%(AdditionalDependenies);gdiplus.lib;Comctl32.lib;Shlwapi.lib;Winmm.lib;opengl32.lib;glfw3.lib;glew32.lib;LiteZip.lib;opencv_bgsegm451.lib;opencv_bioinspired451.lib;opencv_calib3d451.lib;opencv_ccalib451.lib;opencv_core451.lib;opencv_datasets451.lib;opencv_dnn451.lib;opencv_dnn_objdetect451.lib;opencv_dnn_superres451.lib;opencv_dpm451.lib;opencv_face451.lib;opencv_features2d451.lib;opencv_flann451.lib;opencv_fuzzy451.lib;opencv_gapi451.lib;opencv_hdf451.lib;opencv_hfs451.lib;opencv_highgui451.lib;opencv_imgcodecs451.lib;opencv_imgproc451.lib;opencv_img_hash451.lib;opencv_intensity_transform451.lib;opencv_line_descriptor451.lib;opencv_mcc451.lib;opencv_ml451.lib;opencv_objdetect451.lib;opencv_optflow451.lib;opencv_phase_unwrapping451.lib;opencv_photo451.lib;opencv_plot451.lib;opencv_quality451.lib;opencv_rapid451.lib;opencv_reg451.lib;opencv_rgbd451.lib;opencv_shape451.lib;opencv_stereo451.lib;opencv_stitching451.lib;opencv_structured_light451.lib;opencv_superres451.lib;opencv_surface_matching451.lib;opencv_text451.lib;opencv_tracking451.lib;opencv_video451.lib;opencv_videoio451.lib;opencv_videostab451.lib;opencv_xfeatures2d451.lib;opencv_ximgproc451.lib;opencv_xobjdetect451.lib;opencv_xphoto451.lib;libserialport64.lib; ws2_32.lib; zedmd64.lib; + $(CoreLibraryDependencies);%(AdditionalDependenies);gdiplus.lib;Comctl32.lib;Shlwapi.lib;Winmm.lib;opengl32.lib;glfw3.lib;glew32.lib;LiteZip.lib;opencv_bgsegm451.lib;opencv_bioinspired451.lib;opencv_calib3d451.lib;opencv_ccalib451.lib;opencv_core451.lib;opencv_datasets451.lib;opencv_dnn451.lib;opencv_dnn_objdetect451.lib;opencv_dnn_superres451.lib;opencv_dpm451.lib;opencv_face451.lib;opencv_features2d451.lib;opencv_flann451.lib;opencv_fuzzy451.lib;opencv_gapi451.lib;opencv_hdf451.lib;opencv_hfs451.lib;opencv_highgui451.lib;opencv_imgcodecs451.lib;opencv_imgproc451.lib;opencv_img_hash451.lib;opencv_intensity_transform451.lib;opencv_line_descriptor451.lib;opencv_mcc451.lib;opencv_ml451.lib;opencv_objdetect451.lib;opencv_optflow451.lib;opencv_phase_unwrapping451.lib;opencv_photo451.lib;opencv_plot451.lib;opencv_quality451.lib;opencv_rapid451.lib;opencv_reg451.lib;opencv_rgbd451.lib;opencv_shape451.lib;opencv_stereo451.lib;opencv_stitching451.lib;opencv_structured_light451.lib;opencv_superres451.lib;opencv_surface_matching451.lib;opencv_text451.lib;opencv_tracking451.lib;opencv_video451.lib;opencv_videoio451.lib;opencv_videostab451.lib;opencv_xfeatures2d451.lib;opencv_ximgproc451.lib;opencv_xobjdetect451.lib;opencv_xphoto451.lib;libserialport64.lib;ws2_32.lib;zedmd64.lib;Dwmapi.lib 3000000 diff --git a/OGL_Immediate_2D.cpp b/OGL_Immediate_2D.cpp index 4e5f337..898f9c9 100644 --- a/OGL_Immediate_2D.cpp +++ b/OGL_Immediate_2D.cpp @@ -9,8 +9,7 @@ int text_CreateTextureCircle(GLFWwindow* glfww) { glfwMakeContextCurrent(glfww); - /* Generate texture - */ + /* Generate texture */ GLuint texid; UINT8 texel[64] = { 0,255,255,255,255,255,255,0, 255,255,255,255,255,255,255,255, @@ -26,8 +25,7 @@ int text_CreateTextureCircle(GLFWwindow* glfww) glGenTextures(1, &texid); glBindTexture(GL_TEXTURE_2D, texid); - /* Setup texture filters - */ + /* Setup texture filters */ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); diff --git a/cRom.h b/cRom.h index 7b77b17..4a2bc25 100644 --- a/cRom.h +++ b/cRom.h @@ -204,3 +204,12 @@ typedef struct { UINT32 hashcode; } sFrames; +/*typedef struct { + DWORD lastTime[MAX_COLOR_ROTATION]; + + UINT8 ncol[MAX_COLOR_ROTATION]; + UINT16 colors[MAX_LENGTH_COLOR_ROTATION]; + UINT8 acfirst[MAX_COLOR_ROTATION]; + DWORD timespan[MAX_COLOR_ROTATION]; +} sColRot;*/ + diff --git a/gifenc.c b/gifenc.c new file mode 100644 index 0000000..ca493c1 --- /dev/null +++ b/gifenc.c @@ -0,0 +1,241 @@ +#include "gifenc.h" + +#include +#include +#include +#include +#include +#include +#ifdef _WIN32 +#include +#else +#include +#endif + +#pragma warning(disable : 4996) + +/* helper to write a little-endian 16-bit number portably */ +#define write_num(fd, n) write((fd), (uint8_t []) {(n) & 0xFF, (n) >> 8}, 2) + +static uint8_t vga[0x30] = { + 0x00, 0x00, 0x00, + 0xAA, 0x00, 0x00, + 0x00, 0xAA, 0x00, + 0xAA, 0x55, 0x00, + 0x00, 0x00, 0xAA, + 0xAA, 0x00, 0xAA, + 0x00, 0xAA, 0xAA, + 0xAA, 0xAA, 0xAA, + 0x55, 0x55, 0x55, + 0xFF, 0x55, 0x55, + 0x55, 0xFF, 0x55, + 0xFF, 0xFF, 0x55, + 0x55, 0x55, 0xFF, + 0xFF, 0x55, 0xFF, + 0x55, 0xFF, 0xFF, + 0xFF, 0xFF, 0xFF, +}; + +struct Node { + uint16_t key; + struct Node *children[]; +}; +typedef struct Node Node; + +static Node * +new_node(uint16_t key, int degree) +{ + Node *node = calloc(1, sizeof(*node) + degree * sizeof(Node *)); + if (node) + node->key = key; + return node; +} + +static Node * +new_trie(int degree, int *nkeys) +{ + Node *root = new_node(0, degree); + /* Create nodes for single pixels. */ + for (*nkeys = 0; *nkeys < degree; (*nkeys)++) + root->children[*nkeys] = new_node(*nkeys, degree); + *nkeys += 2; /* skip clear code and stop code */ + return root; +} + +static void +del_trie(Node *root, int degree) +{ + if (!root) + return; + for (int i = 0; i < degree; i++) + del_trie(root->children[i], degree); + free(root); +} + +#define write_and_store(s, dst, fd, src, n) \ +do { \ + write(fd, src, n); \ + if (s) { \ + memcpy(dst, src, n); \ + dst += n; \ + } \ +} while (0); + +static void put_loop(ge_GIF *gif, uint16_t loop); + +ge_GIF *ge_new_gif(const char *fname, uint16_t width, uint16_t height, int depth, int bgindex, int loop) +{ + ge_GIF* gif = calloc(1, sizeof(*gif) + width * height); + if (!gif) + goto no_gif; + gif->w = width; gif->h = height; + gif->bgindex = bgindex; + gif->frame = (uint8_t*)&gif[1]; + gif->back = &gif->frame[width*height]; + gif->depth = depth; +#ifdef _WIN32 + gif->fd = creat(fname, S_IWRITE); +#else + gif->fd = creat(fname, 0666); +#endif + if (gif->fd == -1) + goto no_fd; +#ifdef _WIN32 + setmode(gif->fd, O_BINARY); +#endif + write(gif->fd, "GIF89a", 6); + write_num(gif->fd, width); + write_num(gif->fd, height); + unsigned char flags = 0x70; // no GCT, 2^8 color in the original image (don't care), no sort, size of GCT 2^(7+1) (don't care) + write(gif->fd, (uint8_t []) {flags, (uint8_t) bgindex, 0x00}, 3); // background color = bgindex, ratio = 0 (no default ratio) + put_loop(gif, (uint16_t) loop); // add the NETSCAPE 2.0 option for loop (loop = 0 infinite loop) + return gif; +no_fd: + free(gif); +no_gif: + return NULL; +} + +static void put_loop(ge_GIF *gif, uint16_t loop) +{ + write(gif->fd, (uint8_t []) {'!', 0xFF, 0x0B}, 3); + write(gif->fd, "NETSCAPE2.0", 11); + write(gif->fd, (uint8_t []) {0x03, 0x01}, 2); + write_num(gif->fd, loop); + write(gif->fd, "\0", 1); +} + +/* Add packed key to buffer, updating offset and partial. + * gif->offset holds position to put next *bit* + * gif->partial holds bits to include in next byte */ +static void put_key(ge_GIF *gif, uint16_t key, int key_size) +{ + int byte_offset, bit_offset, bits_to_write; + byte_offset = gif->offset / 8; + bit_offset = gif->offset % 8; + gif->partial |= ((uint32_t) key) << bit_offset; + bits_to_write = bit_offset + key_size; + while (bits_to_write >= 8) { + gif->buffer[byte_offset++] = gif->partial & 0xFF; + if (byte_offset == 0xFF) { + write(gif->fd, "\xFF", 1); + write(gif->fd, gif->buffer, 0xFF); + byte_offset = 0; + } + gif->partial >>= 8; + bits_to_write -= 8; + } + gif->offset = (gif->offset + key_size) % (0xFF * 8); +} + +static void end_key(ge_GIF *gif) +{ + int byte_offset; + byte_offset = gif->offset / 8; + if (gif->offset % 8) + gif->buffer[byte_offset++] = gif->partial & 0xFF; + if (byte_offset) { + write(gif->fd, (uint8_t []) {byte_offset}, 1); + write(gif->fd, gif->buffer, byte_offset); + } + write(gif->fd, "\0", 1); + gif->offset = gif->partial = 0; +} + +static void put_image(ge_GIF *gif, uint16_t w, uint16_t h, uint16_t x, uint16_t y, uint8_t* palette) +{ + int nkeys, key_size, i, j; + Node *node, *child, *root; + int degree = 1 << gif->depth; + + write(gif->fd, ",", 1); + write_num(gif->fd, x); + write_num(gif->fd, y); + write_num(gif->fd, w); + write_num(gif->fd, h); + unsigned char lcd = 0x80 + gif->depth - 1; + write(gif->fd, (uint8_t[]) { lcd }, 1); // gif->depth }, 2);// 0x80 because there is a local color table and there are 2^gif->depth colors in the table, we must write depth-1 + // we write the local color table + int ncol = 3 * degree; + write(gif->fd, palette, ncol); + write(gif->fd, (uint8_t[]) { gif->depth }, 1); // gif->depth }, 2);// 0x80 because there is a local color table and there are 2^gif->depth colors in the table, we must write depth-1 + root = node = new_trie(degree, &nkeys); + key_size = gif->depth + 1; + put_key(gif, degree, key_size); /* clear code */ + for (i = y; i < y+h; i++) { + for (j = x; j < x+w; j++) { + uint8_t pixel = gif->frame[i*gif->w+j] & (degree - 1); + child = node->children[pixel]; + if (child) { + node = child; + } else { + put_key(gif, node->key, key_size); + if (nkeys < 0x1000) { + if (nkeys == (1 << key_size)) + key_size++; + node->children[pixel] = new_node(nkeys++, degree); + } else { + put_key(gif, degree, key_size); /* clear code */ + del_trie(root, degree); + root = node = new_trie(degree, &nkeys); + key_size = gif->depth + 1; + } + node = root->children[pixel]; + } + } + } + put_key(gif, node->key, key_size); + put_key(gif, degree + 1, key_size); /* stop code */ + end_key(gif); + del_trie(root, degree); +} + +static void add_graphics_control_extension(ge_GIF *gif, uint16_t d) +{ + uint8_t flags = 0;// 1;// 2 << 2 + 1; + write(gif->fd, (uint8_t []) {'!', 0xF9, 0x04, flags}, 4); + write_num(gif->fd, d); + write(gif->fd, (uint8_t []) {0xFF, 0x00}, 2); +} + +void ge_add_frame(ge_GIF *gif, uint8_t* palette, uint16_t delay) +{ + uint8_t *tmp; + if (delay || (gif->bgindex >= 0)) + add_graphics_control_extension(gif, delay); + put_image(gif, gif->w, gif->h, 0, 0, palette); + gif->nframes++; + if (gif->bgindex < 0) { + tmp = gif->back; + gif->back = gif->frame; + gif->frame = tmp; + } +} + +void +ge_close_gif(ge_GIF* gif) +{ + write(gif->fd, ";", 1); + close(gif->fd); + free(gif); +} diff --git a/gifenc.h b/gifenc.h new file mode 100644 index 0000000..00502e7 --- /dev/null +++ b/gifenc.h @@ -0,0 +1,29 @@ +#ifndef GIFENC_H +#define GIFENC_H + +#include + +#ifdef __cplusplus +extern "C" { +#endif + +typedef struct ge_GIF { + uint16_t w, h; + int depth; + int bgindex; + int fd; + int offset; + int nframes; + uint8_t *frame, *back; + uint32_t partial; + uint8_t buffer[0xFF]; +} ge_GIF; + +ge_GIF* ge_new_gif(const char* fname, uint16_t width, uint16_t height, int depth, int bgindex, int loop); +void ge_add_frame(ge_GIF *gif, uint8_t* palette, uint16_t delay); +void ge_close_gif(ge_GIF* gif); + +#ifdef __cplusplus +} +#endif +#endif /* GIFENC_H */ diff --git a/serumdll.cpp b/serumdll.cpp index d153164..a6d5e20 100644 --- a/serumdll.cpp +++ b/serumdll.cpp @@ -78,6 +78,7 @@ void DownscaleRGB565Frame(UINT16* frame64, UINT16* frame32, UINT width64) bool ColorizeAFrame(UINT8* vpframe, UINT16** newframe32, UINT16** newframe64, UINT* frameID, bool* is32fr, bool* is64fr) { Serum_Colorize(vpframe); + *frameID = pSerum->frameID; *newframe32 = pSerum->frame32; *newframe64 = pSerum->frame64; if (pSerum->width32 > 0) *is32fr = true; else *is32fr = false; @@ -92,13 +93,13 @@ bool ColorizeAFrame(UINT8* vpframe, UINT16** newframe32, UINT16** newframe64, UI bool ColorRotateAFrame(UINT16** newframe32, UINT8** modelt32, UINT16** newframe64, UINT8** modelt64) { - bool isrot; - isrot = Serum_Rotate(); + UINT isrot = Serum_Rotate(); *newframe32 = pSerum->frame32; *newframe64 = pSerum->frame64; if (modelt32) *modelt32 = ModifiedElements32; if (modelt64) *modelt64 = ModifiedElements64; - return isrot; + if (isrot > 0) return true; + return false; } void StopLibSerum(void)