Discussing by memory alignment

zhaozj2021-02-16  52

The last time I saw the problem of memory on the memory of memory, I thought this now.

I don't need to discuss it, I have been solved by the CPU. At the time, I considered a way.

This problem is thought of when the problem is rotated.

The solution to the bitmap is applied to sharing with you:

Void crotatebitmapview :: onfileopen () {// Load bitmap CFiledialog DLG (True, "BMP", "*. BMP"); if (DLG.Domodal ()! = idok) return; cfile file; file.open dlg.GetFileName (), CFile :: modeRead); file.Read (& m_bfHeader, sizeof (BITMAPFILEHEADER)); int nSize = m_bfHeader.bfOffBits - sizeof (BITMAPFILEHEADER); m_pBMPInfo = (LPBITMAPINFOHEADER) new char [nSize]; file.Read (m_pBMPInfo, nSize); DWORD dwBitlen = m_bfHeader.bfSize - m_bfHeader.bfOffBits; m_lpBMPSrcBits = (LPBYTE) new char [dwBitlen]; file.Read (m_lpBMPSrcBits, dwBitlen); file.Close (); Invalidate (true);}

(! M_lpBMPSrcBits) // Rotate 90 degrees to the rightvoid CRotateBitmapView :: OnTodoRight () {if return; int i, j; int newWidth = 0; switch (m_pBMPInfo-> biBitCount) {case 1: return; case 4: m_BitsSize = (((M_PBmpinfo-> Biheight 1) / 2 3) / 4 * 4) * m_pbmpinfo-> biwidth; m_lpbmpdstbits = (lpbyte) new char [m_bitssize]; MEMSET (M_LPBMPDSTBITS, 0, M_BITSSIZE); BYTE TEMPBYTE; / / memset (& tempbyte, 0,1); tempbyte = 0; m_lpBMPDstBitsCopy = m_lpBMPDstBits; for (i = 0; i biWidth; i ) {// the last pixel row from the forward m_lpBMPSrcBitsCopy = m_lpBMPSrcBits ( m_pbmpinfo-> biwidth 1) / 2 - (i 2) / 2; m_lpbmpdstbits = m_lpbmpdstbitscopy i * ((m_pbmpinfo-> biheight 1) / 2 3) / 4 * 4); for (j = 0 J biheight; j ) {if (m_pbmpinfo-> biwidth% 2 == 0) {IF ((i 1)% 2 == 1) {tempbyte = * m_lpbmpsrcbitscopy; tempByte = Tempbyte << 4; TempByte = Tempbyte >> 4; IF ((J 1)% 2 == 1) Tempbyte = Tempbyte << 4; * m_lpbmpdstbits = (* m_lpbmpdstbits) | TempByte; M_LPBMPSRCBITSCOPY = ((m_pbmpin FO-> BiWidth 1) / 2 3) / 4 * 4;} else {tempbyte = * m_lpbmpsrcbitscopy; tempByte = Tempbyte >> 4; TempByte = Tempbyte << 4; IF (((J 1)% 2 == 0) TempByte = Tempbyte >> 4; * m_lpbmpdstbits = (* m_lpbmpdstbits) | TempByte; M_LpBmpsrcBitscopy = (M_PBmpinfo-> BiWidth 1) / 2 3) / 4 * 4;}} else {IF ((i 1)% 2 == 1) {TEMPBYTE = * m_lpbmpsrcbitscopy; tempbyte = tempbyte >> 4; Tempbyte =

Tempbyte << 4; IF ((J 1)% 2 == 0) Tempbyte = Tempbyte >> 4; * m_lpbmpdstbits = (* m_lpbmpdstbits) | TempByte; M_LPBMPSRCBITSCOPY = ((m_pbmpinfo-> biwidth 1) / 2 3) / 4 * 4;} else {tempbyte = * (m_lpbmpsrcbitscopy-1); tempByte = Tempbyte << 4; tempbyte = tempbyte >> 4; if ((j 1)% 2 == 1) Tempbyte = Tempbyte < <4; * m_lpbmpdstbits = (* m_lpbmpdstbits) | TempByte; M_LpBmpsrcBitscopy = (M_PBmpinfo-> BiWidth 1) / 2 3) / 4 * 4;}}} (((J 1)% 2 == 0) m_lpBMPDstBits ;}} break; case 8: m_BitsSize = ((m_pBMPInfo-> biHeight 3) / 4 * 4) * m_pBMPInfo-> biWidth; m_lpBMPDstBits = (LPBYTE) new char [m_BitsSize]; memset (m_lpBMPDstBits, 0, m_BitsSize) ; M_lpbmpdstbitscopy = m_lpbmpdstbits; for (i = 1; i <= m_pBmpinfo-> biwidth; i ) {// from the row last pixel forward m_lpbmpsrcbitscopy = m_lpbmpsrcbits m_pbmpinfo-> biwidth - i; for (j = 0; J biheight; j ) {memcpy (m_lpbmpdstbits , m_lpbmpsrcbitscopy, 1); m_lpbmpsrcbitscopy = (m_pbmpinfo -> BIWIDTH 3) / 4 * 4; // to the next line} m_lpbmpdstbits = (m_pbmpinfo-> biheight 3) / 4 * 4) - m_pbmpinfo-> biheight; // to the top} Break; Case 24 : m_BitsSize = (m_pBMPInfo-> biHeight * 24 31) / 32 * 4 * m_pBMPInfo-> biWidth; m_lpBMPDstBits = (LPBYTE) new char [m_BitsSize]; memset (m_lpBMPDstBits, 0, m_BitsSize); m_lpBMPDstBitsCopy = m_lpBMPDstBits; for (i = 1; i <= m_pbmpinfo-> biwidth; i ) {// From the row last pixel forward m_lpbmpsrcbitscopy = m_lpbmpsrcbits

m_pBMPInfo-> biWidth * 3 - i * 3; for (j = 0; j biHeight; j ) {memcpy (m_lpBMPDstBits, m_lpBMPSrcBitsCopy, 3); m_lpBMPDstBits = 3; // next pixel m_lpBMPSrcBitsCopy = ( M_PBmpinfo-> BiWidth * 24 31) / 32 * 4; // Under the old picture} m_lpbmpdstbits = m_lpbmpdstbitscopy ((M_PBmpinfo-> Biheight * 24 31) / 32) * 4) * i; // New the next line of FIG} break; case 32: break;} if (m_lpBMPSrcBits = NULL!) {delete m_lpBMPSrcBits; m_lpBMPSrcBits = NULL;} m_lpBMPSrcBits = m_lpBMPDstBitsCopy; newWidth = m_pBMPInfo-> biHeight; m_pBMPInfo-> biHeight = m_pBMPInfo-> biWidth; M_PBmpinfo-> BiWidth = newwidth; invalidate (true);} void crotatebitmapview :: overdraw (cdc * pdc) {crotatebitmapdoc * pdoc = getDocument (); assert_valid (pdoc); ////

if (m_lpBMPSrcBits! = NULL) {StretchDIBits (pDC-> GetSafeHdc (), 50,50, m_pBMPInfo-> biWidth, m_pBMPInfo-> biHeight, 0, 0, m_pBMPInfo-> biWidth, m_pBMPInfo-> biHeight, m_lpBMPSrcBits, (LPBITMAPINFO) M_PBmpinfo, Dib_RGB_COLORS, SRCCOPY);}}

My last word is: http://www.9cbs.net/develop/read_article.asp? Id = 24769

If you have any opinions, you can also discuss with me.

My mailbox is: sunqing_nt@hotmail.com (is also my MSN)

转载请注明原文地址:https://www.9cbs.com/read-22729.html

New Post(0)