06-11-2023, 03:57 AM
(This post was last modified: 06-11-2023, 04:00 AM by DerVVulfman.)
(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).