Possible means to speed up Bitmap TONE code?
#4
(06-11-2023, 01:27 AM)Kain Nobel Wrote: I think the code is wrong. For the tone value operation, I think you'd need to employ a "min / max" array function or use modulous to cut the number to it's proper negative or positive value.

First off.. um... The basis for the code was your own 'Grayscale' script for the MACL, used to evaluate and alter the individual pixels of an image and convert an image to grayscale.  Insofar as employing a min/max function, that's what the simple 'tone_ranges' method performs. 

Kainer's Greyscale

Admittedly, correct on one part, there is an error.  and this is the more correct version of the main function:

Code:
  #-------------------------------------------------------------------------
  # * Tone Adjust
  #     r : red adjustment   (defaulted to 0 middle of -255 - 255 range)
  #     g : green adjustment (defaulted to 0 middle of -255 - 255 range)
  #     b : blue adjustment  (defaulted to 0 middle of -255 - 255 range)
  #-------------------------------------------------------------------------
  def tone_adjust(r=0, g=0, b=0)
    time = Time.now
    # Cycle through the bitmaps pixels
    for x in 0..self.width
      for y in 0..self.height
        #
        color = self.get_pixel(x, y)                  # Get single pixel color
        next if color.alpha == 0                      # Skip if transparent
        rr = color.red   + r                          # Adjust the red
        gg = color.green + g                          # Adjust the green
        bb = color.blue  + b                          # Adjust the blue
        rr = tone_ranges(rr)                          # Keep within ranges
        gg = tone_ranges(gg)                          # '              '
        bb = tone_ranges(bb)                          # '              '
        self.set_pixel(x, y, Color.new(rr, gg, bb))   # Replace the pixel
        #
      end
    end
    p "Execution Time: #{Time.now - time}"
  end

Yes, I employed the execution time to the code to determine if it was faster with fill_rect than with set_pixel.  It is not.

(06-11-2023, 01:43 AM)kyonides Wrote: It makes you think so mainly because set_pixel "might" look for the color and then set it, while fill_rect would simply dump it all there. At the end it gotta be a slight advantage at most, yet, the benchmarking would make the difference. And a large picture gotta be use as a sample for that benchmarking!

Big-size file benchmarking?  Now some context... Imagine if you will that you are converting a veeery large png bitmap like a 120KB 16-shaded grayscale image (600 x 6615px in size). Using this method with setPixel on my PC, it takes 3.815 to convert the image.  If I were to use fill_rect, it takes 4.131 seconds.

More context, this for my layered spritesheet tool.  It uses direct bitmap editing so it can save output in pure .png format of any size (relative to RMXP's max size capacity) and with alpha transparency support.


(06-11-2023, 01:43 AM)kyonides Wrote: The main problem that I can see between set_pixel and fill_rect is that for large areas, fill_rect is ideal. Heck, it just checks and convert the color from RGSS to C or C++ or C# once. set_pixel would have to do that conversion tons of times instead. And it IS a slow conversion.

Fill rect merely fills a rectangle area with a color as its name implies, and is not a shader.  Otherwise, it would be the ideal tone_adjust code for the bitmap class. I see nothing in the documentation for fill_rect about it checking and converting anything.

Help Documentation (even VX too) Wrote:fill_rect(x, y, width, height, color)
fill_rect(rect, color)

    Fills the bitmap box (x, y, width, height) or rect (Rect) with color (Color).
Up is down, left is right and sideways is straight ahead. - Cord "Circle of Iron", 1978 (written by Bruce Lee and James Coburn... really...)

[Image: QrnbKlx.jpg]
[Image: sGz1ErF.png]    [Image: liM4ikn.png]    [Image: fdzKgZA.png]    [Image: sj0H81z.png]
[Image: QL7oRau.png]    [Image: uSqjY09.png]    [Image: GAA3qE9.png]    [Image: 2Hmnx1G.png]    [Image: BwtNdKw.png%5B]
  Above are clickable links
Reply }


Messages In This Thread
RE: Possible means to speed up Bitmap TONE code? - by DerVVulfman - 06-11-2023, 03:57 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
   Permanently modifying move speed Keeroh 5 9,600 05-24-2017, 05:47 AM
Last Post: DerVVulfman
   Meagan's Particles' speed Raou 6 9,246 04-01-2015, 03:43 PM
Last Post: Raou
   Custom Game_Event code lags too much! MechanicalPen 4 6,636 06-27-2013, 11:22 PM
Last Post: MechanicalPen
   Ruby, RGSS & General Code Discussion Kain Nobel 6 10,875 12-22-2012, 05:11 AM
Last Post: MechanicalPen
   Getting bitmap width and height of leading party member? PK8 5 8,548 08-27-2012, 11:41 AM
Last Post: Kain Nobel
   Pixelmovement and speed ark 2 5,654 05-31-2010, 05:51 PM
Last Post: ark
   VX Show Picture Event Command Code? PK8 2 6,361 02-27-2009, 11:30 PM
Last Post: PK8



Users browsing this thread: 3 Guest(s)