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 6191203
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T02:43:21+00:00 2026-05-24T02:43:21+00:00

i’ve an app that places a fisheye distortion on a bitmap. I’ve been given

  • 0

i’ve an app that places a fisheye distortion on a bitmap. I’ve been given help to loop through the bitmap concurrently, assigning a thread to each core of the phones processor(s). this should make the image processing run faster. I’m getting a NPE, i don’t think the PartialProcessing.call() method is returning a partialResult. has anyone any ideas? thanks

public class MultiProcessorFilter {



    private static final String TAG = "mpf";




    public Bitmap barrel (Bitmap input, float k){


          int []arr = new int[input.getWidth()*input.getHeight()];
          // replace the j, i for loops:
          int jMax = input.getHeight();
          int jMid = jMax / 2;
          int iMax = input.getWidth();
          int iMid = iMax / 2;

          ExecutorService threadPool = Executors.newFixedThreadPool(2);

          FutureTask<PartialResult> task1 = (FutureTask<PartialResult>) threadPool.submit(new PartialProcessing(0, jMid - 1, input, k, iMid, iMax)); 
          FutureTask<PartialResult> task2 = (FutureTask<PartialResult>) threadPool.submit(new PartialProcessing(jMid, jMax - 1,input, k, iMid, iMax)); 
          Log.e(TAG, "*********** about to call task1.get()");
          try{
          PartialResult result1 = task1.get();// blocks until the thread returns the result
          Log.e(TAG, "*********** just called task1.get()");
          result1.fill(arr);
          Log.e(TAG, "*********** result1 arr length = " + arr.length);
          PartialResult result2 = task2.get(); // blocks until the thread returns the result
          result2.fill(arr);

          }catch(Exception e){
              e.printStackTrace();
          }
          Bitmap dst2 = Bitmap.createBitmap(arr,input.getWidth(),input.getHeight(),input.getConfig());
        return dst2;


        }




    public class PartialResult {
           int startP;
           int endP;
           int[] storedValues;

           public PartialResult(int startp, int endp){

               this.startP = startp;
               this.endP = endp;

           }

           public void addValue(int p, int result) {
                 storedValues[p] = result;
           }

           public void fill(int[] arr) {
              for (int p = startP; p < endP; p++)
                 arr[p] = storedValues[p];
              }
           }




    public class PartialProcessing implements Callable<PartialResult> {
        int startJ;
        int endJ;

       // ... other members needed for the computation such as
        private int[] scalar;
        private float xscale;
        private float yscale;
        private float xshift;
        private float yshift;
        private float thresh = 1;
        private int [] s1;
        private int [] s2;
        private int [] s3;
        private int [] s4;
        private int [] s;
        private Bitmap input;
        private float k;
        private int startI;
        private int endI;


        public PartialProcessing(int startj, int endj, Bitmap input, float k, int starti, int endi) {

            this.startJ = startj;
            this.endJ = endj;
            this.input = input;
            this.k = k;
            this.startI = starti;
            this.endI = endi;

        }

        int [] getARGB(Bitmap buf,int x, int y){

            int rgb = buf.getPixel(y, x); // Returns by default ARGB.
            // int [] scalar = new int[4];
           //  scalar[0] = (rgb >>> 24) & 0xFF;
             scalar[1] = (rgb >>> 16) & 0xFF;
             scalar[2] = (rgb >>> 8) & 0xFF;
             scalar[3] = (rgb >>> 0) & 0xFF;
             return scalar;

        }

        //... add other methods needed for the computation that where in class Filters

        float getRadialX(float x,float y,float cx,float cy,float k){

            x = (x*xscale+xshift);
            y = (y*yscale+yshift);
            float res = x+((x-cx)*k*((x-cx)*(x-cx)+(y-cy)*(y-cy)));
            return res;
          }

          float getRadialY(float x,float y,float cx,float cy,float k){

            x = (x*xscale+xshift);
            y = (y*yscale+yshift);
            float res = y+((y-cy)*k*((x-cx)*(x-cx)+(y-cy)*(y-cy)));
            return res;
          }



          float calc_shift(float x1,float x2,float cx,float k){

            float x3 = (float)(x1+(x2-x1)*0.5);
            float res1 = x1+((x1-cx)*k*((x1-cx)*(x1-cx)));
            float res3 = x3+((x3-cx)*k*((x3-cx)*(x3-cx)));

            if(res1>-thresh && res1 < thresh)
              return x1;
            if(res3<0){
              return calc_shift(x3,x2,cx,k);
            }
            else{
              return calc_shift(x1,x3,cx,k);
            }
          }


          void sampleImage(Bitmap arr, float idx0, float idx1)
          {

             // s = new int [4];
            if(idx0<0 || idx1<0 || idx0>(arr.getHeight()-1) || idx1>(arr.getWidth()-1)){
              s[0]=0;
              s[1]=0;
              s[2]=0;
              s[3]=0;
              return;
            }

            float idx0_fl=(float) Math.floor(idx0);
            float idx0_cl=(float) Math.ceil(idx0);
            float idx1_fl=(float) Math.floor(idx1);
            float idx1_cl=(float) Math.ceil(idx1);



             s1 = getARGB(arr,(int)idx0_fl,(int)idx1_fl);
             s2 = getARGB(arr,(int)idx0_fl,(int)idx1_cl);
             s3 = getARGB(arr,(int)idx0_cl,(int)idx1_cl);
             s4 = getARGB(arr,(int)idx0_cl,(int)idx1_fl);

            float x = idx0 - idx0_fl;
            float y = idx1 - idx1_fl;

           // s[0]= (int) (s1[0]*(1-x)*(1-y) + s2[0]*(1-x)*y + s3[0]*x*y + s4[0]*x*(1-y));
            s[1]= (int) (s1[1]*(1-x)*(1-y) + s2[1]*(1-x)*y + s3[1]*x*y + s4[1]*x*(1-y));
            s[2]= (int) (s1[2]*(1-x)*(1-y) + s2[2]*(1-x)*y + s3[2]*x*y + s4[2]*x*(1-y));
            s[3]= (int) (s1[3]*(1-x)*(1-y) + s2[3]*(1-x)*y + s3[3]*x*y + s4[3]*x*(1-y));


          }


        // this will be called on some new thread
        @Override public PartialResult call() {
            PartialResult partialResult = new PartialResult(startJ, endJ);

            float centerX=input.getWidth()/2; //center of distortion
            float centerY=input.getHeight()/2;



            int width = input.getWidth(); //image bounds
            int height = input.getHeight();



              xshift = calc_shift(0,centerX-1,centerX,k);

              float newcenterX = width-centerX;
              float xshift_2 = calc_shift(0,newcenterX-1,newcenterX,k);

              yshift = calc_shift(0,centerY-1,centerY,k);

              float newcenterY = height-centerY;
              float yshift_2 = calc_shift(0,newcenterY-1,newcenterY,k);

              xscale = (width-xshift-xshift_2)/width;

              yscale = (height-yshift-yshift_2)/height;


            int p = startI; // not 0! at the start since we don't start at j = 0
            int origPixel = 0;
            int color = 0;
            for (int j = startJ; j <  endJ; j++){
                for (int i = startI; i < endI; i++, p++){
                    //... copy the rest of the code


                     origPixel = input.getPixel(i,j);

            float x = getRadialX((float)j,(float)i,centerX,centerY,k);


            float y = getRadialY((float)j,(float)i,centerX,centerY,k);

            sampleImage(input,x,y);

             color = ((s[1]&0x0ff)<<16)|((s[2]&0x0ff)<<8)|(s[3]&0x0ff);

             if(((i-centerX)*(i-centerX) + (j-centerY)*(j-centerY)) <= 5500){

                //arr[p]=color;
                 partialResult.addValue(p, color);

            }else{

                //arr[p]=origPixel;
                partialResult.addValue(p, origPixel);



            }

                }






                   // partialResult.addValue(p, color);
        }
            return partialResult;
    }


}

}//end of MultiProcesorFilter

.

07-25 18:29:29.263: WARN/System.err(2289): java.util.concurrent.ExecutionException: java.lang.NullPointerException
07-25 18:29:29.263: WARN/System.err(2289):     at java.util.concurrent.FutureTask$Sync.innerGet(FutureTask.java:223)
07-25 18:29:29.263: WARN/System.err(2289):     at java.util.concurrent.FutureTask.get(FutureTask.java:82)
07-25 18:29:29.268: WARN/System.err(2289):     at com.tecmark.MultiProcessorFilter.barrel(MultiProcessorFilter.java:39)
07-25 18:29:29.268: WARN/System.err(2289):     at com.tecmark.TouchView$2.run(TouchView.java:147)
07-25 18:29:29.268: WARN/System.err(2289):     at java.lang.Thread.run(Thread.java:1096)
07-25 18:29:29.268: WARN/System.err(2289): Caused by: java.lang.NullPointerException
07-25 18:29:29.268: WARN/System.err(2289):     at com.tecmark.MultiProcessorFilter$PartialProcessing.sampleImage(MultiProcessorFilter.java:170)
07-25 18:29:29.273: WARN/System.err(2289):     at com.tecmark.MultiProcessorFilter$PartialProcessing.call(MultiProcessorFilter.java:245)
07-25 18:29:29.273: WARN/System.err(2289):     at com.tecmark.MultiProcessorFilter$PartialProcessing.call(MultiProcessorFilter.java:1)
07-25 18:29:29.273: WARN/System.err(2289):     at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:305)
07-25 18:29:29.273: WARN/System.err(2289):     at java.util.concurrent.FutureTask.run(FutureTask.java:137)
07-25 18:29:29.278: WARN/System.err(2289):     at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1068)
07-25 18:29:29.278: WARN/System.err(2289):     at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:561)
07-25 18:29:29.278: WARN/System.err(2289):     ... 1 more

[update]

07-25 22:41:41.121: WARN/System.err(2212): Caused by: java.lang.NullPointerException
07-25 22:41:41.126: WARN/System.err(2212):     at com.tecmark.MultiProcessorFilter$PartialResult.addValue(MultiProcessorFilter.java:70)
07-25 22:41:41.126: WARN/System.err(2212):     at com.tecmark.MultiProcessorFilter$PartialProcessing.call(MultiProcessorFilter.java:262)
07-25 22:41:41.126: WARN/System.err(2212):     at com.tecmark.MultiProcessorFilter$PartialProcessing.call(MultiProcessorFilter.java:1)
07-25 22:41:41.126: WARN/System.err(2212):     at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:305)
07-25 22:41:41.131: WARN/System.err(2212):     at java.util.concurrent.FutureTask.run(FutureTask.java:137)
07-25 22:41:41.131: WARN/System.err(2212):     at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1068)
07-25 22:41:41.131: WARN/System.err(2212):     at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:561)
07-25 22:41:41.131: WARN/System.err(2212):     ... 1 more
  • 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-05-24T02:43:22+00:00Added an answer on May 24, 2026 at 2:43 am

    in sampleImage method,

    // s = new int [4];
    

    initialization of array s is commented out and I didn’t notice it being initialized anywhere else

    if s is indeed not initialized then

    s[0]=0; // just curious isn't this line 170 in MultiProcessorFilter.java?
    

    would throw NPE

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I am trying to loop through a bunch of documents I have to put
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have a jquery bug and I've been looking for hours now, I can't
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I've got a string that has curly quotes in it. I'd like to replace
I have a French site that I want to parse, but am running into
I am doing a simple coin flipping experiment for class that involves flipping a
We're building an app, our first using Rails 3, and we're having to build

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.