{"id":98845,"date":"2018-05-28T07:00:00","date_gmt":"2018-05-28T21:00:00","guid":{"rendered":"https:\/\/blogs.msdn.microsoft.com\/oldnewthing\/?p=98845"},"modified":"2019-03-13T00:44:26","modified_gmt":"2019-03-13T07:44:26","slug":"20180528-00","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/oldnewthing\/20180528-00\/?p=98845","title":{"rendered":"How are <CODE>BitBlt<\/CODE> raster opcodes calculated?"},"content":{"rendered":"<p>Commenter R P asks  <a HREF=\"https:\/\/blogs.msdn.microsoft.com\/oldnewthing\/20180209-00\/?p=97995#comment-1325265\">what the low-order 16 bits of the <code>BitBlt<\/code> raster opcodes mean<\/a>. <\/p>\n<p><a HREF=\"https:\/\/msdn.microsoft.com\/en-us\/library\/windows\/desktop\/dd145130(v=vs.85).aspx\">The documentation explains<\/a> that the high-order 16 bits of the raster opcode are the zero-extended 8-bit value that represents the result of the raster operation  given the 8 combinations of three binary inputs (pattern, source, and destination). This is the easy part to understand. <\/p>\n<p>The documentation also says that the low-order 16 bits are an operation code, but gives no information as to how the operation code is determined. <\/p>\n<p>Okay, let&#8217;s dig through the history. <\/p>\n<p>Initially, the <code>BitBlt<\/code> raster opcodes were only 16-bit values, consisting of the operation codes. The higher-order 16 bits were added later because it turns out that people preferred table lookups to parsing operation codes. <\/p>\n<p>Okay, that&#8217;s enough beating around the bush. How do I parse the operation codes? <\/p>\n<p>The operation code is interpreted as follows: <\/p>\n<table CLASS=\"cp3\" BORDER=\"1\" CELLPADDING=\"3\" STYLE=\"border-collapse: collapse;text-align: center\">\n<tr>\n<th STYLE=\"width: 10pt\">15<\/th>\n<th STYLE=\"width: 10pt\">14<\/th>\n<th STYLE=\"width: 10pt\">13<\/th>\n<th STYLE=\"width: 10pt\">12<\/th>\n<th STYLE=\"width: 10pt\">11<\/th>\n<th STYLE=\"width: 10pt\">10<\/th>\n<th STYLE=\"width: 10pt\"> 9<\/th>\n<th STYLE=\"width: 10pt\"> 8<\/th>\n<th STYLE=\"width: 10pt\"> 7<\/th>\n<th STYLE=\"width: 10pt\"> 6<\/th>\n<th STYLE=\"width: 20pt\"> 5<\/th>\n<th STYLE=\"width: 10pt\"> 4<\/th>\n<th STYLE=\"width: 10pt\"> 3<\/th>\n<th STYLE=\"width: 10pt\"> 2<\/th>\n<th STYLE=\"width: 10pt\"> 1<\/th>\n<th STYLE=\"width: 10pt\"> 0<\/th>\n<\/tr>\n<tr>\n<td COLSPAN=\"2\">op5<\/td>\n<td COLSPAN=\"2\">op4<\/td>\n<td COLSPAN=\"2\">op3<\/td>\n<td COLSPAN=\"2\">op2<\/td>\n<td COLSPAN=\"2\">op1<\/td>\n<td>op6<\/td>\n<td COLSPAN=\"3\">template<\/td>\n<td COLSPAN=\"2\">bias<\/td>\n<\/tr>\n<\/table>\n<p>Operations 1 through 5 select one of the following logical operations: <\/p>\n<table CLASS=\"cp3\" BORDER=\"1\" CELLPADDING=\"3\" STYLE=\"border-collapse: collapse\">\n<tr>\n<th>Value<\/th>\n<th>Operation<\/th>\n<th>Abbreviation<\/th>\n<\/tr>\n<tr>\n<td>0<\/td>\n<td>not<\/td>\n<td>n<\/td>\n<\/tr>\n<tr>\n<td>1<\/td>\n<td>exclusive or<\/td>\n<td>x<\/td>\n<\/tr>\n<tr>\n<td>2<\/td>\n<td>or<\/td>\n<td>o<\/td>\n<\/tr>\n<tr>\n<td>3<\/td>\n<td>and<\/td>\n<td>a<\/td>\n<\/tr>\n<\/table>\n<p>Operation 6 encodes an optional final <i>not<\/i> operation. <\/p>\n<table CLASS=\"cp3\" BORDER=\"1\" CELLPADDING=\"3\" STYLE=\"border-collapse: collapse\">\n<tr>\n<th>Value<\/th>\n<th>Operation<\/th>\n<th>Abbreviation<\/th>\n<\/tr>\n<tr>\n<td>0<\/td>\n<td>no operation<\/td>\n<td>&nbsp;<\/td>\n<\/tr>\n<tr>\n<td>1<\/td>\n<td>not<\/td>\n<td>n<\/td>\n<\/tr>\n<\/table>\n<p>The operations imply the number of input parameters required. Each binary operation pops two arguments off the stack and pushes the result back onto the stack, for a net reduction of one. The unary <i>not<\/i> operation pops one argument off the stack and pushes the result back onto the stack, for no net change. And when we&#8217;re finished, we want one final result on the stack. Therefore, the number of items that need to be placed onto the stack is one more than the number of binary operations. <\/p>\n<p>The template and bias tell you what those parameters are. First, the template selects one of the following sequences of elements. <\/p>\n<table CLASS=\"cp3\" BORDER=\"1\" CELLPADDING=\"3\" STYLE=\"border-collapse: collapse\">\n<tr>\n<th>Value<\/th>\n<th>Template<\/th>\n<\/tr>\n<tr>\n<td>0<\/td>\n<td>SPDD<\/td>\n<\/tr>\n<tr>\n<td>1<\/td>\n<td>SPD<\/td>\n<\/tr>\n<tr>\n<td>2<\/td>\n<td>SDP<\/td>\n<\/tr>\n<tr>\n<td>3<\/td>\n<td>(not used)<\/td>\n<\/tr>\n<tr>\n<td>4<\/td>\n<td>(not used)<\/td>\n<\/tr>\n<tr>\n<td>5<\/td>\n<td>SSP*DS<\/td>\n<\/tr>\n<tr>\n<td>6<\/td>\n<td>SSP*PDS<\/td>\n<\/tr>\n<tr>\n<td>7<\/td>\n<td>SSD*PDS<\/td>\n<\/tr>\n<\/table>\n<p>Two of the templates are not currently used and are reserved for future expansion. <\/p>\n<p>The bias specifies how many initial template elements to ignore. After that, take the template elements until you have consumed one more than the number of binary operations. Also take the asterisk, if you encounter one. And if you run out of template elements, then start over from the beginning. <\/p>\n<p>Okay, now we put all the pieces together. <\/p>\n<ul>\n<li>For each template element:<\/li>\n<ul>\n<li>If it is a letter, then push that input onto the stack.<\/li>\n<li>If it is an asterisk, then perform the next operation.<\/li>\n<\/ul>\n<li>After you have used up all the template elements,     perform all of the remaining operations.<\/li>\n<li>When you&#8217;re done, there should be one value left on the stack.     That is the result of the <code>BitBlt<\/code> operation.<\/li>\n<\/ul>\n<p>Consider the raster opcode <code>0x00010289<\/code>. The operation index is 1, which decodes as follows: <\/p>\n<table CLASS=\"cp3\" BORDER=\"1\" CELLPADDING=\"3\" STYLE=\"border-collapse: collapse\">\n<tr>\n<th>P<\/th>\n<td>1<\/td>\n<td>1<\/td>\n<td>1<\/td>\n<td>1<\/td>\n<td>0<\/td>\n<td>0<\/td>\n<td>0<\/td>\n<td>0<\/td>\n<\/tr>\n<tr>\n<th>S<\/th>\n<td>1<\/td>\n<td>1<\/td>\n<td>0<\/td>\n<td>0<\/td>\n<td>1<\/td>\n<td>1<\/td>\n<td>0<\/td>\n<td>0<\/td>\n<\/tr>\n<tr>\n<th>D<\/th>\n<td>1<\/td>\n<td>0<\/td>\n<td>1<\/td>\n<td>0<\/td>\n<td>1<\/td>\n<td>0<\/td>\n<td>1<\/td>\n<td>0<\/td>\n<\/tr>\n<tr STYLE=\"border-top: solid 2px black\">\n<th>Result<\/th>\n<td>0<\/td>\n<td>0<\/td>\n<td>0<\/td>\n<td>0<\/td>\n<td>0<\/td>\n<td>0<\/td>\n<td>0<\/td>\n<td>1<\/td>\n<\/tr>\n<\/table>\n<p>The operation code is <code>0x0289<\/code>, which decodes as follows: <\/p>\n<table CLASS=\"cp3\" BORDER=\"1\" CELLPADDING=\"3\" STYLE=\"border-collapse: collapse;text-align: center\">\n<tr>\n<th STYLE=\"width: 10pt\">15<\/th>\n<th STYLE=\"width: 10pt\">14<\/th>\n<th STYLE=\"width: 10pt\">13<\/th>\n<th STYLE=\"width: 10pt\">12<\/th>\n<th STYLE=\"width: 10pt\">11<\/th>\n<th STYLE=\"width: 10pt\">10<\/th>\n<th STYLE=\"width: 10pt\"> 9<\/th>\n<th STYLE=\"width: 10pt\"> 8<\/th>\n<th STYLE=\"width: 10pt\"> 7<\/th>\n<th STYLE=\"width: 10pt\"> 6<\/th>\n<th STYLE=\"width: 20pt\"> 5<\/th>\n<th STYLE=\"width: 10pt\"> 4<\/th>\n<th STYLE=\"width: 10pt\"> 3<\/th>\n<th STYLE=\"width: 10pt\"> 2<\/th>\n<th STYLE=\"width: 10pt\"> 1<\/th>\n<th STYLE=\"width: 10pt\"> 0<\/th>\n<\/tr>\n<tr>\n<td COLSPAN=\"2\">op5<\/td>\n<td COLSPAN=\"2\">op4<\/td>\n<td COLSPAN=\"2\">op3<\/td>\n<td COLSPAN=\"2\">op2<\/td>\n<td COLSPAN=\"2\">op1<\/td>\n<td>op6<\/td>\n<td COLSPAN=\"3\">template<\/td>\n<td COLSPAN=\"2\">bias<\/td>\n<\/tr>\n<tr>\n<td>0<\/td>\n<td>0<\/td>\n<td>0<\/td>\n<td>0<\/td>\n<td>0<\/td>\n<td>0<\/td>\n<td>1<\/td>\n<td>0<\/td>\n<td>1<\/td>\n<td>0<\/td>\n<td>0<\/td>\n<td>0<\/td>\n<td>1<\/td>\n<td>0<\/td>\n<td>0<\/td>\n<td>1<\/td>\n<\/tr>\n<tr>\n<td COLSPAN=\"2\">0<\/td>\n<td COLSPAN=\"2\">0<\/td>\n<td COLSPAN=\"2\">0<\/td>\n<td COLSPAN=\"2\">2<\/td>\n<td COLSPAN=\"2\">2<\/td>\n<td>0<\/td>\n<td COLSPAN=\"3\">2<\/td>\n<td COLSPAN=\"2\">1<\/td>\n<\/tr>\n<tr>\n<td COLSPAN=\"2\">n<\/td>\n<td COLSPAN=\"2\">n<\/td>\n<td COLSPAN=\"2\">n<\/td>\n<td COLSPAN=\"2\">o<\/td>\n<td COLSPAN=\"2\">o<\/td>\n<td>&nbsp;<\/td>\n<td COLSPAN=\"3\">SDP<\/td>\n<td COLSPAN=\"2\">1<\/td>\n<\/tr>\n<\/table>\n<p>There are two binary operation codes (the two <i>or<\/i> operations), so we will need three parameters. <\/p>\n<ul>\n<li>The bias tells us to skip the first template element,     so we skip the S.<\/li>\n<li>The next element in the template is a D, so we push the destination.<\/li>\n<li>The next element in the template is a P, so we push the pattern.<\/li>\n<li>We have run out of template elements, so we wrap around and     see that we have an S, so we push the source.<\/li>\n<li>Now to use up the remaining operations, in order:<\/li>\n<li>Operation 1 tells us to pop the top two values from the stack,     <i>or<\/i> them together, and push the result back onto the stack.<\/li>\n<li>Operation 2 tells us to pop the top two values from the stack,     <i>or<\/i> them together, and push the result back onto the stack.<\/li>\n<li>Operation 3 tells us to pop the top value from the stack,     <i>bitwise-not<\/i> it, and push the result back onto the stack.<\/li>\n<li>Operation 4 tells us to pop the top value from the stack,     <i>bitwise-not<\/i> it, and push the result back onto the stack.<\/li>\n<li>Operation 5 tells us to pop the top value from the stack,     <i>bitwise-not<\/i> it, and push the result back onto the stack.<\/li>\n<li>Operation 6 tells us to do nothing.<\/li>\n<li>The final value on the stack is the result of the <code>BitBlt<\/code>     operation.<\/li>\n<\/ul>\n<p>In RPN, this encodes compactly as <code>DPSoonnn<\/code> <\/p>\n<p>It looks like a lot of work, but that&#8217;s because I spelled it out in painstaking detail. A shorter version would be <\/p>\n<ul>\n<li>The template says SDP, and the bias is 1, so we start at the D     and take three parameters (wrapping around if necessary),     which gives us <code>DPS<\/code>.<\/li>\n<li>Then we append the operations, which is <code>oonnn<\/code>. <\/ul>\n<p>Observe that <code>nn<\/code> bitwise-negates the top item on the stack, and then bitwise-negates it again. The two operations cancel out, which means that any <code>nn<\/code> sequence can be optimized out. In practice, these <code>nn<\/code> operations will appear at the end. If you&#8217;re encoding operations, and you have an even number of leftover operation slots, then you pad out the unused operations with <i>not<\/i>. If you have an odd number of leftover operation slots, then you put <i>not<\/i> in all but the last slot. (Operation 6 is the only one that can be left empty.) <\/p>\n<p>Removing the redundant <\/code>nn<\/code> leaves us with <code>DPSoon<\/code>, which matches the value given in <a HREF=\"https:\/\/msdn.microsoft.com\/en-us\/library\/dd145130(v=vs.85).aspx\">the table<\/a>. <\/p>\n<p>Let&#8217;s try one of the more complicated operations. Operation index <code>0xD4<\/code> is <code>0x00D41D78<\/code>. The operation code is <code>0x1D78<\/code>: <\/p>\n<table CLASS=\"cp3\" BORDER=\"1\" CELLPADDING=\"3\" STYLE=\"border-collapse: collapse;text-align: center\">\n<tr>\n<th STYLE=\"width: 10pt\">15<\/th>\n<th STYLE=\"width: 10pt\">14<\/th>\n<th STYLE=\"width: 10pt\">13<\/th>\n<th STYLE=\"width: 10pt\">12<\/th>\n<th STYLE=\"width: 10pt\">11<\/th>\n<th STYLE=\"width: 10pt\">10<\/th>\n<th STYLE=\"width: 10pt\"> 9<\/th>\n<th STYLE=\"width: 10pt\"> 8<\/th>\n<th STYLE=\"width: 10pt\"> 7<\/th>\n<th STYLE=\"width: 10pt\"> 6<\/th>\n<th STYLE=\"width: 20pt\"> 5<\/th>\n<th STYLE=\"width: 10pt\"> 4<\/th>\n<th STYLE=\"width: 10pt\"> 3<\/th>\n<th STYLE=\"width: 10pt\"> 2<\/th>\n<th STYLE=\"width: 10pt\"> 1<\/th>\n<th STYLE=\"width: 10pt\"> 0<\/th>\n<\/tr>\n<tr>\n<td COLSPAN=\"2\">op5<\/td>\n<td COLSPAN=\"2\">op4<\/td>\n<td COLSPAN=\"2\">op3<\/td>\n<td COLSPAN=\"2\">op2<\/td>\n<td COLSPAN=\"2\">op1<\/td>\n<td>op6<\/td>\n<td COLSPAN=\"3\">template<\/td>\n<td COLSPAN=\"2\">bias<\/td>\n<\/tr>\n<tr>\n<td>0<\/td>\n<td>0<\/td>\n<td>0<\/td>\n<td>1<\/td>\n<td>1<\/td>\n<td>1<\/td>\n<td>0<\/td>\n<td>1<\/td>\n<td>0<\/td>\n<td>1<\/td>\n<td>1<\/td>\n<td>1<\/td>\n<td>1<\/td>\n<td>0<\/td>\n<td>0<\/td>\n<td>0<\/td>\n<\/tr>\n<tr>\n<td COLSPAN=\"2\">0<\/td>\n<td COLSPAN=\"2\">1<\/td>\n<td COLSPAN=\"2\">3<\/td>\n<td COLSPAN=\"2\">1<\/td>\n<td COLSPAN=\"2\">1<\/td>\n<td>1<\/td>\n<td COLSPAN=\"3\">6<\/td>\n<td COLSPAN=\"2\">0<\/td>\n<\/tr>\n<tr>\n<td COLSPAN=\"2\">n<\/td>\n<td COLSPAN=\"2\">x<\/td>\n<td COLSPAN=\"2\">a<\/td>\n<td COLSPAN=\"2\">x<\/td>\n<td COLSPAN=\"2\">x<\/td>\n<td>n<\/td>\n<td COLSPAN=\"3\">SSP*PD<\/td>\n<td COLSPAN=\"2\">0<\/td>\n<\/tr>\n<\/table>\n<p>There are four binary operations, so we need five parameters. There is no bias, so we start at the beginning with <code>SSP<\/code>. Next is an asterisk, so we replace it with the first operation, which is <code>x<\/code>. Then we continue with the template, which gives us <code>PD<\/code>. And then we perform the leftover operations, which are <code>xaxnn<\/code>. The resulting RPN is <code>SSPxPDxaxnn<\/code>, which after canceling out the <code>nn<\/code> leaves <code>SSPxPDxax<\/code>. And this matches the value in the table. <\/p>\n<p>If you write a program to apply this algorithm to all of the raster operations, you&#8217;ll find that decoding the operation code results in the published RPN, with the exception of operation indices 0 and 255. <\/p>\n<p>Let&#8217;s decode operation index 0, whose operation code is <code>0x0042<\/code>. <\/p>\n<table CLASS=\"cp3\" BORDER=\"1\" CELLPADDING=\"3\" STYLE=\"border-collapse: collapse;text-align: center\">\n<tr>\n<th STYLE=\"width: 10pt\">15<\/th>\n<th STYLE=\"width: 10pt\">14<\/th>\n<th STYLE=\"width: 10pt\">13<\/th>\n<th STYLE=\"width: 10pt\">12<\/th>\n<th STYLE=\"width: 10pt\">11<\/th>\n<th STYLE=\"width: 10pt\">10<\/th>\n<th STYLE=\"width: 10pt\"> 9<\/th>\n<th STYLE=\"width: 10pt\"> 8<\/th>\n<th STYLE=\"width: 10pt\"> 7<\/th>\n<th STYLE=\"width: 10pt\"> 6<\/th>\n<th STYLE=\"width: 20pt\"> 5<\/th>\n<th STYLE=\"width: 10pt\"> 4<\/th>\n<th STYLE=\"width: 10pt\"> 3<\/th>\n<th STYLE=\"width: 10pt\"> 2<\/th>\n<th STYLE=\"width: 10pt\"> 1<\/th>\n<th STYLE=\"width: 10pt\"> 0<\/th>\n<\/tr>\n<tr>\n<td COLSPAN=\"2\">op5<\/td>\n<td COLSPAN=\"2\">op4<\/td>\n<td COLSPAN=\"2\">op3<\/td>\n<td COLSPAN=\"2\">op2<\/td>\n<td COLSPAN=\"2\">op1<\/td>\n<td>op6<\/td>\n<td COLSPAN=\"3\">template<\/td>\n<td COLSPAN=\"2\">bias<\/td>\n<\/tr>\n<tr>\n<td>0<\/td>\n<td>0<\/td>\n<td>0<\/td>\n<td>0<\/td>\n<td>0<\/td>\n<td>0<\/td>\n<td>0<\/td>\n<td>0<\/td>\n<td>0<\/td>\n<td>1<\/td>\n<td>0<\/td>\n<td>0<\/td>\n<td>0<\/td>\n<td>0<\/td>\n<td>1<\/td>\n<td>0<\/td>\n<\/tr>\n<tr>\n<td COLSPAN=\"2\">0<\/td>\n<td COLSPAN=\"2\">0<\/td>\n<td COLSPAN=\"2\">0<\/td>\n<td COLSPAN=\"2\">0<\/td>\n<td COLSPAN=\"2\">1<\/td>\n<td>0<\/td>\n<td COLSPAN=\"3\">0<\/td>\n<td COLSPAN=\"2\">2<\/td>\n<\/tr>\n<tr>\n<td COLSPAN=\"2\">n<\/td>\n<td COLSPAN=\"2\">n<\/td>\n<td COLSPAN=\"2\">n<\/td>\n<td COLSPAN=\"2\">n<\/td>\n<td COLSPAN=\"2\">x<\/td>\n<td>&nbsp;<\/td>\n<td COLSPAN=\"3\">SPDD<\/td>\n<td COLSPAN=\"2\">2<\/td>\n<\/tr>\n<\/table>\n<p>This decodes as <code>DDxnnnn<\/code>, which simplifies to <code>DDx<\/code>, but the published RPN is just <code>0<\/code>. Aha, but we also know that anything <i>xor<\/i>&#8216;d with itself is zero, so <code>DDx<\/code> simplifies further to <code>0<\/code>. <\/p>\n<p>Similarly, operation index 255 has operation code <code>0x0062<\/code> which decodes as follows: <\/p>\n<table CLASS=\"cp3\" BORDER=\"1\" CELLPADDING=\"3\" STYLE=\"border-collapse: collapse;text-align: center\">\n<tr>\n<th STYLE=\"width: 10pt\">15<\/th>\n<th STYLE=\"width: 10pt\">14<\/th>\n<th STYLE=\"width: 10pt\">13<\/th>\n<th STYLE=\"width: 10pt\">12<\/th>\n<th STYLE=\"width: 10pt\">11<\/th>\n<th STYLE=\"width: 10pt\">10<\/th>\n<th STYLE=\"width: 10pt\"> 9<\/th>\n<th STYLE=\"width: 10pt\"> 8<\/th>\n<th STYLE=\"width: 10pt\"> 7<\/th>\n<th STYLE=\"width: 10pt\"> 6<\/th>\n<th STYLE=\"width: 20pt\"> 5<\/th>\n<th STYLE=\"width: 10pt\"> 4<\/th>\n<th STYLE=\"width: 10pt\"> 3<\/th>\n<th STYLE=\"width: 10pt\"> 2<\/th>\n<th STYLE=\"width: 10pt\"> 1<\/th>\n<th STYLE=\"width: 10pt\"> 0<\/th>\n<\/tr>\n<tr>\n<td COLSPAN=\"2\">op5<\/td>\n<td COLSPAN=\"2\">op4<\/td>\n<td COLSPAN=\"2\">op3<\/td>\n<td COLSPAN=\"2\">op2<\/td>\n<td COLSPAN=\"2\">op1<\/td>\n<td>op6<\/td>\n<td COLSPAN=\"3\">template<\/td>\n<td COLSPAN=\"2\">bias<\/td>\n<\/tr>\n<tr>\n<td>0<\/td>\n<td>0<\/td>\n<td>0<\/td>\n<td>0<\/td>\n<td>0<\/td>\n<td>0<\/td>\n<td>0<\/td>\n<td>0<\/td>\n<td>0<\/td>\n<td>1<\/td>\n<td>1<\/td>\n<td>0<\/td>\n<td>0<\/td>\n<td>0<\/td>\n<td>1<\/td>\n<td>0<\/td>\n<\/tr>\n<tr>\n<td COLSPAN=\"2\">0<\/td>\n<td COLSPAN=\"2\">0<\/td>\n<td COLSPAN=\"2\">0<\/td>\n<td COLSPAN=\"2\">0<\/td>\n<td COLSPAN=\"2\">1<\/td>\n<td>1<\/td>\n<td COLSPAN=\"3\">0<\/td>\n<td COLSPAN=\"2\">2<\/td>\n<\/tr>\n<tr>\n<td COLSPAN=\"2\">n<\/td>\n<td COLSPAN=\"2\">n<\/td>\n<td COLSPAN=\"2\">n<\/td>\n<td COLSPAN=\"2\">n<\/td>\n<td COLSPAN=\"2\">x<\/td>\n<td>n<\/td>\n<td COLSPAN=\"3\">SPDD<\/td>\n<td COLSPAN=\"2\">2<\/td>\n<\/tr>\n<\/table>\n<p>This decodes as <code>DDxnnnnn<\/code>, which simplifies to <code>DDxn<\/code>, and since we learned that <code>DDx<\/code> is <code>0<\/code>, this gives us <code>0n<\/code>, which simplifies further to just <code>1<\/code>, which matches the published RPN. <\/p>\n<p>Back to history: As I noted earlier, the raster opcodes were initially 16-bit values, and the idea was that <code>BitBlt<\/code> implementations would parse and execute the expressions encoded in the operation code. In practice, people just looked up the value in a table of precomputed operation codes and used that to decide how to perform the operation. As a result, the operation index was added to the raster opcode, so that implementations who want to use a table lookup have a single byte to look up instead of having to do a binary search on the 16-bit operation code. Both the operation index and operation code are present so that the values work both with drivers that use lookup tables and drivers which parse the operation code and execute the miniature expression language. <\/p>\n<p>Over time, the drivers that executed the miniature expression language died out. All anybody cares about nowadays is the operation index. <\/p>\n","protected":false},"excerpt":{"rendered":"<p>The complicated language of raster operation codes.<\/p>\n","protected":false},"author":1069,"featured_media":111744,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[1],"tags":[2],"class_list":["post-98845","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-oldnewthing","tag-history"],"acf":[],"blog_post_summary":"<p>The complicated language of raster operation codes.<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/posts\/98845","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/users\/1069"}],"replies":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/comments?post=98845"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/posts\/98845\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/media\/111744"}],"wp:attachment":[{"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/media?parent=98845"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/categories?post=98845"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/tags?post=98845"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}