C++ (Qt)BITMAPINFO* pBmi; /// Заполнение картинки (для Windows)void SubSahara::FillBitmapInfo(){ #ifdef Q_WS_WIN memset(pBmi,0,sizeof(BITMAPINFO) + sizeof(RGBQUAD) * 256); pBmi -> bmiHeader.biSize = sizeof(BITMAPINFOHEADER); pBmi -> bmiHeader.biWidth = spSize.x; pBmi -> bmiHeader.biHeight = spSize.y; pBmi -> bmiHeader.biPlanes = 1; pBmi -> bmiHeader.biBitCount = 8; pBmi -> bmiHeader.biCompression = BI_RGB; pBmi -> bmiHeader.biSizeImage = 0; pBmi -> bmiHeader.biClrUsed = pDisplay -> PaletteSize(); pBmi -> bmiHeader.biClrImportant = 0; for(int i = 0; i < pBmi->bmiHeader.biClrUsed; ++i) { pBmi -> bmiColors[i].rgbRed = pDisplay -> GetPaletteR(i); pBmi -> bmiColors[i].rgbGreen = pDisplay -> GetPaletteG(i); pBmi -> bmiColors[i].rgbBlue = pDisplay -> GetPaletteB(i); } #endif // Q_WS_WIN}
C++ (Qt) QImage image(3, 3, QImage::Format_RGB32); QRgb value; value = qRgb(189, 149, 39); // 0xffbd9527 image.setPixel(1, 1, value); value = qRgb(122, 163, 39); // 0xff7aa327 image.setPixel(0, 1, value); image.setPixel(1, 0, value); value = qRgb(237, 187, 51); // 0xffedba31 image.setPixel(2, 1, value);
C++ (Qt)const QSize size( spSize.x, spSize.y );QImage image( size, QImage::Format_ARGB32 );int i = 0;for ( int y = 0; y < size.height(); ++y ){ uchar * p = image.scanLine( y ); for ( int x = 0; x < size.width(); ++x ) { p[0] = 255; p[1] = pDisplay->GetPaletteR( i ); p[2] = pDisplay->GetPaletteG( i ); p[3] = pDisplay->GetPaletteB( i ); ++i; p += 4; }} pBmi = QPixmap::fromImage( image ).toWinHBITMAP();
C++ (Qt)pDisplay -> PaletteSize()
C++ (Qt)QImage* bitmap; bitmap = new QImage(spSize, QImage::Format_ARGB32);
C++ (Qt)int i = 0; for(int y=0; y<bitmap -> height(); ++y) { uchar *p = bitmap -> scanLine(y); for(int x=0; x<bitmap -> width(); ++x) { if(i >= pDisplay -> PaletteSize()) i %= pDisplay -> PaletteSize(); p[0] = 255; p[1] = pDisplay -> GetPaletteR(i); p[2] = pDisplay -> GetPaletteG(i); p[3] = pDisplay -> GetPaletteB(i); ++i; p += 4; } }
C++ (Qt)const QSize size( spSize.x, spSize.y );QImage image( size, QImage::Format_ARGB32 );for ( int y = 0; y < size.height(); ++y ){ uchar * p = image.scanLine( y ); for ( int x = 0; x < size.width(); ++x ) { // Получаем индекс из исходной картинки int i = indexFromSource( x, y ); p[0] = 255; p[1] = pDisplay->GetPaletteR( i ); p[2] = pDisplay->GetPaletteG( i ); p[3] = pDisplay->GetPaletteB( i ); p += 4; }}
C++ (Qt)// Класс набора необходимых Сахаровских классовclass SubSahara{protected: SPOINT spSize; SPOINT begSize; GPOINT geoCenter; TImageDrawer* pImageDrawer; MEM256Display* pDisplay; MEM256Device* pDevice; TImageManager* pImageManager; #ifdef Q_WS_WIN BITMAPINFO* pBmi; #endif // Q_WS_WIN bool bInit; ///< флажок инициализировано или нет QImage* bitmap; ///< картинка карты protected: void SaharaInit(int dx, int dy); void SaharaShutdown(); void FillBitmapInfo();public: SubSahara(int iWidth, int iHeight); ~SubSahara(); #ifdef Q_WS_WIN void Draw(HDC hdc); #endif // Q_WS_WIN void Draw(QPainter* painter); void SetBitmapSize(int Xbeg, int Ybeg, int Xend, int Yend); void SetBitmapSize(int dx, int dy);}; /// Констуктор: все указатели наобъекты инициируются нулевыми указателямиSubSahara::SubSahara(int iWidth, int iHeight): bInit(false), pImageDrawer(0), pDisplay(0), pImageManager(0), pDevice(0), bitmap(new QImage(iWidth, iHeight, QImage::Format_ARGB32)) #ifdef Q_WS_WIN , pBmi(static_cast<BITMAPINFO*> (HeapAlloc(GetProcessHeap(), 0, sizeof(BITMAPINFO) + sizeof(RGBQUAD) * 256))) #endif // Q_WS_WIN{ SaharaInit(iWidth, iHeight);} /// Инициализация указателей на объекты соответствующими классамиvoid SubSahara::SaharaInit(int dx, int dy){ spSize = SPOINT(dx, dy); ResourceLoader *pRL = new FResourceLoader(); pRL -> RegisterBMPResource(&gbPointSymbBitmap, "SYMBPOINT"); pDisplay = new MEM256Display(*pRL); pImageManager = new TImageManager(*pDisplay); pImageDrawer = new TImageDrawer(nIdDCW = pImageManager -> GetFreeId()); pImageDrawer -> SetBoundRect(SRECT(SPOINT(0, 0), spSize)); pImageManager -> RegisterImageStack(pImageDrawer); pDevice = new MEM256Device(*pDisplay, spSize); #ifdef Q_WS_WIN FillBitmapInfo(); #endif // Q_WS_WIN bInit = true;} /// Функция отрисовки карты (для Windows)#ifdef Q_WS_WIN void SubSahara::Draw(HDC hdc) { if(!bInit) return; for(int y = begSize.y; y<spSize.y; ++y) { SetDIBitsToDevice(hdc, ///< handle to DC begSize.x, ///< x-coord of destination upper-left corner y, ///< y-coord of destination upper-left corner spSize.x, ///< source rectangle width 1, ///< source rectangle height 0, ///< x-coord of source lower-left corner 0, ///< y-coord of source lower-left corner 0, ///< first scan line in array 1, ///< number of scan lines ///< array of DIB bits (CONST VOID *)(pDevice->GetSurface() + spSize.x * y), pBmi, ///< bitmap information DIB_RGB_COLORS); } }#endif // Q_WS_WIN /// Функция отрисовки картыvoid SubSahara::Draw(QPainter* painter){ painter -> drawImage(QPoint(0, 0), *bitmap); } /// Заполнение картинки (для Windows)void SubSahara::FillBitmapInfo(){ int i = 0, index = 0; bool flag = false; for(int y=0; y<bitmap -> height(); ++y) { uchar *p = bitmap -> scanLine(y); for(int x=0; x<bitmap -> width(); ++x) { if(i >= pDisplay -> PaletteSize()) { flag = true; i = index % pDisplay -> PaletteSize(); } if(flag) i = index % pDisplay -> PaletteSize(); p[0] = 255; p[1] = pDisplay -> GetPaletteR(i); p[2] = pDisplay -> GetPaletteG(i); p[3] = pDisplay -> GetPaletteB(i); ++i; ++index; p += 4; } }} /*/// Заполнение картинки (для Windows)void SubSahara::FillBitmapInfo(){#ifdef Q_WS_WIN memset(pBmi,0,sizeof(BITMAPINFO) + sizeof(RGBQUAD) * 256); pBmi -> bmiHeader.biSize = sizeof(BITMAPINFOHEADER); pBmi -> bmiHeader.biWidth = spSize.x; pBmi -> bmiHeader.biHeight = spSize.y; pBmi -> bmiHeader.biPlanes = 1; pBmi -> bmiHeader.biBitCount = 8; pBmi -> bmiHeader.biCompression = BI_RGB; pBmi -> bmiHeader.biSizeImage = 0; pBmi -> bmiHeader.biClrUsed = pDisplay -> PaletteSize(); pBmi -> bmiHeader.biClrImportant = 0; for(int i = 0; i < pBmi->bmiHeader.biClrUsed; ++i) { pBmi -> bmiColors[i].rgbRed = pDisplay -> GetPaletteR(i); pBmi -> bmiColors[i].rgbGreen = pDisplay -> GetPaletteG(i); pBmi -> bmiColors[i].rgbBlue = pDisplay -> GetPaletteB(i); } #endif // Q_WS_WIN}*/ /// Установка размера картинкиvoid SubSahara::SetBitmapSize(int dx, int dy){ if(spSize.x != dx || spSize.y != dy) { spSize = SPOINT(dx, dy); pImageDrawer -> SetBoundRect(SRECT(SPOINT(0, 0), spSize)); pDevice -> SetSize(spSize); if(bitmap != 0) { delete bitmap; bitmap = 0; } bitmap = new QImage(dx, dy, QImage::Format_ARGB32); FillBitmapInfo(); }} /// Установка размера картинкиvoid SubSahara::SetBitmapSize(int Xbeg, int Ybeg, int Xend, int Yend){ if(spSize.x != Xend || spSize.y != Yend) { spSize = SPOINT(Xend, Yend); begSize = SPOINT(Xbeg, Ybeg); pImageDrawer -> SetBoundRect(SRECT(SPOINT(0, 0), spSize)); pDevice -> SetSize(spSize); if(bitmap != 0) { delete bitmap; bitmap = 0; } bitmap = new QImage(Xend, Yend, QImage::Format_ARGB32); FillBitmapInfo(); }} /// Рисование карты и траектории Сахаройvoid TrackWidget::paintEvent(QPaintEvent* events){ QPainter painter(this); pSahara -> Refresh(); pSahara -> Draw(&painter); /*#ifdef Q_WS_WIN pSahara -> Draw(painter.paintEngine() -> getDC()); ///< oтрисовка карты #endif // Q_WS_WIN*/ if(measure_flag) { painter.setPen(QPen(Qt::black, 1, Qt::SolidLine)); ///< установка цвета линий QPoint p1(calc_distance -> beginPoint()), p2(calc_distance -> endPoint()); painter.drawLine(p1, p2); } painter.setPen(QPen(Qt::blue, 1, Qt::SolidLine)); ///< установка цвета траектории QWidget::paintEvent(events);}
C++ (Qt)const QSize size( spSize.x, spSize.y );QImage image( size, QImage::Format_ARGB32 );for ( int y = 0; y < size.height(); ++y ){ const uchar *scrImage = pDevice->GetSurface() + y * size.width(); uchar * p = image.scanLine( y ); for ( int x = 0; x < size.width(); ++x ) { // Получаем индекс из исходной картинки uchar i = *srcImage++; p[0] = 255; p[1] = pDisplay->GetPaletteR( i ); p[2] = pDisplay->GetPaletteG( i ); p[3] = pDisplay->GetPaletteB( i ); p += 4; }}
C++ (Qt)p[3] = 255; p[2] = pDisplay->GetPaletteR( i ); p[1] = pDisplay->GetPaletteG( i ); p[0] = pDisplay->GetPaletteB( i );