New answers tagged

1

Fight the urge to squeeze multiple "things" into one line. Your script will be easier to read and maintain with all declarations and constructs occupying their own rightful place. Spend the extra lines, you'll be happy you did a year from now. Use curly braces to encapsulate language constructs (e.g. if-else and foreach, etc.), this combined with ...


3

The way I see it your requirements can be summarized as: Have a central repository of images. Load Images from a some data source. Save Persist Images. Give a cell its appropriate image based on an identifier. The main issue I see is that the cells are tightly coupled to the ImageCache object, it might be better to have some sort of ViewModel or controller ...


0

Oh my you are right that is rather slow. I see that the accepted answer is a significant improvement however it can be done even faster Flat array The pixel buffer is a flat array of bytes, you waste a lot of cycles converting 2D coordinates {x,y} to the flat index. It is quicker to convert the flat index to 2D for each of the four points you find. You ...


3

In your code you're calling GetImageData for each pixel adding a lot of call that are not necessary, you can do this by calling it once for the entire canvas and getting the data from the array. GetImageData returns a 1 dim array with RGBA for each pixel like : [R(pixel1),G(Pixel1),B(Pixel1),A(Pixel1),R(pixel2),G(Pixel2),...etc] this means that you can ...


1

General feedback There are a few ways that some of the loops can be simplified (see below). These may or may not improve the high CPU issue. The code makes some repeated calls to functions with the same values in close proximity (e.g. calling th() with each value of rgb twice in rgbToHex()). Storing the returned values and re-using the stored values would ...


Top 50 recent answers are included