static int gx_image1_mask_sput(const gs_image_common_t *pic, stream *s, const gs_color_space **ignore_ppcs) { const gs_image_t *pim = (const gs_image_t *)pic; uint control = (gx_image_matrix_is_default((const gs_data_image_t *)pim) ? 0 : MI_ImageMatrix) | (pim->Decode[0] != 0 ? MI_Decode : 0) | (pim->Interpolate ? MI_Interpolate : 0) | (pim->adjust ? MI_adjust : 0) | (pim->Alpha << MI_Alpha_SHIFT) | ((pim->BitsPerComponent - 1) << MI_BPC_SHIFT); sput_variable_uint(s, control); sput_variable_uint(s, (uint)pim->Width); sput_variable_uint(s, (uint)pim->Height); if (control & MI_ImageMatrix) sput_matrix(s, &pim->ImageMatrix); return 0; }
/* * Width, encoded as a variable-length uint * Height, encoded ditto * ImageMatrix (if A = 1), per gs_matrix_store/fetch * Decode (if D = 1): blocks of up to 4 components * aabbccdd, where each xx is decoded as: * 00 = default, 01 = swapped default, * 10 = (0,V), 11 = (U,V) * non-defaulted components (up to 8 floats) */ int gx_pixel_image_sput(const gs_pixel_image_t *pim, stream *s, const gs_color_space **ppcs, int extra) { const gs_color_space *pcs = pim->ColorSpace; int bpc = pim->BitsPerComponent; int num_components = gs_color_space_num_components(pcs); int num_decode; uint control = extra << PI_BITS; float decode_default_1 = 1; int i; uint ignore; /* Construct the control word. */ if (!gx_image_matrix_is_default((const gs_data_image_t *)pim)) control |= PI_ImageMatrix; switch (pim->format) { case gs_image_format_chunky: case gs_image_format_component_planar: switch (bpc) { case 1: case 2: case 4: case 8: case 12: break; default: return_error(gs_error_rangecheck); } break; case gs_image_format_bit_planar: if (bpc < 1 || bpc > 8) return_error(gs_error_rangecheck); } control |= (bpc - 1) << PI_BPC_SHIFT; control |= pim->format << PI_FORMAT_SHIFT; num_decode = num_components * 2; if (gs_color_space_get_index(pcs) == gs_color_space_index_Indexed) decode_default_1 = (float)pcs->params.indexed.hival; for (i = 0; i < num_decode; ++i) if (pim->Decode[i] != DECODE_DEFAULT(i, decode_default_1)) { control |= PI_Decode; break; } if (pim->Interpolate) control |= PI_Interpolate; if (pim->CombineWithColor) control |= PI_CombineWithColor; /* Write the encoding on the stream. */ if_debug3('b', "[b]put control=0x%x, Width=%d, Height=%d\n", control, pim->Width, pim->Height); sput_variable_uint(s, control); sput_variable_uint(s, (uint)pim->Width); sput_variable_uint(s, (uint)pim->Height); if (control & PI_ImageMatrix) { debug_b_print_matrix(pim); sput_matrix(s, &pim->ImageMatrix); } if (control & PI_Decode) { int i; uint dflags = 1; float decode[8]; int di = 0; debug_b_print_decode(pim, num_decode); for (i = 0; i < num_decode; i += 2) { float u = pim->Decode[i], v = pim->Decode[i + 1]; float dv = DECODE_DEFAULT(i + 1, decode_default_1); if (dflags >= 0x100) { sputc(s, (byte)(dflags & 0xff)); sputs(s, (const byte *)decode, di * sizeof(float), &ignore); dflags = 1; di = 0; } dflags <<= 2; if (u == 0 && v == dv) DO_NOTHING; else if (u == dv && v == 0) dflags += 1; else { if (u != 0) { dflags++; decode[di++] = u; } dflags += 2; decode[di++] = v; } } sputc(s, (byte)((dflags << (8 - num_decode)) & 0xff)); sputs(s, (const byte *)decode, di * sizeof(float), &ignore); } *ppcs = pcs; return 0; }