Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8023181
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T22:29:49+00:00 2026-06-04T22:29:49+00:00

So I have a function that converts an image to grayscale. It takes in

  • 0

So I have a function that converts an image to grayscale.
It takes in an url for the origonal image, and an output canvas to put the output onto.
The function runs very quick on most browsers however very slow on mobile browsers (~3-4s for a 700×700 image). For this reason I want to cache (on the client) the grayscale image data, then when a request for the image comes multiple times, I want to serve up the cached grayscale data and not have to recalculate it.

I have whipped up a test on jsfiddle. Here it is: http://jsfiddle.net/RCkDX/4/
In the test page I display the origonal image at the top, I output the canvas that is used to do the calculation at the bottom and the two canvas’ in the middle they should output the same as the bottom image (except with cached data).

At the moment I get a ‘Uncaught TypeError: Type error’, I think its because it doesnt seem to like the cache data, I have tried moving things around, trying different methods but have not had any luck.

It is important that I do not use dataurls to cache as the android mobile browser I am using will display a little blue question mark icon at the moment (not the correct data on the canvas), so any option without dataurls would work.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-04T22:29:50+00:00Added an answer on June 4, 2026 at 10:29 pm

    @jezternz, I think 'Uncaught TypeError: Type error' in your code occurs because readyCanvas function called from returnFunc each time (no difference: cache exist or not); and inside readyCanvas grayscaleCache[src] can return undefined if no cache. In my code example (jsfiddle.net/RCkDX/5) readyCanvas called from returnFunc only if grayscaleCache[src] is defined (cache is constructed and saved).
    From my code removed setTimeout. Main reason: for simplify example.

    If you need to build code with no blocking page (without freeze UI) you must provide more complex code for managing cache. For example:

    • grayscaleCache[src] is undefined that mean “no cache and cache is not under construction by any previous request” – you need to start caching procedure;
    • grayscaleCache[src] equals to null that mean “cache is under construction by previous request” – you dont need to start caching procedure, you must only wait (check with setTimeout) when cache is ready;
    • grayscaleCache[src] is not undefined and not null – “cache is ready” – use cache.
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a function that takes longitude and latitude and converts it to x
I have a small C# function that takes any generic SQLDataReader and converts it
I have this function called ProperCase that takes a string, then converts the first
I have a function that creates an image with the canvas object. The last
I have a function that converts a relative path (e.g. log\crash.txt) to the full
I have this function that converts all special chars to uppercase: function uc_latin1($str) {
I have a function that converts 60000 into 60k or 60100 into 60.1k But
I have an image file that is a grayscale 8 bit unsigned integer raw
I have a function that convert ticks to time_t format long ticks = DateTime.Now.Ticks;
I have function that has : ob_start(); //Include of some files $content = ob_get_contents();

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.