Reptillian Posted February 16, 2021 Share Posted February 16, 2021 (edited) How this code works is to create a 3D box, and to grab the mode from the created 3D box. It only should run once. I do admit that code needs to be improved on though. It's made to solve this thread (though too late to post there) - -1 implies that if there is more than 1 mode, then the canvas will not be filled with colors. Otherwise, you can choose which mode to fill on the canvas. Spoiler // Name: // Submenu: // Author: // Title: // Version: // Desc: // Keywords: // URL: // Help: #region UICode IntSliderControl color_position = -1; // [-1,100] Color Position #endregion int[,,] col3d = null; bool proceed=true; List<int> r_cols = new List<int>(); List<int> g_cols = new List<int>(); List<int> b_cols = new List<int>(); List<int> r_cols_mf = new List<int>(); List<int> g_cols_mf = new List<int>(); List<int> b_cols_mf = new List<int>(); List<int> counts = new List<int>(); int maxfreqcounts=0; void PreRender(Surface dst, Surface src) { if (proceed){ int size_of_count = 0; int maxval=0; Rectangle selection = EnvironmentParameters.SelectionBounds; col3d = new int[256,256,256]; for (int y = selection.Top; y < selection.Bottom; y++) { for (int x = selection.Left; x < selection.Right; x++) { ColorBgra img_pixels = src[x,y]; col3d[img_pixels.R,img_pixels.G,img_pixels.B]++; } } for (int xcol3d = 0 ; xcol3d < 256 ; xcol3d++) { for (int ycol3d = 0 ; ycol3d < 256 ; ycol3d++) { for (int zcol3d = 0 ; zcol3d < 256 ; zcol3d++) { if(col3d[xcol3d,ycol3d,zcol3d]>0){ r_cols.Add(xcol3d); g_cols.Add(ycol3d); b_cols.Add(zcol3d); counts.Add(col3d[xcol3d,ycol3d,zcol3d]); size_of_count++; } } } } for (int nmv = 0 ; nmv <size_of_count ; nmv++){ if(counts[nmv]>maxval){maxval=counts[nmv];} } for (int nmf = 0 ; nmf <size_of_count ; nmf++){ if(counts[nmf]==maxval){ r_cols_mf.Add(r_cols[nmf]); g_cols_mf.Add(g_cols[nmf]); b_cols_mf.Add(b_cols[nmf]); maxfreqcounts++; } } proceed=false; } } void Render(Surface dst, Surface src, Rectangle rect) { // Delete any of these lines you don't need; ColorBgra currentPixel; for (int y = rect.Top; y < rect.Bottom; y++) { if (IsCancelRequested) return; for (int x = rect.Left; x < rect.Right; x++) { currentPixel = src[x,y]; if (color_position==-1) { if(maxfreqcounts>1) {dst[x,y]=src[x,y];} else {dst[x,y] = ColorBgra.FromBgraClamped(b_cols_mf[0], g_cols_mf[0], r_cols_mf[0], 255);} } else {dst[x,y] = ColorBgra.FromBgraClamped(b_cols_mf[color_position%maxfreqcounts], g_cols_mf[color_position%maxfreqcounts], r_cols_mf[color_position%maxfreqcounts], 255);} } } } Edited February 16, 2021 by Reptillian Quote G'MIC Filter Developer I am away from this forum for undetermined amount of time: If you really need anything related to my PDN plugin or my G'MIC filter within G'MIC plugin, then you can contact me via Paint.NET discord, and mention me. Link to comment Share on other sites More sharing options...
midora Posted February 16, 2021 Share Posted February 16, 2021 @Reptillian Could you please add a source picture and the result? Just to get a better idea what you like to achieve. I guess I have a rough idea what you like to do but the result is not what I expect. Quote Link to comment Share on other sites More sharing options...
Reptillian Posted February 16, 2021 Author Share Posted February 16, 2021 (edited) 2 hours ago, midora said: @Reptillian Could you please add a source picture and the result? Just to get a better idea what you like to achieve. I guess I have a rough idea what you like to do but the result is not what I expect. Before: After: All it does is to take the color with the most common appearance. It does that by accumulating 3D box info, and extracting info from a 3D box. As mentioned, -1 only takes in 1 mode, otherwise you would have to choose the color when it's not -1. If no changes appear on -1, that means there are more than 1 mode or no mode exists. Edited February 16, 2021 by Reptillian Quote G'MIC Filter Developer I am away from this forum for undetermined amount of time: If you really need anything related to my PDN plugin or my G'MIC filter within G'MIC plugin, then you can contact me via Paint.NET discord, and mention me. Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.