bool Renderer::TakeScreenshot(const char* directory_name) { // Fill our path string char filename[50]; time_t now = time(nullptr); strftime(filename, _countof(filename), "SS.%Y.%m.%d.%H.%M.%S.jpg", localtime(&now)); char delimeter[2] = { system::GetPathDelimeter(), '\0' }; size_t size = strlen(directory_name) + strlen(filename) + 2; // 1 is for delimeter, another 1 is for \0 char *full_filename = new char[size]; strcpy(full_filename, directory_name); strcat(full_filename, delimeter); strcat(full_filename, filename); system::CreateDirectory(directory_name); // create directory if it doesn't exist Image image; // allocate memory and read pixels u8 *data = image.Allocate(width_, height_, Image::Format::kRGB8); ReadPixels(width_, height_, data); if (!image.Save(full_filename)) { delete[] full_filename; return false; } delete[] full_filename; return true; }
static void dump_image(const GrGLInterface* gl, uint32_t screenWidth, uint32_t screenHeight, const char* filename) { // read back pixels uint32_t readback[screenWidth * screenHeight]; GR_GL_CALL(gl, ReadPixels(0, // x 0, // y screenWidth, // width screenHeight, // height GR_GL_RGBA, //format GR_GL_UNSIGNED_BYTE, //type readback)); // dump png SkBitmap bm; if (!bm.tryAllocPixels(SkImageInfo::MakeN32Premul(screenWidth, screenHeight))) { SkDebugf("couldn't allocate bitmap\n"); return; } bm.setPixels(readback); if (!SkImageEncoder::EncodeFile(filename, bm, SkImageEncoder::kPNG_Type, 100)) { SkDebugf("------ failed to encode %s\n", filename); remove(filename); // remove any partial file return; } }
// // Read() // void JLSInputStream::Read(void* pvoid, size_t cbyteAvailable) { ReadHeader(); JLS_ERROR error = CheckParameterCoherent(&_info); if (error != OK) throw JlsException(error); ReadPixels(pvoid, cbyteAvailable); }
bool ASceneCaptureToDiskCamera::SaveCaptureToDisk(const FString &FilePath) const { TArray<FColor> OutBMP; if (!ReadPixels(OutBMP)) { return false; } for (FColor &color : OutBMP) { color.A = 255; } const FIntPoint DestSize(GetImageSizeX(), GetImageSizeY()); FString ResultPath; FHighResScreenshotConfig &HighResScreenshotConfig = GetHighResScreenshotConfig(); return HighResScreenshotConfig.SaveImage(FilePath, OutBMP, DestSize, &ResultPath); }
bool ScreenShot(const char *filename) { SDL_Surface *surf = SDL_CreateRGBSurface(0, screensize.x(), screensize.y(), 24, 0x000000ff, 0x0000ff00, 0x00ff0000, 0xff000000); if (!surf) return false; auto pixels = ReadPixels(int2(0), screensize, false); SDL_LockSurface(surf); for (int i = 0; i < screensize.y(); i++) memcpy(((char *)surf->pixels) + surf->pitch * i, pixels + 3 * screensize.x() * (screensize.y() - i - 1), screensize.x() * 3); SDL_UnlockSurface(surf); delete[] pixels; bool ok = !SDL_SaveBMP(surf, filename); SDL_FreeSurface(surf); return ok; }
static void ApplyChannel (GPtr globals, ReadChannelDesc *source, PixelMemoryDesc *sDesc, ReadChannelDesc *mask, PixelMemoryDesc *mDesc, WriteChannelDesc *dest, ChannelReadPort destRead, PixelMemoryDesc *dDesc, PixelMemoryDesc *rDesc, size_t *done, size_t total) { VRect limit; int32 row, col, row2, col2; unsigned8 *s, *m, *d; unsigned8 *r = (unsigned8 *)rDesc->data; Boolean initRandom = (*r == kInitRandom); limit = source->bounds; TrimVRect (&limit, &dest->bounds); if (mask != NULL) TrimVRect (&limit, &mask->bounds); if (limit.right <= limit.left || limit.bottom <= limit.top) return; for (row = limit.top; row < limit.bottom; row += kBlockRows) for (col = limit.left; col < limit.right; col += kBlockCols) { VRect area; PSScaling scaling; VRect wrote; if (TestAbort ()) { gResult = userCanceledErr; return; } area.top = row; area.bottom = row + kBlockRows; area.left = col; area.right = col + kBlockCols; if (limit.bottom < area.bottom) area.bottom = limit.bottom; if (limit.right < area.right ) area.right = limit.right; scaling.sourceRect = area; scaling.destinationRect = area; gResult = ReadPixels (destRead, &scaling, &area, dDesc, &wrote); if (gResult != noErr) return; if (!EqualVRects (&area, &wrote)) { gResult = -1; return; } gResult = ReadPixels (source->port, &scaling, &area, sDesc, &wrote); if (gResult != noErr) return; if (!EqualVRects (&area, &wrote)) { gResult = -1; return; } if (mask != NULL) { gResult = ReadPixels (mask->port, &scaling, &area, mDesc, &wrote); if (gResult != noErr) return; if (!EqualVRects (&area, &wrote)) { gResult = -1; return; } } m = (unsigned8 *) mDesc->data; /* mask all set and ready to go */ /* heart of the routine. Compares source pixel and destination pixel and, if destination is smaller, replaces it with source */ s = (unsigned8 *) sDesc->data; d = (unsigned8 *) dDesc->data; r = (unsigned8 *) rDesc->data; for (row2 = kBlockRows; row2 > 0; --row2) for (col2 = kBlockCols; col2 > 0; --col2) { switch (gWhatArea) { case iSelectMin: if (mask != NULL && *m < *s ) *s = *m; if (*s > 127) *d = *s; else *d = 0; break; case iSelectMax: if (mask != NULL && *m < *s ) *s = *m; if (*s < 128) *d = 255 - *s; // if (*d < *s) *d = *s; else *d = 0; break; case iSelectRandom: if (initRandom) { if ((((unsigned16) rand ()) % 100) < gPercent) *r = kRandomOn; // flag as picked else *r = kRandomOff; // flag as off } if (*r == kRandomOn) *d = 255; else *d = 0; break; } ++s; ++d; ++r; if (mask != NULL) ++m; } gResult = WritePixels (dest->port, &area, dDesc); if (gResult != noErr) return; *done += (area.right - area.left) * (area.bottom - area.top); PIUpdateProgress ((int32)*done, (int32)total); } }
// // Read() // void JLSInputStream::Read(void* pvoid, LONG cbyteAvailable) { ReadHeader(); ReadPixels(pvoid, cbyteAvailable); }
void TextureViewGL::Update(nextar::RenderContext* rc, uint32 msg, ContextObject::ContextParamPtr params) { RenderContext_Base_GL* gl = static_cast<RenderContext_Base_GL*>(rc); if (msg & TextureBase::MSG_TEX_READ) { ReadPixels(gl, *const_cast<TextureBase::ReadPixelUpdateParams*>( reinterpret_cast<const TextureBase::ReadPixelUpdateParams*>(params))); return; } // todo Incorrect implementation if (msg & (TextureBase::MSG_TEX_CREATE|TextureBase::MSG_TEX_UPLOAD)) { const TextureBase::UpdateParams& textureParams = *reinterpret_cast<const TextureBase::UpdateParams*>(params); PixelFormat imageFormat = textureParams.textureFormat; if (textureParams.image) imageFormat = textureParams.image->GetFormat(); if (!IsCreated()) { pixelFormat = RenderContext_Base_GL::GetGlPixelFormat(imageFormat, textureParams.textureFormat); if (pixelFormat.internalFormat == GL_NONE) { Warn( "Currently image should be of compatible format with texture!"); return; } texture = gl->CreateTexture(); target = RenderContext_Base_GL::GetGlTextureType( textureParams.type); gl->ActivateTexture(target, texture); if (textureParams.textureFlags & TextureBase::PRE_ALLOCATE_STORAGE) { gl->AllocateTexture(target, (GLint) textureParams.desc.maxMipMapCount, pixelFormat.internalFormat, textureParams.desc.maxWidth, textureParams.desc.maxHeight, textureParams.desc.maxDepth); } } else gl->ActivateTexture(target, texture); if (textureParams.image && (msg & TextureBase::MSG_TEX_UPLOAD)) { Image& img = *textureParams.image; uint32 numMips = img.GetNumMipMaps(); uint32 numFaces = img.GetNumFaces(); NEX_ASSERT(numFaces == 1 || numFaces == 6); GLenum realTarget = target; if (target == GL_TEXTURE_CUBE_MAP || target == GL_TEXTURE_CUBE_MAP_ARRAY) realTarget = GL_TEXTURE_CUBE_MAP_POSITIVE_X; for (uint32 f = 0; f < numFaces; ++f) { for (uint32 i = 0; i < numMips; ++i) { PixelBox box = img.GetPixelBox(f, i); if (!box.IsSimpleArray()) { Warn("Pixel box has pixel padding. Cannot copy."); continue; } if (textureParams.textureFlags & TextureBase::PRE_ALLOCATE_STORAGE) gl->WriteTextureLevel(realTarget + f, (GLint) (textureParams.baseMipLevel + i), pixelFormat, box.GetWidth(), box.GetHeight(), box.GetDepth(), box.data, box.GetDataSize()); else gl->AllocateTextureLevel(realTarget + f, (GLint) (textureParams.baseMipLevel + i), pixelFormat, box.GetWidth(), box.GetHeight(), box.GetDepth(), box.data, box.GetDataSize()); } gl->SetMipLevels(realTarget + f, textureParams.baseMipLevel, textureParams.lowestMipLevel); } // update number of mip levels } } else if (msg & TextureBase::MSG_TEX_RESIZE) { if (IsCreated()) gl->DestroyTexture(texture); const TextureBase::ResizeParams& textureParams = *reinterpret_cast<const TextureBase::ResizeParams*>(params); texture = gl->CreateTexture(); gl->ActivateTexture(target, texture); gl->AllocateTexture(target, (GLint) textureParams.desc.maxMipMapCount, pixelFormat.internalFormat, textureParams.desc.maxWidth, textureParams.desc.maxHeight, textureParams.desc.maxDepth); } }
bool FileFormatInstance::Read( UInt32Image::sample* buffer, int startRow, int rowCount, int channel ) { return ReadPixels( handle, buffer, startRow, rowCount, channel, 32, false ); }
bool FileFormatInstance::Read( pcl::DImage::sample* buffer, int startRow, int rowCount, int channel ) { return ReadPixels( handle, buffer, startRow, rowCount, channel, 64, true ); }