示例#1
0
文件: main.cpp 项目: hnney/Stanford
// Keyboard event handler:
static void keyboard(unsigned char key, int x, int y) {
  switch (key) {
    // quit
    case '+':
    case '=':
      if (mode == MODE_VIEW) {
        hdr_view_max /= 2.f;
        scale_hdr(hdr, hdr_view_max, image);
      }
      else if (mode == MODE_VP) {
        shutter_time *= powf(2.f, 1.f/3.f); // 1/3 stop
        virtual_photo(hdr, cr, shutter_time, image);
      }
      else if (mode == MODE_TONEMAP) {
        key_lum += .05f;
        tonemap(hdr, key_lum, image);
      }
      break;
    case '-':
    case '_':
      if (mode == MODE_VIEW) {
        hdr_view_max *= 2.f;
        scale_hdr(hdr, hdr_view_max, image);
      }
      else if (mode == MODE_VP) {
        shutter_time /= powf(2.f, 1.f/3.f); // 1/3 stop
        virtual_photo(hdr, cr, shutter_time, image);
      }
      else if (mode == MODE_TONEMAP) {
        key_lum -= .05f;
        tonemap(hdr, key_lum, image);
      }

      break;
    case 's':
    case 'S':
      if (mode == MODE_VIEW)
        image->Save("view.jpg");
      else if (mode == MODE_VP)
        image->Save("vp.jpg");
      else if (mode == MODE_TONEMAP)
        image->Save("tonemap.jpg");
      break;
    case char(27):
    case 'q':
    case 'Q':
      exit(0);
  }

  glutPostRedisplay();
}
示例#2
0
//---------------------------------------------------------------
// Purpose: 
//---------------------------------------------------------------
void CPostProcessor::ApplyPostProcessing( UINT sceneTex, UINT sceneDepthTex, UINT bufferTex, UINT destTex )
{
	glPushAttrib(GL_VIEWPORT_BIT);
	glBindFramebuffer(GL_FRAMEBUFFER, m_iFramebuffer);

	Assert(sceneTex != destTex && sceneDepthTex != destTex);

	int bloomLodStart = render_bloom_lod_start.GetInt();
	int bloomLodLevels = render_bloom_lod_levels.GetInt();

	//Bloom effect
	brightpass( sceneTex, m_bufTex2, m_LumTexs[m_LumTexIndex] );

	//Use destTex as temporary buffer
	for(int i = bloomLodStart; i < bloomLodStart+bloomLodLevels; i++)
		blur(true, m_bufTex2, bufferTex, i);
	for(int i = bloomLodStart; i < bloomLodStart+bloomLodLevels; i++)
		blur(false, bufferTex, m_bufTex2, i);

	//bloomComplete(sceneTex, bufferTex);

	calcExposure(sceneTex);
	tonemap(sceneTex, sceneDepthTex, m_bufTex2, m_LumTexs[m_LumTexIndex], destTex);

	//calcExposure(sceneTex);

	glPopAttrib();
}
示例#3
0
	void thread_run(DeviceTask *task)
	{
		if(task->type == DeviceTask::TONEMAP) {
			tonemap(*task, task->buffer, task->rgba);
		}
		else if(task->type == DeviceTask::PATH_TRACE) {
			RenderTile tile;
			
			/* keep rendering tiles until done */
			while(task->acquire_tile(this, tile)) {
				int start_sample = tile.start_sample;
				int end_sample = tile.start_sample + tile.num_samples;

				for(int sample = start_sample; sample < end_sample; sample++) {
					if (task->get_cancel()) {
						if(task->need_finish_queue == false)
							break;
					}

					path_trace(tile, sample);

					tile.sample = sample + 1;

					task->update_progress(tile);
				}

				task->release_tile(tile);
			}
		}
	}
示例#4
0
int main() {
	// 37°20′N 121°54′W
	float t = 2.0;
	int J = 122;
	
	float latitude, longitude;
		
	// san jose
	latitude = math::degreesToRadians<float>(34.55);
	longitude = math::degreesToRadians<float>(110.25f);
	
	float SM = 8.0/24*2*math::pi<float>();
	float L = longitude;

	int p = 0;
	for (int i = 1; i < 49; i++) {
		util::Image image(256, 256, util::Image::Color(0));
		std::stringstream ss;
		
		ss << "skylight-" << std::setw(3) << std::setfill('0') << p++ << ".bmp";
		
		float ts = (float)i / 4.0 + 5.0;
		
		matrix3x1 sunVector = simulation::Skylight::SunDirection(J, ts, latitude, longitude, SM);
				
		simulation::Skylight::compute(image, sunVector, 2.0f);
		
		tonemap(image);
	
		image.make32bit();
		image.write(ss.str().c_str(), 24);
	}

	return 0;
}
void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
{
  mxArray *im_m;
  const mwSize *dims;
  double *im;
  int nrbins, N, M, K, L;
  bool dolog;
    
  if (nrhs<2)
      mexErrMsgIdAndTxt("dtm_rgb:fewinput","Input should be an image and the number of output bins.");
  //associate inputs/outputs
  
  if (!mxIsDouble(prhs[0]))
      mexErrMsgIdAndTxt("dtm_rgb:notdoubleim","Input image should be double");
  
  im_m = plhs[0] = mxDuplicateArray(prhs[0]);
  
  
  K = (int)mxGetScalar(prhs[1]);
  
  
  //figure out dimensions
  dims = mxGetDimensions(prhs[0]);
  L = mxGetNumberOfDimensions(prhs[0]);
  if (L<3)
      mexErrMsgIdAndTxt("dtm_rgb:notrgbinput","Input should be rgb-image.");
  
  
  N = (int)dims[0];
  M = (int)dims[1];
  
      
  if (nrhs>2)
      dolog = (bool)mxGetScalar(prhs[2]);
  else
      dolog = true;
  
  if (nrhs>3)
      nrbins = (int)mxGetScalar(prhs[3]);
  else
      nrbins = -1;
  
  im = mxGetPr(im_m);
  

  tonemap(im,N,M,K,nrbins,dolog);
  

    

}
示例#6
0
/*!
  \details
  No detailed.
  */
void ToneMappingOperator::map(System& system,
                              const HdrImage& hdr_image,
                              LdrImage* ldr_image) const noexcept
{
  ZISC_ASSERT(ldr_image != nullptr, "The LDR image is null.");
  ZISC_ASSERT(hdr_image.widthResolution() == ldr_image->widthResolution(),
              "The image width is difference between HDR and LDR images.");
  ZISC_ASSERT(hdr_image.heightResolution() == ldr_image->heightResolution(),
              "The image height is difference between HDR and LDR images.");
  auto map_luminance = [this, &system, &hdr_image, ldr_image](const uint task_id)
  {
    // Set the calculation range
    const auto range = system.calcTaskRange(hdr_image.numOfPixels(), task_id);
    // Apply tonemap to each pixel
    for (uint index = range[0]; index < range[1]; ++index) {
      auto rgba32 = Rgba32{};
      if (0.0 < hdr_image[index].y()) {
        auto xyz = hdr_image[index];
        // Tone mapping
        {
          auto yxy = ColorConversion::toYxy(xyz);
          const Float l = tonemap(exposure() * yxy.Y());
          yxy.Y() = zisc::clamp(l, 0.0, 1.0);
          xyz = ColorConversion::toXyz(yxy);
        }
        // Convert XYZ to RGB
        {
          const auto to_rgb_matrix = getXyzToRgbMatrix(system.colorSpace());
          auto rgb = ColorConversion::toRgb(xyz, to_rgb_matrix);
          rgb.clampAll(0.0, 1.0);
          rgb.correctGamma(inverseGamma());
          rgba32 = ColorConversion::toIntRgb(rgb);
        }
      }
      ldr_image->get(index) = rgba32;
    }
  };

  {
    auto& threads = system.threadManager();
    auto& work_resource = system.globalMemoryManager();
    constexpr uint begin = 0;
    const uint end = threads.numOfThreads();
    auto result = threads.enqueueLoop(map_luminance, begin, end, &work_resource);
    result.wait();
  }
}
	void task_add(DeviceTask& maintask)
	{
		list<DeviceTask> tasks;

		/* arbitrary limit to work around apple ATI opencl issue */
		if(platform_name == "Apple")
			maintask.split_max_size(tasks, 76800);
		else
			tasks.push_back(maintask);

		DeviceTask task;

		foreach(DeviceTask& task, tasks) {
			if(task.type == DeviceTask::TONEMAP)
				tonemap(task);
			else if(task.type == DeviceTask::PATH_TRACE)
				path_trace(task);
		}
	}
示例#8
0
文件: main.cpp 项目: hnney/Stanford
int main(int argc, char** argv)
{
  //
  // Initialize GLUT.
  //
  glutInit(&argc, argv);
  glutInitDisplayMode( GLUT_DOUBLE | GLUT_RGBA | GLUT_DEPTH);
  glutInitWindowPosition(20, 20);
  glutInitWindowSize(
      WIN_WIDTH, WIN_HEIGHT);
  glutCreateWindow("CS148 Assignment 5");


  if (argc < 2) {
    usage();
  }

  if ( strcmp(argv[1], "-response") == 0) {
    if (argc != 4)
      usage();
    mode = MODE_RESPONSE;

    // Defaults
    float lambda = 50.f;
    int nsamples = 100;

    vector<Photo> photos;
    LoadHDRStack(argv[2], photos);
    cr.SolveForResponse(photos, lambda, nsamples);

    cr.Save(argv[3]);
    exit(0);
  }
  else if ( strcmp(argv[1], "-create") == 0) {
    if (argc != 5)
      usage();
    mode = MODE_CREATE;
    vector<Photo> photos;
    LoadHDRStack(argv[2], photos);
      
    cr.Load(argv[3]);
    hdr = recover_hdr(photos, cr);
    hdr->Save(argv[4]);
    exit(0);
  }
  else {
    hdr = new STHDRImage(argv[2]);
    if(hdr)
      image = new STImage(hdr->GetWidth(), hdr->GetHeight());
    else
      usage();

    if ( strcmp(argv[1], "-view") == 0) {
      if (argc != 3)
        usage();
      mode = MODE_VIEW;
      scale_hdr(hdr, hdr_view_max, image);
    }
    else if ( strcmp(argv[1], "-vp") == 0) {
      if (argc != 4)
        usage();
      mode = MODE_VP;
      cr.Load(argv[3]);
      virtual_photo(hdr, cr, shutter_time, image);
    }
    else if ( strcmp(argv[1], "-tonemap") == 0) {
      if (argc != 3)
        usage();
      mode = MODE_TONEMAP;
      tonemap(hdr, key_lum, image);
    }
    else {
      usage();
    }
  }

  glutReshapeWindow(image->GetWidth(), image->GetHeight());

  glutDisplayFunc(display);
  glutKeyboardFunc(keyboard);
  glutReshapeFunc(reshape);
  glutMainLoop();

  if(image) {
    delete image;
  }

  return 0;
}
示例#9
0
static int filter_frame(AVFilterLink *link, AVFrame *in)
{
    TonemapContext *s = link->dst->priv;
    AVFilterLink *outlink = link->dst->outputs[0];
    AVFrame *out;
    const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(link->format);
    const AVPixFmtDescriptor *odesc = av_pix_fmt_desc_get(outlink->format);
    int ret, x, y;
    double peak = s->peak;

    if (!desc || !odesc) {
        av_frame_free(&in);
        return AVERROR_BUG;
    }

    out = ff_get_video_buffer(outlink, outlink->w, outlink->h);
    if (!out) {
        av_frame_free(&in);
        return AVERROR(ENOMEM);
    }

    ret = av_frame_copy_props(out, in);
    if (ret < 0) {
        av_frame_free(&in);
        av_frame_free(&out);
        return ret;
    }

    /* input and output transfer will be linear */
    if (in->color_trc == AVCOL_TRC_UNSPECIFIED) {
        av_log(s, AV_LOG_WARNING, "Untagged transfer, assuming linear light\n");
        out->color_trc = AVCOL_TRC_LINEAR;
    } else if (in->color_trc != AVCOL_TRC_LINEAR)
        av_log(s, AV_LOG_WARNING, "Tonemapping works on linear light only\n");

    /* read peak from side data if not passed in */
    if (!peak) {
        peak = ff_determine_signal_peak(in);
        av_log(s, AV_LOG_DEBUG, "Computed signal peak: %f\n", peak);
    }

    /* load original color space even if pixel format is RGB to compute overbrights */
    s->coeffs = &luma_coefficients[in->colorspace];
    if (s->desat > 0 && (in->colorspace == AVCOL_SPC_UNSPECIFIED || !s->coeffs)) {
        if (in->colorspace == AVCOL_SPC_UNSPECIFIED)
            av_log(s, AV_LOG_WARNING, "Missing color space information, ");
        else if (!s->coeffs)
            av_log(s, AV_LOG_WARNING, "Unsupported color space '%s', ",
                   av_color_space_name(in->colorspace));
        av_log(s, AV_LOG_WARNING, "desaturation is disabled\n");
        s->desat = 0;
    }

    /* do the tone map */
    for (y = 0; y < out->height; y++)
        for (x = 0; x < out->width; x++)
            tonemap(s, out, in, desc, x, y, peak);

    /* copy/generate alpha if needed */
    if (desc->flags & AV_PIX_FMT_FLAG_ALPHA && odesc->flags & AV_PIX_FMT_FLAG_ALPHA) {
        av_image_copy_plane(out->data[3], out->linesize[3],
                            in->data[3], in->linesize[3],
                            out->linesize[3], outlink->h);
    } else if (odesc->flags & AV_PIX_FMT_FLAG_ALPHA) {
        for (y = 0; y < out->height; y++) {
            for (x = 0; x < out->width; x++) {
                AV_WN32(out->data[3] + x * odesc->comp[3].step + y * out->linesize[3],
                        av_float2int(1.0f));
            }
        }
    }

    av_frame_free(&in);

    ff_update_hdr_metadata(out, peak);

    return ff_filter_frame(outlink, out);
}