Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Modify water filter #106

Open
qq2225936589 opened this issue Sep 7, 2020 · 4 comments
Open

Modify water filter #106

qq2225936589 opened this issue Sep 7, 2020 · 4 comments
Assignees
Labels

Comments

@qq2225936589
Copy link

qq2225936589 commented Sep 7, 2020

I don't know how to submit the code
`

 newoffset = offset + geo->w*(dy>>3) + (dx>>3);
  if(newoffset<geo->size/sizeof(uint32_t) && offset<(geo->w)*(geo->h))
  {
    c = BkGdImage[newoffset];
    out[offset] = c;
  }`

Please check the link below for the complete code

https://github.com/qq2225936589/frei0r_win32/blob/master/water.cpp

@ddennedy
Copy link
Collaborator

ddennedy commented Sep 7, 2020

Why?

@qq2225936589
Copy link
Author

The original water filter crashed on the windows system

@ddennedy
Copy link
Collaborator

OK, it was difficult to follow because this filter was not integrated into either build system, it was outdated for the current frei0r.hpp. I did not apply your change to use height+1. Here is my diff

diff --git a/src/Makefile.am b/src/Makefile.am
index 9e8a9c4..1ef849d 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -134,6 +134,7 @@ plugin_LTLIBRARIES = \
 	value.la \
 	vertigo.la \
 	vignette.la \
+	water.la \
 	xfade0r.la
 
 if HAVE_GAVL
diff --git a/src/filter/CMakeLists.txt b/src/filter/CMakeLists.txt
index fb23e89..d9fd2db 100644
--- a/src/filter/CMakeLists.txt
+++ b/src/filter/CMakeLists.txt
@@ -97,3 +97,4 @@ add_subdirectory (tutorial)
 add_subdirectory (twolay0r)
 add_subdirectory (vertigo)
 add_subdirectory (vignette)
+add_subdirectory (water)
diff --git a/src/filter/water/water.cpp b/src/filter/water/water.cpp
index 1d9a589..6dc53ba 100644
--- a/src/filter/water/water.cpp
+++ b/src/filter/water/water.cpp
@@ -144,11 +144,11 @@ public:
     //    free(buffer);
   }
 
-  virtual void update() {
+  virtual void update(double time, uint32_t* out, const uint32_t* in) {
 
     memcpy(BkGdImage, in, width*height*sizeof(uint32_t));
     
-    water_update();
+    water_update(out);
 
   }
   
@@ -190,14 +190,14 @@ private:
   void water_clear();
   void water_distort();
   void water_setphysics(double physics);
-  void water_update();
+  void water_update(uint32_t *out);
   void water_drop(int x, int y);
   void water_bigsplash(int x, int y);
   void water_surfer();
   void water_swirl();
   void water_3swirls();
   
-  void DrawWater(int page);
+  void DrawWater(int page, uint32_t* out);
   void CalcWater(int npage, int density);
   void CalcWaterBigFilter(int npage, int density);
   
@@ -322,7 +322,7 @@ void Water::water_setphysics(double physics) {
   }
 }
 
-void Water::water_update() {
+void Water::water_update(uint32_t* out) {
 
   if(rain) {
     raincount++;
@@ -334,7 +334,7 @@ void Water::water_update() {
 
   if(swirl) water_swirl();
   if(surfer) water_surfer();
-  DrawWater(Hpage);
+  DrawWater(Hpage, out);
 
   CalcWater(Hpage^1, density);
   Hpage ^=1 ;
@@ -458,27 +458,30 @@ void Water::water_3swirls() {
 }
 
 /* internal physics routines */
-void Water::DrawWater(int page) {
+void Water::DrawWater(int page, uint32_t *out) {
   int dx, dy;
   int x, y;
-  int c;
   int offset=geo->w + 1;
+  int newoffset;
+  int maxoffset = geo->w * geo->h;
   int *ptr = (int*)&Height[page][0];
   
   for (y = calc_optimization; offset < y; offset += 2) {
     for (x = offset+geo->w-2; offset < x; offset++) {
       dx = ptr[offset] - ptr[offset+1];
       dy = ptr[offset] - ptr[offset+geo->w];
-      c = BkGdImage[offset + geo->w*(dy>>3) + (dx>>3)];
-      
-      out[offset] = c;
+      newoffset = offset + geo->w*(dy>>3) + (dx>>3);
+      if (newoffset < maxoffset) {
+        out[offset] = BkGdImage[newoffset];
+      }
 
       offset++;
       dx = ptr[offset] - ptr[offset+1];
       dy = ptr[offset] - ptr[offset+geo->w];
-      c = BkGdImage[offset + geo->w*(dy>>3) + (dx>>3)];
-
-      out[offset] = c;      
+      newoffset = offset + geo->w*(dy>>3) + (dx>>3);
+      if (newoffset < maxoffset) {
+        out[offset] = BkGdImage[newoffset];
+      }
     }
   }
 }

@ddennedy
Copy link
Collaborator

This code is not ready to be integrated into build at this time. There is a bunch of unused code, unused parameters, and uninitialized variables.

@jaromil jaromil self-assigned this Dec 28, 2022
@jaromil jaromil added the bug label Dec 30, 2022
jaromil added a commit that referenced this issue Aug 2, 2023
jaromil added a commit that referenced this issue Aug 2, 2023
jaromil added a commit that referenced this issue Aug 4, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants