Toribash
Original Post
Invisible Texture Prevention
While perusing a the ban list (for no apparent reason) I noticed staff have to manually ban people for invisible textures. My idea is probably stupid and not plausible. Here it is though. I don't know if its even possible either.

Anyway, I would like to suggest some kind of line of code in the shop that analyzes textures when uploading textures with an alpha channel (.png) must not contain less than X percentage of blank pixels or the system automatically blocks it. Something that tailors itself to the size of the texture as well.

Here's an example using no less than 70% of the area of the texture and 30% blank allowed.

  • 16384 pixels in a 128 texture square means 11468.8 pixels must be filled with a color.
  • 45875.2 pixels on a 256 texture must be filled.
  • 183500.8 pixels on a 512 texture must be filled.
I just thought it would be useful for the staff because it's kind of a fire-and-forget solution to invisible textures.
Buy me food and tell me I'm cute.
I don't see why this wouldn't work. I'm always 100% certain that it's possible or atleast something similar is and don't see a reason not to implement it. While experimenting with transparency is fun, it can also lead to unfair moments where bodyparts aren't visable.

The question is if Hampa is open for these kind of suggestions, where something has to be implemented that fixes an old problem which might not be in focus.
Yeah, that's my main thing. I don't know if hampa or anyone currently on the staffing team has the time to create some kind of monitoring system like this. Also, no idea if they would have an extra server or whatever to manage this functionality.
Buy me food and tell me I'm cute.
I think this would actually be a massive headache to implement. I can't see a way of implementing this without stepping through every pixel in an image (which is sure to significantly slow upload - especially for those people who choose to use a .PNG without transparency).

I guess the first thing to do would be to check if a particular PNG image contains alpha or not:

<?php
      function get_colourtype($file){
          return (ord(@file_get_contents($file, NULL, NULL, 25, 1,)) ==6);
      }
?>
This should work because the color-type of a PNG image is stored at byte offset 25. If the 25th byte is 6 the colour-type is RGB + alpha. This will only work for PNGs however.

The above function will detect, at the very least, if a PNG will allow transparency, whether there actually is transparency present is another matter entirely. But at least with the function above we can make a semi-intelligent guess and prevent the overhead of checking unnecessarily.

The next step however, is unfortunately to perform a complete search, pixel-by-pixel. I cannot think of another way to do it. I guess if users who choose to use PNGs for texture upload with a RGB + alpha colour type were okay with longer wait times then this solution might be acceptable.

<?php
    function has_Transparency($imageData){
         //Get the width and height of the image for looping
         $w =imagesx($imageData);
         $h = imagesy($imageData);

         //Define an acceptable level of transparency
         $cutOff = ($w * $h) * 0.7;
         $transparentCounter = 0;

         //Iterate through pixels and amend transparency counter.
         //Break loop if cut off point (70% is reached). 
         for($i = 0; $i < $w; $i++){
            for($j = 0; $j < $h; j++){
                $rgba = imagecolorat($imgData, $i, $j);
                if(($rgba & 0x7F000000) >> 24) $transparentCounter++;
                if($transparentCounter == $cutOff) return true; 
            }
        }
        return false; 
    }
?>
That should work (I haven't tested it), although it is not going to be particularly efficient. There is probably a more intelligent way to search for transparency, but I'm starting to think that'll be beyond the effort of just having users report misuse and dealing with it then.
nice one man,
I recommend a list to deal with that and make it scan every neighbour pixel.
with this you would not be so messed with sequential overhead.

I know sequential loops are a bit of overhead as the complexity grows as a power of loops count.

with lists you would do the same as the bucket fill of computer graphics libs,
make sure to use graphics processor.
Last edited by dengue; Feb 23, 2018 at 03:35 AM.
Originally Posted by Fee View Post
The next step however, is unfortunately to perform a complete search, pixel-by-pixel. I cannot think of another way to do it. I guess if users who choose to use PNGs for texture upload with a RGB + alpha colour type were okay with longer wait times then this solution might be acceptable.

<?php
    function has_Transparency($imageData){
         //Get the width and height of the image for looping
         $w =imagesx($imageData);
         $h = imagesy($imageData);

         //Define an acceptable level of transparency
         $cutOff = ($w * $h) * 0.7;
         $transparentCounter = 0;

         //Iterate through pixels and amend transparency counter.
         //Break loop if cut off point (70% is reached). 
         for($i = 0; $i < $w; $i++){
            for($j = 0; $j < $h; j++){
                $rgba = imagecolorat($imgData, $i, $j);
                if(($rgba & 0x7F000000) >> 24) $transparentCounter++;
                if($transparentCounter == $cutOff) return true; 
            }
        }
        return false; 
    }
?>
That should work (I haven't tested it), although it is not going to be particularly efficient. There is probably a more intelligent way to search for transparency, but I'm starting to think that'll be beyond the effort of just having users report misuse and dealing with it then.

Checking every pixel would not be that slow, 512x512 textures have only 262144 pixels, which is pretty small for a computer to check, it would take at worst a few milliseconds.
Originally Posted by dengue View Post
nice one man,
I recommend a list to deal with that and make it scan every neighbour pixel.
with this you would not be so messed with sequential overhead.

I know sequential loops are a bit of overhead as the complexity grows as a power of loops count.

with lists you would do the same as the bucket fill of computer graphics libs,
make sure to use graphics processor.

Most servers don't have GPUs though, sequential accesses are the fastest BTW, checking every pixel wouldn't be that slow, it would take a few milliseconds at worst.
Originally Posted by Fee View Post
I think this would actually be a massive headache to implement. I can't see a way of implementing this without stepping through every pixel in an image (which is sure to significantly slow upload - especially for those people who choose to use a .PNG without transparency).

Why would it even matter if it slows down or not? Does it matter waiting 5 seconds for a anti-cheat to load when you play, let's say a FPS game? Then why would it matter to wait 5 seconds on this case?

And of course, I'm implying you are using a toaster to upload the image. Because otherwise it probably won't take a single second.
Last edited by TananPro; Feb 23, 2018 at 04:56 PM.
the processing is server side, after you completed the upload the server may process in its time.
The problem here isnt to process a single image, is to process multiple images
in a queue, it may be slow.
Pretty sure that the servers have ImageMagick available to them. Relevant.
Squad Squad Squad lead?
The standardization of Toribash Squad roles may have gone too far!