void Image3unorm8::copyArray(const Color4* src, int w, int h) { resize(w, h); int N = w * h; Color3unorm8* dst = getCArray(); for (int i = 0; i < N; ++i) { dst[i] = Color3unorm8(src[i].rgb()); } }
void Image1uint8::copyArray(const Color1* src, int w, int h) { resize(w, h); int N = w * h; Color1uint8* dst = getCArray(); for (int i = 0; i < N; ++i) { dst[i] = Color1uint8(src[i]); } }
void Image1unorm8::copyArray(const Color4unorm8* ptr, int w, int h) { resize(w, h); int N = w * h; Color1unorm8* dst = getCArray(); for (int i = 0; i < N; ++i) { dst[i].value = (ptr[i].r + ptr[i].g + ptr[i].b) / 3; } }
void Image3unorm8::copyArray(const Color1* src, int w, int h) { resize(w, h); int N = w * h; Color3unorm8* dst = getCArray(); for (int i = 0; i < N; ++i) { dst[i].r = dst[i].g = dst[i].b = Color1unorm8(src[i]).value; } }
void Image4uint8::copyArray(const Color3* src, int w, int h) { resize(w, h); int N = w * h; Color4uint8* dst = getCArray(); for (int i = 0; i < N; ++i) { dst[i] = Color4uint8(Color4(src[i], 1.0f)); } }
void Image1uint8::copyArray(const Color4* src, int w, int h) { resize(w, h); int N = w * h; Color1uint8* dst = getCArray(); for (int i = 0; i < N; ++i) { dst[i] = Color1uint8(Color1(src[i].rgb().average())); } }
void Image1::copyArray(const Color3* src, int w, int h) { resize(w, h); int N = w * h; Color1* dst = getCArray(); for (int i = 0; i < N; ++i) { dst[i] = Color1(src[i].average()); } }
void Image1uint8::copyArray(const Color3uint8* src, int w, int h) { resize(w, h); int N = w * h; Color1uint8* dst = getCArray(); for (int i = 0; i < N; ++i) { dst[i].value = (src[i].r + src[i].g + src[i].b) / 3; } }
void Image3unorm8::copyArray(const Color4unorm8* ptr, int w, int h) { resize(w, h); int N = w * h; Color3unorm8* dst = getCArray(); for (int i = 0; i < N; ++i) { dst[i] = Color3unorm8(ptr[i].r, ptr[i].g, ptr[i].b); } }
void Image4uint8::copyArray(const Color1* src, int w, int h) { resize(w, h); int N = w * h; Color4uint8* dst = getCArray(); for (int i = 0; i < N; ++i) { dst[i].r = dst[i].g = dst[i].b = Color1uint8(src[i]).value; dst[i].a = 255; } }
void Image4::copyArray(const Color1* src, int w, int h) { resize(w, h); int N = w * h; Color4* dst = getCArray(); for (int i = 0; i < N; ++i) { dst[i].r = dst[i].g = dst[i].b = src[i].value; dst[i].a = 1.0f; } }
shared_ptr<class Image1unorm8> Image3unorm8::getChannel(int c) const { debugAssert(c >= 0 && c <= 2); shared_ptr<Image1unorm8> dst = Image1unorm8::createEmpty(width(), height(), wrapMode()); const Color3unorm8* srcArray = getCArray(); Color1unorm8* dstArray = dst->getCArray(); const int N = width() * height(); for (int i = 0; i < N; ++i) { dstArray[i] = Color1unorm8(srcArray[i][c]); } return dst; }
ReferenceCountedPointer<class Image1uint8> Image4uint8::getChannel(int c) const { debugAssert(c >= 0 && c <= 3); Image1uint8Ref dst = Image1uint8::createEmpty(width(), height(), wrapMode()); const Color4uint8* srcArray = getCArray(); Color1uint8* dstArray = dst->getCArray(); const int N = width() * height(); for (int i = 0; i < N; ++i) { dstArray[i] = Color1uint8(srcArray[i][c]); } return dst; }
/** Saves in any of the formats supported by G3D::GImage. */ void Image4uint8::save(const std::string& filename, GImage::Format fmt) { GImage im(width(), height(), 4); System::memcpy(im.byte(), getCArray(), width() * height() * 4); im.save(filename, fmt); }
/** Saves in any of the formats supported by G3D::GImage. */ void Image3unorm8::save(const String& filename) { shared_ptr<CPUPixelTransferBuffer> buffer = CPUPixelTransferBuffer::create(width(), height(), format(), MemoryManager::create()); System::memcpy(buffer->buffer(), getCArray(), (size_t)width() * height() * format()->cpuBitsPerPixel / 8); shared_ptr<Image> image = Image::fromPixelTransferBuffer(buffer); image->save(filename); }
void Image3uint8::copyArray(const Color4uint8* ptr, int w, int h) { resize(w, h); // Copy 3/4 bytes GImage::RGBAtoRGB((const uint8*)ptr, (uint8*)getCArray(), w * h); }
void Image4uint8::copyArray(const Color3uint8* ptr, int w, int h) { resize(w, h); GImage::RGBtoRGBA((const g3d_uint8*)ptr, (g3d_uint8*)getCArray(), w * h); }
void Image4uint8::copyArray(const Color4uint8* ptr, int w, int h) { resize(w, h); System::memcpy(getCArray(), ptr, w * h * 4); }
void Image3unorm8::copyArray(const Color3unorm8* ptr, int w, int h) { resize(w, h); System::memcpy(getCArray(), ptr, w * h * 3); }
void Image1::copyArray(const Color1* src, int w, int h) { resize(w, h); System::memcpy(getCArray(), src, w * h * sizeof(Color1)); }