void note::quantizeLength( const int _q_grid ) { setLength( quantized( length(), _q_grid ) ); if( length() == 0 ) { setLength( _q_grid ); } }
static GBL::Frame_t quantizedBitExpansion(const GBL::Frame_t& frame, const uint8_t nbOfClasses) { assert(nbOfClasses > 0); assert(nbOfClasses <= GBL::NB_BITS_IN_A_BYTE * sizeof(valueType)); GBL::Frame_t quantized(frame.rows, frame.cols, frame.type()); const uint32_t interval = (std::numeric_limits<valueType>::max() - std::numeric_limits<valueType>::min() + 1) / nbOfClasses; for(uint16_t row = 0; row < frame.rows; ++row) { for(uint16_t col = 0; col < frame.cols; ++col) { uint8_t intervalIndex = 0; uint32_t intervalMaxValue = std::numeric_limits<valueType>::min() + interval; while(frame.at<valueType>(row, col) >= intervalMaxValue) { ++intervalIndex; intervalMaxValue += interval; } quantized.at<valueType>(row, col) = 0x01 << intervalIndex; } } return quantized; }
void note::quantizePos( const int _q_grid ) { setPos( quantized( pos(), _q_grid ) ); }
SaveResult write_bmp(const FilePath& filePath, const Bitmap& bmp, BitmapQuality quality) { BinaryWriter out(filePath); if (!out.good()){ return SaveResult::SaveFailed(error_open_file_write(filePath)); } const auto bitsPerPixel = bits_per_pixel(quality); const IntSize size(bmp.GetSize()); const int rowStride = bmp_row_stride(bitsPerPixel, size.w); switch(quality){ // Note: No default, to ensure warning if unhandled enum value case BitmapQuality::COLOR_8BIT: { const auto pixelData = quantized(bmp, Dithering::ON); PaletteColors paletteColors(pixelData.palette.size()); write_struct(out, create_bitmap_file_header(paletteColors, rowStride, size.h)); write_struct(out, create_bitmap_info_header_8bipp(bmp.GetSize(), default_DPI(), PaletteColors(pixelData.palette.size()), false)); write_8bipp_BI_RGB(out, pixelData); return SaveResult::SaveSuccessful(); } case BitmapQuality::GRAY_8BIT: { MappedColors pixelData(desaturate_AlphaMap(bmp), grayscale_color_table()); PaletteColors paletteColors(pixelData.palette.size()); write_struct(out, create_bitmap_file_header(paletteColors, rowStride, size.h)); write_struct(out, create_bitmap_info_header_8bipp(bmp.GetSize(), default_DPI(), PaletteColors(pixelData.palette.size()), false)); write_8bipp_BI_RGB(out, pixelData); return SaveResult::SaveSuccessful(); } case BitmapQuality::COLOR_24BIT: { write_struct(out, create_bitmap_file_header(PaletteColors(0), rowStride, size.h)); write_struct(out, create_bitmap_info_header_24bipp(bmp.GetSize(), default_DPI(), false)); write_24bipp_BI_RGB(out, bmp); return SaveResult::SaveSuccessful(); } } assert(false); return SaveResult::SaveFailed(utf8_string("Internal error in save_bitmap")); }