C / C++ SHIFT / OFFSET / MOVE a Bitmap to the LEFT or RIGHT?

C / C++ SHIFT / OFFSET / MOVE a Bitmap to the LEFT or RIGHT?

Content Index :

C / C++ SHIFT / OFFSET / MOVE a Bitmap to the LEFT or RIGHT?
Tag : cpp , By : Der Ketzer
Date : November 25 2020, 07:06 PM

should help you out You didn't explain your goal very well, but I presume you want the "wrap-around" to be on a per-line basis. So, the n pixels at the left of each line should end up flowing to the right of the line instead.
Just shifting the bytes around the whole image, you will instead end up with those bytes on the previous line, because the bytes are in a 1D sequence and you didn't build in any logic to pay heed to the notional "width" of your image.
#include <iostream>

int main()
    // Some constants
    const size_t width = 6;
    const size_t height = 4;
    const size_t bitmapBytes = width*height;

    // Actual data
    char oldBitmapBytes[bitmapBytes] =
        '1', '2', '3', '4', '5', '6',
        'a', 'b', 'c', 'd', 'e', 'f',
        '.', ',', '/', '~', '#', '$',
        '!', '-', '!', '+', '!', '?'

    char newBitmapBytes[bitmapBytes];

    // Variables
    const size_t x_offset = 2;

    // Some utilities
    auto convertCoordsToIndex = [&](const size_t x, const size_t y)
        return y*width + x;

    auto printBitmap = [&](const char* bitmapBytes)
        for (size_t row = 0; row < height; row++)
            for (size_t col = 0; col < width; col++)
                std::cout << bitmapBytes[convertCoordsToIndex(col, row)];
            std::cout << '\n';

    // Display original bitmap

    // Shift by x_offset

    for (size_t row = 0; row < height; row++)
       for (size_t col = 0; col < width; col++)
          const size_t adjustedCol = (col + x_offset) % width;
          const size_t oldIndex = convertCoordsToIndex(col, row);
          const size_t newIndex = convertCoordsToIndex(adjustedCol, row);

          newBitmapBytes[newIndex] = oldBitmapBytes[oldIndex];

    // Display shifted bitmap
    std::cout << '\n';

// Output:
//   123456
//   abcdef
//   .,/~#$
//   !-!+!?
//   561234
//   efabcd
//   #$.,/~
//   !?!-!+

No Comments Right Now !

Boards Message :
You Must Login Or Sign Up to Add Your Comments .

Share : facebook icon twitter icon

Move Android bitmap/canvas away from the top left

Tag : android , By : Bobblegate
Date : March 29 2020, 07:55 AM
hope this fix your issue The way I resolved it was by adding the layout_marginLeft and layout_marginTop to my custom view in the xml layout.

Android bitmap shift/move issues

Tag : android , By : Brianna
Date : March 29 2020, 07:55 AM
With these it helps When there is only a simple transform set on Canvas (a simple transform = translate only, no rotate, no scale), Skia, Android's 2D rendering library, aligns bitmaps to the pixel grid. This means that a move by less than 1 pixel might not be visible at all. A silly workaround is to set a very, very small scale or rotate transform on Canvas before drawing your bitmap. This has the side effect of not snapping bitmaps to the pixel grid.
I think I should just add a new API on Paint to let apps do subpixel positioning of bitmaps no matter what transform is set.

What is the difference between directly assigning the result of left shift operation to a variable and the left shift as

Tag : c , By : SA.
Date : March 29 2020, 07:55 AM
wish help you to fix your issue In the following expression, the result of the left shift operation is assigned to the variable i. , The C standard says:

jQuery check for clicking left ctrl + left shift and left ctrl + right shift

Tag : javascript , By : Janko
Date : March 29 2020, 07:55 AM

Autohotkey remapping alt+j to left but alt+shift+j doesn't select left nor do alt+ctr+j move a caret , if getKeyState do

Tag : vim , By : Brownell
Date : March 29 2020, 07:55 AM
Related Posts Related QUESTIONS :
  • Member function of class with template arguments and default arguments outside class
  • Is it possible to implement a non-owning "slightly smart" pointer on top of standard weak pointers?
  • how to configure the AcquireCredentialsHandleA correctly
  • Using private versions of global extern variables with OpenMP
  • Eigen Block wrong amount of columns and rows
  • Memory alignment rules in inheritance
  • Is nullptr falsy?
  • tm_wday returns a large integer outside 0-6 range
  • Scope a using declaration, inside a header
  • How to specify constructor's template arguments inside a new expression?
  • Sort an array via x86 Assembly (embedded in C++)?? Possible?
  • How to Replace only Part of the Variable using #define
  • How do you compare the performace of valarrays vs built-in arrays?
  • Is it normal for C++ static initialization to appear twice in the same backtrace?
  • c++ generate a good random seed for psudo random number generators
  • Why isn't my operator overloading working properly?
  • Getting meaningful error messages from fstream's in C++
  • C++: Converting Julian dates to Gregorian
  • Could someone explain this interesting behaviour with Sleep(1)?
  • Is it possible to roll a significantly faster version of modf
  • Updating pointer using signals and slots
  • How are classes more secure than structures?
  • finding "distance" between two pixel's colors
  • C++ Greatest Number Verification
  • Why does my token return NULL and how can I fix it?(c++)
  • C++ enforce conditions on inherited classes
  • what happened if an exception is not captured?
  • Redundant naming in C/C++ typedefs/structs
  • question about STL thread-safe and STL debugging
  • killing a separate thread having a socket
  • Returning the size of available virtual memory at run-time in C++
  • Parallel computing for integrals
  • How do I force my std::map to deallocate memory used?
  • C++ Templates: implicit conversion, no matching function for call to ctor
  • Adding python script to c++ project
  • C++ private pointer "leaking"?
  • Initializing Primitive Array to One Value
  • how is push_back implemented in STL vector?
  • C++ Profiling: KiFastSystemCallRet
  • Multiple rows with a single INSERT in SQLServer 2008
  • Use super class's address/pointer in initialization list
  • double fork using vfork
  • Convert char pointer (char*) to struct
  • Does anyone have good tips for using pc-lint?
  • C++ How fast is passing around objects?
  • template type's ctor arguments at instantiation time
  • Get list of windows in taskbar on Windows 7?
  • Curl connection options
  • Best cross-platform solution for network server?
  • simple c++ file opening issue
  • Switching from C++ (with a lot of STL use) to C for interpreter building
  • How can I access the JPEG image pixels as a 3D array like we do in MATLAB?
  • What wording in the C++ standard allows static_cast<non-void-type*>(malloc(N)); to work?
  • Avoid allocating in constructor or preserve simplicity (and RAII?)
  • Can C++ raise an error when std array initialization is too small?
  • Reference to end is ambiguous
  • Problem with basic usage of std::enable_if
  • How to print out a decimal number as octal number using setiosflags in C++
  • Open Visual Studio with solution and specific file and line
  • Enum value based on template type
  • shadow
    Privacy Policy - Terms - Contact Us © scrbit.com