void apply_gamma( float gamma, PixelIter start, PixelIter end) const { for( PixelIter it( start); it != end; ++it) { boost::gil::get_color( *it, boost::gil::red_t()) = apply_gamma( boost::gil::get_color( *it, boost::gil::red_t()), gamma); boost::gil::get_color( *it, boost::gil::green_t()) = apply_gamma( boost::gil::get_color( *it, boost::gil::green_t()), gamma); boost::gil::get_color( *it, boost::gil::blue_t()) = apply_gamma( boost::gil::get_color( *it, boost::gil::blue_t()), gamma); } }
static void DrawAndFrame(SkCanvas* canvas, const SkBitmap& orig, SkScalar x, SkScalar y) { SkBitmap bm; orig.copyTo(&bm); apply_gamma(bm); canvas->drawBitmap(bm, x, y, nullptr); SkPaint paint; paint.setStyle(SkPaint::kStroke_Style); paint.setColor(0xFFFFCCCC); canvas->drawRect(SkRect::MakeIWH(bm.width(), bm.height()).makeOffset(x, y).makeOutset(0.5f, 0.5f), paint); }
void png_writer_t::do_write_image( const boost::filesystem::path& p, const image::const_image_view_t& view, const adobe::dictionary_t& params) const { int channels = adobe::get_value( params, adobe::name_t( "channels")).cast<int>(); std::auto_ptr<OpenImageIO::ImageOutput> out( OpenImageIO::ImageOutput::create( p.external_file_string())); if( !out.get()) throw std::runtime_error( "Write PNG: Can't open output file"); if( channels) channels = 3; else channels = 4; OpenImageIO::ImageSpec spec( view.width(), view.height(), channels, TypeDesc::UINT8); spec.quant_dither = 0.0f; if( !out->open( p.external_file_string(), spec)) throw( std::runtime_error( "Can't open output file")); std::vector<image::pixel_t> scanline( view.width()); for( int y = 0; y < view.height(); ++y) { std::copy( view.row_begin( y), view.row_end( y), scanline.begin()); apply_gamma( 1.0f / 2.2f, scanline.begin(), scanline.end()); clamp( scanline.begin(), scanline.end()); if( !out->write_scanline( y, 0, TypeDesc::FLOAT, (void *) &( *scanline.begin()), sizeof( image::pixel_t))) throw( std::runtime_error( "Write image: Can't write pixels")); } if( !out->close()) throw std::runtime_error( "Write image: Can't close file"); }
void CL_AnimDump (void) { byte *buffer; char checkname[MAX_OSPATH]; int c, temp,o; unsigned int i; FILE *f; // create the scrnshots directory if it doesn't exist Com_sprintf (checkname, sizeof(checkname), "%s/animdump", ri.FS_Gamedir()); Sys_Mkdir (checkname); // // find a file name to save it to // for (i = cl_anim_count; i <= 99999999; i++) { Com_sprintf(checkname, sizeof(checkname), "%s/animdump/anim%5i.tga", ri.FS_Gamedir(), i); for (o = 0; o < strlen(checkname); o++) if (checkname[o] == ' ') checkname[o] = '0'; f = fopen (checkname, "rb"); if (!f) break; // file doesn't exist fclose(f); } if (i == 100000000) { ri.Cvar_Set("cl_animdump", "0"); ri.Con_Printf(PRINT_ALL, "CL_AnimDump: Max frames exported.\n"); return; } cl_anim_count = i; buffer = malloc(vid.width*vid.height*3 + 18); memset (buffer, 0, 18); buffer[2] = 2; // uncompressed type buffer[12] = vid.width&255; buffer[13] = vid.width>>8; buffer[14] = vid.height&255; buffer[15] = vid.height>>8; buffer[16] = 24; // pixel size qgl.PixelStorei(GL_PACK_ALIGNMENT, 1); qgl.ReadPixels(0, 0, vid.width, vid.height, GL_RGB, GL_UNSIGNED_BYTE, buffer + 18); apply_gamma(buffer + 18, vid.width, vid.height); // jitgamma -- apply video gammaramp to screenshot // swap rgb to bgr c = 18 + vid.width * vid.height * 3; for (i=18 ; i<c ; i+=3) { temp = buffer[i]; buffer[i] = buffer[i+2]; buffer[i+2] = temp; } f = fopen (checkname, "wb"); fwrite (buffer, 1, c, f); fclose (f); free (buffer); }