Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6337817
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T19:19:26+00:00 2026-05-24T19:19:26+00:00

Trying to work by the design guidelines for GIL, I use bits__ for my

  • 0

Trying to work by the design guidelines for GIL, I use bits__ for my channel data types. I often have external data I’m wrapping into GIL image views. However, even using the bits__ types for data pointers, I have to add in a reinterpret_cast before I can create my image views. Take the following code

int width = 3;
int height = 2;

boost::gil::bits8 data8[] = {0, 1, 100, 200, 50, 51};
boost::gil::bits8* pBits8 = data8;
boost::gil::gray8_ptr_t pGray8 = pBits8;

boost::gil::gray8_view_t v = interleaved_view(width, height, pGray8, width * sizeof(boost::gil::bits8));

Results in the error on line 6 “error C2440: ‘initializing’ : cannot convert from ‘boost::gil::bits8 *’ to ‘boost::gil::gray8_ptr_t’
1> Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast”

Delving into the source code as much as I can, it appears these types really are unreleated. bits8 is just unsigned char, but gray8_ptr_t is a pointer to a struct pixel<bits8,gray_layout_t>. The only element of this struct is a single bits8, so a reinterpret_cast looks safe. It also works fine for the tests I’ve thrown at it.

However, I wrap external data into image views quite often, and having a reinterpret_cast in every place feels problematic. Is there a safer way of constructing a pixel pointer for use in GIL?

Current workaround:

template<class Dest, class Src>
Dest gil_safe_ptr_cast(Src src)
{
    // this cast is unsafe, use reinterpret_cast 
    BOOST_STATIC_ASSERT(false);
}
template<> boost::gil::gray8_ptr_t gil_safe_ptr_cast(boost::gil::bits8* pBits8)
{
    return reinterpret_cast<boost::gil::gray8_ptr_t>(pBits8);
}
boost::gil::bits8* pBits8 = data8;
boost::gil::gray8_ptr_t pGray8 = gil_safe_ptr_cast<boost::gil::gray8_ptr_t>(pBits8); // works
boost::gil::bits16* pBits16 = NULL;
boost::gil::gray8_ptr_t pGray82 = gil_safe_ptr_cast<boost::gil::gray8_ptr_t>(pBits16); // compile error as expected
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T19:19:27+00:00Added an answer on May 24, 2026 at 7:19 pm
    template<class Dest, class Src>
    Dest gil_safe_ptr_cast(Src src)
    {
        // this cast is unsafe, use reinterpret_cast 
        BOOST_STATIC_ASSERT(false);
    }
    template<> boost::gil::gray8_ptr_t gil_safe_ptr_cast(boost::gil::bits8* pBits8)
    {
        return reinterpret_cast<boost::gil::gray8_ptr_t>(pBits8);
    }
    boost::gil::bits8* pBits8 = data8;
    boost::gil::gray8_ptr_t pGray8 = gil_safe_ptr_cast<boost::gil::gray8_ptr_t>(pBits8); // works
    boost::gil::bits16* pBits16 = NULL;
    boost::gil::gray8_ptr_t pGray82 = gil_safe_ptr_cast<boost::gil::gray8_ptr_t>(pBits16); // compile error as expected
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to design an object model (for C#), and can't work out
I have been trying to work my way through Project Euler, and have noticed
I'm trying to work through the problems on projecteuler.net but I keep running into
I'm trying to work out how to best complete my design work on my
Without getting into all of the gory details, I am trying to design a
Programming Student here...trying to work on a project but I'm stuck. The project is
Weve recently been trying to work on an application that uses pandastream to encode
I'm trying to work through Project Euler and I'm hitting a barrier on problem
I'm trying to work my way through Ron Jeffries's Extreme Programming Adventures in C#.
I am trying to work out the best database model for the current setup:

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.