ImageEx ImageEx::toColorSpace( ColorSpace to ) const{ Timer t( "ImageEx::toColorSpace" ); if( color_space.components() != to.components() || to.components() != 3 ) throw std::runtime_error( "Unsupported color space conversion" ); ImageEx out( *this ); out.color_space = to; //Upscale planes auto img_size = out.getSize(); for( auto& info : out.planes ) if( info.p.getSize() != img_size ) info.p = info.p.scale_cubic( img_size ); for( unsigned iy=0; iy<img_size.height(); iy++ ){ ColorRow row( out, iy ); for( unsigned ix=0; ix<img_size.width(); ix++ ) row.set( ix, color_space.convert( row[ix], to ) ); } return out; }
bool ColorZone::within(ColorSpace c) { float h0 = c.getH() - Hlo; h0 -= (float)floor(h0); float h1 = HHi - Hlo; if (h1 < 1) h1 -= (float)floor(h1); return c.valid() && YLo <= c.getY() && c.getY() <= YHi && SLo <= c.getS() && c.getS() <= SHi && h0 <= h1; }
void BMPYUVImage::updateBitmap() { ColorSpace c; for (int j = 0; j < height; ++j) for (int i = 0; i < width; ++i) { c.setYuv(yImg[i][j], uImg[i][j], vImg[i][j]); int r, g, b; switch (this->bitmapType) { case Color: r = c.getRb(); g = c.getGb(); b = c.getBb(); break; case Y: r = g = b = yImg[i][j]; break; case U: r = g = b = uImg[i][j]; break; case V: r = g = b = vImg[i][j]; break; case Red: r = g = b = c.getRb(); break; case Green: r = g = b = c.getGb(); break; case Blue: r = g = b = c.getBb(); break; case Hue: if (c.getS() >= 0.25f && c.getY() >= 0.2f) { ColorSpace h = ColorSpace(); h.setHsz(c.getH(), c.getS(), 0.875f); r = h.getRb(); g = h.getGb(); b = h.getBb(); } else r = g = b = 0; break; case Saturation: r = g = b = c.getSb(); break; case Value: r = g = b = c.getZb(); break; default: r = g = b = 0; break; } QRgb value = qRgb(r, g, b); bitmap.setPixel(i, j, value); } }
void BMPYUVImage::updateBitmap() { yuvImage.updateFromRawImage(); if (this->needToResizeBitmap()) { bitmap = QImage(yuvImage.getWidth(), yuvImage.getHeight(), QImage::Format_RGB32); } ColorSpace c; for (int j = 0; j < getHeight(); ++j) for (int i = 0; i < getWidth(); ++i) { c.setYuv(yuvImage.getY(i,j), yuvImage.getU(i,j), yuvImage.getV(i,j)); int r, g, b; switch (this->bitmapType) { case Color: r = c.getRb(); g = c.getGb(); b = c.getBb(); break; case Y: r = g = b = c.getY(); break; case U: r = g = b = c.getU(); break; case V: r = g = b = c.getV(); break; case Red: r = g = b = c.getRb(); break; case Green: r = g = b = c.getGb(); break; case Blue: r = g = b = c.getBb(); break; case Hue: if (c.getS() >= 0.25f && c.getY() >= 0.2f) { ColorSpace h = ColorSpace(); h.setHsz(c.getH(), c.getS(), 0.875f); r = h.getRb(); g = h.getGb(); b = h.getBb(); } else r = g = b = 0; break; case Saturation: r = g = b = c.getSb(); break; case Value: r = g = b = c.getZb(); break; default: r = g = b = 0; break; } QRgb value = qRgb(r, g, b); bitmap.setPixel(i, j, value); } }