c++ - optimization issue with splitting an image into channels -

here code, "algorithm" trying take bayer image, or rgb image, , separate channel g, luma (or grayscale) different channels of color,
an example bayer pattern

void utilities::separatechannels(int* channelr, int* channelg, int* channelb, double*& gr, double*& r, double*& b, double*& gb,int _width, int _height, int _colororder) { //swith case color order int counter_r = 0; int counter_gr = 0; int counter_gb = 0; int counter_b = 0; switch (_colororder) { //grbg case 0: (int j = 0; j < _width; j++) { (int = 0; < _height; i++) { if (i % 2 == 0 && j % 2 == 0) { gr[counter_gr] = channelg[i*_width+ j]; counter_gr++; } else if (i % 2 == 0 && j % 2 == 1) { r[counter_r] = channelg[i*_width+ j]; counter_r++; } else if (i % 2 == 1 && j % 2 == 0) { b[counter_b] =channelg[i*_width+ j]; counter_b++; } else if (i % 2 == 1 && j % 2 == 1) { gb[counter_gb] = channelg[i*_width+ j]; counter_gb++; } } } i ran profiler on 70 images, attached results. can suggest way optimize code?
swap loops, first iterate on height. can calculate * _width before second loop , calculate 1 time instead of _width times.
Comments
Post a Comment