idx
int64 | func
string | target
int64 |
|---|---|---|
484,827
|
ut64 MACH0_(get_baddr)(struct MACH0_(obj_t) * bin) {
int i;
if (bin->hdr.filetype != MH_EXECUTE && bin->hdr.filetype != MH_DYLINKER &&
bin->hdr.filetype != MH_FILESET) {
return 0;
}
for (i = 0; i < bin->nsegs; i++) {
if (bin->segs[i].fileoff == 0 && bin->segs[i].filesize != 0) {
return bin->segs[i].vmaddr;
}
}
return 0;
}
| 0
|
309,044
|
void TypingCommand::forwardDeleteKeyPressed(Document& document,
EditingState* editingState,
Options options,
TextGranularity granularity) {
if (granularity == CharacterGranularity) {
LocalFrame* frame = document.frame();
if (TypingCommand* lastTypingCommand =
lastTypingCommandIfStillOpenForTyping(frame)) {
updateSelectionIfDifferentFromCurrentSelection(lastTypingCommand, frame);
lastTypingCommand->setShouldPreventSpellChecking(options &
PreventSpellChecking);
lastTypingCommand->forwardDeleteKeyPressed(
granularity, options & KillRing, editingState);
return;
}
}
TypingCommand::create(document, ForwardDeleteKey, "", options, granularity)
->apply();
}
| 0
|
179,128
|
void PrintPreviewMessageHandler::OnDidGetPreviewPageCount(
const PrintHostMsg_DidGetPreviewPageCount_Params& params) {
if (params.page_count <= 0) {
NOTREACHED();
return;
}
PrintPreviewUI* print_preview_ui = GetPrintPreviewUI();
if (!print_preview_ui)
return;
if (params.clear_preview_data)
print_preview_ui->ClearAllPreviewData();
print_preview_ui->OnDidGetPreviewPageCount(params);
}
| 0
|
366,937
|
static int inode_has_perm(const struct cred *cred,
struct inode *inode,
u32 perms,
struct common_audit_data *adp)
{
struct inode_security_struct *isec;
struct common_audit_data ad;
u32 sid;
validate_creds(cred);
if (unlikely(IS_PRIVATE(inode)))
return 0;
sid = cred_sid(cred);
isec = inode->i_security;
if (!adp) {
adp = &ad;
COMMON_AUDIT_DATA_INIT(&ad, FS);
ad.u.fs.inode = inode;
}
return avc_has_perm(sid, isec->sid, isec->sclass, perms, adp);
}
| 0
|
268,526
|
int send_sig_info(int sig, struct siginfo *info, struct task_struct *p)
{
/*
* Make sure legacy kernel users don't send in bad values
* (normal paths check this in check_kill_permission).
*/
if (!valid_signal(sig))
return -EINVAL;
return do_send_sig_info(sig, info, p, false);
}
| 0
|
498,984
|
static RzList *parse_format(RzCore *core, char *fmt) {
if (!fmt || !*fmt) {
return NULL;
}
RzList *ret = rz_list_new();
if (!ret) {
return NULL;
}
Sdb *s = core->analysis->sdb_fmts;
const char *spec = rz_config_get(core->config, "analysis.types.spec");
char arr[10] = { 0 };
char *ptr = strchr(fmt, '%');
fmt[strlen(fmt) - 1] = '\0';
while (ptr) {
ptr++;
// strip [width] specifier
while (IS_DIGIT(*ptr)) {
ptr++;
}
rz_str_ncpy(arr, ptr, sizeof(arr) - 1);
char *tmp = arr;
while (tmp && (IS_LOWER(*tmp) || IS_UPPER(*tmp))) {
tmp++;
}
*tmp = '\0';
const char *query = sdb_fmt("spec.%s.%s", spec, arr);
char *type = (char *)sdb_const_get(s, query, 0);
if (type) {
rz_list_append(ret, type);
}
ptr = strchr(ptr, '%');
}
return ret;
}
| 0
|
483,744
|
void fw_devlink_pause(void)
{
mutex_lock(&defer_fw_devlink_lock);
defer_fw_devlink_count++;
mutex_unlock(&defer_fw_devlink_lock);
}
| 0
|
206,915
|
static char *exif_get_sectionlist(int sectionlist TSRMLS_DC)
{
int i, len, ml = 0;
char *sections;
for(i=0; i<SECTION_COUNT; i++) {
ml += strlen(exif_get_sectionname(i))+2;
}
sections = safe_emalloc(ml, 1, 1);
sections[0] = '\0';
len = 0;
for(i=0; i<SECTION_COUNT; i++) {
if (sectionlist&(1<<i)) {
snprintf(sections+len, ml-len, "%s, ", exif_get_sectionname(i));
len = strlen(sections);
}
}
if (len>2)
sections[len-2] = '\0';
return sections;
}
| 0
|
321,900
|
static int v9fs_synth_name_to_path(FsContext *ctx, V9fsPath *dir_path,
const char *name, V9fsPath *target)
{
V9fsSynthNode *node;
V9fsSynthNode *dir_node;
/* "." and ".." are not allowed */
if (!strcmp(name, ".") || !strcmp(name, "..")) {
errno = EINVAL;
return -1;
}
if (!dir_path) {
dir_node = &v9fs_synth_root;
} else {
dir_node = *(V9fsSynthNode **)dir_path->data;
}
if (!strcmp(name, "/")) {
node = dir_node;
goto out;
}
/* search for the name in the childern */
rcu_read_lock();
QLIST_FOREACH(node, &dir_node->child, sibling) {
if (!strcmp(node->name, name)) {
break;
}
}
rcu_read_unlock();
if (!node) {
errno = ENOENT;
return -1;
}
out:
/* Copy the node pointer to fid */
target->data = g_malloc(sizeof(void *));
memcpy(target->data, &node, sizeof(void *));
target->size = sizeof(void *);
return 0;
}
| 0
|
101,758
|
bool CIRCNetwork::Connect() {
if (!GetIRCConnectEnabled() || m_pIRCSock || !HasServers()) return false;
CServer* pServer = GetNextServer();
if (!pServer) return false;
if (CZNC::Get().GetServerThrottle(pServer->GetName())) {
// Can't connect right now, schedule retry later
CZNC::Get().AddNetworkToQueue(this);
return false;
}
CZNC::Get().AddServerThrottle(pServer->GetName());
bool bSSL = pServer->IsSSL();
#ifndef HAVE_LIBSSL
if (bSSL) {
PutStatus(
t_f("Cannot connect to {1}, because ZNC is not compiled with SSL "
"support.")(pServer->GetString(false)));
CZNC::Get().AddNetworkToQueue(this);
return false;
}
#endif
CIRCSock* pIRCSock = new CIRCSock(this);
pIRCSock->SetPass(pServer->GetPass());
pIRCSock->SetSSLTrustedPeerFingerprints(m_ssTrustedFingerprints);
pIRCSock->SetTrustAllCerts(GetTrustAllCerts());
pIRCSock->SetTrustPKI(GetTrustPKI());
DEBUG("Connecting user/network [" << m_pUser->GetUserName() << "/"
<< m_sName << "]");
bool bAbort = false;
NETWORKMODULECALL(OnIRCConnecting(pIRCSock), m_pUser, this, nullptr,
&bAbort);
if (bAbort) {
DEBUG("Some module aborted the connection attempt");
PutStatus(t_s("Some module aborted the connection attempt"));
delete pIRCSock;
CZNC::Get().AddNetworkToQueue(this);
return false;
}
CString sSockName = "IRC::" + m_pUser->GetUserName() + "::" + m_sName;
CZNC::Get().GetManager().Connect(pServer->GetName(), pServer->GetPort(),
sSockName, 120, bSSL, GetBindHost(),
pIRCSock);
return true;
}
| 0
|
512,467
|
int CRYPTO_THREAD_cleanup_local(CRYPTO_THREAD_LOCAL *key)
{
*key = OPENSSL_CRYPTO_THREAD_LOCAL_KEY_MAX + 1;
return 1;
}
| 0
|
368,297
|
router_get_by_descriptor_digest(const char *digest)
{
tor_assert(digest);
if (!routerlist) return NULL;
return sdmap_get(routerlist->desc_digest_map, digest);
}
| 0
|
348,318
|
compute_tag(dns_name_t *name, dns_rdata_dnskey_t *dnskey, isc_mem_t *mctx,
dns_keytag_t *tag)
{
isc_result_t result;
dns_rdata_t rdata = DNS_RDATA_INIT;
unsigned char data[4096];
isc_buffer_t buffer;
dst_key_t *dstkey = NULL;
isc_buffer_init(&buffer, data, sizeof(data));
dns_rdata_fromstruct(&rdata, dnskey->common.rdclass,
dns_rdatatype_dnskey, dnskey, &buffer);
result = dns_dnssec_keyfromrdata(name, &rdata, mctx, &dstkey);
if (result == ISC_R_SUCCESS)
*tag = dst_key_id(dstkey);
dst_key_free(&dstkey);
return (result);
}
| 1
|
245,979
|
NaClIPCAdapter::~NaClIPCAdapter() {
task_runner_->PostTask(FROM_HERE,
base::Bind(&DeleteChannel, io_thread_data_.channel_.release()));
}
| 0
|
291,541
|
BOOLEAN SkipIP6ExtensionHeader(
IPv6Header *ip6Hdr,
ULONG dataLength,
PULONG ip6HdrLength,
PUCHAR nextHdr)
{
IPv6ExtHeader* ip6ExtHdr;
if (*ip6HdrLength + sizeof(*ip6ExtHdr) > dataLength)
return FALSE;
ip6ExtHdr = (IPv6ExtHeader *)RtlOffsetToPointer(ip6Hdr, *ip6HdrLength);
*nextHdr = ip6ExtHdr->ip6ext_next_header;
*ip6HdrLength += (ip6ExtHdr->ip6ext_hdr_len + 1) * IP6_EXT_HDR_GRANULARITY;
return TRUE;
}
| 0
|
134,496
|
void ar6000_dtimexpiry_event(struct ar6_softc *ar)
{
bool isMcastQueued = false;
struct sk_buff *skb = NULL;
/* If there are no associated STAs, ignore the DTIM expiry event.
* There can be potential race conditions where the last associated
* STA may disconnect & before the host could clear the 'Indicate DTIM'
* request to the firmware, the firmware would have just indicated a DTIM
* expiry event. The race is between 'clear DTIM expiry cmd' going
* from the host to the firmware & the DTIM expiry event happening from
* the firmware to the host.
*/
if (ar->sta_list_index == 0) {
return;
}
A_MUTEX_LOCK(&ar->mcastpsqLock);
isMcastQueued = A_NETBUF_QUEUE_EMPTY(&ar->mcastpsq);
A_MUTEX_UNLOCK(&ar->mcastpsqLock);
A_ASSERT(isMcastQueued == false);
/* Flush the mcast psq to the target */
/* Set the STA flag to DTIMExpired, so that the frame will go out */
ar->DTIMExpired = true;
A_MUTEX_LOCK(&ar->mcastpsqLock);
while (!A_NETBUF_QUEUE_EMPTY(&ar->mcastpsq)) {
skb = A_NETBUF_DEQUEUE(&ar->mcastpsq);
A_MUTEX_UNLOCK(&ar->mcastpsqLock);
ar6000_data_tx(skb, ar->arNetDev);
A_MUTEX_LOCK(&ar->mcastpsqLock);
}
A_MUTEX_UNLOCK(&ar->mcastpsqLock);
/* Reset the DTIMExpired flag back to 0 */
ar->DTIMExpired = false;
/* Clear the LSB of the BitMapCtl field of the TIM IE */
wmi_set_pvb_cmd(ar->arWmi, MCAST_AID, 0);
}
| 0
|
240,349
|
views::View* ShellSurface::GetContentsView() {
return this;
}
| 0
|
315,310
|
void AppLaunchObserver::Observe(int type,
const content::NotificationSource& source,
const content::NotificationDetails& details) {
if (type == chrome::NOTIFICATION_BROWSER_WINDOW_READY) {
new_window_id_ =
ExtensionTabUtil::GetWindowId(content::Source<Browser>(source).ptr());
return;
}
DCHECK_EQ(content::NOTIFICATION_LOAD_STOP, type);
SessionTabHelper* session_tab_helper = SessionTabHelper::FromWebContents(
content::Source<NavigationController>(source)->GetWebContents());
if ((launch_container_ == extension_misc::LAUNCH_TAB) ||
(session_tab_helper &&
(session_tab_helper->window_id().id() == new_window_id_))) {
if (automation_) {
AutomationJSONReply(automation_,
reply_message_.release()).SendSuccess(NULL);
}
delete this;
}
}
| 0
|
273,434
|
static int vdbeRecordCompareString(
int nKey1, const void *pKey1, /* Left key */
UnpackedRecord *pPKey2 /* Right key */
){
const u8 *aKey1 = (const u8*)pKey1;
int serial_type;
int res;
assert( pPKey2->aMem[0].flags & MEM_Str );
vdbeAssertFieldCountWithinLimits(nKey1, pKey1, pPKey2->pKeyInfo);
getVarint32(&aKey1[1], serial_type);
if( serial_type<12 ){
res = pPKey2->r1; /* (pKey1/nKey1) is a number or a null */
}else if( !(serial_type & 0x01) ){
res = pPKey2->r2; /* (pKey1/nKey1) is a blob */
}else{
int nCmp;
int nStr;
int szHdr = aKey1[0];
nStr = (serial_type-12) / 2;
if( (szHdr + nStr) > nKey1 ){
pPKey2->errCode = (u8)SQLITE_CORRUPT_BKPT;
return 0; /* Corruption */
}
nCmp = MIN( pPKey2->aMem[0].n, nStr );
res = memcmp(&aKey1[szHdr], pPKey2->aMem[0].z, nCmp);
if( res>0 ){
res = pPKey2->r2;
}else if( res<0 ){
res = pPKey2->r1;
}else{
res = nStr - pPKey2->aMem[0].n;
if( res==0 ){
if( pPKey2->nField>1 ){
res = sqlite3VdbeRecordCompareWithSkip(nKey1, pKey1, pPKey2, 1);
}else{
res = pPKey2->default_rc;
pPKey2->eqSeen = 1;
}
}else if( res>0 ){
res = pPKey2->r2;
}else{
res = pPKey2->r1;
}
}
}
assert( vdbeRecordCompareDebug(nKey1, pKey1, pPKey2, res)
|| CORRUPT_DB
|| pPKey2->pKeyInfo->db->mallocFailed
);
return res;
}
| 0
|
264,354
|
int libevt_record_values_read_end_of_file(
libevt_record_values_t *record_values,
uint8_t *record_data,
size_t record_data_size,
libcerror_error_t **error )
{
static char *function = "libevt_record_values_read_end_of_file";
uint32_t size = 0;
uint32_t size_copy = 0;
#if defined( HAVE_DEBUG_OUTPUT )
uint32_t value_32bit = 0;
#endif
if( record_values == NULL )
{
libcerror_error_set(
error,
LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
"%s: invalid record values.",
function );
return( -1 );
}
if( record_data == NULL )
{
libcerror_error_set(
error,
LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
"%s: invalid record data.",
function );
return( -1 );
}
if( record_data_size > (size_t) SSIZE_MAX )
{
libcerror_error_set(
error,
LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
LIBCERROR_ARGUMENT_ERROR_VALUE_EXCEEDS_MAXIMUM,
"%s: invalid record data size value exceeds maximum.",
function );
return( -1 );
}
if( record_data_size < sizeof( evt_record_end_of_file_t ) )
{
libcerror_error_set(
error,
LIBCERROR_ERROR_DOMAIN_RUNTIME,
LIBCERROR_RUNTIME_ERROR_VALUE_OUT_OF_BOUNDS,
"%s: record data size value out of bounds.",
function );
return( -1 );
}
byte_stream_copy_to_uint32_little_endian(
( (evt_record_end_of_file_t *) record_data )->size,
size );
byte_stream_copy_to_uint32_little_endian(
( (evt_record_end_of_file_t *) record_data )->size_copy,
size_copy );
#if defined( HAVE_DEBUG_OUTPUT )
if( libcnotify_verbose != 0 )
{
libcnotify_printf(
"%s: size\t\t\t\t: %" PRIu32 "\n",
function,
size );
byte_stream_copy_to_uint32_little_endian(
( (evt_record_end_of_file_t *) record_data )->signature1,
value_32bit );
libcnotify_printf(
"%s: signature1\t\t\t: 0x%08" PRIx32 "\n",
function,
value_32bit );
byte_stream_copy_to_uint32_little_endian(
( (evt_record_end_of_file_t *) record_data )->signature2,
value_32bit );
libcnotify_printf(
"%s: signature2\t\t\t: 0x%08" PRIx32 "\n",
function,
value_32bit );
byte_stream_copy_to_uint32_little_endian(
( (evt_record_end_of_file_t *) record_data )->signature3,
value_32bit );
libcnotify_printf(
"%s: signature3\t\t\t: 0x%08" PRIx32 "\n",
function,
value_32bit );
byte_stream_copy_to_uint32_little_endian(
( (evt_record_end_of_file_t *) record_data )->signature4,
value_32bit );
libcnotify_printf(
"%s: signature4\t\t\t: 0x%08" PRIx32 "\n",
function,
value_32bit );
byte_stream_copy_to_uint32_little_endian(
( (evt_record_end_of_file_t *) record_data )->first_record_offset,
value_32bit );
libcnotify_printf(
"%s: first record offset\t\t: 0x%08" PRIx32 "\n",
function,
value_32bit );
byte_stream_copy_to_uint32_little_endian(
( (evt_record_end_of_file_t *) record_data )->end_of_file_record_offset,
value_32bit );
libcnotify_printf(
"%s: end of file record offset\t: 0x%08" PRIx32 "\n",
function,
value_32bit );
byte_stream_copy_to_uint32_little_endian(
( (evt_record_end_of_file_t *) record_data )->last_record_number,
value_32bit );
libcnotify_printf(
"%s: last record number\t\t: %" PRIu32 "\n",
function,
value_32bit );
byte_stream_copy_to_uint32_little_endian(
( (evt_record_end_of_file_t *) record_data )->first_record_number,
value_32bit );
libcnotify_printf(
"%s: first record number\t\t: %" PRIu32 "\n",
function,
value_32bit );
libcnotify_printf(
"%s: size copy\t\t\t: %" PRIu32 "\n",
function,
size_copy );
libcnotify_printf(
"\n" );
}
#endif
if( size != size_copy )
{
libcerror_error_set(
error,
LIBCERROR_ERROR_DOMAIN_INPUT,
LIBCERROR_INPUT_ERROR_VALUE_MISMATCH,
"%s: value mismatch for size and size copy.",
function );
return( -1 );
}
if( record_data_size != (size_t) size )
{
libcerror_error_set(
error,
LIBCERROR_ERROR_DOMAIN_INPUT,
LIBCERROR_INPUT_ERROR_VALUE_MISMATCH,
"%s: value mismatch for record data size and size.",
function );
return( -1 );
}
/* TODO correct values in IO handle if necessary */
return( 1 );
}
| 0
|
406,262
|
COMPAT_SYSCALL_DEFINE5(waitid,
int, which, compat_pid_t, pid,
struct compat_siginfo __user *, infop, int, options,
struct compat_rusage __user *, uru)
{
struct rusage ru;
struct waitid_info info = {.status = 0};
long err = kernel_waitid(which, pid, &info, options, uru ? &ru : NULL);
int signo = 0;
if (err > 0) {
signo = SIGCHLD;
err = 0;
if (uru) {
/* kernel_waitid() overwrites everything in ru */
if (COMPAT_USE_64BIT_TIME)
err = copy_to_user(uru, &ru, sizeof(ru));
else
err = put_compat_rusage(&ru, uru);
if (err)
return -EFAULT;
}
}
if (!infop)
return err;
if (!access_ok(VERIFY_WRITE, infop, sizeof(*infop)))
goto Efault;
user_access_begin();
unsafe_put_user(signo, &infop->si_signo, Efault);
unsafe_put_user(0, &infop->si_errno, Efault);
unsafe_put_user(info.cause, &infop->si_code, Efault);
unsafe_put_user(info.pid, &infop->si_pid, Efault);
unsafe_put_user(info.uid, &infop->si_uid, Efault);
unsafe_put_user(info.status, &infop->si_status, Efault);
user_access_end();
return err;
Efault:
user_access_end();
return -EFAULT;
}
| 0
|
442,987
|
static void update_cr0_intercept(struct vcpu_svm *svm)
{
ulong gcr0 = svm->vcpu.arch.cr0;
u64 *hcr0 = &svm->vmcb->save.cr0;
*hcr0 = (*hcr0 & ~SVM_CR0_SELECTIVE_MASK)
| (gcr0 & SVM_CR0_SELECTIVE_MASK);
mark_dirty(svm->vmcb, VMCB_CR);
if (gcr0 == *hcr0) {
clr_cr_intercept(svm, INTERCEPT_CR0_READ);
clr_cr_intercept(svm, INTERCEPT_CR0_WRITE);
} else {
set_cr_intercept(svm, INTERCEPT_CR0_READ);
set_cr_intercept(svm, INTERCEPT_CR0_WRITE);
}
}
| 0
|
21,827
|
IN_PROC_BROWSER_TEST_F ( VirtualKeyboardBrowserTest , HideKeyboardKeyTest ) {
RunTest ( base : : FilePath ( FILE_PATH_LITERAL ( "hide_keyboard_key_test.js" ) ) ) ;
}
| 0
|
305,897
|
void uwsgi_write_pidfile(char *pidfile_name) {
uwsgi_log("writing pidfile to %s\n", pidfile_name);
if (uwsgi_write_intfile(pidfile_name, (int) getpid())) {
uwsgi_log("could not write pidfile.\n");
}
}
| 0
|
491,742
|
ecma_date_date_from_time (ecma_number_t time) /**< time value */
{
JERRY_ASSERT (!ecma_number_is_nan (time));
int32_t year = ecma_date_year_from_time (time);
int32_t day_within_year = ecma_date_day_from_time (time) - ecma_date_day_from_year (year);
JERRY_ASSERT (day_within_year >= 0 && day_within_year < ECMA_DATE_DAYS_IN_LEAP_YEAR);
int32_t in_leap_year = ecma_date_in_leap_year (year);
int32_t month = 11;
for (int i = 1; i < 12; i++)
{
if (day_within_year < first_day_in_month[in_leap_year][i])
{
month = i - 1;
break;
}
}
return day_within_year + 1 - first_day_in_month[in_leap_year][month];
} /* ecma_date_date_from_time */
| 0
|
342,331
|
static abi_ulong setup_arg_pages(abi_ulong p, struct linux_binprm *bprm,
struct image_info *info)
{
abi_ulong stack_base, size, error;
int i;
/* Create enough stack to hold everything. If we don't use
* it for args, we'll use it for something else...
*/
size = guest_stack_size;
if (size < MAX_ARG_PAGES*TARGET_PAGE_SIZE)
size = MAX_ARG_PAGES*TARGET_PAGE_SIZE;
error = target_mmap(0,
size + qemu_host_page_size,
PROT_READ | PROT_WRITE,
MAP_PRIVATE | MAP_ANONYMOUS,
-1, 0);
if (error == -1) {
perror("stk mmap");
exit(-1);
}
/* we reserve one extra page at the top of the stack as guard */
target_mprotect(error + size, qemu_host_page_size, PROT_NONE);
info->stack_limit = error;
stack_base = error + size - MAX_ARG_PAGES*TARGET_PAGE_SIZE;
p += stack_base;
for (i = 0 ; i < MAX_ARG_PAGES ; i++) {
if (bprm->page[i]) {
info->rss++;
/* FIXME - check return value of memcpy_to_target() for failure */
memcpy_to_target(stack_base, bprm->page[i], TARGET_PAGE_SIZE);
free(bprm->page[i]);
}
stack_base += TARGET_PAGE_SIZE;
}
return p;
}
| 0
|
158,564
|
IRC_PROTOCOL_CALLBACK(008)
{
IRC_PROTOCOL_MIN_ARGS(4);
weechat_printf_date_tags (
irc_msgbuffer_get_target_buffer (server, argv[2], command, NULL, NULL),
date,
irc_protocol_tags (command, "irc_numeric", NULL, address),
_("%sServer notice mask for %s%s%s: %s"),
weechat_prefix ("network"),
irc_nick_color_for_msg (server, 1, NULL, argv[2]),
argv[2],
IRC_COLOR_RESET,
(argv_eol[3][0] == ':') ? argv_eol[3] + 1 : argv_eol[3]);
return WEECHAT_RC_OK;
}
| 0
|
476,831
|
static int nft_dup_netdev_offload(struct nft_offload_ctx *ctx,
struct nft_flow_rule *flow,
const struct nft_expr *expr)
{
const struct nft_dup_netdev *priv = nft_expr_priv(expr);
int oif = ctx->regs[priv->sreg_dev].data.data[0];
return nft_fwd_dup_netdev_offload(ctx, flow, FLOW_ACTION_MIRRED, oif);
}
| 0
|
338,569
|
target_ulong helper_rdhwr_performance(CPUMIPSState *env)
{
check_hwrena(env, 4);
return env->CP0_Performance0;
}
| 1
|
310,076
|
void FrameLoaderClient::dispatchDidFailProvisionalLoad(const ResourceError& error)
{
dispatchDidFailLoad(error);
}
| 0
|
165,170
|
void RenderWidgetHostImpl::StopInputEventAckTimeout() {
if (input_event_ack_timeout_)
input_event_ack_timeout_->Stop();
if (!input_event_ack_start_time_.is_null()) {
base::TimeDelta elapsed = clock_->NowTicks() - input_event_ack_start_time_;
const base::TimeDelta kMinimumHangTimeToReport =
base::TimeDelta::FromSeconds(5);
if (elapsed >= kMinimumHangTimeToReport)
UMA_HISTOGRAM_LONG_TIMES("Renderer.Hung.Duration", elapsed);
input_event_ack_start_time_ = TimeTicks();
}
RendererIsResponsive();
}
| 0
|
437,493
|
static int io_accept(struct io_kiocb *req, const struct io_uring_sqe *sqe,
struct io_kiocb **nxt, bool force_nonblock)
{
#if defined(CONFIG_NET)
struct sockaddr __user *addr;
int __user *addr_len;
unsigned file_flags;
int flags, ret;
if (unlikely(req->ctx->flags & (IORING_SETUP_IOPOLL|IORING_SETUP_SQPOLL)))
return -EINVAL;
if (sqe->ioprio || sqe->off || sqe->len || sqe->buf_index)
return -EINVAL;
addr = (struct sockaddr __user *) (unsigned long) READ_ONCE(sqe->addr);
addr_len = (int __user *) (unsigned long) READ_ONCE(sqe->addr2);
flags = READ_ONCE(sqe->accept_flags);
file_flags = force_nonblock ? O_NONBLOCK : 0;
ret = __sys_accept4_file(req->file, file_flags, addr, addr_len, flags);
if (ret == -EAGAIN && force_nonblock) {
req->work.flags |= IO_WQ_WORK_NEEDS_FILES;
return -EAGAIN;
}
if (ret == -ERESTARTSYS)
ret = -EINTR;
if (ret < 0 && (req->flags & REQ_F_LINK))
req->flags |= REQ_F_FAIL_LINK;
io_cqring_add_event(req, ret);
io_put_req_find_next(req, nxt);
return 0;
#else
return -EOPNOTSUPP;
#endif
}
| 0
|
317,000
|
ValidityMessage::ValidityMessage(const base::string16& text, bool sure)
: text(text), sure(sure) {}
| 0
|
223,513
|
find_clp_in_name_tree(struct xdr_netobj *name, struct rb_root *root)
{
int cmp;
struct rb_node *node = root->rb_node;
struct nfs4_client *clp;
while (node) {
clp = rb_entry(node, struct nfs4_client, cl_namenode);
cmp = compare_blob(&clp->cl_name, name);
if (cmp > 0)
node = node->rb_left;
else if (cmp < 0)
node = node->rb_right;
else
return clp;
}
return NULL;
}
| 0
|
26,445
|
static gboolean gst_asf_demux_check_buffer_is_header ( GstASFDemux * demux , GstBuffer * buf ) {
AsfObject obj ;
GstMapInfo map ;
gboolean valid ;
g_assert ( buf != NULL ) ;
GST_LOG_OBJECT ( demux , "Checking if buffer is a header" ) ;
gst_buffer_map ( buf , & map , GST_MAP_READ ) ;
if ( map . size < ASF_OBJECT_HEADER_SIZE ) {
gst_buffer_unmap ( buf , & map ) ;
return FALSE ;
}
valid = asf_demux_peek_object ( demux , map . data , ASF_OBJECT_HEADER_SIZE , & obj , TRUE ) ;
gst_buffer_unmap ( buf , & map ) ;
if ( valid && obj . id == ASF_OBJ_HEADER ) {
return TRUE ;
}
return FALSE ;
}
| 0
|
489,174
|
GF_Err btrt_box_dump(GF_Box *a, FILE * trace)
{
GF_BitRateBox *p = (GF_BitRateBox*)a;
gf_isom_box_dump_start(a, "BitRateBox", trace);
gf_fprintf(trace, "BufferSizeDB=\"%d\" avgBitRate=\"%d\" maxBitRate=\"%d\">\n", p->bufferSizeDB, p->avgBitrate, p->maxBitrate);
gf_isom_box_dump_done("BitRateBox", a, trace);
return GF_OK;
}
| 0
|
213,123
|
void DownloadManagerImpl::InterceptNavigation(
std::unique_ptr<network::ResourceRequest> resource_request,
std::vector<GURL> url_chain,
scoped_refptr<network::ResourceResponse> response,
network::mojom::URLLoaderClientEndpointsPtr url_loader_client_endpoints,
net::CertStatus cert_status,
int frame_tree_node_id) {
DCHECK_CURRENTLY_ON(BrowserThread::UI);
if (!delegate_) {
DropDownload();
return;
}
const GURL& url = resource_request->url;
const std::string& method = resource_request->method;
ResourceRequestInfo::WebContentsGetter web_contents_getter =
base::BindRepeating(WebContents::FromFrameTreeNodeId, frame_tree_node_id);
base::OnceCallback<void(bool /* download allowed */)>
on_download_checks_done = base::BindOnce(
&DownloadManagerImpl::InterceptNavigationOnChecksComplete,
weak_factory_.GetWeakPtr(), web_contents_getter,
std::move(resource_request), std::move(url_chain),
std::move(response), cert_status,
std::move(url_loader_client_endpoints));
delegate_->CheckDownloadAllowed(std::move(web_contents_getter), url, method,
std::move(on_download_checks_done));
}
| 0
|
429,378
|
long writeFile(const DataBuf& buf, const std::wstring& wpath)
{
FileIo file(wpath);
if (file.open("wb") != 0) {
throw WError(kerFileOpenFailed, wpath, "wb", strError().c_str());
}
return file.write(buf.pData_, buf.size_);
}
| 0
|
387,045
|
static void ssl_ticket_keys_free( ssl_ticket_keys *tkeys )
{
aes_free( &tkeys->enc );
aes_free( &tkeys->dec );
polarssl_zeroize( tkeys, sizeof(ssl_ticket_keys) );
}
| 0
|
74,567
|
void kvm_exit(void)
{
kvm_exit_debug();
misc_deregister(&kvm_dev);
kmem_cache_destroy(kvm_vcpu_cache);
kvm_async_pf_deinit();
unregister_syscore_ops(&kvm_syscore_ops);
unregister_reboot_notifier(&kvm_reboot_notifier);
unregister_cpu_notifier(&kvm_cpu_notifier);
on_each_cpu(hardware_disable_nolock, NULL, 1);
kvm_arch_hardware_unsetup();
kvm_arch_exit();
kvm_irqfd_exit();
free_cpumask_var(cpus_hardware_enabled);
}
| 0
|
93,993
|
static int dictIndexOf(tr_variant const* dict, tr_quark const key)
{
if (tr_variantIsDict(dict))
{
for (size_t i = 0; i < dict->val.l.count; ++i)
{
if (dict->val.l.vals[i].key == key)
{
return (int)i;
}
}
}
return -1;
}
| 0
|
22,958
|
static void vvalue_strbuf_append_r8 ( wmem_strbuf_t * strbuf , void * ptr ) {
double r8 = * ( double * ) ptr ;
wmem_strbuf_append_printf ( strbuf , "%g" , r8 ) ;
}
| 0
|
423,403
|
file_regfree(file_regex_t *rx)
{
if (rx->rc == 0)
regfree(&rx->rx);
#ifdef USE_C_LOCALE
(void)uselocale(rx->old_lc_ctype);
freelocale(rx->c_lc_ctype);
#else
(void)setlocale(LC_CTYPE, rx->old_lc_ctype);
#endif
}
| 0
|
165,758
|
NaClProcessHost::NaClProcessHost(const std::wstring& url)
: BrowserChildProcessHost(NACL_LOADER_PROCESS),
reply_msg_(NULL),
internal_(new NaClInternal()),
running_on_wow64_(false),
ALLOW_THIS_IN_INITIALIZER_LIST(callback_factory_(this)) {
set_name(WideToUTF16Hack(url));
#if defined(OS_WIN)
running_on_wow64_ = (base::win::OSInfo::GetInstance()->wow64_status() ==
base::win::OSInfo::WOW64_ENABLED);
#endif
}
| 0
|
321,007
|
static void vp56_decode_mb(VP56Context *s, int row, int col, int is_alpha)
{
AVFrame *frame_current, *frame_ref;
VP56mb mb_type;
VP56Frame ref_frame;
int b, ab, b_max, plane, off;
if (s->framep[VP56_FRAME_CURRENT]->key_frame)
mb_type = VP56_MB_INTRA;
else
mb_type = vp56_decode_mv(s, row, col);
ref_frame = vp56_reference_frame[mb_type];
s->dsp.clear_blocks(*s->block_coeff);
s->parse_coeff(s);
vp56_add_predictors_dc(s, ref_frame);
frame_current = s->framep[VP56_FRAME_CURRENT];
frame_ref = s->framep[ref_frame];
if (mb_type != VP56_MB_INTRA && !frame_ref->data[0])
return;
ab = 6*is_alpha;
b_max = 6 - 2*is_alpha;
switch (mb_type) {
case VP56_MB_INTRA:
for (b=0; b<b_max; b++) {
plane = ff_vp56_b2p[b+ab];
s->dsp.idct_put(frame_current->data[plane] + s->block_offset[b],
s->stride[plane], s->block_coeff[b]);
}
break;
case VP56_MB_INTER_NOVEC_PF:
case VP56_MB_INTER_NOVEC_GF:
for (b=0; b<b_max; b++) {
plane = ff_vp56_b2p[b+ab];
off = s->block_offset[b];
s->dsp.put_pixels_tab[1][0](frame_current->data[plane] + off,
frame_ref->data[plane] + off,
s->stride[plane], 8);
s->dsp.idct_add(frame_current->data[plane] + off,
s->stride[plane], s->block_coeff[b]);
}
break;
case VP56_MB_INTER_DELTA_PF:
case VP56_MB_INTER_V1_PF:
case VP56_MB_INTER_V2_PF:
case VP56_MB_INTER_DELTA_GF:
case VP56_MB_INTER_4V:
case VP56_MB_INTER_V1_GF:
case VP56_MB_INTER_V2_GF:
for (b=0; b<b_max; b++) {
int x_off = b==1 || b==3 ? 8 : 0;
int y_off = b==2 || b==3 ? 8 : 0;
plane = ff_vp56_b2p[b+ab];
vp56_mc(s, b, plane, frame_ref->data[plane], s->stride[plane],
16*col+x_off, 16*row+y_off);
s->dsp.idct_add(frame_current->data[plane] + s->block_offset[b],
s->stride[plane], s->block_coeff[b]);
}
break;
}
}
| 0
|
474,694
|
get_cached_region (GeglOperation *operation,
const GeglRectangle *roi)
{
return get_bounding_box (operation);
}
| 0
|
277,903
|
MagickExport const IndexPacket *GetVirtualIndexQueue(const Image *image)
{
CacheInfo
*restrict cache_info;
const int
id = GetOpenMPThreadId();
assert(image != (const Image *) NULL);
assert(image->signature == MagickSignature);
assert(image->cache != (Cache) NULL);
cache_info=(CacheInfo *) image->cache;
assert(cache_info->signature == MagickSignature);
if (cache_info->methods.get_virtual_indexes_from_handler !=
(GetVirtualIndexesFromHandler) NULL)
return(cache_info->methods.get_virtual_indexes_from_handler(image));
assert(id < (int) cache_info->number_threads);
return(GetVirtualIndexesFromNexus(cache_info,cache_info->nexus_info[id]));
}
| 0
|
392,317
|
bool MillerRabin_Test::is_witness(const BigInt& a)
{
if(a < 2 || a >= n_minus_1)
throw Invalid_Argument("Bad size for nonce in Miller-Rabin test");
BigInt y = pow_mod(a);
if(y == 1 || y == n_minus_1)
return false;
for(size_t i = 1; i != s; ++i)
{
y = reducer.square(y);
if(y == 1) // found a non-trivial square root
return true;
if(y == n_minus_1) // -1, trivial square root, so give up
return false;
}
// If we reached here then n fails the Fermat test
return true;
}
| 0
|
325,045
|
static void vnc_dpy_setdata(DisplayChangeListener *dcl,
DisplayState *ds)
{
VncDisplay *vd = ds->opaque;
qemu_pixman_image_unref(vd->guest.fb);
vd->guest.fb = pixman_image_ref(ds->surface->image);
vd->guest.format = ds->surface->format;
vnc_dpy_update(dcl, ds, 0, 0, ds_get_width(ds), ds_get_height(ds));
}
| 1
|
268,508
|
TEST_F(SslContextImplTest, TestCipherSuites) {
const std::string yaml = R"EOF(
common_tls_context:
tls_params:
cipher_suites: "-ALL:+[AES128-SHA|BOGUS1-SHA256]:BOGUS2-SHA:AES256-SHA"
)EOF";
envoy::extensions::transport_sockets::tls::v3::UpstreamTlsContext tls_context;
TestUtility::loadFromYaml(TestEnvironment::substitute(yaml), tls_context);
ClientContextConfigImpl cfg(tls_context, factory_context_);
EXPECT_THROW_WITH_MESSAGE(
manager_.createSslClientContext(store_, cfg, nullptr), EnvoyException,
"Failed to initialize cipher suites "
"-ALL:+[AES128-SHA|BOGUS1-SHA256]:BOGUS2-SHA:AES256-SHA. The following "
"ciphers were rejected when tried individually: BOGUS1-SHA256, BOGUS2-SHA");
}
| 0
|
420,001
|
purge_if_name_removed(const gs_memory_t *mem, cached_char * cc, void *vsave)
{
return alloc_name_index_is_since_save(mem, cc->code, vsave);
}
| 0
|
376,228
|
void sctp_assoc_update_retran_path(struct sctp_association *asoc)
{
struct sctp_transport *t, *next;
struct list_head *head = &asoc->peer.transport_addr_list;
struct list_head *pos;
/* Find the next transport in a round-robin fashion. */
t = asoc->peer.retran_path;
pos = &t->transports;
next = NULL;
while (1) {
/* Skip the head. */
if (pos->next == head)
pos = head->next;
else
pos = pos->next;
t = list_entry(pos, struct sctp_transport, transports);
/* Try to find an active transport. */
if ((t->state == SCTP_ACTIVE) ||
(t->state == SCTP_UNKNOWN)) {
break;
} else {
/* Keep track of the next transport in case
* we don't find any active transport.
*/
if (!next)
next = t;
}
/* We have exhausted the list, but didn't find any
* other active transports. If so, use the next
* transport.
*/
if (t == asoc->peer.retran_path) {
t = next;
break;
}
}
asoc->peer.retran_path = t;
SCTP_DEBUG_PRINTK_IPADDR("sctp_assoc_update_retran_path:association"
" %p addr: ",
" port: %d\n",
asoc,
(&t->ipaddr),
ntohs(t->ipaddr.v4.sin_port));
}
| 0
|
198,438
|
void WebRuntimeFeatures::EnableWebGLImageChromium(bool enable) {
RuntimeEnabledFeatures::SetWebGLImageChromiumEnabled(enable);
}
| 0
|
473,493
|
int nsim_bpf_init(struct netdevsim *ns)
{
struct dentry *ddir = ns->nsim_dev_port->ddir;
int err;
err = bpf_offload_dev_netdev_register(ns->nsim_dev->bpf_dev,
ns->netdev);
if (err)
return err;
debugfs_create_u32("bpf_offloaded_id", 0400, ddir,
&ns->bpf_offloaded_id);
ns->bpf_tc_accept = true;
debugfs_create_bool("bpf_tc_accept", 0600, ddir,
&ns->bpf_tc_accept);
debugfs_create_bool("bpf_tc_non_bound_accept", 0600, ddir,
&ns->bpf_tc_non_bound_accept);
ns->bpf_xdpdrv_accept = true;
debugfs_create_bool("bpf_xdpdrv_accept", 0600, ddir,
&ns->bpf_xdpdrv_accept);
ns->bpf_xdpoffload_accept = true;
debugfs_create_bool("bpf_xdpoffload_accept", 0600, ddir,
&ns->bpf_xdpoffload_accept);
ns->bpf_map_accept = true;
debugfs_create_bool("bpf_map_accept", 0600, ddir,
&ns->bpf_map_accept);
return 0;
}
| 0
|
101,535
|
_movU(int n)
{
int i, m = searchKeyNum();
if (Currentbuf->firstLine == NULL)
return;
for (i = 0; i < m; i++)
cursorUp(Currentbuf, n);
displayBuffer(Currentbuf, B_NORMAL);
}
| 0
|
271,143
|
int BlackPreservingSampler(register const cmsUInt16Number In[], register cmsUInt16Number Out[], register void* Cargo)
{
int i;
cmsFloat32Number Inf[4], Outf[4];
cmsFloat32Number LabK[4];
cmsFloat64Number SumCMY, SumCMYK, Error, Ratio;
cmsCIELab ColorimetricLab, BlackPreservingLab;
PreserveKPlaneParams* bp = (PreserveKPlaneParams*) Cargo;
// Convert from 16 bits to floating point
for (i=0; i < 4; i++)
Inf[i] = (cmsFloat32Number) (In[i] / 65535.0);
// Get the K across Tone curve
LabK[3] = cmsEvalToneCurveFloat(bp ->KTone, Inf[3]);
// If going across black only, keep black only
if (In[0] == 0 && In[1] == 0 && In[2] == 0) {
Out[0] = Out[1] = Out[2] = 0;
Out[3] = _cmsQuickSaturateWord(LabK[3] * 65535.0);
return TRUE;
}
// Try the original transform,
cmsPipelineEvalFloat( Inf, Outf, bp ->cmyk2cmyk);
// Store a copy of the floating point result into 16-bit
for (i=0; i < 4; i++)
Out[i] = _cmsQuickSaturateWord(Outf[i] * 65535.0);
// Maybe K is already ok (mostly on K=0)
if ( fabs(Outf[3] - LabK[3]) < (3.0 / 65535.0) ) {
return TRUE;
}
// K differ, mesure and keep Lab measurement for further usage
// this is done in relative colorimetric intent
cmsDoTransform(bp->hProofOutput, Out, &ColorimetricLab, 1);
// Is not black only and the transform doesn't keep black.
// Obtain the Lab of output CMYK. After that we have Lab + K
cmsDoTransform(bp ->cmyk2Lab, Outf, LabK, 1);
// Obtain the corresponding CMY using reverse interpolation
// (K is fixed in LabK[3])
if (!cmsPipelineEvalReverseFloat(LabK, Outf, Outf, bp ->LabK2cmyk)) {
// Cannot find a suitable value, so use colorimetric xform
// which is already stored in Out[]
return TRUE;
}
// Make sure to pass thru K (which now is fixed)
Outf[3] = LabK[3];
// Apply TAC if needed
SumCMY = Outf[0] + Outf[1] + Outf[2];
SumCMYK = SumCMY + Outf[3];
if (SumCMYK > bp ->MaxTAC) {
Ratio = 1 - ((SumCMYK - bp->MaxTAC) / SumCMY);
if (Ratio < 0)
Ratio = 0;
}
else
Ratio = 1.0;
Out[0] = _cmsQuickSaturateWord(Outf[0] * Ratio * 65535.0); // C
Out[1] = _cmsQuickSaturateWord(Outf[1] * Ratio * 65535.0); // M
Out[2] = _cmsQuickSaturateWord(Outf[2] * Ratio * 65535.0); // Y
Out[3] = _cmsQuickSaturateWord(Outf[3] * 65535.0);
// Estimate the error (this goes 16 bits to Lab DBL)
cmsDoTransform(bp->hProofOutput, Out, &BlackPreservingLab, 1);
Error = cmsDeltaE(&ColorimetricLab, &BlackPreservingLab);
if (Error > bp -> MaxError)
bp->MaxError = Error;
return TRUE;
}
| 0
|
495,850
|
static int extract_url (const char *url, int default_port,
struct request_s *request)
{
char *p;
int port;
/* Split the URL on the slash to separate host from path */
p = strchr (url, '/');
if (p != NULL) {
int len;
len = p - url;
request->host = (char *) safemalloc (len + 1);
memcpy (request->host, url, len);
request->host[len] = '\0';
request->path = safestrdup (p);
} else {
request->host = safestrdup (url);
request->path = safestrdup ("/");
}
if (!request->host || !request->path)
goto ERROR_EXIT;
/* Remove the username/password if they're present */
strip_username_password (request->host);
/* Find a proper port in www.site.com:8001 URLs */
port = strip_return_port (request->host);
request->port = (port != 0) ? port : default_port;
/* Remove any surrounding '[' and ']' from IPv6 literals */
p = strrchr (request->host, ']');
if (p && (*(request->host) == '[')) {
memmove(request->host, request->host + 1,
strlen(request->host) - 2);
*p = '\0';
p--;
*p = '\0';
}
return 0;
ERROR_EXIT:
if (request->host)
safefree (request->host);
if (request->path)
safefree (request->path);
return -1;
}
| 0
|
384,410
|
static void ide_resize_cb(void *opaque)
{
IDEState *s = opaque;
uint64_t nb_sectors;
if (!s->identify_set) {
return;
}
blk_get_geometry(s->blk, &nb_sectors);
s->nb_sectors = nb_sectors;
/* Update the identify data buffer. */
if (s->drive_kind == IDE_CFATA) {
ide_cfata_identify_size(s);
} else {
/* IDE_CD uses a different set of callbacks entirely. */
assert(s->drive_kind != IDE_CD);
ide_identify_size(s);
}
}
| 0
|
381,539
|
HttpTransact::HandleCacheOpenReadHitFreshness(State* s)
{
CacheHTTPInfo *&obj = s->cache_info.object_read;
ink_release_assert((s->request_sent_time == UNDEFINED_TIME) && (s->response_received_time == UNDEFINED_TIME));
DebugTxn("http_seq", "[HttpTransact::HandleCacheOpenReadHitFreshness] Hit in cache");
if (delete_all_document_alternates_and_return(s, true)) {
DebugTxn("http_trans", "[HandleCacheOpenReadHitFreshness] Delete and return");
s->cache_info.action = CACHE_DO_DELETE;
s->next_action = HttpTransact::SM_ACTION_INTERNAL_CACHE_DELETE;
return;
}
s->request_sent_time = obj->request_sent_time_get();
s->response_received_time = obj->response_received_time_get();
// There may be clock skew if one of the machines
// went down and we do not have the correct delta
// for it. this is just to deal with the effects
// of the skew by setting minimum and maximum times
// so that ages are not negative, etc.
s->request_sent_time = min(s->client_request_time, s->request_sent_time);
s->response_received_time = min(s->client_request_time, s->response_received_time);
ink_assert(s->request_sent_time <= s->response_received_time);
DebugTxn("http_trans", "[HandleCacheOpenReadHitFreshness] request_sent_time : %" PRId64,
(int64_t)s->request_sent_time);
DebugTxn("http_trans", "[HandleCacheOpenReadHitFreshness] response_received_time : %" PRId64,
(int64_t)s->response_received_time);
// if the plugin has already decided the freshness, we don't need to
// do it again
if (s->cache_lookup_result == HttpTransact::CACHE_LOOKUP_NONE) {
// is the document still fresh enough to be served back to
// the client without revalidation?
Freshness_t freshness = what_is_document_freshness(s, &s->hdr_info.client_request, obj->response_get());
switch (freshness) {
case FRESHNESS_FRESH:
DebugTxn("http_seq", "[HttpTransact::HandleCacheOpenReadHitFreshness] " "Fresh copy");
s->cache_lookup_result = HttpTransact::CACHE_LOOKUP_HIT_FRESH;
break;
case FRESHNESS_WARNING:
DebugTxn("http_seq", "[HttpTransact::HandleCacheOpenReadHitFreshness] " "Heuristic-based Fresh copy");
s->cache_lookup_result = HttpTransact::CACHE_LOOKUP_HIT_WARNING;
break;
case FRESHNESS_STALE:
DebugTxn("http_seq", "[HttpTransact::HandleCacheOpenReadHitFreshness] " "Stale in cache");
s->cache_lookup_result = HttpTransact::CACHE_LOOKUP_HIT_STALE;
s->is_revalidation_necessary = true; // to identify a revalidation occurrence
break;
default:
ink_assert(!("what_is_document_freshness has returned unsupported code."));
break;
}
}
ink_assert(s->cache_lookup_result != HttpTransact::CACHE_LOOKUP_MISS);
if (s->cache_lookup_result == HttpTransact::CACHE_LOOKUP_HIT_STALE)
SET_VIA_STRING(VIA_DETAIL_CACHE_LOOKUP, VIA_DETAIL_MISS_EXPIRED);
if (!s->force_dns) { // If DNS is not performed before
if (need_to_revalidate(s)) {
TRANSACT_RETURN(SM_ACTION_API_CACHE_LOOKUP_COMPLETE, CallOSDNSLookup); // content needs to be revalidated and we did not perform a dns ....calling DNS lookup
} else { // document can be served can cache
TRANSACT_RETURN(SM_ACTION_API_CACHE_LOOKUP_COMPLETE, HttpTransact::HandleCacheOpenReadHit);
}
} else { // we have done dns . Its up to HandleCacheOpenReadHit to decide to go OS or serve from cache
TRANSACT_RETURN(SM_ACTION_API_CACHE_LOOKUP_COMPLETE, HttpTransact::HandleCacheOpenReadHit);
}
}
| 0
|
84,644
|
xfs_inode_from_disk(
struct xfs_inode *ip,
struct xfs_dinode *from)
{
struct xfs_icdinode *to = &ip->i_d;
struct inode *inode = VFS_I(ip);
/*
* Convert v1 inodes immediately to v2 inode format as this is the
* minimum inode version format we support in the rest of the code.
*/
to->di_version = from->di_version;
if (to->di_version == 1) {
set_nlink(inode, be16_to_cpu(from->di_onlink));
to->di_projid_lo = 0;
to->di_projid_hi = 0;
to->di_version = 2;
} else {
set_nlink(inode, be32_to_cpu(from->di_nlink));
to->di_projid_lo = be16_to_cpu(from->di_projid_lo);
to->di_projid_hi = be16_to_cpu(from->di_projid_hi);
}
to->di_format = from->di_format;
to->di_uid = be32_to_cpu(from->di_uid);
to->di_gid = be32_to_cpu(from->di_gid);
to->di_flushiter = be16_to_cpu(from->di_flushiter);
/*
* Time is signed, so need to convert to signed 32 bit before
* storing in inode timestamp which may be 64 bit. Otherwise
* a time before epoch is converted to a time long after epoch
* on 64 bit systems.
*/
inode->i_atime.tv_sec = (int)be32_to_cpu(from->di_atime.t_sec);
inode->i_atime.tv_nsec = (int)be32_to_cpu(from->di_atime.t_nsec);
inode->i_mtime.tv_sec = (int)be32_to_cpu(from->di_mtime.t_sec);
inode->i_mtime.tv_nsec = (int)be32_to_cpu(from->di_mtime.t_nsec);
inode->i_ctime.tv_sec = (int)be32_to_cpu(from->di_ctime.t_sec);
inode->i_ctime.tv_nsec = (int)be32_to_cpu(from->di_ctime.t_nsec);
inode->i_generation = be32_to_cpu(from->di_gen);
inode->i_mode = be16_to_cpu(from->di_mode);
to->di_size = be64_to_cpu(from->di_size);
to->di_nblocks = be64_to_cpu(from->di_nblocks);
to->di_extsize = be32_to_cpu(from->di_extsize);
to->di_nextents = be32_to_cpu(from->di_nextents);
to->di_anextents = be16_to_cpu(from->di_anextents);
to->di_forkoff = from->di_forkoff;
to->di_aformat = from->di_aformat;
to->di_dmevmask = be32_to_cpu(from->di_dmevmask);
to->di_dmstate = be16_to_cpu(from->di_dmstate);
to->di_flags = be16_to_cpu(from->di_flags);
if (to->di_version == 3) {
inode_set_iversion_queried(inode,
be64_to_cpu(from->di_changecount));
to->di_crtime.t_sec = be32_to_cpu(from->di_crtime.t_sec);
to->di_crtime.t_nsec = be32_to_cpu(from->di_crtime.t_nsec);
to->di_flags2 = be64_to_cpu(from->di_flags2);
to->di_cowextsize = be32_to_cpu(from->di_cowextsize);
}
}
| 0
|
54,330
|
static PyObject *__pyx_pw_17clickhouse_driver_14bufferedreader_14BufferedReader_6buffer_1__get__(PyObject *__pyx_v_self) {
PyObject *__pyx_r = 0;
__Pyx_RefNannyDeclarations
__Pyx_RefNannySetupContext("__get__ (wrapper)", 0);
__pyx_r = __pyx_pf_17clickhouse_driver_14bufferedreader_14BufferedReader_6buffer___get__(((struct __pyx_obj_17clickhouse_driver_14bufferedreader_BufferedReader *)__pyx_v_self));
/* function exit code */
__Pyx_RefNannyFinishContext();
return __pyx_r;
}
| 0
|
50,636
|
static int rb_check_pages(struct ring_buffer_per_cpu *cpu_buffer)
{
struct list_head *head = cpu_buffer->pages;
struct buffer_page *bpage, *tmp;
/* Reset the head page if it exists */
if (cpu_buffer->head_page)
rb_set_head_page(cpu_buffer);
rb_head_page_deactivate(cpu_buffer);
if (RB_WARN_ON(cpu_buffer, head->next->prev != head))
return -1;
if (RB_WARN_ON(cpu_buffer, head->prev->next != head))
return -1;
if (rb_check_list(cpu_buffer, head))
return -1;
list_for_each_entry_safe(bpage, tmp, head, list) {
if (RB_WARN_ON(cpu_buffer,
bpage->list.next->prev != &bpage->list))
return -1;
if (RB_WARN_ON(cpu_buffer,
bpage->list.prev->next != &bpage->list))
return -1;
if (rb_check_list(cpu_buffer, &bpage->list))
return -1;
}
rb_head_page_activate(cpu_buffer);
return 0;
}
| 0
|
386,913
|
do_move (GVfsBackend *backend,
GVfsJobMove *job,
const char *source,
const char *destination,
GFileCopyFlags flags,
GFileProgressCallback progress_callback,
gpointer progress_callback_data)
{
SoupMessage *msg;
SoupURI *source_uri;
SoupURI *target_uri;
guint status;
GFileType source_ft, target_ft;
GError *error = NULL;
gboolean res;
if (flags & G_FILE_COPY_BACKUP)
{
if (flags & G_FILE_COPY_NO_FALLBACK_FOR_MOVE)
{
g_vfs_job_failed_literal (G_VFS_JOB (job),
G_IO_ERROR,
G_IO_ERROR_CANT_CREATE_BACKUP,
_("Backups not supported"));
}
else
{
/* Return G_IO_ERROR_NOT_SUPPORTED instead of G_IO_ERROR_CANT_CREATE_BACKUP
* to be proceeded with copy and delete fallback (see g_file_move). */
g_vfs_job_failed_literal (G_VFS_JOB (job),
G_IO_ERROR,
G_IO_ERROR_NOT_SUPPORTED,
"Operation not supported");
}
return;
}
source_uri = g_vfs_backend_dav_uri_for_path (backend, source, FALSE);
msg = soup_message_new_from_uri (SOUP_METHOD_MOVE, source_uri);
target_uri = g_vfs_backend_dav_uri_for_path (backend, destination, FALSE);
res = stat_location (backend, target_uri, &target_ft, NULL, &error);
if (!res && !g_error_matches (error, G_IO_ERROR, G_IO_ERROR_NOT_FOUND))
{
g_vfs_job_failed_from_error (G_VFS_JOB (job), error);
g_error_free (error);
return;
}
if (res)
{
if (flags & G_FILE_COPY_OVERWRITE)
{
res = stat_location (backend, source_uri, &source_ft, NULL, &error);
if (res)
{
if (target_ft == G_FILE_TYPE_DIRECTORY)
{
if (source_ft == G_FILE_TYPE_DIRECTORY)
g_vfs_job_failed_literal (G_VFS_JOB(job),
G_IO_ERROR,
G_IO_ERROR_WOULD_MERGE,
_("Can't move directory over directory"));
else
g_vfs_job_failed_literal (G_VFS_JOB(job),
G_IO_ERROR,
G_IO_ERROR_IS_DIRECTORY,
_("Can't move over directory"));
return;
}
else if (source_ft == G_FILE_TYPE_DIRECTORY)
{
/* Overwriting a file with a directory, first remove the
* file */
SoupMessage *msg;
msg = soup_message_new_from_uri (SOUP_METHOD_DELETE,
target_uri);
status = g_vfs_backend_dav_send_message (backend, msg);
if (!SOUP_STATUS_IS_SUCCESSFUL (status))
{
http_job_failed (G_VFS_JOB (job), msg);
g_object_unref (msg);
return;
}
g_object_unref (msg);
}
}
else
{
g_vfs_job_failed_from_error (G_VFS_JOB (job), error);
g_error_free (error);
return;
}
}
else
{
g_vfs_job_failed_literal (G_VFS_JOB(job),
G_IO_ERROR,
G_IO_ERROR_EXISTS,
_("Target file exists"));
}
}
message_add_destination_header (msg, target_uri);
message_add_overwrite_header (msg, flags & G_FILE_COPY_OVERWRITE);
status = g_vfs_backend_dav_send_message (backend, msg);
/*
* The precondition of SOUP_STATUS_PRECONDITION_FAILED (412) in
* this case was triggered by the "Overwrite: F" header which
* means that the target already exists.
* Also if we get a REDIRECTION it means that there was no
* "Location" header, since otherwise that would have triggered
* our redirection handler. This probably means we are dealing
* with an web dav implementation (like mod_dav) that also sends
* redirects for the destionaion (i.e. "Destination: /foo" header)
* which very likely means that the target also exists (and is a
* directory). That or the webdav server is broken.
* We could find out by doing another stat and but I think this is
* such a corner case that we are totally fine with returning
* G_IO_ERROR_EXISTS.
* */
if (SOUP_STATUS_IS_SUCCESSFUL (status))
{
g_vfs_job_succeeded (G_VFS_JOB (job));
}
else if (status == SOUP_STATUS_PRECONDITION_FAILED ||
SOUP_STATUS_IS_REDIRECTION (status))
g_vfs_job_failed (G_VFS_JOB (job), G_IO_ERROR,
G_IO_ERROR_EXISTS,
_("Target file already exists"));
else
http_job_failed (G_VFS_JOB (job), msg);
g_object_unref (msg);
soup_uri_free (source_uri);
soup_uri_free (target_uri);
}
| 0
|
181,227
|
void AssertCBIsNull() {
ASSERT_TRUE(cb.is_null());
cb_already_run = true;
}
| 0
|
310,038
|
static MagickBooleanType WriteGIFImage(const ImageInfo *image_info,Image *image,
ExceptionInfo *exception)
{
int
c;
ImageInfo
*write_info;
MagickBooleanType
status;
MagickOffsetType
scene;
RectangleInfo
page;
register ssize_t
i;
register unsigned char
*q;
size_t
bits_per_pixel,
delay,
imageListLength,
length,
one;
ssize_t
j,
opacity;
unsigned char
*colormap,
*global_colormap;
/*
Open output image file.
*/
assert(image_info != (const ImageInfo *) NULL);
assert(image_info->signature == MagickCoreSignature);
assert(image != (Image *) NULL);
assert(image->signature == MagickCoreSignature);
if (image->debug != MagickFalse)
(void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
assert(exception != (ExceptionInfo *) NULL);
assert(exception->signature == MagickCoreSignature);
status=OpenBlob(image_info,image,WriteBinaryBlobMode,exception);
if (status == MagickFalse)
return(status);
/*
Allocate colormap.
*/
global_colormap=(unsigned char *) AcquireQuantumMemory(768UL,
sizeof(*global_colormap));
colormap=(unsigned char *) AcquireQuantumMemory(768UL,sizeof(*colormap));
if ((global_colormap == (unsigned char *) NULL) ||
(colormap == (unsigned char *) NULL))
{
if (global_colormap != (unsigned char *) NULL)
global_colormap=(unsigned char *) RelinquishMagickMemory(
global_colormap);
if (colormap != (unsigned char *) NULL)
colormap=(unsigned char *) RelinquishMagickMemory(colormap);
ThrowWriterException(ResourceLimitError,"MemoryAllocationFailed");
}
for (i=0; i < 768; i++)
colormap[i]=(unsigned char) 0;
/*
Write GIF header.
*/
write_info=CloneImageInfo(image_info);
if (LocaleCompare(write_info->magick,"GIF87") != 0)
(void) WriteBlob(image,6,(unsigned char *) "GIF89a");
else
{
(void) WriteBlob(image,6,(unsigned char *) "GIF87a");
write_info->adjoin=MagickFalse;
}
/*
Determine image bounding box.
*/
page.width=image->columns;
if (image->page.width > page.width)
page.width=image->page.width;
page.height=image->rows;
if (image->page.height > page.height)
page.height=image->page.height;
page.x=image->page.x;
page.y=image->page.y;
(void) WriteBlobLSBShort(image,(unsigned short) page.width);
(void) WriteBlobLSBShort(image,(unsigned short) page.height);
/*
Write images to file.
*/
if ((write_info->adjoin != MagickFalse) &&
(GetNextImageInList(image) != (Image *) NULL))
write_info->interlace=NoInterlace;
scene=0;
one=1;
imageListLength=GetImageListLength(image);
do
{
(void) TransformImageColorspace(image,sRGBColorspace,exception);
opacity=(-1);
if (IsImageOpaque(image,exception) != MagickFalse)
{
if ((image->storage_class == DirectClass) || (image->colors > 256))
(void) SetImageType(image,PaletteType,exception);
}
else
{
double
alpha,
beta;
/*
Identify transparent colormap index.
*/
if ((image->storage_class == DirectClass) || (image->colors > 256))
(void) SetImageType(image,PaletteBilevelAlphaType,exception);
for (i=0; i < (ssize_t) image->colors; i++)
if (image->colormap[i].alpha != OpaqueAlpha)
{
if (opacity < 0)
{
opacity=i;
continue;
}
alpha=fabs(image->colormap[i].alpha-TransparentAlpha);
beta=fabs(image->colormap[opacity].alpha-TransparentAlpha);
if (alpha < beta)
opacity=i;
}
if (opacity == -1)
{
(void) SetImageType(image,PaletteBilevelAlphaType,exception);
for (i=0; i < (ssize_t) image->colors; i++)
if (image->colormap[i].alpha != OpaqueAlpha)
{
if (opacity < 0)
{
opacity=i;
continue;
}
alpha=fabs(image->colormap[i].alpha-TransparentAlpha);
beta=fabs(image->colormap[opacity].alpha-TransparentAlpha);
if (alpha < beta)
opacity=i;
}
}
if (opacity >= 0)
{
image->colormap[opacity].red=image->transparent_color.red;
image->colormap[opacity].green=image->transparent_color.green;
image->colormap[opacity].blue=image->transparent_color.blue;
}
}
if ((image->storage_class == DirectClass) || (image->colors > 256))
ThrowWriterException(ResourceLimitError,"MemoryAllocationFailed");
for (bits_per_pixel=1; bits_per_pixel < 8; bits_per_pixel++)
if ((one << bits_per_pixel) >= image->colors)
break;
q=colormap;
for (i=0; i < (ssize_t) image->colors; i++)
{
*q++=ScaleQuantumToChar(ClampToQuantum(image->colormap[i].red));
*q++=ScaleQuantumToChar(ClampToQuantum(image->colormap[i].green));
*q++=ScaleQuantumToChar(ClampToQuantum(image->colormap[i].blue));
}
for ( ; i < (ssize_t) (one << bits_per_pixel); i++)
{
*q++=(unsigned char) 0x0;
*q++=(unsigned char) 0x0;
*q++=(unsigned char) 0x0;
}
if ((GetPreviousImageInList(image) == (Image *) NULL) ||
(write_info->adjoin == MagickFalse))
{
/*
Write global colormap.
*/
c=0x80;
c|=(8-1) << 4; /* color resolution */
c|=(bits_per_pixel-1); /* size of global colormap */
(void) WriteBlobByte(image,(unsigned char) c);
for (j=0; j < (ssize_t) image->colors; j++)
if (IsPixelInfoEquivalent(&image->background_color,image->colormap+j))
break;
(void) WriteBlobByte(image,(unsigned char)
(j == (ssize_t) image->colors ? 0 : j)); /* background color */
(void) WriteBlobByte(image,(unsigned char) 0x00); /* reserved */
length=(size_t) (3*(one << bits_per_pixel));
(void) WriteBlob(image,length,colormap);
for (j=0; j < 768; j++)
global_colormap[j]=colormap[j];
}
if (LocaleCompare(write_info->magick,"GIF87") != 0)
{
const char
*value;
/*
Write graphics control extension.
*/
(void) WriteBlobByte(image,(unsigned char) 0x21);
(void) WriteBlobByte(image,(unsigned char) 0xf9);
(void) WriteBlobByte(image,(unsigned char) 0x04);
c=image->dispose << 2;
if (opacity >= 0)
c|=0x01;
(void) WriteBlobByte(image,(unsigned char) c);
delay=(size_t) (100*image->delay/MagickMax((size_t)
image->ticks_per_second,1));
(void) WriteBlobLSBShort(image,(unsigned short) delay);
(void) WriteBlobByte(image,(unsigned char) (opacity >= 0 ? opacity :
0));
(void) WriteBlobByte(image,(unsigned char) 0x00);
value=GetImageProperty(image,"comment",exception);
if (value != (const char *) NULL)
{
register const char
*p;
size_t
count;
/*
Write comment extension.
*/
(void) WriteBlobByte(image,(unsigned char) 0x21);
(void) WriteBlobByte(image,(unsigned char) 0xfe);
for (p=value; *p != '\0'; )
{
count=MagickMin(strlen(p),255);
(void) WriteBlobByte(image,(unsigned char) count);
for (i=0; i < (ssize_t) count; i++)
(void) WriteBlobByte(image,(unsigned char) *p++);
}
(void) WriteBlobByte(image,(unsigned char) 0x00);
}
if ((GetPreviousImageInList(image) == (Image *) NULL) &&
(GetNextImageInList(image) != (Image *) NULL) &&
(image->iterations != 1))
{
/*
Write Netscape Loop extension.
*/
(void) LogMagickEvent(CoderEvent,GetMagickModule(),
" Writing GIF Extension %s","NETSCAPE2.0");
(void) WriteBlobByte(image,(unsigned char) 0x21);
(void) WriteBlobByte(image,(unsigned char) 0xff);
(void) WriteBlobByte(image,(unsigned char) 0x0b);
(void) WriteBlob(image,11,(unsigned char *) "NETSCAPE2.0");
(void) WriteBlobByte(image,(unsigned char) 0x03);
(void) WriteBlobByte(image,(unsigned char) 0x01);
(void) WriteBlobLSBShort(image,(unsigned short) (image->iterations ?
image->iterations-1 : 0));
(void) WriteBlobByte(image,(unsigned char) 0x00);
}
if ((image->gamma != 1.0f/2.2f))
{
char
attributes[MagickPathExtent];
ssize_t
count;
/*
Write ImageMagick extension.
*/
(void) LogMagickEvent(CoderEvent,GetMagickModule(),
" Writing GIF Extension %s","ImageMagick");
(void) WriteBlobByte(image,(unsigned char) 0x21);
(void) WriteBlobByte(image,(unsigned char) 0xff);
(void) WriteBlobByte(image,(unsigned char) 0x0b);
(void) WriteBlob(image,11,(unsigned char *) "ImageMagick");
count=FormatLocaleString(attributes,MagickPathExtent,"gamma=%g",
image->gamma);
(void) WriteBlobByte(image,(unsigned char) count);
(void) WriteBlob(image,(size_t) count,(unsigned char *) attributes);
(void) WriteBlobByte(image,(unsigned char) 0x00);
}
ResetImageProfileIterator(image);
for ( ; ; )
{
char
*name;
const StringInfo
*profile;
name=GetNextImageProfile(image);
if (name == (const char *) NULL)
break;
profile=GetImageProfile(image,name);
if (profile != (StringInfo *) NULL)
{
if ((LocaleCompare(name,"ICC") == 0) ||
(LocaleCompare(name,"ICM") == 0) ||
(LocaleCompare(name,"IPTC") == 0) ||
(LocaleCompare(name,"8BIM") == 0) ||
(LocaleNCompare(name,"gif:",4) == 0))
{
ssize_t
offset;
unsigned char
*datum;
datum=GetStringInfoDatum(profile);
length=GetStringInfoLength(profile);
(void) WriteBlobByte(image,(unsigned char) 0x21);
(void) WriteBlobByte(image,(unsigned char) 0xff);
(void) WriteBlobByte(image,(unsigned char) 0x0b);
if ((LocaleCompare(name,"ICC") == 0) ||
(LocaleCompare(name,"ICM") == 0))
{
/*
Write ICC extension.
*/
(void) WriteBlob(image,11,(unsigned char *) "ICCRGBG1012");
(void) LogMagickEvent(CoderEvent,GetMagickModule(),
" Writing GIF Extension %s","ICCRGBG1012");
}
else
if ((LocaleCompare(name,"IPTC") == 0))
{
/*
Write IPTC extension.
*/
(void) WriteBlob(image,11,(unsigned char *) "MGKIPTC0000");
(void) LogMagickEvent(CoderEvent,GetMagickModule(),
" Writing GIF Extension %s","MGKIPTC0000");
}
else
if ((LocaleCompare(name,"8BIM") == 0))
{
/*
Write 8BIM extension.
*/
(void) WriteBlob(image,11,(unsigned char *)
"MGK8BIM0000");
(void) LogMagickEvent(CoderEvent,GetMagickModule(),
" Writing GIF Extension %s","MGK8BIM0000");
}
else
{
char
extension[MagickPathExtent];
/*
Write generic extension.
*/
(void) CopyMagickString(extension,name+4,
sizeof(extension));
(void) WriteBlob(image,11,(unsigned char *) extension);
(void) LogMagickEvent(CoderEvent,GetMagickModule(),
" Writing GIF Extension %s",name);
}
offset=0;
while ((ssize_t) length > offset)
{
size_t
block_length;
if ((length-offset) < 255)
block_length=length-offset;
else
block_length=255;
(void) WriteBlobByte(image,(unsigned char) block_length);
(void) WriteBlob(image,(size_t) block_length,datum+offset);
offset+=(ssize_t) block_length;
}
(void) WriteBlobByte(image,(unsigned char) 0x00);
}
}
}
}
(void) WriteBlobByte(image,','); /* image separator */
/*
Write the image header.
*/
page.x=image->page.x;
page.y=image->page.y;
if ((image->page.width != 0) && (image->page.height != 0))
page=image->page;
(void) WriteBlobLSBShort(image,(unsigned short) (page.x < 0 ? 0 : page.x));
(void) WriteBlobLSBShort(image,(unsigned short) (page.y < 0 ? 0 : page.y));
(void) WriteBlobLSBShort(image,(unsigned short) image->columns);
(void) WriteBlobLSBShort(image,(unsigned short) image->rows);
c=0x00;
if (write_info->interlace != NoInterlace)
c|=0x40; /* pixel data is interlaced */
for (j=0; j < (ssize_t) (3*image->colors); j++)
if (colormap[j] != global_colormap[j])
break;
if (j == (ssize_t) (3*image->colors))
(void) WriteBlobByte(image,(unsigned char) c);
else
{
c|=0x80;
c|=(bits_per_pixel-1); /* size of local colormap */
(void) WriteBlobByte(image,(unsigned char) c);
length=(size_t) (3*(one << bits_per_pixel));
(void) WriteBlob(image,length,colormap);
}
/*
Write the image data.
*/
c=(int) MagickMax(bits_per_pixel,2);
(void) WriteBlobByte(image,(unsigned char) c);
status=EncodeImage(write_info,image,(size_t) MagickMax(bits_per_pixel,2)+1,
exception);
if (status == MagickFalse)
{
global_colormap=(unsigned char *) RelinquishMagickMemory(
global_colormap);
colormap=(unsigned char *) RelinquishMagickMemory(colormap);
write_info=DestroyImageInfo(write_info);
ThrowWriterException(ResourceLimitError,"MemoryAllocationFailed");
}
(void) WriteBlobByte(image,(unsigned char) 0x00);
if (GetNextImageInList(image) == (Image *) NULL)
break;
image=SyncNextImageInList(image);
scene++;
status=SetImageProgress(image,SaveImagesTag,scene,imageListLength);
if (status == MagickFalse)
break;
} while (write_info->adjoin != MagickFalse);
(void) WriteBlobByte(image,';'); /* terminator */
global_colormap=(unsigned char *) RelinquishMagickMemory(global_colormap);
colormap=(unsigned char *) RelinquishMagickMemory(colormap);
write_info=DestroyImageInfo(write_info);
(void) CloseBlob(image);
return(MagickTrue);
}
| 0
|
51,415
|
static int lua_ap_getdir(lua_State *L)
{
request_rec *r;
apr_dir_t *thedir;
apr_finfo_t file_info;
apr_status_t status;
const char *directory;
luaL_checktype(L, 1, LUA_TUSERDATA);
luaL_checktype(L, 2, LUA_TSTRING);
r = ap_lua_check_request_rec(L, 1);
directory = lua_tostring(L, 2);
if (apr_dir_open(&thedir, directory, r->pool) == APR_SUCCESS) {
int i = 0;
lua_newtable(L);
do {
status = apr_dir_read(&file_info, APR_FINFO_NAME, thedir);
if (APR_STATUS_IS_INCOMPLETE(status)) {
continue; /* ignore un-stat()able files */
}
else if (status != APR_SUCCESS) {
break;
}
lua_pushinteger(L, ++i);
lua_pushstring(L, file_info.name);
lua_settable(L, -3);
} while (1);
apr_dir_close(thedir);
return 1;
}
else {
return 0;
}
}
| 0
|
445,612
|
OwnedImpl::OwnedImpl(absl::string_view data) : OwnedImpl() { add(data); }
| 0
|
330,801
|
void cpu_resume_from_signal(CPUState *env1, void *puc)
{
env = env1;
/* XXX: restore cpu registers saved in host registers */
env->exception_index = -1;
longjmp(env->jmp_env, 1);
}
| 0
|
278,068
|
const Cluster* Segment::FindCluster(long long time_ns) const {
if ((m_clusters == NULL) || (m_clusterCount <= 0))
return &m_eos;
{
Cluster* const pCluster = m_clusters[0];
assert(pCluster);
assert(pCluster->m_index == 0);
if (time_ns <= pCluster->GetTime())
return pCluster;
}
long i = 0;
long j = m_clusterCount;
while (i < j) {
const long k = i + (j - i) / 2;
assert(k < m_clusterCount);
Cluster* const pCluster = m_clusters[k];
assert(pCluster);
assert(pCluster->m_index == k);
const long long t = pCluster->GetTime();
if (t <= time_ns)
i = k + 1;
else
j = k;
assert(i <= j);
}
assert(i == j);
assert(i > 0);
assert(i <= m_clusterCount);
const long k = i - 1;
Cluster* const pCluster = m_clusters[k];
assert(pCluster);
assert(pCluster->m_index == k);
assert(pCluster->GetTime() <= time_ns);
return pCluster;
}
| 0
|
15,577
|
static void authenticate ( const struct passwd * pw ) {
const struct passwd * lpw = NULL ;
const char * cp , * srvname = NULL ;
int retval ;
switch ( su_mode ) {
case SU_MODE : srvname = simulate_login ? PAM_SRVNAME_SU_L : PAM_SRVNAME_SU ;
break ;
case RUNUSER_MODE : srvname = simulate_login ? PAM_SRVNAME_RUNUSER_L : PAM_SRVNAME_RUNUSER ;
break ;
default : abort ( ) ;
break ;
}
retval = pam_start ( srvname , pw -> pw_name , & conv , & pamh ) ;
if ( is_pam_failure ( retval ) ) goto done ;
if ( isatty ( 0 ) && ( cp = ttyname ( 0 ) ) != NULL ) {
const char * tty ;
if ( strncmp ( cp , "/dev/" , 5 ) == 0 ) tty = cp + 5 ;
else tty = cp ;
retval = pam_set_item ( pamh , PAM_TTY , tty ) ;
if ( is_pam_failure ( retval ) ) goto done ;
}
lpw = current_getpwuid ( ) ;
if ( lpw && lpw -> pw_name ) {
retval = pam_set_item ( pamh , PAM_RUSER , ( const void * ) lpw -> pw_name ) ;
if ( is_pam_failure ( retval ) ) goto done ;
}
if ( su_mode == RUNUSER_MODE ) {
if ( restricted ) errx ( EXIT_FAILURE , _ ( "may not be used by non-root users" ) ) ;
return ;
}
retval = pam_authenticate ( pamh , 0 ) ;
if ( is_pam_failure ( retval ) ) goto done ;
retval = pam_acct_mgmt ( pamh , 0 ) ;
if ( retval == PAM_NEW_AUTHTOK_REQD ) {
retval = pam_chauthtok ( pamh , PAM_CHANGE_EXPIRED_AUTHTOK ) ;
}
done : log_syslog ( pw , ! is_pam_failure ( retval ) ) ;
if ( is_pam_failure ( retval ) ) {
const char * msg ;
log_btmp ( pw ) ;
msg = pam_strerror ( pamh , retval ) ;
pam_end ( pamh , retval ) ;
sleep ( getlogindefs_num ( "FAIL_DELAY" , 1 ) ) ;
errx ( EXIT_FAILURE , "%s" , msg ? msg : _ ( "incorrect password" ) ) ;
}
}
| 0
|
269,136
|
MagickExport MagickBooleanType SetImageProperty(Image *image,
const char *property,const char *value,ExceptionInfo *exception)
{
MagickBooleanType
status;
MagickStatusType
flags;
assert(image != (Image *) NULL);
assert(image->signature == MagickCoreSignature);
if (image->debug != MagickFalse)
(void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
if (image->properties == (void *) NULL)
image->properties=NewSplayTree(CompareSplayTreeString,
RelinquishMagickMemory,RelinquishMagickMemory); /* create splay-tree */
if (value == (const char *) NULL)
return(DeleteImageProperty(image,property)); /* delete if NULL */
status=MagickTrue;
if (strlen(property) <= 1)
{
/*
Do not 'set' single letter properties - read only shorthand.
*/
(void) ThrowMagickException(exception,GetMagickModule(),OptionError,
"SetReadOnlyProperty","`%s'",property);
return(MagickFalse);
}
/* FUTURE: binary chars or quotes in key should produce a error */
/* Set attributes with known names or special prefixes
return result is found, or break to set a free form properity
*/
switch (*property)
{
#if 0 /* Percent escape's sets values with this prefix: for later use
Throwing an exception causes this setting to fail */
case '8':
{
if (LocaleNCompare("8bim:",property,5) == 0)
{
(void) ThrowMagickException(exception,GetMagickModule(),
OptionError,"SetReadOnlyProperty","`%s'",property);
return(MagickFalse);
}
break;
}
#endif
case 'B':
case 'b':
{
if (LocaleCompare("background",property) == 0)
{
(void) QueryColorCompliance(value,AllCompliance,
&image->background_color,exception);
/* check for FUTURE: value exception?? */
/* also add user input to splay tree */
}
break; /* not an attribute, add as a property */
}
case 'C':
case 'c':
{
if (LocaleCompare("channels",property) == 0)
{
(void) ThrowMagickException(exception,GetMagickModule(),OptionError,
"SetReadOnlyProperty","`%s'",property);
return(MagickFalse);
}
if (LocaleCompare("colorspace",property) == 0)
{
ssize_t
colorspace;
colorspace=ParseCommandOption(MagickColorspaceOptions,MagickFalse,
value);
if (colorspace < 0)
return(MagickFalse); /* FUTURE: value exception?? */
return(SetImageColorspace(image,(ColorspaceType) colorspace,exception));
}
if (LocaleCompare("compose",property) == 0)
{
ssize_t
compose;
compose=ParseCommandOption(MagickComposeOptions,MagickFalse,value);
if (compose < 0)
return(MagickFalse); /* FUTURE: value exception?? */
image->compose=(CompositeOperator) compose;
return(MagickTrue);
}
if (LocaleCompare("compress",property) == 0)
{
ssize_t
compression;
compression=ParseCommandOption(MagickCompressOptions,MagickFalse,
value);
if (compression < 0)
return(MagickFalse); /* FUTURE: value exception?? */
image->compression=(CompressionType) compression;
return(MagickTrue);
}
break; /* not an attribute, add as a property */
}
case 'D':
case 'd':
{
if (LocaleCompare("delay",property) == 0)
{
GeometryInfo
geometry_info;
flags=ParseGeometry(value,&geometry_info);
if ((flags & GreaterValue) != 0)
{
if (image->delay > (size_t) floor(geometry_info.rho+0.5))
image->delay=(size_t) floor(geometry_info.rho+0.5);
}
else
if ((flags & LessValue) != 0)
{
if (image->delay < (size_t) floor(geometry_info.rho+0.5))
image->delay=(ssize_t)
floor(geometry_info.sigma+0.5);
}
else
image->delay=(size_t) floor(geometry_info.rho+0.5);
if ((flags & SigmaValue) != 0)
image->ticks_per_second=(ssize_t) floor(geometry_info.sigma+0.5);
return(MagickTrue);
}
if (LocaleCompare("delay_units",property) == 0)
{
(void) ThrowMagickException(exception,GetMagickModule(),
OptionError,"SetReadOnlyProperty","`%s'",property);
return(MagickFalse);
}
if (LocaleCompare("density",property) == 0)
{
GeometryInfo
geometry_info;
flags=ParseGeometry(value,&geometry_info);
image->resolution.x=geometry_info.rho;
image->resolution.y=geometry_info.sigma;
if ((flags & SigmaValue) == 0)
image->resolution.y=image->resolution.x;
return(MagickTrue);
}
if (LocaleCompare("depth",property) == 0)
{
image->depth=StringToUnsignedLong(value);
return(MagickTrue);
}
if (LocaleCompare("dispose",property) == 0)
{
ssize_t
dispose;
dispose=ParseCommandOption(MagickDisposeOptions,MagickFalse,value);
if (dispose < 0)
return(MagickFalse); /* FUTURE: value exception?? */
image->dispose=(DisposeType) dispose;
return(MagickTrue);
}
break; /* not an attribute, add as a property */
}
#if 0 /* Percent escape's sets values with this prefix: for later use
Throwing an exception causes this setting to fail */
case 'E':
case 'e':
{
if (LocaleNCompare("exif:",property,5) == 0)
{
(void) ThrowMagickException(exception,GetMagickModule(),
OptionError,"SetReadOnlyProperty","`%s'",property);
return(MagickFalse);
}
break; /* not an attribute, add as a property */
}
case 'F':
case 'f':
{
if (LocaleNCompare("fx:",property,3) == 0)
{
(void) ThrowMagickException(exception,GetMagickModule(),
OptionError,"SetReadOnlyProperty","`%s'",property);
return(MagickFalse);
}
break; /* not an attribute, add as a property */
}
#endif
case 'G':
case 'g':
{
if (LocaleCompare("gamma",property) == 0)
{
image->gamma=StringToDouble(value,(char **) NULL);
return(MagickTrue);
}
if (LocaleCompare("gravity",property) == 0)
{
ssize_t
gravity;
gravity=ParseCommandOption(MagickGravityOptions,MagickFalse,value);
if (gravity < 0)
return(MagickFalse); /* FUTURE: value exception?? */
image->gravity=(GravityType) gravity;
return(MagickTrue);
}
break; /* not an attribute, add as a property */
}
case 'H':
case 'h':
{
if (LocaleCompare("height",property) == 0)
{
(void) ThrowMagickException(exception,GetMagickModule(),
OptionError,"SetReadOnlyProperty","`%s'",property);
return(MagickFalse);
}
break; /* not an attribute, add as a property */
}
case 'I':
case 'i':
{
if (LocaleCompare("intensity",property) == 0)
{
ssize_t
intensity;
intensity=ParseCommandOption(MagickIntentOptions,MagickFalse,
value);
if (intensity < 0)
return(MagickFalse);
image->intensity=(PixelIntensityMethod) intensity;
return(MagickTrue);
}
if (LocaleCompare("intent",property) == 0)
{
ssize_t
rendering_intent;
rendering_intent=ParseCommandOption(MagickIntentOptions,MagickFalse,
value);
if (rendering_intent < 0)
return(MagickFalse); /* FUTURE: value exception?? */
image->rendering_intent=(RenderingIntent) rendering_intent;
return(MagickTrue);
}
if (LocaleCompare("interpolate",property) == 0)
{
ssize_t
interpolate;
interpolate=ParseCommandOption(MagickInterpolateOptions,MagickFalse,
value);
if (interpolate < 0)
return(MagickFalse); /* FUTURE: value exception?? */
image->interpolate=(PixelInterpolateMethod) interpolate;
return(MagickTrue);
}
#if 0 /* Percent escape's sets values with this prefix: for later use
Throwing an exception causes this setting to fail */
if (LocaleNCompare("iptc:",property,5) == 0)
{
(void) ThrowMagickException(exception,GetMagickModule(),
OptionError,"SetReadOnlyProperty","`%s'",property);
return(MagickFalse);
}
#endif
break; /* not an attribute, add as a property */
}
case 'K':
case 'k':
if (LocaleCompare("kurtosis",property) == 0)
{
(void) ThrowMagickException(exception,GetMagickModule(),
OptionError,"SetReadOnlyProperty","`%s'",property);
return(MagickFalse);
}
break; /* not an attribute, add as a property */
case 'L':
case 'l':
{
if (LocaleCompare("loop",property) == 0)
{
image->iterations=StringToUnsignedLong(value);
return(MagickTrue);
}
break; /* not an attribute, add as a property */
}
case 'M':
case 'm':
if ( (LocaleCompare("magick",property) == 0) ||
(LocaleCompare("max",property) == 0) ||
(LocaleCompare("mean",property) == 0) ||
(LocaleCompare("min",property) == 0) ||
(LocaleCompare("min",property) == 0) )
{
(void) ThrowMagickException(exception,GetMagickModule(),OptionError,
"SetReadOnlyProperty","`%s'",property);
return(MagickFalse);
}
break; /* not an attribute, add as a property */
case 'O':
case 'o':
if (LocaleCompare("opaque",property) == 0)
{
(void) ThrowMagickException(exception,GetMagickModule(),
OptionError,"SetReadOnlyProperty","`%s'",property);
return(MagickFalse);
}
break; /* not an attribute, add as a property */
case 'P':
case 'p':
{
if (LocaleCompare("page",property) == 0)
{
char
*geometry;
geometry=GetPageGeometry(value);
flags=ParseAbsoluteGeometry(geometry,&image->page);
geometry=DestroyString(geometry);
return(MagickTrue);
}
#if 0 /* Percent escape's sets values with this prefix: for later use
Throwing an exception causes this setting to fail */
if (LocaleNCompare("pixel:",property,6) == 0)
{
(void) ThrowMagickException(exception,GetMagickModule(),
OptionError,"SetReadOnlyProperty","`%s'",property);
return(MagickFalse);
}
#endif
if (LocaleCompare("profile",property) == 0)
{
ImageInfo
*image_info;
StringInfo
*profile;
image_info=AcquireImageInfo();
(void) CopyMagickString(image_info->filename,value,MagickPathExtent);
(void) SetImageInfo(image_info,1,exception);
profile=FileToStringInfo(image_info->filename,~0UL,exception);
if (profile != (StringInfo *) NULL)
status=SetImageProfile(image,image_info->magick,profile,exception);
image_info=DestroyImageInfo(image_info);
return(MagickTrue);
}
break; /* not an attribute, add as a property */
}
case 'R':
case 'r':
{
if (LocaleCompare("rendering-intent",property) == 0)
{
ssize_t
rendering_intent;
rendering_intent=ParseCommandOption(MagickIntentOptions,MagickFalse,
value);
if (rendering_intent < 0)
return(MagickFalse); /* FUTURE: value exception?? */
image->rendering_intent=(RenderingIntent) rendering_intent;
return(MagickTrue);
}
break; /* not an attribute, add as a property */
}
case 'S':
case 's':
if ( (LocaleCompare("size",property) == 0) ||
(LocaleCompare("skewness",property) == 0) ||
(LocaleCompare("scenes",property) == 0) ||
(LocaleCompare("standard-deviation",property) == 0) )
{
(void) ThrowMagickException(exception,GetMagickModule(),
OptionError,"SetReadOnlyProperty","`%s'",property);
return(MagickFalse);
}
break; /* not an attribute, add as a property */
case 'T':
case 't':
{
if (LocaleCompare("tile-offset",property) == 0)
{
char
*geometry;
geometry=GetPageGeometry(value);
flags=ParseAbsoluteGeometry(geometry,&image->tile_offset);
geometry=DestroyString(geometry);
return(MagickTrue);
}
break; /* not an attribute, add as a property */
}
case 'U':
case 'u':
{
if (LocaleCompare("units",property) == 0)
{
ssize_t
units;
units=ParseCommandOption(MagickResolutionOptions,MagickFalse,value);
if (units < 0)
return(MagickFalse); /* FUTURE: value exception?? */
image->units=(ResolutionType) units;
return(MagickTrue);
}
break; /* not an attribute, add as a property */
}
case 'V':
case 'v':
{
if (LocaleCompare("version",property) == 0)
{
(void) ThrowMagickException(exception,GetMagickModule(),
OptionError,"SetReadOnlyProperty","`%s'",property);
return(MagickFalse);
}
break; /* not an attribute, add as a property */
}
case 'W':
case 'w':
{
if (LocaleCompare("width",property) == 0)
{
(void) ThrowMagickException(exception,GetMagickModule(),
OptionError,"SetReadOnlyProperty","`%s'",property);
return(MagickFalse);
}
break; /* not an attribute, add as a property */
}
#if 0 /* Percent escape's sets values with this prefix: for later use
Throwing an exception causes this setting to fail */
case 'X':
case 'x':
{
if (LocaleNCompare("xmp:",property,4) == 0)
{
(void) ThrowMagickException(exception,GetMagickModule(),
OptionError,"SetReadOnlyProperty","`%s'",property);
return(MagickFalse);
}
break; /* not an attribute, add as a property */
}
#endif
}
/* Default: not an attribute, add as a property */
status=AddValueToSplayTree((SplayTreeInfo *) image->properties,
ConstantString(property),ConstantString(value));
/* FUTURE: error if status is bad? */
return(status);
}
| 0
|
509,699
|
static void test_mdev3885()
{
int rc;
MYSQL *conn;
myheader("test_mdev3885");
conn= client_connect(0, MYSQL_PROTOCOL_TCP, 0);
rc= mysql_kill(conn, mysql_thread_id(conn));
DIE_UNLESS(rc);
mysql_close(conn);
}
| 0
|
411,180
|
// Compilation procedure.
unsigned int compile(char *ss, char *se, const unsigned int depth, unsigned int *const p_ref,
const bool is_single) {
if (depth>256) {
cimg::strellipsize(expr,64);
throw CImgArgumentException("[" cimg_appname "_math_parser] "
"CImg<%s>::%s: Call stack overflow (infinite recursion?), "
"in expression '%s%s%s'.",
pixel_type(),_cimg_mp_calling_function,
(ss - 4)>expr._data?"...":"",
(ss - 4)>expr._data?ss - 4:expr._data,
se<&expr.back()?"...":"");
}
char c1, c2, c3, c4;
// Simplify expression when possible.
do {
c2 = 0;
if (ss<se) {
while (*ss && ((signed char)*ss<=' ' || *ss==';')) ++ss;
while (se>ss && ((signed char)(c1 = *(se - 1))<=' ' || c1==';')) --se;
}
while (*ss=='(' && *(se - 1)==')' && std::strchr(ss,')')==se - 1) {
++ss; --se; c2 = 1;
}
} while (c2 && ss<se);
if (se<=ss || !*ss) {
cimg::strellipsize(expr,64);
throw CImgArgumentException("[" cimg_appname "_math_parser] "
"CImg<%s>::%s: %s%s Missing %s, in expression '%s%s%s'.",
pixel_type(),_cimg_mp_calling_function,s_op,*s_op?":":"",
*s_op=='F'?"argument":"item",
(ss_op - 4)>expr._data?"...":"",
(ss_op - 4)>expr._data?ss_op - 4:expr._data,
ss_op + std::strlen(ss_op)<&expr.back()?"...":"");
}
const char *const previous_s_op = s_op, *const previous_ss_op = ss_op;
const unsigned int depth1 = depth + 1;
unsigned int pos, p1, p2, p3, arg1, arg2, arg3, arg4, arg5, arg6;
char
*const se1 = se - 1, *const se2 = se - 2, *const se3 = se - 3,
*const ss1 = ss + 1, *const ss2 = ss + 2, *const ss3 = ss + 3, *const ss4 = ss + 4,
*const ss5 = ss + 5, *const ss6 = ss + 6, *const ss7 = ss + 7, *const ss8 = ss + 8,
*s, *ps, *ns, *s0, *s1, *s2, *s3, sep = 0, end = 0;
double val, val1, val2;
mp_func op;
// 'p_ref' is a 'unsigned int[7]' used to return a reference to an image or vector value
// linked to the returned memory slot (reference that cannot be determined at compile time).
// p_ref[0] can be { 0 = scalar (unlinked) | 1 = vector value | 2 = image value (offset) |
// 3 = image value (coordinates) | 4 = image value as a vector (offsets) |
// 5 = image value as a vector (coordinates) }.
// Depending on p_ref[0], the remaining p_ref[k] have the following meaning:
// When p_ref[0]==0, p_ref is actually unlinked.
// When p_ref[0]==1, p_ref = [ 1, vector_ind, offset ].
// When p_ref[0]==2, p_ref = [ 2, image_ind (or ~0U), is_relative, offset ].
// When p_ref[0]==3, p_ref = [ 3, image_ind (or ~0U), is_relative, x, y, z, c ].
// When p_ref[0]==4, p_ref = [ 4, image_ind (or ~0U), is_relative, offset ].
// When p_ref[0]==5, p_ref = [ 5, image_ind (or ~0U), is_relative, x, y, z ].
if (p_ref) { *p_ref = 0; p_ref[1] = p_ref[2] = p_ref[3] = p_ref[4] = p_ref[5] = p_ref[6] = ~0U; }
const char saved_char = *se; *se = 0;
const unsigned int clevel = level[ss - expr._data], clevel1 = clevel + 1;
bool is_sth, is_relative;
CImg<uintT> ref;
CImgList<ulongT> _opcode;
CImg<charT> variable_name;
// Look for a single value or a pre-defined variable.
int nb = cimg_sscanf(ss,"%lf%c%c",&val,&(sep=0),&(end=0));
#if cimg_OS==2
// Check for +/-NaN and +/-inf as Microsoft's sscanf() version is not able
// to read those particular values.
if (!nb && (*ss=='+' || *ss=='-' || *ss=='i' || *ss=='I' || *ss=='n' || *ss=='N')) {
is_sth = true;
s = ss;
if (*s=='+') ++s; else if (*s=='-') { ++s; is_sth = false; }
if (!cimg::strcasecmp(s,"inf")) { val = cimg::type<double>::inf(); nb = 1; }
else if (!cimg::strcasecmp(s,"nan")) { val = cimg::type<double>::nan(); nb = 1; }
if (nb==1 && !is_sth) val = -val;
}
#endif
if (nb==1) _cimg_mp_constant(val);
if (nb==2 && sep=='%') _cimg_mp_constant(val/100);
if (ss1==se) switch (*ss) { // One-char reserved variable
case 'c' : _cimg_mp_return(reserved_label['c']!=~0U?reserved_label['c']:_cimg_mp_slot_c);
case 'd' : _cimg_mp_return(reserved_label['d']!=~0U?reserved_label['d']:20);
case 'e' : _cimg_mp_return(reserved_label['e']!=~0U?reserved_label['e']:27);
case 'h' : _cimg_mp_return(reserved_label['h']!=~0U?reserved_label['h']:19);
case 'l' : _cimg_mp_return(reserved_label['l']!=~0U?reserved_label['l']:26);
case 'r' : _cimg_mp_return(reserved_label['r']!=~0U?reserved_label['r']:22);
case 's' : _cimg_mp_return(reserved_label['s']!=~0U?reserved_label['s']:21);
case 't' : _cimg_mp_return(reserved_label['t']!=~0U?reserved_label['t']:17);
case 'w' : _cimg_mp_return(reserved_label['w']!=~0U?reserved_label['w']:18);
case 'x' : _cimg_mp_return(reserved_label['x']!=~0U?reserved_label['x']:_cimg_mp_slot_x);
case 'y' : _cimg_mp_return(reserved_label['y']!=~0U?reserved_label['y']:_cimg_mp_slot_y);
case 'z' : _cimg_mp_return(reserved_label['z']!=~0U?reserved_label['z']:_cimg_mp_slot_z);
case 'u' :
if (reserved_label['u']!=~0U) _cimg_mp_return(reserved_label['u']);
_cimg_mp_scalar2(mp_u,0,1);
case 'g' :
if (reserved_label['g']!=~0U) _cimg_mp_return(reserved_label['g']);
_cimg_mp_scalar0(mp_g);
case 'i' :
if (reserved_label['i']!=~0U) _cimg_mp_return(reserved_label['i']);
_cimg_mp_scalar0(mp_i);
case 'I' :
_cimg_mp_op("Variable 'I'");
if (reserved_label['I']!=~0U) _cimg_mp_return(reserved_label['I']);
_cimg_mp_check_vector0(imgin._spectrum);
need_input_copy = true;
pos = vector(imgin._spectrum);
CImg<ulongT>::vector((ulongT)mp_Joff,pos,0,0,imgin._spectrum).move_to(code);
_cimg_mp_return(pos);
case 'R' :
if (reserved_label['R']!=~0U) _cimg_mp_return(reserved_label['R']);
need_input_copy = true;
_cimg_mp_scalar6(mp_ixyzc,_cimg_mp_slot_x,_cimg_mp_slot_y,_cimg_mp_slot_z,0,0,0);
case 'G' :
if (reserved_label['G']!=~0U) _cimg_mp_return(reserved_label['G']);
need_input_copy = true;
_cimg_mp_scalar6(mp_ixyzc,_cimg_mp_slot_x,_cimg_mp_slot_y,_cimg_mp_slot_z,1,0,0);
case 'B' :
if (reserved_label['B']!=~0U) _cimg_mp_return(reserved_label['B']);
need_input_copy = true;
_cimg_mp_scalar6(mp_ixyzc,_cimg_mp_slot_x,_cimg_mp_slot_y,_cimg_mp_slot_z,2,0,0);
case 'A' :
if (reserved_label['A']!=~0U) _cimg_mp_return(reserved_label['A']);
need_input_copy = true;
_cimg_mp_scalar6(mp_ixyzc,_cimg_mp_slot_x,_cimg_mp_slot_y,_cimg_mp_slot_z,3,0,0);
}
else if (ss2==se) { // Two-chars reserved variable
arg1 = arg2 = ~0U;
if (*ss=='w' && *ss1=='h') // wh
_cimg_mp_return(reserved_label[0]!=~0U?reserved_label[0]:23);
if (*ss=='p' && *ss1=='i') // pi
_cimg_mp_return(reserved_label[3]!=~0U?reserved_label[3]:28);
if (*ss=='i') {
if (*ss1>='0' && *ss1<='9') { // i0...i9
pos = 19 + *ss1 - '0';
if (reserved_label[pos]!=~0U) _cimg_mp_return(reserved_label[pos]);
need_input_copy = true;
_cimg_mp_scalar6(mp_ixyzc,_cimg_mp_slot_x,_cimg_mp_slot_y,_cimg_mp_slot_z,pos - 19,0,0);
}
switch (*ss1) {
case 'm' : arg1 = 4; arg2 = 0; break; // im
case 'M' : arg1 = 5; arg2 = 1; break; // iM
case 'a' : arg1 = 6; arg2 = 2; break; // ia
case 'v' : arg1 = 7; arg2 = 3; break; // iv
case 's' : arg1 = 8; arg2 = 12; break; // is
case 'p' : arg1 = 9; arg2 = 13; break; // ip
case 'c' : // ic
if (reserved_label[10]!=~0U) _cimg_mp_return(reserved_label[10]);
if (mem_img_median==~0U) mem_img_median = imgin?constant(imgin.median()):0;
_cimg_mp_return(mem_img_median);
break;
}
}
else if (*ss1=='m') switch (*ss) {
case 'x' : arg1 = 11; arg2 = 4; break; // xm
case 'y' : arg1 = 12; arg2 = 5; break; // ym
case 'z' : arg1 = 13; arg2 = 6; break; // zm
case 'c' : arg1 = 14; arg2 = 7; break; // cm
}
else if (*ss1=='M') switch (*ss) {
case 'x' : arg1 = 15; arg2 = 8; break; // xM
case 'y' : arg1 = 16; arg2 = 9; break; // yM
case 'z' : arg1 = 17; arg2 = 10; break; // zM
case 'c' : arg1 = 18; arg2 = 11; break; // cM
}
if (arg1!=~0U) {
if (reserved_label[arg1]!=~0U) _cimg_mp_return(reserved_label[arg1]);
if (!img_stats) {
img_stats.assign(1,14,1,1,0).fill(imgin.get_stats(),false);
mem_img_stats.assign(1,14,1,1,~0U);
}
if (mem_img_stats[arg2]==~0U) mem_img_stats[arg2] = constant(img_stats[arg2]);
_cimg_mp_return(mem_img_stats[arg2]);
}
} else if (ss3==se) { // Three-chars reserved variable
if (*ss=='w' && *ss1=='h' && *ss2=='d') // whd
_cimg_mp_return(reserved_label[1]!=~0U?reserved_label[1]:24);
} else if (ss4==se) { // Four-chars reserved variable
if (*ss=='w' && *ss1=='h' && *ss2=='d' && *ss3=='s') // whds
_cimg_mp_return(reserved_label[2]!=~0U?reserved_label[2]:25);
}
pos = ~0U;
is_sth = false;
for (s0 = ss, s = ss1; s<se1; ++s)
if (*s==';' && level[s - expr._data]==clevel) { // Separator ';'
arg1 = code_end._width;
arg2 = compile(s0,s++,depth,0,is_single);
if (code_end._width==arg1) pos = arg2; // makes 'end()' return void
is_sth = true;
while (*s && ((signed char)*s<=' ' || *s==';')) ++s;
s0 = s;
}
if (is_sth) {
arg1 = code_end._width;
arg2 = compile(s0,se,depth,p_ref,is_single);
if (code_end._width==arg1) pos = arg2; // makes 'end()' return void
_cimg_mp_return(pos);
}
// Declare / assign variable, vector value or image value.
for (s = ss1, ps = ss, ns = ss2; s<se1; ++s, ++ps, ++ns)
if (*s=='=' && *ns!='=' && *ps!='=' && *ps!='>' && *ps!='<' && *ps!='!' &&
*ps!='+' && *ps!='-' && *ps!='*' && *ps!='/' && *ps!='%' &&
*ps!='>' && *ps!='<' && *ps!='&' && *ps!='|' && *ps!='^' &&
level[s - expr._data]==clevel) {
variable_name.assign(ss,(unsigned int)(s + 1 - ss)).back() = 0;
cimg::strpare(variable_name,false,true);
const unsigned int l_variable_name = (unsigned int)std::strlen(variable_name);
char *const ve1 = ss + l_variable_name - 1;
_cimg_mp_op("Operator '='");
// Assign image value (direct).
if (l_variable_name>2 && (*ss=='i' || *ss=='j' || *ss=='I' || *ss=='J') && (*ss1=='(' || *ss1=='[') &&
(reserved_label[*ss]==~0U || *ss1=='(' || !_cimg_mp_is_vector(reserved_label[*ss]))) {
is_relative = *ss=='j' || *ss=='J';
if (*ss1=='[' && *ve1==']') { // i/j/I/J[_#ind,offset] = value
if (!is_single) is_parallelizable = false;
if (*ss2=='#') { // Index specified
s0 = ss3; while (s0<ve1 && (*s0!=',' || level[s0 - expr._data]!=clevel1)) ++s0;
p1 = compile(ss3,s0++,depth1,0,is_single);
_cimg_mp_check_list(true);
} else { p1 = ~0U; s0 = ss2; }
arg1 = compile(s0,ve1,depth1,0,is_single); // Offset
_cimg_mp_check_type(arg1,0,1,0);
arg2 = compile(s + 1,se,depth1,0,is_single); // Value to assign
if (_cimg_mp_is_vector(arg2)) {
p2 = ~0U; // 'p2' must be the dimension of the vector-valued operand if any
if (p1==~0U) p2 = imgin._spectrum;
else if (_cimg_mp_is_constant(p1)) {
p3 = (unsigned int)cimg::mod((int)mem[p1],listin.width());
p2 = listin[p3]._spectrum;
}
_cimg_mp_check_vector0(p2);
} else p2 = 0;
_cimg_mp_check_type(arg2,2,*ss>='i'?1:3,p2);
if (p_ref) {
*p_ref = _cimg_mp_is_vector(arg2)?4:2;
p_ref[1] = p1;
p_ref[2] = (unsigned int)is_relative;
p_ref[3] = arg1;
if (_cimg_mp_is_vector(arg2))
set_variable_vector(arg2); // Prevent from being used in further optimization
else if (_cimg_mp_is_comp(arg2)) memtype[arg2] = -2;
if (p1!=~0U && _cimg_mp_is_comp(p1)) memtype[p1] = -2;
if (_cimg_mp_is_comp(arg1)) memtype[arg1] = -2;
}
if (p1!=~0U) {
if (!listout) _cimg_mp_return(arg2);
if (*ss>='i')
CImg<ulongT>::vector((ulongT)(is_relative?mp_list_set_joff:mp_list_set_ioff),
arg2,p1,arg1).move_to(code);
else if (_cimg_mp_is_scalar(arg2))
CImg<ulongT>::vector((ulongT)(is_relative?mp_list_set_Joff_s:mp_list_set_Ioff_s),
arg2,p1,arg1).move_to(code);
else
CImg<ulongT>::vector((ulongT)(is_relative?mp_list_set_Joff_v:mp_list_set_Ioff_v),
arg2,p1,arg1,_cimg_mp_size(arg2)).move_to(code);
} else {
if (!imgout) _cimg_mp_return(arg2);
if (*ss>='i')
CImg<ulongT>::vector((ulongT)(is_relative?mp_set_joff:mp_set_ioff),
arg2,arg1).move_to(code);
else if (_cimg_mp_is_scalar(arg2))
CImg<ulongT>::vector((ulongT)(is_relative?mp_set_Joff_s:mp_set_Ioff_s),
arg2,arg1).move_to(code);
else
CImg<ulongT>::vector((ulongT)(is_relative?mp_set_Joff_v:mp_set_Ioff_v),
arg2,arg1,_cimg_mp_size(arg2)).move_to(code);
}
_cimg_mp_return(arg2);
}
if (*ss1=='(' && *ve1==')') { // i/j/I/J(_#ind,_x,_y,_z,_c) = value
if (!is_single) is_parallelizable = false;
if (*ss2=='#') { // Index specified
s0 = ss3; while (s0<ve1 && (*s0!=',' || level[s0 - expr._data]!=clevel1)) ++s0;
p1 = compile(ss3,s0++,depth1,0,is_single);
_cimg_mp_check_list(true);
} else { p1 = ~0U; s0 = ss2; }
arg1 = is_relative?0U:(unsigned int)_cimg_mp_slot_x;
arg2 = is_relative?0U:(unsigned int)_cimg_mp_slot_y;
arg3 = is_relative?0U:(unsigned int)_cimg_mp_slot_z;
arg4 = is_relative?0U:(unsigned int)_cimg_mp_slot_c;
arg5 = compile(s + 1,se,depth1,0,is_single); // Value to assign
if (s0<ve1) { // X or [ X,_Y,_Z,_C ]
s1 = s0; while (s1<ve1 && (*s1!=',' || level[s1 - expr._data]!=clevel1)) ++s1;
arg1 = compile(s0,s1,depth1,0,is_single);
if (_cimg_mp_is_vector(arg1)) { // Coordinates specified as a vector
p2 = _cimg_mp_size(arg1); // Vector size
++arg1;
if (p2>1) {
arg2 = arg1 + 1;
if (p2>2) {
arg3 = arg2 + 1;
if (p2>3) arg4 = arg3 + 1;
}
}
} else if (s1<ve1) { // Y
s2 = ++s1; while (s2<ve1 && (*s2!=',' || level[s2 - expr._data]!=clevel1)) ++s2;
arg2 = compile(s1,s2,depth1,0,is_single);
if (s2<ve1) { // Z
s3 = ++s2; while (s3<ve1 && (*s3!=',' || level[s3 - expr._data]!=clevel1)) ++s3;
arg3 = compile(s2,s3,depth1,0,is_single);
if (s3<ve1) arg4 = compile(++s3,ve1,depth1,0,is_single); // C
}
}
}
if (_cimg_mp_is_vector(arg5)) {
p2 = ~0U; // 'p2' must be the dimension of the vector-valued operand if any
if (p1==~0U) p2 = imgin._spectrum;
else if (_cimg_mp_is_constant(p1)) {
p3 = (unsigned int)cimg::mod((int)mem[p1],listin.width());
p2 = listin[p3]._spectrum;
}
_cimg_mp_check_vector0(p2);
} else p2 = 0;
_cimg_mp_check_type(arg5,2,*ss>='i'?1:3,p2);
if (p_ref) {
*p_ref = _cimg_mp_is_vector(arg5)?5:3;
p_ref[1] = p1;
p_ref[2] = (unsigned int)is_relative;
p_ref[3] = arg1;
p_ref[4] = arg2;
p_ref[5] = arg3;
p_ref[6] = arg4;
if (_cimg_mp_is_vector(arg5))
set_variable_vector(arg5); // Prevent from being used in further optimization
else if (_cimg_mp_is_comp(arg5)) memtype[arg5] = -2;
if (p1!=~0U && _cimg_mp_is_comp(p1)) memtype[p1] = -2;
if (_cimg_mp_is_comp(arg1)) memtype[arg1] = -2;
if (_cimg_mp_is_comp(arg2)) memtype[arg2] = -2;
if (_cimg_mp_is_comp(arg3)) memtype[arg3] = -2;
if (_cimg_mp_is_comp(arg4)) memtype[arg4] = -2;
}
if (p1!=~0U) {
if (!listout) _cimg_mp_return(arg5);
if (*ss>='i')
CImg<ulongT>::vector((ulongT)(is_relative?mp_list_set_jxyzc:mp_list_set_ixyzc),
arg5,p1,arg1,arg2,arg3,arg4).move_to(code);
else if (_cimg_mp_is_scalar(arg5))
CImg<ulongT>::vector((ulongT)(is_relative?mp_list_set_Jxyz_s:mp_list_set_Ixyz_s),
arg5,p1,arg1,arg2,arg3).move_to(code);
else
CImg<ulongT>::vector((ulongT)(is_relative?mp_list_set_Jxyz_v:mp_list_set_Ixyz_v),
arg5,p1,arg1,arg2,arg3,_cimg_mp_size(arg5)).move_to(code);
} else {
if (!imgout) _cimg_mp_return(arg5);
if (*ss>='i')
CImg<ulongT>::vector((ulongT)(is_relative?mp_set_jxyzc:mp_set_ixyzc),
arg5,arg1,arg2,arg3,arg4).move_to(code);
else if (_cimg_mp_is_scalar(arg5))
CImg<ulongT>::vector((ulongT)(is_relative?mp_set_Jxyz_s:mp_set_Ixyz_s),
arg5,arg1,arg2,arg3).move_to(code);
else
CImg<ulongT>::vector((ulongT)(is_relative?mp_set_Jxyz_v:mp_set_Ixyz_v),
arg5,arg1,arg2,arg3,_cimg_mp_size(arg5)).move_to(code);
}
_cimg_mp_return(arg5);
}
}
// Assign vector value (direct).
if (l_variable_name>3 && *ve1==']' && *ss!='[') {
s0 = ve1; while (s0>ss && (*s0!='[' || level[s0 - expr._data]!=clevel)) --s0;
is_sth = true; // is_valid_variable_name?
if (*ss>='0' && *ss<='9') is_sth = false;
else for (ns = ss; ns<s0; ++ns)
if (!is_varchar(*ns)) { is_sth = false; break; }
if (is_sth && s0>ss) {
variable_name[s0 - ss] = 0; // Remove brackets in variable name
arg1 = ~0U; // Vector slot
arg2 = compile(++s0,ve1,depth1,0,is_single); // Index
arg3 = compile(s + 1,se,depth1,0,is_single); // Value to assign
_cimg_mp_check_type(arg3,2,1,0);
if (variable_name[1]) { // Multi-char variable
cimglist_for(variable_def,i) if (!std::strcmp(variable_name,variable_def[i])) {
arg1 = variable_pos[i]; break;
}
} else arg1 = reserved_label[*variable_name]; // Single-char variable
if (arg1==~0U) compile(ss,s0 - 1,depth1,0,is_single); // Variable does not exist -> error
else { // Variable already exists
if (_cimg_mp_is_scalar(arg1)) compile(ss,s,depth1,0,is_single); // Variable is not a vector -> error
if (_cimg_mp_is_constant(arg2)) { // Constant index -> return corresponding variable slot directly
nb = (int)mem[arg2];
if (nb>=0 && nb<(int)_cimg_mp_size(arg1)) {
arg1+=nb + 1;
CImg<ulongT>::vector((ulongT)mp_copy,arg1,arg3).move_to(code);
_cimg_mp_return(arg1);
}
compile(ss,s,depth1,0,is_single); // Out-of-bounds reference -> error
}
// Case of non-constant index -> return assigned value + linked reference
if (p_ref) {
*p_ref = 1;
p_ref[1] = arg1;
p_ref[2] = arg2;
if (_cimg_mp_is_comp(arg3)) memtype[arg3] = -2; // Prevent from being used in further optimization
if (_cimg_mp_is_comp(arg2)) memtype[arg2] = -2;
}
CImg<ulongT>::vector((ulongT)mp_vector_set_off,arg3,arg1,(ulongT)_cimg_mp_size(arg1),
arg2,arg3).
move_to(code);
_cimg_mp_return(arg3);
}
}
}
// Assign user-defined macro.
if (l_variable_name>2 && *ve1==')' && *ss!='(') {
s0 = ve1; while (s0>ss && *s0!='(') --s0;
is_sth = std::strncmp(variable_name,"debug(",6) &&
std::strncmp(variable_name,"print(",6); // is_valid_function_name?
if (*ss>='0' && *ss<='9') is_sth = false;
else for (ns = ss; ns<s0; ++ns)
if (!is_varchar(*ns)) { is_sth = false; break; }
if (is_sth && s0>ss) { // Looks like a valid function declaration
s0 = variable_name._data + (s0 - ss);
*s0 = 0;
s1 = variable_name._data + l_variable_name - 1; // Pointer to closing parenthesis
CImg<charT>(variable_name._data,(unsigned int)(s0 - variable_name._data + 1)).move_to(macro_def,0);
++s; while (*s && (signed char)*s<=' ') ++s;
CImg<charT>(s,(unsigned int)(se - s + 1)).move_to(macro_body,0);
p1 = 1; // Indice of current parsed argument
for (s = s0 + 1; s<=s1; ++p1, s = ns + 1) { // Parse function arguments
if (p1>24) {
*se = saved_char;
cimg::strellipsize(variable_name,64);
s0 = ss - 4>expr._data?ss - 4:expr._data;
cimg::strellipsize(s0,64);
throw CImgArgumentException("[" cimg_appname "_math_parser] "
"CImg<%s>::%s: %s: Too much specified arguments (>24) in macro "
"definition '%s()', in expression '%s%s%s'.",
pixel_type(),_cimg_mp_calling_function,s_op,
variable_name._data,
s0!=expr._data?"...":"",s0,se<&expr.back()?"...":"");
}
while (*s && (signed char)*s<=' ') ++s;
if (*s==')' && p1==1) break; // Function has no arguments
s2 = s; // Start of the argument name
is_sth = true; // is_valid_argument_name?
if (*s>='0' && *s<='9') is_sth = false;
else for (ns = s; ns<s1 && *ns!=',' && (signed char)*ns>' '; ++ns)
if (!is_varchar(*ns)) { is_sth = false; break; }
s3 = ns; // End of the argument name
while (*ns && (signed char)*ns<=' ') ++ns;
if (!is_sth || s2==s3 || (*ns!=',' && ns!=s1)) {
*se = saved_char;
cimg::strellipsize(variable_name,64);
s0 = ss - 4>expr._data?ss - 4:expr._data;
cimg::strellipsize(s0,64);
throw CImgArgumentException("[" cimg_appname "_math_parser] "
"CImg<%s>::%s: %s: %s name specified for argument %u when defining "
"macro '%s()', in expression '%s%s%s'.",
pixel_type(),_cimg_mp_calling_function,s_op,
is_sth?"Empty":"Invalid",p1,
variable_name._data,
s0!=expr._data?"...":"",s0,se<&expr.back()?"...":"");
}
if (ns==s1 || *ns==',') { // New argument found
*s3 = 0;
p2 = (unsigned int)(s3 - s2); // Argument length
for (ps = std::strstr(macro_body[0],s2); ps; ps = std::strstr(ps,s2)) { // Replace by arg number
if (!((ps>macro_body[0]._data && is_varchar(*(ps - 1))) ||
(ps + p2<macro_body[0].end() && is_varchar(*(ps + p2))))) {
if (ps>macro_body[0]._data && *(ps - 1)=='#') { // Remove pre-number sign
*(ps - 1) = (char)p1;
if (ps + p2<macro_body[0].end() && *(ps + p2)=='#') { // Has pre & post number signs
std::memmove(ps,ps + p2 + 1,macro_body[0].end() - ps - p2 - 1);
macro_body[0]._width-=p2 + 1;
} else { // Has pre number sign only
std::memmove(ps,ps + p2,macro_body[0].end() - ps - p2);
macro_body[0]._width-=p2;
}
} else if (ps + p2<macro_body[0].end() && *(ps + p2)=='#') { // Remove post-number sign
*(ps++) = (char)p1;
std::memmove(ps,ps + p2,macro_body[0].end() - ps - p2);
macro_body[0]._width-=p2;
} else { // Not near a number sign
if (p2<3) {
ps-=(ulongT)macro_body[0]._data;
macro_body[0].resize(macro_body[0]._width - p2 + 3,1,1,1,0);
ps+=(ulongT)macro_body[0]._data;
} else macro_body[0]._width-=p2 - 3;
std::memmove(ps + 3,ps + p2,macro_body[0].end() - ps - 3);
*(ps++) = '(';
*(ps++) = (char)p1;
*(ps++) = ')';
}
} else ++ps;
}
}
}
// Store number of arguments.
macro_def[0].resize(macro_def[0]._width + 1,1,1,1,0).back() = (char)(p1 - 1);
// Detect parts of function body inside a string.
is_inside_string(macro_body[0]).move_to(macro_body_is_string,0);
_cimg_mp_return_nan();
}
}
// Check if the variable name could be valid. If not, this is probably an lvalue assignment.
is_sth = true; // is_valid_variable_name?
const bool is_const = l_variable_name>6 && !std::strncmp(variable_name,"const ",6);
s0 = variable_name._data;
if (is_const) {
s0+=6; while ((signed char)*s0<=' ') ++s0;
variable_name.resize(variable_name.end() - s0,1,1,1,0,0,1);
}
if (*variable_name>='0' && *variable_name<='9') is_sth = false;
else for (ns = variable_name._data; *ns; ++ns)
if (!is_varchar(*ns)) { is_sth = false; break; }
// Assign variable (direct).
if (is_sth) {
arg3 = variable_name[1]?~0U:*variable_name; // One-char variable
if (variable_name[1] && !variable_name[2]) { // Two-chars variable
c1 = variable_name[0];
c2 = variable_name[1];
if (c1=='w' && c2=='h') arg3 = 0; // wh
else if (c1=='p' && c2=='i') arg3 = 3; // pi
else if (c1=='i') {
if (c2>='0' && c2<='9') arg3 = 19 + c2 - '0'; // i0...i9
else if (c2=='m') arg3 = 4; // im
else if (c2=='M') arg3 = 5; // iM
else if (c2=='a') arg3 = 6; // ia
else if (c2=='v') arg3 = 7; // iv
else if (c2=='s') arg3 = 8; // is
else if (c2=='p') arg3 = 9; // ip
else if (c2=='c') arg3 = 10; // ic
} else if (c2=='m') {
if (c1=='x') arg3 = 11; // xm
else if (c1=='y') arg3 = 12; // ym
else if (c1=='z') arg3 = 13; // zm
else if (c1=='c') arg3 = 14; // cm
} else if (c2=='M') {
if (c1=='x') arg3 = 15; // xM
else if (c1=='y') arg3 = 16; // yM
else if (c1=='z') arg3 = 17; // zM
else if (c1=='c') arg3 = 18; // cM
}
} else if (variable_name[1] && variable_name[2] && !variable_name[3]) { // Three-chars variable
c1 = variable_name[0];
c2 = variable_name[1];
c3 = variable_name[2];
if (c1=='w' && c2=='h' && c3=='d') arg3 = 1; // whd
} else if (variable_name[1] && variable_name[2] && variable_name[3] &&
!variable_name[4]) { // Four-chars variable
c1 = variable_name[0];
c2 = variable_name[1];
c3 = variable_name[2];
c4 = variable_name[3];
if (c1=='w' && c2=='h' && c3=='d' && c4=='s') arg3 = 2; // whds
} else if (!std::strcmp(variable_name,"interpolation")) arg3 = 29; // interpolation
else if (!std::strcmp(variable_name,"boundary")) arg3 = 30; // boundary
arg1 = ~0U;
arg2 = compile(s + 1,se,depth1,0,is_single);
if (is_const) _cimg_mp_check_constant(arg2,2,0);
if (arg3!=~0U) // One-char variable, or variable in reserved_labels
arg1 = reserved_label[arg3];
else // Multi-char variable name : check for existing variable with same name
cimglist_for(variable_def,i)
if (!std::strcmp(variable_name,variable_def[i])) { arg1 = variable_pos[i]; break; }
if (arg1==~0U) { // Create new variable
if (_cimg_mp_is_vector(arg2)) { // Vector variable
arg1 = is_comp_vector(arg2)?arg2:vector_copy(arg2);
set_variable_vector(arg1);
} else { // Scalar variable
if (is_const) arg1 = arg2;
else {
arg1 = _cimg_mp_is_comp(arg2)?arg2:scalar1(mp_copy,arg2);
memtype[arg1] = -1;
}
}
if (arg3!=~0U) reserved_label[arg3] = arg1;
else {
if (variable_def._width>=variable_pos._width) variable_pos.resize(-200,1,1,1,0);
variable_pos[variable_def._width] = arg1;
variable_name.move_to(variable_def);
}
} else { // Variable already exists -> assign a new value
if (is_const || _cimg_mp_is_constant(arg1)) {
*se = saved_char;
cimg::strellipsize(variable_name,64);
s0 = ss - 4>expr._data?ss - 4:expr._data;
cimg::strellipsize(s0,64);
throw CImgArgumentException("[" cimg_appname "_math_parser] "
"CImg<%s>::%s: %s: Invalid assignment of %sconst variable '%s'%s, "
"in expression '%s%s%s'.",
pixel_type(),_cimg_mp_calling_function,s_op,
_cimg_mp_is_constant(arg1)?"already-defined ":"non-",
variable_name._data,
!_cimg_mp_is_constant(arg1) && is_const?" as a new const variable":"",
s0!=expr._data?"...":"",s0,se<&expr.back()?"...":"");
}
_cimg_mp_check_type(arg2,2,_cimg_mp_is_vector(arg1)?3:1,_cimg_mp_size(arg1));
if (_cimg_mp_is_vector(arg1)) { // Vector
if (_cimg_mp_is_vector(arg2)) // From vector
CImg<ulongT>::vector((ulongT)mp_vector_copy,arg1,arg2,(ulongT)_cimg_mp_size(arg1)).
move_to(code);
else // From scalar
CImg<ulongT>::vector((ulongT)mp_vector_init,arg1,1,(ulongT)_cimg_mp_size(arg1),arg2).
move_to(code);
} else // Scalar
CImg<ulongT>::vector((ulongT)mp_copy,arg1,arg2).move_to(code);
}
_cimg_mp_return(arg1);
}
// Assign lvalue (variable name was not valid for a direct assignment).
arg1 = ~0U;
is_sth = (bool)std::strchr(variable_name,'?'); // Contains_ternary_operator?
if (is_sth) break; // Do nothing and make ternary operator prioritary over assignment
if (l_variable_name>2 && (std::strchr(variable_name,'(') || std::strchr(variable_name,'['))) {
ref.assign(7);
arg1 = compile(ss,s,depth1,ref,is_single); // Lvalue slot
arg2 = compile(s + 1,se,depth1,0,is_single); // Value to assign
if (*ref==1) { // Vector value (scalar): V[k] = scalar
_cimg_mp_check_type(arg2,2,1,0);
arg3 = ref[1]; // Vector slot
arg4 = ref[2]; // Index
if (p_ref) std::memcpy(p_ref,ref,ref._width*sizeof(unsigned int));
CImg<ulongT>::vector((ulongT)mp_vector_set_off,arg2,arg3,(ulongT)_cimg_mp_size(arg3),arg4,arg2).
move_to(code);
_cimg_mp_return(arg2);
}
if (*ref==2) { // Image value (scalar): i/j[_#ind,off] = scalar
if (!is_single) is_parallelizable = false;
_cimg_mp_check_type(arg2,2,1,0);
p1 = ref[1]; // Index
is_relative = (bool)ref[2];
arg3 = ref[3]; // Offset
if (p_ref) std::memcpy(p_ref,ref,ref._width*sizeof(unsigned int));
if (p1!=~0U) {
if (!listout) _cimg_mp_return(arg2);
CImg<ulongT>::vector((ulongT)(is_relative?mp_list_set_joff:mp_list_set_ioff),
arg2,p1,arg3).move_to(code);
} else {
if (!imgout) _cimg_mp_return(arg2);
CImg<ulongT>::vector((ulongT)(is_relative?mp_set_joff:mp_set_ioff),
arg2,arg3).move_to(code);
}
_cimg_mp_return(arg2);
}
if (*ref==3) { // Image value (scalar): i/j(_#ind,_x,_y,_z,_c) = scalar
if (!is_single) is_parallelizable = false;
_cimg_mp_check_type(arg2,2,1,0);
p1 = ref[1]; // Index
is_relative = (bool)ref[2];
arg3 = ref[3]; // X
arg4 = ref[4]; // Y
arg5 = ref[5]; // Z
arg6 = ref[6]; // C
if (p_ref) std::memcpy(p_ref,ref,ref._width*sizeof(unsigned int));
if (p1!=~0U) {
if (!listout) _cimg_mp_return(arg2);
CImg<ulongT>::vector((ulongT)(is_relative?mp_list_set_jxyzc:mp_list_set_ixyzc),
arg2,p1,arg3,arg4,arg5,arg6).move_to(code);
} else {
if (!imgout) _cimg_mp_return(arg2);
CImg<ulongT>::vector((ulongT)(is_relative?mp_set_jxyzc:mp_set_ixyzc),
arg2,arg3,arg4,arg5,arg6).move_to(code);
}
_cimg_mp_return(arg2);
}
if (*ref==4) { // Image value (vector): I/J[_#ind,off] = value
if (!is_single) is_parallelizable = false;
_cimg_mp_check_type(arg2,2,3,_cimg_mp_size(arg1));
p1 = ref[1]; // Index
is_relative = (bool)ref[2];
arg3 = ref[3]; // Offset
if (p_ref) std::memcpy(p_ref,ref,ref._width*sizeof(unsigned int));
if (p1!=~0U) {
if (!listout) _cimg_mp_return(arg2);
if (_cimg_mp_is_scalar(arg2))
CImg<ulongT>::vector((ulongT)(is_relative?mp_list_set_Joff_s:mp_list_set_Ioff_s),
arg2,p1,arg3).move_to(code);
else
CImg<ulongT>::vector((ulongT)(is_relative?mp_list_set_Joff_v:mp_list_set_Ioff_v),
arg2,p1,arg3,_cimg_mp_size(arg2)).move_to(code);
} else {
if (!imgout) _cimg_mp_return(arg2);
if (_cimg_mp_is_scalar(arg2))
CImg<ulongT>::vector((ulongT)(is_relative?mp_set_Joff_s:mp_set_Ioff_s),
arg2,arg3).move_to(code);
else
CImg<ulongT>::vector((ulongT)(is_relative?mp_set_Joff_v:mp_set_Ioff_v),
arg2,arg3,_cimg_mp_size(arg2)).move_to(code);
}
_cimg_mp_return(arg2);
}
if (*ref==5) { // Image value (vector): I/J(_#ind,_x,_y,_z,_c) = value
if (!is_single) is_parallelizable = false;
_cimg_mp_check_type(arg2,2,3,_cimg_mp_size(arg1));
p1 = ref[1]; // Index
is_relative = (bool)ref[2];
arg3 = ref[3]; // X
arg4 = ref[4]; // Y
arg5 = ref[5]; // Z
if (p_ref) std::memcpy(p_ref,ref,ref._width*sizeof(unsigned int));
if (p1!=~0U) {
if (!listout) _cimg_mp_return(arg2);
if (_cimg_mp_is_scalar(arg2))
CImg<ulongT>::vector((ulongT)(is_relative?mp_list_set_Jxyz_s:mp_list_set_Ixyz_s),
arg2,p1,arg3,arg4,arg5).move_to(code);
else
CImg<ulongT>::vector((ulongT)(is_relative?mp_list_set_Jxyz_v:mp_list_set_Ixyz_v),
arg2,p1,arg3,arg4,arg5,_cimg_mp_size(arg2)).move_to(code);
} else {
if (!imgout) _cimg_mp_return(arg2);
if (_cimg_mp_is_scalar(arg2))
CImg<ulongT>::vector((ulongT)(is_relative?mp_set_Jxyz_s:mp_set_Ixyz_s),
arg2,arg3,arg4,arg5).move_to(code);
else
CImg<ulongT>::vector((ulongT)(is_relative?mp_set_Jxyz_v:mp_set_Ixyz_v),
arg2,arg3,arg4,arg5,_cimg_mp_size(arg2)).move_to(code);
}
_cimg_mp_return(arg2);
}
if (_cimg_mp_is_vector(arg1)) { // Vector variable: V = value
_cimg_mp_check_type(arg2,2,3,_cimg_mp_size(arg1));
if (_cimg_mp_is_vector(arg2)) // From vector
CImg<ulongT>::vector((ulongT)mp_vector_copy,arg1,arg2,(ulongT)_cimg_mp_size(arg1)).
move_to(code);
else // From scalar
CImg<ulongT>::vector((ulongT)mp_vector_init,arg1,1,(ulongT)_cimg_mp_size(arg1),arg2).
move_to(code);
_cimg_mp_return(arg1);
}
if (_cimg_mp_is_variable(arg1)) { // Scalar variable: s = scalar
_cimg_mp_check_type(arg2,2,1,0);
CImg<ulongT>::vector((ulongT)mp_copy,arg1,arg2).move_to(code);
_cimg_mp_return(arg1);
}
}
// No assignment expressions match -> error
*se = saved_char;
cimg::strellipsize(variable_name,64);
s0 = ss - 4>expr._data?ss - 4:expr._data;
cimg::strellipsize(s0,64);
throw CImgArgumentException("[" cimg_appname "_math_parser] "
"CImg<%s>::%s: %s: Invalid %slvalue '%s', "
"in expression '%s%s%s'.",
pixel_type(),_cimg_mp_calling_function,s_op,
arg1!=~0U && _cimg_mp_is_constant(arg1)?"const ":"",
variable_name._data,
s0!=expr._data?"...":"",s0,se<&expr.back()?"...":"");
}
// Apply unary/binary/ternary operators. The operator precedences should be the same as in C++.
for (s = se2, ps = se3, ns = ps - 1; s>ss1; --s, --ps, --ns) // Here, ns = ps - 1
if (*s=='=' && (*ps=='*' || *ps=='/' || *ps=='^') && *ns==*ps &&
level[s - expr._data]==clevel) { // Self-operators for complex numbers only (**=,//=,^^=)
_cimg_mp_op(*ps=='*'?"Operator '**='":*ps=='/'?"Operator '//='":"Operator '^^='");
ref.assign(7);
arg1 = compile(ss,ns,depth1,ref,is_single); // Vector slot
arg2 = compile(s + 1,se,depth1,0,is_single); // Right operand
_cimg_mp_check_type(arg1,1,2,2);
_cimg_mp_check_type(arg2,2,3,2);
if (_cimg_mp_is_vector(arg2)) { // Complex **= complex
if (*ps=='*')
CImg<ulongT>::vector((ulongT)mp_complex_mul,arg1,arg1,arg2).move_to(code);
else if (*ps=='/')
CImg<ulongT>::vector((ulongT)mp_complex_div_vv,arg1,arg1,arg2).move_to(code);
else
CImg<ulongT>::vector((ulongT)mp_complex_pow_vv,arg1,arg1,arg2).move_to(code);
} else { // Complex **= scalar
if (*ps=='*') {
if (arg2==1) _cimg_mp_return(arg1);
self_vector_s(arg1,mp_self_mul,arg2);
} else if (*ps=='/') {
if (arg2==1) _cimg_mp_return(arg1);
self_vector_s(arg1,mp_self_div,arg2);
} else {
if (arg2==1) _cimg_mp_return(arg1);
CImg<ulongT>::vector((ulongT)mp_complex_pow_vs,arg1,arg1,arg2).move_to(code);
}
}
// Write computed value back in image if necessary.
if (*ref==4) { // Image value (vector): I/J[_#ind,off] **= value
if (!is_single) is_parallelizable = false;
p1 = ref[1]; // Index
is_relative = (bool)ref[2];
arg3 = ref[3]; // Offset
if (p_ref) std::memcpy(p_ref,ref,ref._width*sizeof(unsigned int));
if (p1!=~0U) {
if (!listout) _cimg_mp_return(arg1);
CImg<ulongT>::vector((ulongT)(is_relative?mp_list_set_Joff_v:mp_list_set_Ioff_v),
arg1,p1,arg3,_cimg_mp_size(arg1)).move_to(code);
} else {
if (!imgout) _cimg_mp_return(arg1);
CImg<ulongT>::vector((ulongT)(is_relative?mp_set_Joff_v:mp_set_Ioff_v),
arg1,arg3,_cimg_mp_size(arg1)).move_to(code);
}
} else if (*ref==5) { // Image value (vector): I/J(_#ind,_x,_y,_z,_c) **= value
if (!is_single) is_parallelizable = false;
p1 = ref[1]; // Index
is_relative = (bool)ref[2];
arg3 = ref[3]; // X
arg4 = ref[4]; // Y
arg5 = ref[5]; // Z
if (p_ref) std::memcpy(p_ref,ref,ref._width*sizeof(unsigned int));
if (p1!=~0U) {
if (!listout) _cimg_mp_return(arg1);
CImg<ulongT>::vector((ulongT)(is_relative?mp_list_set_Jxyz_v:mp_list_set_Ixyz_v),
arg1,p1,arg3,arg4,arg5,_cimg_mp_size(arg1)).move_to(code);
} else {
if (!imgout) _cimg_mp_return(arg1);
CImg<ulongT>::vector((ulongT)(is_relative?mp_set_Jxyz_v:mp_set_Ixyz_v),
arg1,arg3,arg4,arg5,_cimg_mp_size(arg1)).move_to(code);
}
}
_cimg_mp_return(arg1);
}
for (s = se2, ps = se3, ns = ps - 1; s>ss1; --s, --ps, --ns) // Here, ns = ps - 1
if (*s=='=' && (*ps=='+' || *ps=='-' || *ps=='*' || *ps=='/' || *ps=='%' ||
*ps=='&' || *ps=='^' || *ps=='|' ||
(*ps=='>' && *ns=='>') || (*ps=='<' && *ns=='<')) &&
level[s - expr._data]==clevel) { // Self-operators (+=,-=,*=,/=,%=,>>=,<<=,&=,^=,|=)
switch (*ps) {
case '+' : op = mp_self_add; _cimg_mp_op("Operator '+='"); break;
case '-' : op = mp_self_sub; _cimg_mp_op("Operator '-='"); break;
case '*' : op = mp_self_mul; _cimg_mp_op("Operator '*='"); break;
case '/' : op = mp_self_div; _cimg_mp_op("Operator '/='"); break;
case '%' : op = mp_self_modulo; _cimg_mp_op("Operator '%='"); break;
case '<' : op = mp_self_bitwise_left_shift; _cimg_mp_op("Operator '<<='"); break;
case '>' : op = mp_self_bitwise_right_shift; _cimg_mp_op("Operator '>>='"); break;
case '&' : op = mp_self_bitwise_and; _cimg_mp_op("Operator '&='"); break;
case '|' : op = mp_self_bitwise_or; _cimg_mp_op("Operator '|='"); break;
default : op = mp_self_pow; _cimg_mp_op("Operator '^='"); break;
}
s1 = *ps=='>' || *ps=='<'?ns:ps;
ref.assign(7);
arg1 = compile(ss,s1,depth1,ref,is_single); // Variable slot
arg2 = compile(s + 1,se,depth1,0,is_single); // Value to apply
// Check for particular case to be simplified.
if ((op==mp_self_add || op==mp_self_sub) && !arg2) _cimg_mp_return(arg1);
if ((op==mp_self_mul || op==mp_self_div) && arg2==1) _cimg_mp_return(arg1);
// Apply operator on a copy to prevent modifying a constant or a variable.
if (*ref && (_cimg_mp_is_constant(arg1) || _cimg_mp_is_vector(arg1) || _cimg_mp_is_variable(arg1))) {
if (_cimg_mp_is_vector(arg1)) arg1 = vector_copy(arg1);
else arg1 = scalar1(mp_copy,arg1);
}
if (*ref==1) { // Vector value (scalar): V[k] += scalar
_cimg_mp_check_type(arg2,2,1,0);
arg3 = ref[1]; // Vector slot
arg4 = ref[2]; // Index
if (p_ref) std::memcpy(p_ref,ref,ref._width*sizeof(unsigned int));
CImg<ulongT>::vector((ulongT)op,arg1,arg2).move_to(code);
CImg<ulongT>::vector((ulongT)mp_vector_set_off,arg1,arg3,(ulongT)_cimg_mp_size(arg3),arg4,arg1).
move_to(code);
_cimg_mp_return(arg1);
}
if (*ref==2) { // Image value (scalar): i/j[_#ind,off] += scalar
if (!is_single) is_parallelizable = false;
_cimg_mp_check_type(arg2,2,1,0);
p1 = ref[1]; // Index
is_relative = (bool)ref[2];
arg3 = ref[3]; // Offset
if (p_ref) std::memcpy(p_ref,ref,ref._width*sizeof(unsigned int));
CImg<ulongT>::vector((ulongT)op,arg1,arg2).move_to(code);
if (p1!=~0U) {
if (!listout) _cimg_mp_return(arg1);
CImg<ulongT>::vector((ulongT)(is_relative?mp_list_set_joff:mp_list_set_ioff),
arg1,p1,arg3).move_to(code);
} else {
if (!imgout) _cimg_mp_return(arg1);
CImg<ulongT>::vector((ulongT)(is_relative?mp_set_joff:mp_set_ioff),
arg1,arg3).move_to(code);
}
_cimg_mp_return(arg1);
}
if (*ref==3) { // Image value (scalar): i/j(_#ind,_x,_y,_z,_c) += scalar
if (!is_single) is_parallelizable = false;
_cimg_mp_check_type(arg2,2,1,0);
p1 = ref[1]; // Index
is_relative = (bool)ref[2];
arg3 = ref[3]; // X
arg4 = ref[4]; // Y
arg5 = ref[5]; // Z
arg6 = ref[6]; // C
if (p_ref) std::memcpy(p_ref,ref,ref._width*sizeof(unsigned int));
CImg<ulongT>::vector((ulongT)op,arg1,arg2).move_to(code);
if (p1!=~0U) {
if (!listout) _cimg_mp_return(arg1);
CImg<ulongT>::vector((ulongT)(is_relative?mp_list_set_jxyzc:mp_list_set_ixyzc),
arg1,p1,arg3,arg4,arg5,arg6).move_to(code);
} else {
if (!imgout) _cimg_mp_return(arg1);
CImg<ulongT>::vector((ulongT)(is_relative?mp_set_jxyzc:mp_set_ixyzc),
arg1,arg3,arg4,arg5,arg6).move_to(code);
}
_cimg_mp_return(arg1);
}
if (*ref==4) { // Image value (vector): I/J[_#ind,off] += value
if (!is_single) is_parallelizable = false;
_cimg_mp_check_type(arg2,2,3,_cimg_mp_size(arg1));
p1 = ref[1]; // Index
is_relative = (bool)ref[2];
arg3 = ref[3]; // Offset
if (p_ref) std::memcpy(p_ref,ref,ref._width*sizeof(unsigned int));
if (_cimg_mp_is_scalar(arg2)) self_vector_s(arg1,op,arg2); else self_vector_v(arg1,op,arg2);
if (p1!=~0U) {
if (!listout) _cimg_mp_return(arg1);
CImg<ulongT>::vector((ulongT)(is_relative?mp_list_set_Joff_v:mp_list_set_Ioff_v),
arg1,p1,arg3,_cimg_mp_size(arg1)).move_to(code);
} else {
if (!imgout) _cimg_mp_return(arg1);
CImg<ulongT>::vector((ulongT)(is_relative?mp_set_Joff_v:mp_set_Ioff_v),
arg1,arg3,_cimg_mp_size(arg1)).move_to(code);
}
_cimg_mp_return(arg1);
}
if (*ref==5) { // Image value (vector): I/J(_#ind,_x,_y,_z,_c) += value
if (!is_single) is_parallelizable = false;
_cimg_mp_check_type(arg2,2,3,_cimg_mp_size(arg1));
p1 = ref[1]; // Index
is_relative = (bool)ref[2];
arg3 = ref[3]; // X
arg4 = ref[4]; // Y
arg5 = ref[5]; // Z
if (p_ref) std::memcpy(p_ref,ref,ref._width*sizeof(unsigned int));
if (_cimg_mp_is_scalar(arg2)) self_vector_s(arg1,op,arg2); else self_vector_v(arg1,op,arg2);
if (p1!=~0U) {
if (!listout) _cimg_mp_return(arg1);
CImg<ulongT>::vector((ulongT)(is_relative?mp_list_set_Jxyz_v:mp_list_set_Ixyz_v),
arg1,p1,arg3,arg4,arg5,_cimg_mp_size(arg1)).move_to(code);
} else {
if (!imgout) _cimg_mp_return(arg1);
CImg<ulongT>::vector((ulongT)(is_relative?mp_set_Jxyz_v:mp_set_Ixyz_v),
arg1,arg3,arg4,arg5,_cimg_mp_size(arg1)).move_to(code);
}
_cimg_mp_return(arg1);
}
if (_cimg_mp_is_vector(arg1)) { // Vector variable: V += value
_cimg_mp_check_type(arg2,2,3,_cimg_mp_size(arg1));
if (_cimg_mp_is_vector(arg2)) self_vector_v(arg1,op,arg2); // Vector += vector
else self_vector_s(arg1,op,arg2); // Vector += scalar
_cimg_mp_return(arg1);
}
if (_cimg_mp_is_variable(arg1)) { // Scalar variable: s += scalar
_cimg_mp_check_type(arg2,2,1,0);
CImg<ulongT>::vector((ulongT)op,arg1,arg2).move_to(code);
_cimg_mp_return(arg1);
}
variable_name.assign(ss,(unsigned int)(s - ss)).back() = 0;
cimg::strpare(variable_name,false,true);
*se = saved_char;
s0 = ss - 4>expr._data?ss - 4:expr._data;
cimg::strellipsize(s0,64);
throw CImgArgumentException("[" cimg_appname "_math_parser] "
"CImg<%s>::%s: %s: Invalid %slvalue '%s', "
"in expression '%s%s%s'.",
pixel_type(),_cimg_mp_calling_function,s_op,
_cimg_mp_is_constant(arg1)?"const ":"",
variable_name._data,
s0!=expr._data?"...":"",s0,se<&expr.back()?"...":"");
}
for (s = ss1; s<se1; ++s)
if (*s=='?' && level[s - expr._data]==clevel) { // Ternary operator 'cond?expr1:expr2'
_cimg_mp_op("Operator '?:'");
s1 = s + 1; while (s1<se1 && (*s1!=':' || level[s1 - expr._data]!=clevel)) ++s1;
arg1 = compile(ss,s,depth1,0,is_single);
_cimg_mp_check_type(arg1,1,1,0);
if (_cimg_mp_is_constant(arg1)) {
if ((bool)mem[arg1]) return compile(s + 1,*s1!=':'?se:s1,depth1,0,is_single);
else return *s1!=':'?0:compile(++s1,se,depth1,0,is_single);
}
p2 = code._width;
arg2 = compile(s + 1,*s1!=':'?se:s1,depth1,0,is_single);
p3 = code._width;
arg3 = *s1==':'?compile(++s1,se,depth1,0,is_single):
_cimg_mp_is_vector(arg2)?vector(_cimg_mp_size(arg2),0):0;
_cimg_mp_check_type(arg3,3,_cimg_mp_is_vector(arg2)?2:1,_cimg_mp_size(arg2));
arg4 = _cimg_mp_size(arg2);
if (arg4) pos = vector(arg4); else pos = scalar();
CImg<ulongT>::vector((ulongT)mp_if,pos,arg1,arg2,arg3,
p3 - p2,code._width - p3,arg4).move_to(code,p2);
_cimg_mp_return(pos);
}
for (s = se3, ns = se2; s>ss; --s, --ns)
if (*s=='|' && *ns=='|' && level[s - expr._data]==clevel) { // Logical or ('||')
_cimg_mp_op("Operator '||'");
arg1 = compile(ss,s,depth1,0,is_single);
_cimg_mp_check_type(arg1,1,1,0);
if (arg1>0 && arg1<=16) _cimg_mp_return(1);
p2 = code._width;
arg2 = compile(s + 2,se,depth1,0,is_single);
_cimg_mp_check_type(arg2,2,1,0);
if (_cimg_mp_is_constant(arg1) && _cimg_mp_is_constant(arg2))
_cimg_mp_constant(mem[arg1] || mem[arg2]);
if (!arg1) _cimg_mp_return(arg2);
pos = scalar();
CImg<ulongT>::vector((ulongT)mp_logical_or,pos,arg1,arg2,code._width - p2).
move_to(code,p2);
_cimg_mp_return(pos);
}
for (s = se3, ns = se2; s>ss; --s, --ns)
if (*s=='&' && *ns=='&' && level[s - expr._data]==clevel) { // Logical and ('&&')
_cimg_mp_op("Operator '&&'");
arg1 = compile(ss,s,depth1,0,is_single);
_cimg_mp_check_type(arg1,1,1,0);
if (!arg1) _cimg_mp_return(0);
p2 = code._width;
arg2 = compile(s + 2,se,depth1,0,is_single);
_cimg_mp_check_type(arg2,2,1,0);
if (_cimg_mp_is_constant(arg1) && _cimg_mp_is_constant(arg2))
_cimg_mp_constant(mem[arg1] && mem[arg2]);
if (arg1>0 && arg1<=16) _cimg_mp_return(arg2);
pos = scalar();
CImg<ulongT>::vector((ulongT)mp_logical_and,pos,arg1,arg2,code._width - p2).
move_to(code,p2);
_cimg_mp_return(pos);
}
for (s = se2; s>ss; --s)
if (*s=='|' && level[s - expr._data]==clevel) { // Bitwise or ('|')
_cimg_mp_op("Operator '|'");
arg1 = compile(ss,s,depth1,0,is_single);
arg2 = compile(s + 1,se,depth1,0,is_single);
_cimg_mp_check_type(arg2,2,3,_cimg_mp_size(arg1));
if (_cimg_mp_is_vector(arg1) && _cimg_mp_is_vector(arg2)) _cimg_mp_vector2_vv(mp_bitwise_or,arg1,arg2);
if (_cimg_mp_is_vector(arg1) && _cimg_mp_is_scalar(arg2)) {
if (!arg2) _cimg_mp_return(arg1);
_cimg_mp_vector2_vs(mp_bitwise_or,arg1,arg2);
}
if (_cimg_mp_is_scalar(arg1) && _cimg_mp_is_vector(arg2)) {
if (!arg1) _cimg_mp_return(arg2);
_cimg_mp_vector2_sv(mp_bitwise_or,arg1,arg2);
}
if (_cimg_mp_is_constant(arg1) && _cimg_mp_is_constant(arg2))
_cimg_mp_constant((longT)mem[arg1] | (longT)mem[arg2]);
if (!arg2) _cimg_mp_return(arg1);
if (!arg1) _cimg_mp_return(arg2);
_cimg_mp_scalar2(mp_bitwise_or,arg1,arg2);
}
for (s = se2; s>ss; --s)
if (*s=='&' && level[s - expr._data]==clevel) { // Bitwise and ('&')
_cimg_mp_op("Operator '&'");
arg1 = compile(ss,s,depth1,0,is_single);
arg2 = compile(s + 1,se,depth1,0,is_single);
_cimg_mp_check_type(arg2,2,3,_cimg_mp_size(arg1));
if (_cimg_mp_is_vector(arg1) && _cimg_mp_is_vector(arg2)) _cimg_mp_vector2_vv(mp_bitwise_and,arg1,arg2);
if (_cimg_mp_is_vector(arg1) && _cimg_mp_is_scalar(arg2)) _cimg_mp_vector2_vs(mp_bitwise_and,arg1,arg2);
if (_cimg_mp_is_scalar(arg1) && _cimg_mp_is_vector(arg2)) _cimg_mp_vector2_sv(mp_bitwise_and,arg1,arg2);
if (_cimg_mp_is_constant(arg1) && _cimg_mp_is_constant(arg2))
_cimg_mp_constant((longT)mem[arg1] & (longT)mem[arg2]);
if (!arg1 || !arg2) _cimg_mp_return(0);
_cimg_mp_scalar2(mp_bitwise_and,arg1,arg2);
}
for (s = se3, ns = se2; s>ss; --s, --ns)
if (*s=='!' && *ns=='=' && level[s - expr._data]==clevel) { // Not equal to ('!=')
_cimg_mp_op("Operator '!='");
arg1 = compile(ss,s,depth1,0,is_single);
arg2 = compile(s + 2,se,depth1,0,is_single);
if (arg1==arg2) _cimg_mp_return(0);
p1 = _cimg_mp_size(arg1);
p2 = _cimg_mp_size(arg2);
if (p1 || p2) {
if (p1 && p2 && p1!=p2) _cimg_mp_return(1);
_cimg_mp_scalar6(mp_vector_neq,arg1,p1,arg2,p2,11,1);
}
if (_cimg_mp_is_constant(arg1) && _cimg_mp_is_constant(arg2)) _cimg_mp_constant(mem[arg1]!=mem[arg2]);
_cimg_mp_scalar2(mp_neq,arg1,arg2);
}
for (s = se3, ns = se2; s>ss; --s, --ns)
if (*s=='=' && *ns=='=' && level[s - expr._data]==clevel) { // Equal to ('==')
_cimg_mp_op("Operator '=='");
arg1 = compile(ss,s,depth1,0,is_single);
arg2 = compile(s + 2,se,depth1,0,is_single);
if (arg1==arg2) _cimg_mp_return(1);
p1 = _cimg_mp_size(arg1);
p2 = _cimg_mp_size(arg2);
if (p1 || p2) {
if (p1 && p2 && p1!=p2) _cimg_mp_return(0);
_cimg_mp_scalar6(mp_vector_eq,arg1,p1,arg2,p2,11,1);
}
if (_cimg_mp_is_constant(arg1) && _cimg_mp_is_constant(arg2)) _cimg_mp_constant(mem[arg1]==mem[arg2]);
_cimg_mp_scalar2(mp_eq,arg1,arg2);
}
for (s = se3, ns = se2; s>ss; --s, --ns)
if (*s=='<' && *ns=='=' && level[s - expr._data]==clevel) { // Less or equal than ('<=')
_cimg_mp_op("Operator '<='");
arg1 = compile(ss,s,depth1,0,is_single);
arg2 = compile(s + 2,se,depth1,0,is_single);
_cimg_mp_check_type(arg2,2,3,_cimg_mp_size(arg1));
if (_cimg_mp_is_vector(arg1) && _cimg_mp_is_vector(arg2)) _cimg_mp_vector2_vv(mp_lte,arg1,arg2);
if (_cimg_mp_is_vector(arg1) && _cimg_mp_is_scalar(arg2)) _cimg_mp_vector2_vs(mp_lte,arg1,arg2);
if (_cimg_mp_is_scalar(arg1) && _cimg_mp_is_vector(arg2)) _cimg_mp_vector2_sv(mp_lte,arg1,arg2);
if (_cimg_mp_is_constant(arg1) && _cimg_mp_is_constant(arg2)) _cimg_mp_constant(mem[arg1]<=mem[arg2]);
if (arg1==arg2) _cimg_mp_return(1);
_cimg_mp_scalar2(mp_lte,arg1,arg2);
}
for (s = se3, ns = se2; s>ss; --s, --ns)
if (*s=='>' && *ns=='=' && level[s - expr._data]==clevel) { // Greater or equal than ('>=')
_cimg_mp_op("Operator '>='");
arg1 = compile(ss,s,depth1,0,is_single);
arg2 = compile(s + 2,se,depth1,0,is_single);
_cimg_mp_check_type(arg2,2,3,_cimg_mp_size(arg1));
if (_cimg_mp_is_vector(arg1) && _cimg_mp_is_vector(arg2)) _cimg_mp_vector2_vv(mp_gte,arg1,arg2);
if (_cimg_mp_is_vector(arg1) && _cimg_mp_is_scalar(arg2)) _cimg_mp_vector2_vs(mp_gte,arg1,arg2);
if (_cimg_mp_is_scalar(arg1) && _cimg_mp_is_vector(arg2)) _cimg_mp_vector2_sv(mp_gte,arg1,arg2);
if (_cimg_mp_is_constant(arg1) && _cimg_mp_is_constant(arg2)) _cimg_mp_constant(mem[arg1]>=mem[arg2]);
if (arg1==arg2) _cimg_mp_return(1);
_cimg_mp_scalar2(mp_gte,arg1,arg2);
}
for (s = se2, ns = se1, ps = se3; s>ss; --s, --ns, --ps)
if (*s=='<' && *ns!='<' && *ps!='<' && level[s - expr._data]==clevel) { // Less than ('<')
_cimg_mp_op("Operator '<'");
arg1 = compile(ss,s,depth1,0,is_single);
arg2 = compile(s + 1,se,depth1,0,is_single);
_cimg_mp_check_type(arg2,2,3,_cimg_mp_size(arg1));
if (_cimg_mp_is_vector(arg1) && _cimg_mp_is_vector(arg2)) _cimg_mp_vector2_vv(mp_lt,arg1,arg2);
if (_cimg_mp_is_vector(arg1) && _cimg_mp_is_scalar(arg2)) _cimg_mp_vector2_vs(mp_lt,arg1,arg2);
if (_cimg_mp_is_scalar(arg1) && _cimg_mp_is_vector(arg2)) _cimg_mp_vector2_sv(mp_lt,arg1,arg2);
if (_cimg_mp_is_constant(arg1) && _cimg_mp_is_constant(arg2)) _cimg_mp_constant(mem[arg1]<mem[arg2]);
if (arg1==arg2) _cimg_mp_return(0);
_cimg_mp_scalar2(mp_lt,arg1,arg2);
}
for (s = se2, ns = se1, ps = se3; s>ss; --s, --ns, --ps)
if (*s=='>' && *ns!='>' && *ps!='>' && level[s - expr._data]==clevel) { // Greather than ('>')
_cimg_mp_op("Operator '>'");
arg1 = compile(ss,s,depth1,0,is_single);
arg2 = compile(s + 1,se,depth1,0,is_single);
_cimg_mp_check_type(arg2,2,3,_cimg_mp_size(arg1));
if (_cimg_mp_is_vector(arg1) && _cimg_mp_is_vector(arg2)) _cimg_mp_vector2_vv(mp_gt,arg1,arg2);
if (_cimg_mp_is_vector(arg1) && _cimg_mp_is_scalar(arg2)) _cimg_mp_vector2_vs(mp_gt,arg1,arg2);
if (_cimg_mp_is_scalar(arg1) && _cimg_mp_is_vector(arg2)) _cimg_mp_vector2_sv(mp_gt,arg1,arg2);
if (_cimg_mp_is_constant(arg1) && _cimg_mp_is_constant(arg2)) _cimg_mp_constant(mem[arg1]>mem[arg2]);
if (arg1==arg2) _cimg_mp_return(0);
_cimg_mp_scalar2(mp_gt,arg1,arg2);
}
for (s = se3, ns = se2; s>ss; --s, --ns)
if (*s=='<' && *ns=='<' && level[s - expr._data]==clevel) { // Left bit shift ('<<')
_cimg_mp_op("Operator '<<'");
arg1 = compile(ss,s,depth1,0,is_single);
arg2 = compile(s + 2,se,depth1,0,is_single);
_cimg_mp_check_type(arg2,2,3,_cimg_mp_size(arg1));
if (_cimg_mp_is_vector(arg1) && _cimg_mp_is_vector(arg2))
_cimg_mp_vector2_vv(mp_bitwise_left_shift,arg1,arg2);
if (_cimg_mp_is_vector(arg1) && _cimg_mp_is_scalar(arg2)) {
if (!arg2) _cimg_mp_return(arg1);
_cimg_mp_vector2_vs(mp_bitwise_left_shift,arg1,arg2);
}
if (_cimg_mp_is_scalar(arg1) && _cimg_mp_is_vector(arg2))
_cimg_mp_vector2_sv(mp_bitwise_left_shift,arg1,arg2);
if (_cimg_mp_is_constant(arg1) && _cimg_mp_is_constant(arg2))
_cimg_mp_constant((longT)mem[arg1]<<(unsigned int)mem[arg2]);
if (!arg1) _cimg_mp_return(0);
if (!arg2) _cimg_mp_return(arg1);
_cimg_mp_scalar2(mp_bitwise_left_shift,arg1,arg2);
}
for (s = se3, ns = se2; s>ss; --s, --ns)
if (*s=='>' && *ns=='>' && level[s - expr._data]==clevel) { // Right bit shift ('>>')
_cimg_mp_op("Operator '>>'");
arg1 = compile(ss,s,depth1,0,is_single);
arg2 = compile(s + 2,se,depth1,0,is_single);
_cimg_mp_check_type(arg2,2,3,_cimg_mp_size(arg1));
if (_cimg_mp_is_vector(arg1) && _cimg_mp_is_vector(arg2))
_cimg_mp_vector2_vv(mp_bitwise_right_shift,arg1,arg2);
if (_cimg_mp_is_vector(arg1) && _cimg_mp_is_scalar(arg2)) {
if (!arg2) _cimg_mp_return(arg1);
_cimg_mp_vector2_vs(mp_bitwise_right_shift,arg1,arg2);
}
if (_cimg_mp_is_scalar(arg1) && _cimg_mp_is_vector(arg2))
_cimg_mp_vector2_sv(mp_bitwise_right_shift,arg1,arg2);
if (_cimg_mp_is_constant(arg1) && _cimg_mp_is_constant(arg2))
_cimg_mp_constant((longT)mem[arg1]>>(unsigned int)mem[arg2]);
if (!arg1) _cimg_mp_return(0);
if (!arg2) _cimg_mp_return(arg1);
_cimg_mp_scalar2(mp_bitwise_right_shift,arg1,arg2);
}
for (ns = se1, s = se2, ps = pexpr._data + (se3 - expr._data); s>ss; --ns, --s, --ps)
if (*s=='+' && (*ns!='+' || ns!=se1) && *ps!='-' && *ps!='+' && *ps!='*' && *ps!='/' && *ps!='%' &&
*ps!='&' && *ps!='|' && *ps!='^' && *ps!='!' && *ps!='~' && *ps!='#' &&
(*ps!='e' || !(ps - pexpr._data>ss - expr._data && (*(ps - 1)=='.' || (*(ps - 1)>='0' &&
*(ps - 1)<='9')))) &&
level[s - expr._data]==clevel) { // Addition ('+')
_cimg_mp_op("Operator '+'");
arg1 = compile(ss,s,depth1,0,is_single);
arg2 = compile(s + 1,se,depth1,0,is_single);
_cimg_mp_check_type(arg2,2,3,_cimg_mp_size(arg1));
if (!arg2) _cimg_mp_return(arg1);
if (!arg1) _cimg_mp_return(arg2);
if (_cimg_mp_is_vector(arg1) && _cimg_mp_is_vector(arg2)) _cimg_mp_vector2_vv(mp_add,arg1,arg2);
if (_cimg_mp_is_vector(arg1) && _cimg_mp_is_scalar(arg2)) _cimg_mp_vector2_vs(mp_add,arg1,arg2);
if (_cimg_mp_is_scalar(arg1) && _cimg_mp_is_vector(arg2)) _cimg_mp_vector2_sv(mp_add,arg1,arg2);
if (_cimg_mp_is_constant(arg1) && _cimg_mp_is_constant(arg2)) _cimg_mp_constant(mem[arg1] + mem[arg2]);
if (code) { // Try to spot linear case 'a*b + c'.
CImg<ulongT> &pop = code.back();
if (pop[0]==(ulongT)mp_mul && _cimg_mp_is_comp(pop[1]) && (pop[1]==arg1 || pop[1]==arg2)) {
arg3 = (unsigned int)pop[1];
arg4 = (unsigned int)pop[2];
arg5 = (unsigned int)pop[3];
code.remove();
CImg<ulongT>::vector((ulongT)mp_linear_add,arg3,arg4,arg5,arg3==arg2?arg1:arg2).move_to(code);
_cimg_mp_return(arg3);
}
}
if (arg2==1) _cimg_mp_scalar1(mp_increment,arg1);
if (arg1==1) _cimg_mp_scalar1(mp_increment,arg2);
_cimg_mp_scalar2(mp_add,arg1,arg2);
}
for (ns = se1, s = se2, ps = pexpr._data + (se3 - expr._data); s>ss; --ns, --s, --ps)
if (*s=='-' && (*ns!='-' || ns!=se1) && *ps!='-' && *ps!='+' && *ps!='*' && *ps!='/' && *ps!='%' &&
*ps!='&' && *ps!='|' && *ps!='^' && *ps!='!' && *ps!='~' && *ps!='#' &&
(*ps!='e' || !(ps - pexpr._data>ss - expr._data && (*(ps - 1)=='.' || (*(ps - 1)>='0' &&
*(ps - 1)<='9')))) &&
level[s - expr._data]==clevel) { // Subtraction ('-')
_cimg_mp_op("Operator '-'");
arg1 = compile(ss,s,depth1,0,is_single);
arg2 = compile(s + 1,se,depth1,0,is_single);
_cimg_mp_check_type(arg2,2,3,_cimg_mp_size(arg1));
if (!arg2) _cimg_mp_return(arg1);
if (_cimg_mp_is_vector(arg1) && _cimg_mp_is_vector(arg2)) _cimg_mp_vector2_vv(mp_sub,arg1,arg2);
if (_cimg_mp_is_vector(arg1) && _cimg_mp_is_scalar(arg2)) _cimg_mp_vector2_vs(mp_sub,arg1,arg2);
if (_cimg_mp_is_scalar(arg1) && _cimg_mp_is_vector(arg2)) {
if (!arg1) _cimg_mp_vector1_v(mp_minus,arg2);
_cimg_mp_vector2_sv(mp_sub,arg1,arg2);
}
if (_cimg_mp_is_constant(arg1) && _cimg_mp_is_constant(arg2)) _cimg_mp_constant(mem[arg1] - mem[arg2]);
if (!arg1) _cimg_mp_scalar1(mp_minus,arg2);
if (code) { // Try to spot linear cases 'a*b - c' and 'c - a*b'.
CImg<ulongT> &pop = code.back();
if (pop[0]==(ulongT)mp_mul && _cimg_mp_is_comp(pop[1]) && (pop[1]==arg1 || pop[1]==arg2)) {
arg3 = (unsigned int)pop[1];
arg4 = (unsigned int)pop[2];
arg5 = (unsigned int)pop[3];
code.remove();
CImg<ulongT>::vector((ulongT)(arg3==arg1?mp_linear_sub_left:mp_linear_sub_right),
arg3,arg4,arg5,arg3==arg1?arg2:arg1).move_to(code);
_cimg_mp_return(arg3);
}
}
if (arg2==1) _cimg_mp_scalar1(mp_decrement,arg1);
_cimg_mp_scalar2(mp_sub,arg1,arg2);
}
for (s = se3, ns = se2; s>ss; --s, --ns)
if (*s=='*' && *ns=='*' && level[s - expr._data]==clevel) { // Complex multiplication ('**')
_cimg_mp_op("Operator '**'");
arg1 = compile(ss,s,depth1,0,is_single);
arg2 = compile(s + 2,se,depth1,0,is_single);
_cimg_mp_check_type(arg1,1,3,2);
_cimg_mp_check_type(arg2,2,3,2);
if (arg2==1) _cimg_mp_return(arg1);
if (arg1==1) _cimg_mp_return(arg2);
if (_cimg_mp_is_vector(arg1) && _cimg_mp_is_vector(arg2)) {
pos = vector(2);
CImg<ulongT>::vector((ulongT)mp_complex_mul,pos,arg1,arg2).move_to(code);
_cimg_mp_return(pos);
}
if (_cimg_mp_is_vector(arg1) && _cimg_mp_is_scalar(arg2)) _cimg_mp_vector2_vs(mp_mul,arg1,arg2);
if (_cimg_mp_is_scalar(arg1) && _cimg_mp_is_vector(arg2)) _cimg_mp_vector2_sv(mp_mul,arg1,arg2);
if (_cimg_mp_is_constant(arg1) && _cimg_mp_is_constant(arg2)) _cimg_mp_constant(mem[arg1]*mem[arg2]);
if (!arg1 || !arg2) _cimg_mp_return(0);
_cimg_mp_scalar2(mp_mul,arg1,arg2);
}
for (s = se3, ns = se2; s>ss; --s, --ns)
if (*s=='/' && *ns=='/' && level[s - expr._data]==clevel) { // Complex division ('//')
_cimg_mp_op("Operator '//'");
arg1 = compile(ss,s,depth1,0,is_single);
arg2 = compile(s + 2,se,depth1,0,is_single);
_cimg_mp_check_type(arg1,1,3,2);
_cimg_mp_check_type(arg2,2,3,2);
if (arg2==1) _cimg_mp_return(arg1);
if (_cimg_mp_is_vector(arg1) && _cimg_mp_is_vector(arg2)) {
pos = vector(2);
CImg<ulongT>::vector((ulongT)mp_complex_div_vv,pos,arg1,arg2).move_to(code);
_cimg_mp_return(pos);
}
if (_cimg_mp_is_vector(arg1) && _cimg_mp_is_scalar(arg2)) _cimg_mp_vector2_vs(mp_div,arg1,arg2);
if (_cimg_mp_is_scalar(arg1) && _cimg_mp_is_vector(arg2)) {
pos = vector(2);
CImg<ulongT>::vector((ulongT)mp_complex_div_sv,pos,arg1,arg2).move_to(code);
_cimg_mp_return(pos);
}
if (_cimg_mp_is_constant(arg1) && _cimg_mp_is_constant(arg2)) _cimg_mp_constant(mem[arg1]/mem[arg2]);
if (!arg1) _cimg_mp_return(0);
_cimg_mp_scalar2(mp_div,arg1,arg2);
}
for (s = se2; s>ss; --s) if (*s=='*' && level[s - expr._data]==clevel) { // Multiplication ('*')
_cimg_mp_op("Operator '*'");
arg1 = compile(ss,s,depth1,0,is_single);
arg2 = compile(s + 1,se,depth1,0,is_single);
p2 = _cimg_mp_size(arg2);
if (p2>0 && _cimg_mp_size(arg1)==p2*p2) { // Particular case of matrix multiplication
pos = vector(p2);
CImg<ulongT>::vector((ulongT)mp_matrix_mul,pos,arg1,arg2,p2,p2,1).move_to(code);
_cimg_mp_return(pos);
}
_cimg_mp_check_type(arg2,2,3,_cimg_mp_size(arg1));
if (arg2==1) _cimg_mp_return(arg1);
if (arg1==1) _cimg_mp_return(arg2);
if (_cimg_mp_is_vector(arg1) && _cimg_mp_is_vector(arg2)) _cimg_mp_vector2_vv(mp_mul,arg1,arg2);
if (_cimg_mp_is_vector(arg1) && _cimg_mp_is_scalar(arg2)) _cimg_mp_vector2_vs(mp_mul,arg1,arg2);
if (_cimg_mp_is_scalar(arg1) && _cimg_mp_is_vector(arg2)) _cimg_mp_vector2_sv(mp_mul,arg1,arg2);
if (_cimg_mp_is_constant(arg1) && _cimg_mp_is_constant(arg2)) _cimg_mp_constant(mem[arg1]*mem[arg2]);
if (code) { // Try to spot double multiplication 'a*b*c'.
CImg<ulongT> &pop = code.back();
if (pop[0]==(ulongT)mp_mul && _cimg_mp_is_comp(pop[1]) && (pop[1]==arg1 || pop[1]==arg2)) {
arg3 = (unsigned int)pop[1];
arg4 = (unsigned int)pop[2];
arg5 = (unsigned int)pop[3];
code.remove();
CImg<ulongT>::vector((ulongT)mp_mul2,arg3,arg4,arg5,arg3==arg2?arg1:arg2).move_to(code);
_cimg_mp_return(arg3);
}
}
if (!arg1 || !arg2) _cimg_mp_return(0);
_cimg_mp_scalar2(mp_mul,arg1,arg2);
}
for (s = se2; s>ss; --s) if (*s=='/' && level[s - expr._data]==clevel) { // Division ('/')
_cimg_mp_op("Operator '/'");
arg1 = compile(ss,s,depth1,0,is_single);
arg2 = compile(s + 1,se,depth1,0,is_single);
_cimg_mp_check_type(arg2,2,3,_cimg_mp_size(arg1));
if (arg2==1) _cimg_mp_return(arg1);
if (_cimg_mp_is_vector(arg1) && _cimg_mp_is_vector(arg2)) _cimg_mp_vector2_vv(mp_div,arg1,arg2);
if (_cimg_mp_is_vector(arg1) && _cimg_mp_is_scalar(arg2)) _cimg_mp_vector2_vs(mp_div,arg1,arg2);
if (_cimg_mp_is_scalar(arg1) && _cimg_mp_is_vector(arg2)) _cimg_mp_vector2_sv(mp_div,arg1,arg2);
if (_cimg_mp_is_constant(arg1) && _cimg_mp_is_constant(arg2)) _cimg_mp_constant(mem[arg1]/mem[arg2]);
if (!arg1) _cimg_mp_return(0);
_cimg_mp_scalar2(mp_div,arg1,arg2);
}
for (s = se2, ns = se1; s>ss; --s, --ns)
if (*s=='%' && *ns!='^' && level[s - expr._data]==clevel) { // Modulo ('%')
_cimg_mp_op("Operator '%'");
arg1 = compile(ss,s,depth1,0,is_single);
arg2 = compile(s + 1,se,depth1,0,is_single);
_cimg_mp_check_type(arg2,2,3,_cimg_mp_size(arg1));
if (_cimg_mp_is_vector(arg1) && _cimg_mp_is_vector(arg2)) _cimg_mp_vector2_vv(mp_modulo,arg1,arg2);
if (_cimg_mp_is_vector(arg1) && _cimg_mp_is_scalar(arg2)) _cimg_mp_vector2_vs(mp_modulo,arg1,arg2);
if (_cimg_mp_is_scalar(arg1) && _cimg_mp_is_vector(arg2)) _cimg_mp_vector2_sv(mp_modulo,arg1,arg2);
if (_cimg_mp_is_constant(arg1) && _cimg_mp_is_constant(arg2))
_cimg_mp_constant(cimg::mod(mem[arg1],mem[arg2]));
_cimg_mp_scalar2(mp_modulo,arg1,arg2);
}
if (se1>ss) {
if (*ss=='+' && (*ss1!='+' || (ss2<se && *ss2>='0' && *ss2<='9'))) { // Unary plus ('+')
_cimg_mp_op("Operator '+'");
_cimg_mp_return(compile(ss1,se,depth1,0,is_single));
}
if (*ss=='-' && (*ss1!='-' || (ss2<se && *ss2>='0' && *ss2<='9'))) { // Unary minus ('-')
_cimg_mp_op("Operator '-'");
arg1 = compile(ss1,se,depth1,0,is_single);
if (_cimg_mp_is_vector(arg1)) _cimg_mp_vector1_v(mp_minus,arg1);
if (_cimg_mp_is_constant(arg1)) _cimg_mp_constant(-mem[arg1]);
_cimg_mp_scalar1(mp_minus,arg1);
}
if (*ss=='!') { // Logical not ('!')
_cimg_mp_op("Operator '!'");
if (*ss1=='!') { // '!!expr' optimized as 'bool(expr)'
arg1 = compile(ss2,se,depth1,0,is_single);
if (_cimg_mp_is_vector(arg1)) _cimg_mp_vector1_v(mp_bool,arg1);
if (_cimg_mp_is_constant(arg1)) _cimg_mp_constant((bool)mem[arg1]);
_cimg_mp_scalar1(mp_bool,arg1);
}
arg1 = compile(ss1,se,depth1,0,is_single);
if (_cimg_mp_is_vector(arg1)) _cimg_mp_vector1_v(mp_logical_not,arg1);
if (_cimg_mp_is_constant(arg1)) _cimg_mp_constant(!mem[arg1]);
_cimg_mp_scalar1(mp_logical_not,arg1);
}
if (*ss=='~') { // Bitwise not ('~')
_cimg_mp_op("Operator '~'");
arg1 = compile(ss1,se,depth1,0,is_single);
if (_cimg_mp_is_vector(arg1)) _cimg_mp_vector1_v(mp_bitwise_not,arg1);
if (_cimg_mp_is_constant(arg1)) _cimg_mp_constant(~(unsigned int)mem[arg1]);
_cimg_mp_scalar1(mp_bitwise_not,arg1);
}
}
for (s = se3, ns = se2; s>ss; --s, --ns)
if (*s=='^' && *ns=='^' && level[s - expr._data]==clevel) { // Complex power ('^^')
_cimg_mp_op("Operator '^^'");
arg1 = compile(ss,s,depth1,0,is_single);
arg2 = compile(s + 2,se,depth1,0,is_single);
_cimg_mp_check_type(arg1,1,3,2);
_cimg_mp_check_type(arg2,2,3,2);
if (arg2==1) _cimg_mp_return(arg1);
pos = vector(2);
if (_cimg_mp_is_vector(arg1) && _cimg_mp_is_vector(arg2)) {
CImg<ulongT>::vector((ulongT)mp_complex_pow_vv,pos,arg1,arg2).move_to(code);
_cimg_mp_return(pos);
}
if (_cimg_mp_is_vector(arg1) && _cimg_mp_is_scalar(arg2)) {
CImg<ulongT>::vector((ulongT)mp_complex_pow_vs,pos,arg1,arg2).move_to(code);
_cimg_mp_return(pos);
}
if (_cimg_mp_is_scalar(arg1) && _cimg_mp_is_vector(arg2)) {
CImg<ulongT>::vector((ulongT)mp_complex_pow_sv,pos,arg1,arg2).move_to(code);
_cimg_mp_return(pos);
}
CImg<ulongT>::vector((ulongT)mp_complex_pow_ss,pos,arg1,arg2).move_to(code);
_cimg_mp_return(pos);
}
for (s = se2; s>ss; --s)
if (*s=='^' && level[s - expr._data]==clevel) { // Power ('^')
_cimg_mp_op("Operator '^'");
arg1 = compile(ss,s,depth1,0,is_single);
arg2 = compile(s + 1,se,depth1,0,is_single);
_cimg_mp_check_type(arg2,2,3,_cimg_mp_size(arg1));
if (arg2==1) _cimg_mp_return(arg1);
if (_cimg_mp_is_vector(arg1) && _cimg_mp_is_vector(arg2)) _cimg_mp_vector2_vv(mp_pow,arg1,arg2);
if (_cimg_mp_is_vector(arg1) && _cimg_mp_is_scalar(arg2)) _cimg_mp_vector2_vs(mp_pow,arg1,arg2);
if (_cimg_mp_is_scalar(arg1) && _cimg_mp_is_vector(arg2)) _cimg_mp_vector2_sv(mp_pow,arg1,arg2);
if (_cimg_mp_is_constant(arg1) && _cimg_mp_is_constant(arg2))
_cimg_mp_constant(std::pow(mem[arg1],mem[arg2]));
switch (arg2) {
case 0 : _cimg_mp_return(1);
case 2 : _cimg_mp_scalar1(mp_sqr,arg1);
case 3 : _cimg_mp_scalar1(mp_pow3,arg1);
case 4 : _cimg_mp_scalar1(mp_pow4,arg1);
default :
if (_cimg_mp_is_constant(arg2)) {
if (mem[arg2]==0.5) { _cimg_mp_scalar1(mp_sqrt,arg1); }
else if (mem[arg2]==0.25) { _cimg_mp_scalar1(mp_pow0_25,arg1); }
}
_cimg_mp_scalar2(mp_pow,arg1,arg2);
}
}
// Percentage computation.
if (*se1=='%') {
arg1 = compile(ss,se1,depth1,0,is_single);
arg2 = _cimg_mp_is_constant(arg1)?0:constant(100);
if (_cimg_mp_is_vector(arg1)) _cimg_mp_vector2_vs(mp_div,arg1,arg2);
if (_cimg_mp_is_constant(arg1)) _cimg_mp_constant(mem[arg1]/100);
_cimg_mp_scalar2(mp_div,arg1,arg2);
}
is_sth = ss1<se1 && (*ss=='+' || *ss=='-') && *ss1==*ss; // is pre-?
if (is_sth || (se2>ss && (*se1=='+' || *se1=='-') && *se2==*se1)) { // Pre/post-decrement and increment
if ((is_sth && *ss=='+') || (!is_sth && *se1=='+')) {
_cimg_mp_op("Operator '++'");
op = mp_self_increment;
} else {
_cimg_mp_op("Operator '--'");
op = mp_self_decrement;
}
ref.assign(7);
arg1 = is_sth?compile(ss2,se,depth1,ref,is_single):
compile(ss,se2,depth1,ref,is_single); // Variable slot
// Apply operator on a copy to prevent modifying a constant or a variable.
if (*ref && (_cimg_mp_is_constant(arg1) || _cimg_mp_is_vector(arg1) || _cimg_mp_is_variable(arg1))) {
if (_cimg_mp_is_vector(arg1)) arg1 = vector_copy(arg1);
else arg1 = scalar1(mp_copy,arg1);
}
if (is_sth) pos = arg1; // Determine return indice, depending on pre/post action
else {
if (_cimg_mp_is_vector(arg1)) pos = vector_copy(arg1);
else pos = scalar1(mp_copy,arg1);
}
if (*ref==1) { // Vector value (scalar): V[k]++
arg3 = ref[1]; // Vector slot
arg4 = ref[2]; // Index
if (is_sth && p_ref) std::memcpy(p_ref,ref,ref._width*sizeof(unsigned int));
CImg<ulongT>::vector((ulongT)op,arg1,1).move_to(code);
CImg<ulongT>::vector((ulongT)mp_vector_set_off,arg1,arg3,(ulongT)_cimg_mp_size(arg3),arg4,arg1).
move_to(code);
_cimg_mp_return(pos);
}
if (*ref==2) { // Image value (scalar): i/j[_#ind,off]++
if (!is_single) is_parallelizable = false;
p1 = ref[1]; // Index
is_relative = (bool)ref[2];
arg3 = ref[3]; // Offset
if (is_sth && p_ref) std::memcpy(p_ref,ref,ref._width*sizeof(unsigned int));
CImg<ulongT>::vector((ulongT)op,arg1).move_to(code);
if (p1!=~0U) {
if (!listout) _cimg_mp_return(pos);
CImg<ulongT>::vector((ulongT)(is_relative?mp_list_set_joff:mp_list_set_ioff),
arg1,p1,arg3).move_to(code);
} else {
if (!imgout) _cimg_mp_return(pos);
CImg<ulongT>::vector((ulongT)(is_relative?mp_set_joff:mp_set_ioff),
arg1,arg3).move_to(code);
}
_cimg_mp_return(pos);
}
if (*ref==3) { // Image value (scalar): i/j(_#ind,_x,_y,_z,_c)++
if (!is_single) is_parallelizable = false;
p1 = ref[1]; // Index
is_relative = (bool)ref[2];
arg3 = ref[3]; // X
arg4 = ref[4]; // Y
arg5 = ref[5]; // Z
arg6 = ref[6]; // C
if (is_sth && p_ref) std::memcpy(p_ref,ref,ref._width*sizeof(unsigned int));
CImg<ulongT>::vector((ulongT)op,arg1).move_to(code);
if (p1!=~0U) {
if (!listout) _cimg_mp_return(pos);
CImg<ulongT>::vector((ulongT)(is_relative?mp_list_set_jxyzc:mp_list_set_ixyzc),
arg1,p1,arg3,arg4,arg5,arg6).move_to(code);
} else {
if (!imgout) _cimg_mp_return(pos);
CImg<ulongT>::vector((ulongT)(is_relative?mp_set_jxyzc:mp_set_ixyzc),
arg1,arg3,arg4,arg5,arg6).move_to(code);
}
_cimg_mp_return(pos);
}
if (*ref==4) { // Image value (vector): I/J[_#ind,off]++
if (!is_single) is_parallelizable = false;
p1 = ref[1]; // Index
is_relative = (bool)ref[2];
arg3 = ref[3]; // Offset
if (is_sth && p_ref) std::memcpy(p_ref,ref,ref._width*sizeof(unsigned int));
self_vector_s(arg1,op==mp_self_increment?mp_self_add:mp_self_sub,1);
if (p1!=~0U) {
if (!listout) _cimg_mp_return(pos);
CImg<ulongT>::vector((ulongT)(is_relative?mp_list_set_Joff_v:mp_list_set_Ioff_v),
arg1,p1,arg3,_cimg_mp_size(arg1)).move_to(code);
} else {
if (!imgout) _cimg_mp_return(pos);
CImg<ulongT>::vector((ulongT)(is_relative?mp_set_Joff_v:mp_set_Ioff_v),
arg1,arg3,_cimg_mp_size(arg1)).move_to(code);
}
_cimg_mp_return(pos);
}
if (*ref==5) { // Image value (vector): I/J(_#ind,_x,_y,_z,_c)++
if (!is_single) is_parallelizable = false;
p1 = ref[1]; // Index
is_relative = (bool)ref[2];
arg3 = ref[3]; // X
arg4 = ref[4]; // Y
arg5 = ref[5]; // Z
if (is_sth && p_ref) std::memcpy(p_ref,ref,ref._width*sizeof(unsigned int));
self_vector_s(arg1,op==mp_self_increment?mp_self_add:mp_self_sub,1);
if (p1!=~0U) {
if (!listout) _cimg_mp_return(pos);
CImg<ulongT>::vector((ulongT)(is_relative?mp_list_set_Jxyz_v:mp_list_set_Ixyz_v),
arg1,p1,arg3,arg4,arg5,_cimg_mp_size(arg1)).move_to(code);
} else {
if (!imgout) _cimg_mp_return(pos);
CImg<ulongT>::vector((ulongT)(is_relative?mp_set_Jxyz_v:mp_set_Ixyz_v),
arg1,arg3,arg4,arg5,_cimg_mp_size(arg1)).move_to(code);
}
_cimg_mp_return(pos);
}
if (_cimg_mp_is_vector(arg1)) { // Vector variable: V++
self_vector_s(arg1,op==mp_self_increment?mp_self_add:mp_self_sub,1);
_cimg_mp_return(pos);
}
if (_cimg_mp_is_variable(arg1)) { // Scalar variable: s++
CImg<ulongT>::vector((ulongT)op,arg1).move_to(code);
_cimg_mp_return(pos);
}
if (is_sth) variable_name.assign(ss2,(unsigned int)(se - ss1));
else variable_name.assign(ss,(unsigned int)(se1 - ss));
variable_name.back() = 0;
cimg::strpare(variable_name,false,true);
*se = saved_char;
cimg::strellipsize(variable_name,64);
s0 = ss - 4>expr._data?ss - 4:expr._data;
cimg::strellipsize(s0,64);
throw CImgArgumentException("[" cimg_appname "_math_parser] "
"CImg<%s>::%s: %s: Invalid %slvalue '%s', "
"in expression '%s%s%s'.",
pixel_type(),_cimg_mp_calling_function,s_op,
_cimg_mp_is_constant(arg1)?"const ":"",
variable_name._data,
s0!=expr._data?"...":"",s0,se<&expr.back()?"...":"");
}
// Array-like access to vectors and image values 'i/j/I/J[_#ind,offset,_boundary]' and 'vector[offset]'.
if (*se1==']' && *ss!='[') {
_cimg_mp_op("Value accessor '[]'");
is_relative = *ss=='j' || *ss=='J';
s0 = s1 = std::strchr(ss,'['); if (s0) { do { --s1; } while ((signed char)*s1<=' '); cimg::swap(*s0,*++s1); }
if ((*ss=='I' || *ss=='J') && *ss1=='[' &&
(reserved_label[*ss]==~0U || !_cimg_mp_is_vector(reserved_label[*ss]))) { // Image value as a vector
if (*ss2=='#') { // Index specified
s0 = ss3; while (s0<se1 && (*s0!=',' || level[s0 - expr._data]!=clevel1)) ++s0;
p1 = compile(ss3,s0++,depth1,0,is_single);
_cimg_mp_check_list(false);
} else { p1 = ~0U; s0 = ss2; }
s1 = s0; while (s1<se1 && (*s1!=',' || level[s1 - expr._data]!=clevel1)) ++s1;
p2 = 1 + (p1!=~0U);
arg1 = compile(s0,s1,depth1,0,is_single); // Offset
_cimg_mp_check_type(arg1,p2,1,0);
arg2 = ~0U;
if (s1<se1) {
arg2 = compile(++s1,se1,depth1,0,is_single); // Boundary
_cimg_mp_check_type(arg2,p2 + 1,1,0);
}
if (p_ref && arg2==~0U) {
*p_ref = 4;
p_ref[1] = p1;
p_ref[2] = (unsigned int)is_relative;
p_ref[3] = arg1;
if (p1!=~0U && _cimg_mp_is_comp(p1)) memtype[p1] = -2; // Prevent from being used in further optimization
if (_cimg_mp_is_comp(arg1)) memtype[arg1] = -2;
}
p2 = ~0U; // 'p2' must be the dimension of the vector-valued operand if any
if (p1==~0U) p2 = imgin._spectrum;
else if (_cimg_mp_is_constant(p1)) {
p3 = (unsigned int)cimg::mod((int)mem[p1],listin.width());
p2 = listin[p3]._spectrum;
}
_cimg_mp_check_vector0(p2);
pos = vector(p2);
if (p1!=~0U) {
CImg<ulongT>::vector((ulongT)(is_relative?mp_list_Joff:mp_list_Ioff),
pos,p1,arg1,arg2==~0U?_cimg_mp_boundary:arg2,p2).move_to(code);
} else {
need_input_copy = true;
CImg<ulongT>::vector((ulongT)(is_relative?mp_Joff:mp_Ioff),
pos,arg1,arg2==~0U?_cimg_mp_boundary:arg2,p2).move_to(code);
}
_cimg_mp_return(pos);
}
if ((*ss=='i' || *ss=='j') && *ss1=='[' &&
(reserved_label[*ss]==~0U || !_cimg_mp_is_vector(reserved_label[*ss]))) { // Image value as a scalar
if (*ss2=='#') { // Index specified
s0 = ss3; while (s0<se1 && (*s0!=',' || level[s0 - expr._data]!=clevel1)) ++s0;
p1 = compile(ss3,s0++,depth1,0,is_single);
} else { p1 = ~0U; s0 = ss2; }
s1 = s0; while (s1<se1 && (*s1!=',' || level[s1 - expr._data]!=clevel1)) ++s1;
arg1 = compile(s0,s1,depth1,0,is_single); // Offset
arg2 = s1<se1?compile(++s1,se1,depth1,0,is_single):~0U; // Boundary
if (p_ref && arg2==~0U) {
*p_ref = 2;
p_ref[1] = p1;
p_ref[2] = (unsigned int)is_relative;
p_ref[3] = arg1;
if (p1!=~0U && _cimg_mp_is_comp(p1)) memtype[p1] = -2; // Prevent from being used in further optimization
if (_cimg_mp_is_comp(arg1)) memtype[arg1] = -2;
}
if (p1!=~0U) {
if (!listin) _cimg_mp_return(0);
pos = scalar3(is_relative?mp_list_joff:mp_list_ioff,p1,arg1,arg2==~0U?_cimg_mp_boundary:arg2);
} else {
if (!imgin) _cimg_mp_return(0);
need_input_copy = true;
pos = scalar2(is_relative?mp_joff:mp_ioff,arg1,arg2==~0U?_cimg_mp_boundary:arg2);
}
memtype[pos] = -2; // Prevent from being used in further optimization
_cimg_mp_return(pos);
}
s0 = se1; while (s0>ss && (*s0!='[' || level[s0 - expr._data]!=clevel)) --s0;
if (s0>ss) { // Vector value
arg1 = compile(ss,s0,depth1,0,is_single);
if (_cimg_mp_is_scalar(arg1)) {
variable_name.assign(ss,(unsigned int)(s0 - ss + 1)).back() = 0;
*se = saved_char;
cimg::strellipsize(variable_name,64);
s0 = ss - 4>expr._data?ss - 4:expr._data;
cimg::strellipsize(s0,64);
throw CImgArgumentException("[" cimg_appname "_math_parser] "
"CImg<%s>::%s: %s: Array brackets used on non-vector variable '%s', "
"in expression '%s%s%s'.",
pixel_type(),_cimg_mp_calling_function,s_op,
variable_name._data,
s0!=expr._data?"...":"",s0,se<&expr.back()?"...":"");
}
s1 = s0 + 1; while (s1<se1 && (*s1!=',' || level[s1 - expr._data]!=clevel1)) ++s1;
if (s1<se1) { // Two arguments -> sub-vector extraction
p1 = _cimg_mp_size(arg1);
arg2 = compile(++s0,s1,depth1,0,is_single); // Starting indice
arg3 = compile(++s1,se1,depth1,0,is_single); // Length
_cimg_mp_check_constant(arg3,2,3);
arg3 = (unsigned int)mem[arg3];
pos = vector(arg3);
CImg<ulongT>::vector((ulongT)mp_vector_crop,pos,arg1,p1,arg2,arg3).move_to(code);
_cimg_mp_return(pos);
}
// One argument -> vector value reference
arg2 = compile(++s0,se1,depth1,0,is_single);
if (_cimg_mp_is_constant(arg2)) { // Constant index
nb = (int)mem[arg2];
if (nb>=0 && nb<(int)_cimg_mp_size(arg1)) _cimg_mp_return(arg1 + 1 + nb);
variable_name.assign(ss,(unsigned int)(s0 - ss)).back() = 0;
*se = saved_char;
cimg::strellipsize(variable_name,64);
s0 = ss - 4>expr._data?ss - 4:expr._data;
cimg::strellipsize(s0,64);
throw CImgArgumentException("[" cimg_appname "_math_parser] "
"CImg<%s>::%s: Out-of-bounds reference '%s[%d]' "
"(vector '%s' has dimension %u), "
"in expression '%s%s%s'.",
pixel_type(),_cimg_mp_calling_function,
variable_name._data,nb,
variable_name._data,_cimg_mp_size(arg1),
s0!=expr._data?"...":"",s0,se<&expr.back()?"...":"");
}
if (p_ref) {
*p_ref = 1;
p_ref[1] = arg1;
p_ref[2] = arg2;
if (_cimg_mp_is_comp(arg2)) memtype[arg2] = -2; // Prevent from being used in further optimization
}
pos = scalar3(mp_vector_off,arg1,_cimg_mp_size(arg1),arg2);
memtype[pos] = -2; // Prevent from being used in further optimization
_cimg_mp_return(pos);
}
}
// Look for a function call, an access to image value, or a parenthesis.
if (*se1==')') {
if (*ss=='(') _cimg_mp_return(compile(ss1,se1,depth1,p_ref,is_single)); // Simple parentheses
_cimg_mp_op("Value accessor '()'");
is_relative = *ss=='j' || *ss=='J';
s0 = s1 = std::strchr(ss,'('); if (s0) { do { --s1; } while ((signed char)*s1<=' '); cimg::swap(*s0,*++s1); }
// I/J(_#ind,_x,_y,_z,_interpolation,_boundary_conditions)
if ((*ss=='I' || *ss=='J') && *ss1=='(') { // Image value as scalar
if (*ss2=='#') { // Index specified
s0 = ss3; while (s0<se1 && (*s0!=',' || level[s0 - expr._data]!=clevel1)) ++s0;
p1 = compile(ss3,s0++,depth1,0,is_single);
_cimg_mp_check_list(false);
} else { p1 = ~0U; s0 = ss2; }
arg1 = is_relative?0U:(unsigned int)_cimg_mp_slot_x;
arg2 = is_relative?0U:(unsigned int)_cimg_mp_slot_y;
arg3 = is_relative?0U:(unsigned int)_cimg_mp_slot_z;
arg4 = arg5 = ~0U;
if (s0<se1) {
s1 = s0; while (s1<se1 && (*s1!=',' || level[s1 - expr._data]!=clevel1)) ++s1;
arg1 = compile(s0,s1,depth1,0,is_single);
if (_cimg_mp_is_vector(arg1)) { // Coordinates specified as a vector
p2 = _cimg_mp_size(arg1);
++arg1;
if (p2>1) {
arg2 = arg1 + 1;
if (p2>2) arg3 = arg2 + 1;
}
if (s1<se1) {
s2 = ++s1; while (s2<se1 && (*s2!=',' || level[s2 - expr._data]!=clevel1)) ++s2;
arg4 = compile(s1,s2,depth1,0,is_single);
arg5 = s2<se1?compile(++s2,se1,depth1,0,is_single):~0U;
}
} else if (s1<se1) {
s2 = ++s1; while (s2<se1 && (*s2!=',' || level[s2 - expr._data]!=clevel1)) ++s2;
arg2 = compile(s1,s2,depth1,0,is_single);
if (s2<se1) {
s3 = ++s2; while (s3<se1 && (*s3!=',' || level[s3 - expr._data]!=clevel1)) ++s3;
arg3 = compile(s2,s3,depth1,0,is_single);
if (s3<se1) {
s2 = ++s3; while (s2<se1 && (*s2!=',' || level[s2 - expr._data]!=clevel1)) ++s2;
arg4 = compile(s3,s2,depth1,0,is_single);
arg5 = s2<se1?compile(++s2,se1,depth1,0,is_single):~0U;
}
}
}
}
if (p_ref && arg4==~0U && arg5==~0U) {
*p_ref = 5;
p_ref[1] = p1;
p_ref[2] = (unsigned int)is_relative;
p_ref[3] = arg1;
p_ref[4] = arg2;
p_ref[5] = arg3;
if (p1!=~0U && _cimg_mp_is_comp(p1)) memtype[p1] = -2; // Prevent from being used in further optimization
if (_cimg_mp_is_comp(arg1)) memtype[arg1] = -2;
if (_cimg_mp_is_comp(arg2)) memtype[arg2] = -2;
if (_cimg_mp_is_comp(arg3)) memtype[arg3] = -2;
}
p2 = ~0U; // 'p2' must be the dimension of the vector-valued operand if any
if (p1==~0U) p2 = imgin._spectrum;
else if (_cimg_mp_is_constant(p1)) {
p3 = (unsigned int)cimg::mod((int)mem[p1],listin.width());
p2 = listin[p3]._spectrum;
}
_cimg_mp_check_vector0(p2);
pos = vector(p2);
if (p1!=~0U)
CImg<ulongT>::vector((ulongT)(is_relative?mp_list_Jxyz:mp_list_Ixyz),
pos,p1,arg1,arg2,arg3,
arg4==~0U?_cimg_mp_interpolation:arg4,
arg5==~0U?_cimg_mp_boundary:arg5,p2).move_to(code);
else {
need_input_copy = true;
CImg<ulongT>::vector((ulongT)(is_relative?mp_Jxyz:mp_Ixyz),
pos,arg1,arg2,arg3,
arg4==~0U?_cimg_mp_interpolation:arg4,
arg5==~0U?_cimg_mp_boundary:arg5,p2).move_to(code);
}
_cimg_mp_return(pos);
}
// i/j(_#ind,_x,_y,_z,_c,_interpolation,_boundary_conditions)
if ((*ss=='i' || *ss=='j') && *ss1=='(') { // Image value as scalar
if (*ss2=='#') { // Index specified
s0 = ss3; while (s0<se1 && (*s0!=',' || level[s0 - expr._data]!=clevel1)) ++s0;
p1 = compile(ss3,s0++,depth1,0,is_single);
} else { p1 = ~0U; s0 = ss2; }
arg1 = is_relative?0U:(unsigned int)_cimg_mp_slot_x;
arg2 = is_relative?0U:(unsigned int)_cimg_mp_slot_y;
arg3 = is_relative?0U:(unsigned int)_cimg_mp_slot_z;
arg4 = is_relative?0U:(unsigned int)_cimg_mp_slot_c;
arg5 = arg6 = ~0U;
if (s0<se1) {
s1 = s0; while (s1<se1 && (*s1!=',' || level[s1 - expr._data]!=clevel1)) ++s1;
arg1 = compile(s0,s1,depth1,0,is_single);
if (_cimg_mp_is_vector(arg1)) { // Coordinates specified as a vector
p2 = _cimg_mp_size(arg1);
++arg1;
if (p2>1) {
arg2 = arg1 + 1;
if (p2>2) {
arg3 = arg2 + 1;
if (p2>3) arg4 = arg3 + 1;
}
}
if (s1<se1) {
s2 = ++s1; while (s2<se1 && (*s2!=',' || level[s2 - expr._data]!=clevel1)) ++s2;
arg5 = compile(s1,s2,depth1,0,is_single);
arg6 = s2<se1?compile(++s2,se1,depth1,0,is_single):~0U;
}
} else if (s1<se1) {
s2 = ++s1; while (s2<se1 && (*s2!=',' || level[s2 - expr._data]!=clevel1)) ++s2;
arg2 = compile(s1,s2,depth1,0,is_single);
if (s2<se1) {
s3 = ++s2; while (s3<se1 && (*s3!=',' || level[s3 - expr._data]!=clevel1)) ++s3;
arg3 = compile(s2,s3,depth1,0,is_single);
if (s3<se1) {
s2 = ++s3; while (s2<se1 && (*s2!=',' || level[s2 - expr._data]!=clevel1)) ++s2;
arg4 = compile(s3,s2,depth1,0,is_single);
if (s2<se1) {
s3 = ++s2; while (s3<se1 && (*s3!=',' || level[s3 - expr._data]!=clevel1)) ++s3;
arg5 = compile(s2,s3,depth1,0,is_single);
arg6 = s3<se1?compile(++s3,se1,depth1,0,is_single):~0U;
}
}
}
}
}
if (p_ref && arg5==~0U && arg6==~0U) {
*p_ref = 3;
p_ref[1] = p1;
p_ref[2] = (unsigned int)is_relative;
p_ref[3] = arg1;
p_ref[4] = arg2;
p_ref[5] = arg3;
p_ref[6] = arg4;
if (p1!=~0U && _cimg_mp_is_comp(p1)) memtype[p1] = -2; // Prevent from being used in further optimization
if (_cimg_mp_is_comp(arg1)) memtype[arg1] = -2;
if (_cimg_mp_is_comp(arg2)) memtype[arg2] = -2;
if (_cimg_mp_is_comp(arg3)) memtype[arg3] = -2;
if (_cimg_mp_is_comp(arg4)) memtype[arg4] = -2;
}
if (p1!=~0U) {
if (!listin) _cimg_mp_return(0);
pos = scalar7(is_relative?mp_list_jxyzc:mp_list_ixyzc,
p1,arg1,arg2,arg3,arg4,
arg5==~0U?_cimg_mp_interpolation:arg5,
arg6==~0U?_cimg_mp_boundary:arg6);
} else {
if (!imgin) _cimg_mp_return(0);
need_input_copy = true;
pos = scalar6(is_relative?mp_jxyzc:mp_ixyzc,
arg1,arg2,arg3,arg4,
arg5==~0U?_cimg_mp_interpolation:arg5,
arg6==~0U?_cimg_mp_boundary:arg6);
}
memtype[pos] = -2; // Prevent from being used in further optimization
_cimg_mp_return(pos);
}
// Mathematical functions.
switch (*ss) {
case '_' :
if (*ss1=='(') // Skip arguments
_cimg_mp_return_nan();
break;
case 'a' :
if (!std::strncmp(ss,"abs(",4)) { // Absolute value
_cimg_mp_op("Function 'abs()'");
arg1 = compile(ss4,se1,depth1,0,is_single);
if (_cimg_mp_is_vector(arg1)) _cimg_mp_vector1_v(mp_abs,arg1);
if (_cimg_mp_is_constant(arg1)) _cimg_mp_constant(cimg::abs(mem[arg1]));
_cimg_mp_scalar1(mp_abs,arg1);
}
if (!std::strncmp(ss,"acos(",5)) { // Arccos
_cimg_mp_op("Function 'acos()'");
arg1 = compile(ss5,se1,depth1,0,is_single);
if (_cimg_mp_is_vector(arg1)) _cimg_mp_vector1_v(mp_acos,arg1);
if (_cimg_mp_is_constant(arg1)) _cimg_mp_constant(std::acos(mem[arg1]));
_cimg_mp_scalar1(mp_acos,arg1);
}
if (!std::strncmp(ss,"arg(",4)) { // Nth argument
_cimg_mp_op("Function 'arg()'");
s1 = ss4; while (s1<se1 && (*s1!=',' || level[s1 - expr._data]!=clevel1)) ++s1;
arg1 = compile(ss4,s1,depth1,0,is_single);
_cimg_mp_check_type(arg1,1,1,0);
s2 = ++s1; while (s2<se1 && (*s2!=',' || level[s2 - expr._data]!=clevel1)) ++s2;
arg2 = compile(s1,s2,depth1,0,is_single);
p2 = _cimg_mp_size(arg2);
p3 = 3;
CImg<ulongT>::vector((ulongT)mp_arg,0,0,p2,arg1,arg2).move_to(_opcode);
for (s = ++s2; s<se; ++s) {
ns = s; while (ns<se && (*ns!=',' || level[ns - expr._data]!=clevel1) &&
(*ns!=')' || level[ns - expr._data]!=clevel)) ++ns;
arg3 = compile(s,ns,depth1,0,is_single);
_cimg_mp_check_type(arg3,p3,p2?2:1,p2);
CImg<ulongT>::vector(arg3).move_to(_opcode);
++p3;
s = ns;
}
(_opcode>'y').move_to(opcode);
opcode[2] = opcode._height;
if (_cimg_mp_is_constant(arg1)) {
p3-=1; // Number of args
arg1 = (unsigned int)(mem[arg1]<0?mem[arg1] + p3:mem[arg1]);
if (arg1<p3) _cimg_mp_return(opcode[4 + arg1]);
if (p2) {
pos = vector(p2);
std::memset(&mem[pos] + 1,0,p2*sizeof(double));
_cimg_mp_return(pos);
} else _cimg_mp_return(0);
}
pos = opcode[1] = p2?vector(p2):scalar();
opcode.move_to(code);
_cimg_mp_return(pos);
}
if (!std::strncmp(ss,"asin(",5)) { // Arcsin
_cimg_mp_op("Function 'asin()'");
arg1 = compile(ss5,se1,depth1,0,is_single);
if (_cimg_mp_is_vector(arg1)) _cimg_mp_vector1_v(mp_asin,arg1);
if (_cimg_mp_is_constant(arg1)) _cimg_mp_constant(std::asin(mem[arg1]));
_cimg_mp_scalar1(mp_asin,arg1);
}
if (!std::strncmp(ss,"atan(",5)) { // Arctan
_cimg_mp_op("Function 'atan()'");
arg1 = compile(ss5,se1,depth1,0,is_single);
if (_cimg_mp_is_vector(arg1)) _cimg_mp_vector1_v(mp_atan,arg1);
if (_cimg_mp_is_constant(arg1)) _cimg_mp_constant(std::atan(mem[arg1]));
_cimg_mp_scalar1(mp_atan,arg1);
}
if (!std::strncmp(ss,"atan2(",6)) { // Arctan2
_cimg_mp_op("Function 'atan2()'");
s1 = ss6; while (s1<se1 && (*s1!=',' || level[s1 - expr._data]!=clevel1)) ++s1;
arg1 = compile(ss6,s1,depth1,0,is_single);
arg2 = compile(++s1,se1,depth1,0,is_single);
_cimg_mp_check_type(arg2,2,3,_cimg_mp_size(arg1));
if (_cimg_mp_is_vector(arg1) && _cimg_mp_is_vector(arg2)) _cimg_mp_vector2_vv(mp_atan2,arg1,arg2);
if (_cimg_mp_is_vector(arg1) && _cimg_mp_is_scalar(arg2)) _cimg_mp_vector2_vs(mp_atan2,arg1,arg2);
if (_cimg_mp_is_scalar(arg1) && _cimg_mp_is_vector(arg2)) _cimg_mp_vector2_sv(mp_atan2,arg1,arg2);
if (_cimg_mp_is_constant(arg1) && _cimg_mp_is_constant(arg2))
_cimg_mp_constant(std::atan2(mem[arg1],mem[arg2]));
_cimg_mp_scalar2(mp_atan2,arg1,arg2);
}
break;
case 'b' :
if (!std::strncmp(ss,"bool(",5)) { // Boolean cast
_cimg_mp_op("Function 'bool()'");
arg1 = compile(ss5,se1,depth1,0,is_single);
if (_cimg_mp_is_vector(arg1)) _cimg_mp_vector1_v(mp_bool,arg1);
if (_cimg_mp_is_constant(arg1)) _cimg_mp_constant((bool)mem[arg1]);
_cimg_mp_scalar1(mp_bool,arg1);
}
if (!std::strncmp(ss,"break(",6)) { // Complex absolute value
if (pexpr[se2 - expr._data]=='(') { // no arguments?
CImg<ulongT>::vector((ulongT)mp_break,_cimg_mp_slot_nan).move_to(code);
_cimg_mp_return_nan();
}
}
if (!std::strncmp(ss,"breakpoint(",11)) { // Break point (for abort test)
_cimg_mp_op("Function 'breakpoint()'");
if (pexpr[se2 - expr._data]=='(') { // no arguments?
CImg<ulongT>::vector((ulongT)mp_breakpoint,_cimg_mp_slot_nan).move_to(code);
_cimg_mp_return_nan();
}
}
break;
case 'c' :
if (!std::strncmp(ss,"cabs(",5)) { // Complex absolute value
_cimg_mp_op("Function 'cabs()'");
arg1 = compile(ss5,se1,depth1,0,is_single);
_cimg_mp_check_type(arg1,0,2,2);
_cimg_mp_scalar2(mp_complex_abs,arg1 + 1,arg1 + 2);
}
if (!std::strncmp(ss,"carg(",5)) { // Complex argument
_cimg_mp_op("Function 'carg()'");
arg1 = compile(ss5,se1,depth1,0,is_single);
_cimg_mp_check_type(arg1,0,2,2);
_cimg_mp_scalar2(mp_atan2,arg1 + 2,arg1 + 1);
}
if (!std::strncmp(ss,"cats(",5)) { // Concatenate strings
_cimg_mp_op("Function 'cats()'");
CImg<ulongT>::vector((ulongT)mp_cats,0,0,0).move_to(_opcode);
arg1 = 0;
for (s = ss5; s<se; ++s) {
ns = s; while (ns<se && (*ns!=',' || level[ns - expr._data]!=clevel1) &&
(*ns!=')' || level[ns - expr._data]!=clevel)) ++ns;
arg1 = compile(s,ns,depth1,0,is_single);
CImg<ulongT>::vector(arg1,_cimg_mp_size(arg1)).move_to(_opcode);
s = ns;
}
_cimg_mp_check_constant(arg1,1,3); // Last argument = output vector size
_opcode.remove();
(_opcode>'y').move_to(opcode);
p1 = (unsigned int)mem[arg1];
pos = vector(p1);
opcode[1] = pos;
opcode[2] = p1;
opcode[3] = opcode._height;
opcode.move_to(code);
_cimg_mp_return(pos);
}
if (!std::strncmp(ss,"cbrt(",5)) { // Cubic root
_cimg_mp_op("Function 'cbrt()'");
arg1 = compile(ss5,se1,depth1,0,is_single);
if (_cimg_mp_is_vector(arg1)) _cimg_mp_vector1_v(mp_cbrt,arg1);
if (_cimg_mp_is_constant(arg1)) _cimg_mp_constant(cimg::cbrt(mem[arg1]));
_cimg_mp_scalar1(mp_cbrt,arg1);
}
if (!std::strncmp(ss,"cconj(",6)) { // Complex conjugate
_cimg_mp_op("Function 'cconj()'");
arg1 = compile(ss6,se1,depth1,0,is_single);
_cimg_mp_check_type(arg1,0,2,2);
pos = vector(2);
CImg<ulongT>::vector((ulongT)mp_complex_conj,pos,arg1).move_to(code);
_cimg_mp_return(pos);
}
if (!std::strncmp(ss,"ceil(",5)) { // Ceil
_cimg_mp_op("Function 'ceil()'");
arg1 = compile(ss5,se1,depth1,0,is_single);
if (_cimg_mp_is_vector(arg1)) _cimg_mp_vector1_v(mp_ceil,arg1);
if (_cimg_mp_is_constant(arg1)) _cimg_mp_constant(std::ceil(mem[arg1]));
_cimg_mp_scalar1(mp_ceil,arg1);
}
if (!std::strncmp(ss,"cexp(",5)) { // Complex exponential
_cimg_mp_op("Function 'cexp()'");
arg1 = compile(ss5,se1,depth1,0,is_single);
_cimg_mp_check_type(arg1,0,2,2);
pos = vector(2);
CImg<ulongT>::vector((ulongT)mp_complex_exp,pos,arg1).move_to(code);
_cimg_mp_return(pos);
}
if (!std::strncmp(ss,"clog(",5)) { // Complex logarithm
_cimg_mp_op("Function 'clog()'");
arg1 = compile(ss5,se1,depth1,0,is_single);
_cimg_mp_check_type(arg1,0,2,2);
pos = vector(2);
CImg<ulongT>::vector((ulongT)mp_complex_log,pos,arg1).move_to(code);
_cimg_mp_return(pos);
}
if (!std::strncmp(ss,"continue(",9)) { // Complex absolute value
if (pexpr[se2 - expr._data]=='(') { // no arguments?
CImg<ulongT>::vector((ulongT)mp_continue,_cimg_mp_slot_nan).move_to(code);
_cimg_mp_return_nan();
}
}
if (!std::strncmp(ss,"copy(",5)) { // Memory copy
_cimg_mp_op("Function 'copy()'");
ref.assign(14);
s1 = ss5; while (s1<se1 && (*s1!=',' || level[s1 - expr._data]!=clevel1)) ++s1;
arg1 = p1 = compile(ss5,s1,depth1,ref,is_single);
s2 = ++s1; while (s2<se1 && (*s2!=',' || level[s2 - expr._data]!=clevel1)) ++s2;
arg2 = compile(s1,s2,depth1,ref._data + 7,is_single);
arg3 = ~0U; arg4 = arg5 = arg6 = 1;
if (s2<se1) {
s3 = ++s2; while (s3<se1 && (*s3!=',' || level[s3 - expr._data]!=clevel1)) ++s3;
arg3 = compile(s2,s3,depth1,0,is_single);
if (s3<se1) {
s1 = ++s3; while (s1<se1 && (*s1!=',' || level[s1 - expr._data]!=clevel1)) ++s1;
arg4 = compile(s3,s1,depth1,0,is_single);
if (s1<se1) {
s2 = ++s1; while (s2<se1 && (*s2!=',' || level[s2 - expr._data]!=clevel1)) ++s2;
arg5 = compile(s1,s2,depth1,0,is_single);
arg6 = s2<se1?compile(++s2,se1,depth1,0,is_single):1;
}
}
}
if (_cimg_mp_is_vector(arg1) && !ref[0]) ++arg1;
if (_cimg_mp_is_vector(arg2)) {
if (arg3==~0U) arg3 = _cimg_mp_size(arg2);
if (!ref[7]) ++arg2;
}
if (arg3==~0U) arg3 = 1;
_cimg_mp_check_type(arg3,3,1,0);
_cimg_mp_check_type(arg4,4,1,0);
_cimg_mp_check_type(arg5,5,1,0);
_cimg_mp_check_type(arg6,5,1,0);
CImg<ulongT>(1,22).move_to(code);
code.back().get_shared_rows(0,7).fill((ulongT)mp_memcopy,p1,arg1,arg2,arg3,arg4,arg5,arg6);
code.back().get_shared_rows(8,21).fill(ref);
_cimg_mp_return(p1);
}
if (!std::strncmp(ss,"cos(",4)) { // Cosine
_cimg_mp_op("Function 'cos()'");
arg1 = compile(ss4,se1,depth1,0,is_single);
if (_cimg_mp_is_vector(arg1)) _cimg_mp_vector1_v(mp_cos,arg1);
if (_cimg_mp_is_constant(arg1)) _cimg_mp_constant(std::cos(mem[arg1]));
_cimg_mp_scalar1(mp_cos,arg1);
}
if (!std::strncmp(ss,"cosh(",5)) { // Hyperbolic cosine
_cimg_mp_op("Function 'cosh()'");
arg1 = compile(ss5,se1,depth1,0,is_single);
if (_cimg_mp_is_vector(arg1)) _cimg_mp_vector1_v(mp_cosh,arg1);
if (_cimg_mp_is_constant(arg1)) _cimg_mp_constant(std::cosh(mem[arg1]));
_cimg_mp_scalar1(mp_cosh,arg1);
}
if (!std::strncmp(ss,"critical(",9)) { // Critical section (single thread at a time)
_cimg_mp_op("Function 'critical()'");
p1 = code._width;
arg1 = compile(ss + 9,se1,depth1,p_ref,true);
CImg<ulongT>::vector((ulongT)mp_critical,arg1,code._width - p1).move_to(code,p1);
_cimg_mp_return(arg1);
}
if (!std::strncmp(ss,"crop(",5)) { // Image crop
_cimg_mp_op("Function 'crop()'");
if (*ss5=='#') { // Index specified
s0 = ss6; while (s0<se1 && (*s0!=',' || level[s0 - expr._data]!=clevel1)) ++s0;
p1 = compile(ss6,s0++,depth1,0,is_single);
_cimg_mp_check_list(false);
} else { p1 = ~0U; s0 = ss5; need_input_copy = true; }
pos = 0;
is_sth = false; // Coordinates specified as a vector?
if (ss5<se1) for (s = s0; s<se; ++s, ++pos) {
ns = s; while (ns<se && (*ns!=',' || level[ns - expr._data]!=clevel1) &&
(*ns!=')' || level[ns - expr._data]!=clevel)) ++ns;
arg1 = compile(s,ns,depth1,0,is_single);
if (!pos && _cimg_mp_is_vector(arg1)) { // Coordinates specified as a vector
opcode = CImg<ulongT>::sequence(_cimg_mp_size(arg1),arg1 + 1,
arg1 + (ulongT)_cimg_mp_size(arg1));
opcode.resize(1,std::min(opcode._height,4U),1,1,0).move_to(_opcode);
is_sth = true;
} else {
_cimg_mp_check_type(arg1,pos + 1,1,0);
CImg<ulongT>::vector(arg1).move_to(_opcode);
}
s = ns;
}
(_opcode>'y').move_to(opcode);
arg1 = 0; arg2 = (p1!=~0U);
switch (opcode._height) {
case 0 : case 1 :
CImg<ulongT>::vector(0,0,0,0,~0U,~0U,~0U,~0U,0).move_to(opcode);
break;
case 2 :
CImg<ulongT>::vector(*opcode,0,0,0,opcode[1],~0U,~0U,~0U,_cimg_mp_boundary).move_to(opcode);
arg1 = arg2?3:2;
break;
case 3 :
CImg<ulongT>::vector(*opcode,0,0,0,opcode[1],~0U,~0U,~0U,opcode[2]).move_to(opcode);
arg1 = arg2?3:2;
break;
case 4 :
CImg<ulongT>::vector(*opcode,opcode[1],0,0,opcode[2],opcode[3],~0U,~0U,_cimg_mp_boundary).
move_to(opcode);
arg1 = (is_sth?2:1) + arg2;
break;
case 5 :
CImg<ulongT>::vector(*opcode,opcode[1],0,0,opcode[2],opcode[3],~0U,~0U,opcode[4]).
move_to(opcode);
arg1 = (is_sth?2:1) + arg2;
break;
case 6 :
CImg<ulongT>::vector(*opcode,opcode[1],opcode[2],0,opcode[3],opcode[4],opcode[5],~0U,
_cimg_mp_boundary).move_to(opcode);
arg1 = (is_sth?2:4) + arg2;
break;
case 7 :
CImg<ulongT>::vector(*opcode,opcode[1],opcode[2],0,opcode[3],opcode[4],opcode[5],~0U,
opcode[6]).move_to(opcode);
arg1 = (is_sth?2:4) + arg2;
break;
case 8 :
CImg<ulongT>::vector(*opcode,opcode[1],opcode[2],opcode[3],opcode[4],opcode[5],opcode[6],
opcode[7],_cimg_mp_boundary).move_to(opcode);
arg1 = (is_sth?2:5) + arg2;
break;
case 9 :
arg1 = (is_sth?2:5) + arg2;
break;
default : // Error -> too much arguments
*se = saved_char;
s0 = ss - 4>expr._data?ss - 4:expr._data;
cimg::strellipsize(s0,64);
throw CImgArgumentException("[" cimg_appname "_math_parser] "
"CImg<%s>::%s: %s: Too much arguments specified, "
"in expression '%s%s%s'.",
pixel_type(),_cimg_mp_calling_function,s_op,
s0!=expr._data?"...":"",s0,se<&expr.back()?"...":"");
}
_cimg_mp_check_type((unsigned int)*opcode,arg2 + 1,1,0);
_cimg_mp_check_type((unsigned int)opcode[1],arg2 + 1 + (is_sth?0:1),1,0);
_cimg_mp_check_type((unsigned int)opcode[2],arg2 + 1 + (is_sth?0:2),1,0);
_cimg_mp_check_type((unsigned int)opcode[3],arg2 + 1 + (is_sth?0:3),1,0);
if (opcode[4]!=(ulongT)~0U) {
_cimg_mp_check_constant((unsigned int)opcode[4],arg1,3);
opcode[4] = (ulongT)mem[opcode[4]];
}
if (opcode[5]!=(ulongT)~0U) {
_cimg_mp_check_constant((unsigned int)opcode[5],arg1 + 1,3);
opcode[5] = (ulongT)mem[opcode[5]];
}
if (opcode[6]!=(ulongT)~0U) {
_cimg_mp_check_constant((unsigned int)opcode[6],arg1 + 2,3);
opcode[6] = (ulongT)mem[opcode[6]];
}
if (opcode[7]!=(ulongT)~0U) {
_cimg_mp_check_constant((unsigned int)opcode[7],arg1 + 3,3);
opcode[7] = (ulongT)mem[opcode[7]];
}
_cimg_mp_check_type((unsigned int)opcode[8],arg1 + 4,1,0);
if (opcode[4]==(ulongT)~0U || opcode[5]==(ulongT)~0U ||
opcode[6]==(ulongT)~0U || opcode[7]==(ulongT)~0U) {
if (p1!=~0U) {
_cimg_mp_check_constant(p1,1,1);
p1 = (unsigned int)cimg::mod((int)mem[p1],listin.width());
}
const CImg<T> &img = p1!=~0U?listin[p1]:imgin;
if (!img) {
*se = saved_char;
s0 = ss - 4>expr._data?ss - 4:expr._data;
cimg::strellipsize(s0,64);
throw CImgArgumentException("[" cimg_appname "_math_parser] "
"CImg<%s>::%s: %s: Cannot crop empty image when "
"some xyzc-coordinates are unspecified, in expression '%s%s%s'.",
pixel_type(),_cimg_mp_calling_function,s_op,
s0!=expr._data?"...":"",s0,se<&expr.back()?"...":"");
}
if (opcode[4]==(ulongT)~0U) opcode[4] = (ulongT)img._width;
if (opcode[5]==(ulongT)~0U) opcode[5] = (ulongT)img._height;
if (opcode[6]==(ulongT)~0U) opcode[6] = (ulongT)img._depth;
if (opcode[7]==(ulongT)~0U) opcode[7] = (ulongT)img._spectrum;
}
pos = vector((unsigned int)(opcode[4]*opcode[5]*opcode[6]*opcode[7]));
CImg<ulongT>::vector((ulongT)mp_crop,
pos,p1,
*opcode,opcode[1],opcode[2],opcode[3],
opcode[4],opcode[5],opcode[6],opcode[7],
opcode[8]).move_to(code);
_cimg_mp_return(pos);
}
if (!std::strncmp(ss,"cross(",6)) { // Cross product
_cimg_mp_op("Function 'cross()'");
s1 = ss6; while (s1<se1 && (*s1!=',' || level[s1 - expr._data]!=clevel1)) ++s1;
arg1 = compile(ss6,s1,depth1,0,is_single);
arg2 = compile(++s1,se1,depth1,0,is_single);
_cimg_mp_check_type(arg1,1,2,3);
_cimg_mp_check_type(arg2,2,2,3);
pos = vector(3);
CImg<ulongT>::vector((ulongT)mp_cross,pos,arg1,arg2).move_to(code);
_cimg_mp_return(pos);
}
if (!std::strncmp(ss,"cut(",4)) { // Cut
_cimg_mp_op("Function 'cut()'");
s1 = ss4; while (s1<se1 && (*s1!=',' || level[s1 - expr._data]!=clevel1)) ++s1;
arg1 = compile(ss4,s1,depth1,0,is_single);
s2 = s1 + 1; while (s2<se1 && (*s2!=',' || level[s2 - expr._data]!=clevel1)) ++s2;
arg2 = compile(++s1,s2,depth1,0,is_single);
arg3 = compile(++s2,se1,depth1,0,is_single);
_cimg_mp_check_type(arg2,2,1,0);
_cimg_mp_check_type(arg3,3,1,0);
if (_cimg_mp_is_vector(arg1)) _cimg_mp_vector3_vss(mp_cut,arg1,arg2,arg3);
if (_cimg_mp_is_constant(arg1) && _cimg_mp_is_constant(arg2) && _cimg_mp_is_constant(arg3)) {
val = mem[arg1];
val1 = mem[arg2];
val2 = mem[arg3];
_cimg_mp_constant(val<val1?val1:val>val2?val2:val);
}
_cimg_mp_scalar3(mp_cut,arg1,arg2,arg3);
}
break;
case 'd' :
if (*ss1=='(') { // Image depth
_cimg_mp_op("Function 'd()'");
if (*ss2=='#') { // Index specified
p1 = compile(ss3,se1,depth1,0,is_single);
_cimg_mp_check_list(false);
} else { if (ss2!=se1) break; p1 = ~0U; }
pos = scalar();
CImg<ulongT>::vector((ulongT)mp_image_d,pos,p1).move_to(code);
_cimg_mp_return(pos);
}
if (!std::strncmp(ss,"date(",5)) { // Current date or file date
_cimg_mp_op("Function 'date()'");
s1 = ss5; while (s1<se1 && (*s1!=',' || level[s1 - expr._data]!=clevel1)) ++s1;
arg1 = ss5!=se1?compile(ss5,s1,depth1,0,is_single):~0U;
is_sth = s1++!=se1; // is_filename
pos = arg1==~0U || _cimg_mp_is_vector(arg1)?vector(arg1==~0U?7:_cimg_mp_size(arg1)):scalar();
if (is_sth) {
*se1 = 0;
variable_name.assign(CImg<charT>::string(s1,true,true).unroll('y'),true);
cimg::strpare(variable_name,false,true);
((CImg<ulongT>::vector((ulongT)mp_date,pos,0,arg1,_cimg_mp_size(pos)),variable_name)>'y').
move_to(opcode);
*se1 = ')';
} else
CImg<ulongT>::vector((ulongT)mp_date,pos,0,arg1,_cimg_mp_size(pos)).move_to(opcode);
opcode[2] = opcode._height;
opcode.move_to(code);
_cimg_mp_return(pos);
}
if (!std::strncmp(ss,"debug(",6)) { // Print debug info
_cimg_mp_op("Function 'debug()'");
p1 = code._width;
arg1 = compile(ss6,se1,depth1,p_ref,is_single);
*se1 = 0;
variable_name.assign(CImg<charT>::string(ss6,true,true).unroll('y'),true);
cimg::strpare(variable_name,false,true);
((CImg<ulongT>::vector((ulongT)mp_debug,arg1,0,code._width - p1),
variable_name)>'y').move_to(opcode);
opcode[2] = opcode._height;
opcode.move_to(code,p1);
*se1 = ')';
_cimg_mp_return(arg1);
}
if (!std::strncmp(ss,"display(",8)) { // Display memory, vector or image
_cimg_mp_op("Function 'display()'");
if (pexpr[se2 - expr._data]=='(') { // no arguments?
CImg<ulongT>::vector((ulongT)mp_display_memory,_cimg_mp_slot_nan).move_to(code);
_cimg_mp_return_nan();
}
if (*ss8!='#') { // Vector
s1 = ss8; while (s1<se1 && (*s1!=',' || level[s1 - expr._data]!=clevel1)) ++s1;
arg1 = compile(ss8,s1,depth1,0,is_single);
arg2 = 0; arg3 = arg4 = arg5 = 1;
if (s1<se1) {
s2 = s1 + 1; while (s2<se1 && (*s2!=',' || level[s2 - expr._data]!=clevel1)) ++s2;
arg2 = compile(s1 + 1,s2,depth1,0,is_single);
if (s2<se1) {
s3 = ++s2; while (s3<se1 && (*s3!=',' || level[s3 - expr._data]!=clevel1)) ++s3;
arg3 = compile(s2,s3,depth1,0,is_single);
if (s3<se1) {
s2 = ++s3; while (s2<se1 && (*s2!=',' || level[s2 - expr._data]!=clevel1)) ++s2;
arg4 = compile(s3,s2,depth1,0,is_single);
arg5 = s2<se1?compile(++s2,se1,depth1,0,is_single):0;
}
}
}
_cimg_mp_check_type(arg2,2,1,0);
_cimg_mp_check_type(arg3,3,1,0);
_cimg_mp_check_type(arg4,4,1,0);
_cimg_mp_check_type(arg5,5,1,0);
c1 = *s1; *s1 = 0;
variable_name.assign(CImg<charT>::string(ss8,true,true).unroll('y'),true);
cimg::strpare(variable_name,false,true);
if (_cimg_mp_is_vector(arg1))
((CImg<ulongT>::vector((ulongT)mp_vector_print,arg1,0,(ulongT)_cimg_mp_size(arg1),0),
variable_name)>'y').move_to(opcode);
else
((CImg<ulongT>::vector((ulongT)mp_print,arg1,0,0),
variable_name)>'y').move_to(opcode);
opcode[2] = opcode._height;
opcode.move_to(code);
((CImg<ulongT>::vector((ulongT)mp_display,arg1,0,(ulongT)_cimg_mp_size(arg1),
arg2,arg3,arg4,arg5),
variable_name)>'y').move_to(opcode);
opcode[2] = opcode._height;
opcode.move_to(code);
*s1 = c1;
_cimg_mp_return(arg1);
} else { // Image
p1 = compile(ss8 + 1,se1,depth1,0,is_single);
_cimg_mp_check_list(true);
CImg<ulongT>::vector((ulongT)mp_image_display,_cimg_mp_slot_nan,p1).move_to(code);
_cimg_mp_return_nan();
}
}
if (!std::strncmp(ss,"det(",4)) { // Matrix determinant
_cimg_mp_op("Function 'det()'");
arg1 = compile(ss4,se1,depth1,0,is_single);
_cimg_mp_check_matrix_square(arg1,1);
p1 = (unsigned int)std::sqrt((float)_cimg_mp_size(arg1));
_cimg_mp_scalar2(mp_det,arg1,p1);
}
if (!std::strncmp(ss,"diag(",5)) { // Diagonal matrix
_cimg_mp_op("Function 'diag()'");
arg1 = compile(ss5,se1,depth1,0,is_single);
if (_cimg_mp_is_scalar(arg1)) _cimg_mp_return(arg1);
p1 = _cimg_mp_size(arg1);
pos = vector(p1*p1);
CImg<ulongT>::vector((ulongT)mp_diag,pos,arg1,p1).move_to(code);
_cimg_mp_return(pos);
}
if (!std::strncmp(ss,"dot(",4)) { // Dot product
_cimg_mp_op("Function 'dot()'");
s1 = ss4; while (s1<se1 && (*s1!=',' || level[s1 - expr._data]!=clevel1)) ++s1;
arg1 = compile(ss4,s1,depth1,0,is_single);
arg2 = compile(++s1,se1,depth1,0,is_single);
_cimg_mp_check_type(arg1,1,2,0);
_cimg_mp_check_type(arg2,2,2,0);
if (_cimg_mp_is_vector(arg1)) _cimg_mp_scalar3(mp_dot,arg1,arg2,_cimg_mp_size(arg1));
_cimg_mp_scalar2(mp_mul,arg1,arg2);
}
if (!std::strncmp(ss,"do(",3) || !std::strncmp(ss,"dowhile(",8)) { // Do..while
_cimg_mp_op("Function 'dowhile()'");
s0 = *ss2=='('?ss3:ss8;
s1 = s0; while (s1<se1 && (*s1!=',' || level[s1 - expr._data]!=clevel1)) ++s1;
arg1 = code._width;
arg6 = mempos;
p1 = compile(s0,s1,depth1,0,is_single); // Body
arg2 = code._width;
p2 = s1<se1?compile(++s1,se1,depth1,0,is_single):p1; // Condition
_cimg_mp_check_type(p2,2,1,0);
CImg<ulongT>::vector((ulongT)mp_dowhile,p1,p2,arg2 - arg1,code._width - arg2,_cimg_mp_size(p1),
p1>=arg6 && !_cimg_mp_is_constant(p1),
p2>=arg6 && !_cimg_mp_is_constant(p2)).move_to(code,arg1);
_cimg_mp_return(p1);
}
if (!std::strncmp(ss,"draw(",5)) { // Draw image
if (!is_single) is_parallelizable = false;
_cimg_mp_op("Function 'draw()'");
if (*ss5=='#') { // Index specified
s0 = ss6; while (s0<se1 && (*s0!=',' || level[s0 - expr._data]!=clevel1)) ++s0;
p1 = compile(ss6,s0++,depth1,0,is_single);
_cimg_mp_check_list(true);
} else { p1 = ~0U; s0 = ss5; }
s1 = s0; while (s1<se1 && (*s1!=',' || level[s1 - expr._data]!=clevel1)) ++s1;
arg1 = compile(s0,s1,depth1,0,is_single);
arg2 = is_relative?0U:(unsigned int)_cimg_mp_slot_x;
arg3 = is_relative?0U:(unsigned int)_cimg_mp_slot_y;
arg4 = is_relative?0U:(unsigned int)_cimg_mp_slot_z;
arg5 = is_relative?0U:(unsigned int)_cimg_mp_slot_c;
s0 = se1;
if (s1<se1) {
s0 = s1 + 1; while (s0<se1 && (*s0!=',' || level[s0 - expr._data]!=clevel1)) ++s0;
arg2 = compile(++s1,s0,depth1,0,is_single);
if (_cimg_mp_is_vector(arg2)) { // Coordinates specified as a vector
p2 = _cimg_mp_size(arg2);
++arg2;
if (p2>1) {
arg3 = arg2 + 1;
if (p2>2) {
arg4 = arg3 + 1;
if (p2>3) arg5 = arg4 + 1;
}
}
++s0;
is_sth = true;
} else {
if (s0<se1) {
is_sth = p1!=~0U;
s1 = s0 + 1; while (s1<se1 && (*s1!=',' || level[s1 - expr._data]!=clevel1)) ++s1;
arg3 = compile(++s0,s1,depth1,0,is_single);
_cimg_mp_check_type(arg3,is_sth?4:3,1,0);
if (s1<se1) {
s0 = s1 + 1; while (s0<se1 && (*s0!=',' || level[s0 - expr._data]!=clevel1)) ++s0;
arg4 = compile(++s1,s0,depth1,0,is_single);
_cimg_mp_check_type(arg4,is_sth?5:4,1,0);
if (s0<se1) {
s1 = s0 + 1; while (s1<se1 && (*s1!=',' || level[s1 - expr._data]!=clevel1)) ++s1;
arg5 = compile(++s0,s1,depth1,0,is_single);
_cimg_mp_check_type(arg5,is_sth?6:5,1,0);
s0 = ++s1;
}
}
}
is_sth = false;
}
}
CImg<ulongT>::vector((ulongT)mp_draw,arg1,(ulongT)_cimg_mp_size(arg1),p1,arg2,arg3,arg4,arg5,
0,0,0,0,1,(ulongT)~0U,0,1).move_to(opcode);
arg2 = arg3 = arg4 = arg5 = ~0U;
p2 = p1!=~0U?0:1;
if (s0<se1) {
s1 = s0; while (s1<se1 && (*s1!=',' || level[s1 - expr._data]!=clevel1)) ++s1;
arg2 = compile(s0,s1,depth1,0,is_single);
_cimg_mp_check_type(arg2,p2 + (is_sth?3:6),1,0);
if (s1<se1) {
s0 = s1 + 1; while (s0<se1 && (*s0!=',' || level[s0 - expr._data]!=clevel1)) ++s0;
arg3 = compile(++s1,s0,depth1,0,is_single);
_cimg_mp_check_type(arg3,p2 + (is_sth?4:7),1,0);
if (s0<se1) {
s1 = s0 + 1; while (s1<se1 && (*s1!=',' || level[s1 - expr._data]!=clevel1)) ++s1;
arg4 = compile(++s0,s1,depth1,0,is_single);
_cimg_mp_check_type(arg4,p2 + (is_sth?5:8),1,0);
if (s1<se1) {
s0 = s1 + 1; while (s0<se1 && (*s0!=',' || level[s0 - expr._data]!=clevel1)) ++s0;
arg5 = compile(++s1,s0,depth1,0,is_single);
_cimg_mp_check_type(arg5,p2 + (is_sth?6:9),1,0);
}
}
}
}
if (s0<s1) s0 = s1;
opcode[8] = (ulongT)arg2;
opcode[9] = (ulongT)arg3;
opcode[10] = (ulongT)arg4;
opcode[11] = (ulongT)arg5;
if (s0<se1) {
s1 = s0 + 1; while (s1<se1 && (*s1!=',' || level[s1 - expr._data]!=clevel1)) ++s1;
arg6 = compile(++s0,s1,depth1,0,is_single);
_cimg_mp_check_type(arg6,0,1,0);
opcode[12] = arg6;
if (s1<se1) {
s0 = s1 + 1; while (s0<se1 && (*s0!=',' || level[s0 - expr._data]!=clevel1)) ++s0;
p2 = compile(++s1,s0,depth1,0,is_single);
_cimg_mp_check_type(p2,0,2,0);
opcode[13] = p2;
opcode[14] = _cimg_mp_size(p2);
p3 = s0<se1?compile(++s0,se1,depth1,0,is_single):1;
_cimg_mp_check_type(p3,0,1,0);
opcode[15] = p3;
}
}
opcode.move_to(code);
_cimg_mp_return(arg1);
}
break;
case 'e' :
if (!std::strncmp(ss,"echo(",5)) { // Echo
_cimg_mp_op("Function 'echo()'");
CImg<ulongT>::vector((ulongT)mp_echo,_cimg_mp_slot_nan,0).move_to(_opcode);
for (s = ss5; s<se; ++s) {
ns = s; while (ns<se && (*ns!=',' || level[ns - expr._data]!=clevel1) &&
(*ns!=')' || level[ns - expr._data]!=clevel)) ++ns;
arg1 = compile(s,ns,depth1,0,is_single);
CImg<ulongT>::vector(arg1,_cimg_mp_size(arg1)).move_to(_opcode);
s = ns;
}
(_opcode>'y').move_to(opcode);
opcode[2] = opcode._height;
opcode.move_to(code);
_cimg_mp_return_nan();
}
if (!std::strncmp(ss,"eig(",4)) { // Matrix eigenvalues/eigenvector
_cimg_mp_op("Function 'eig()'");
arg1 = compile(ss4,se1,depth1,0,is_single);
_cimg_mp_check_matrix_square(arg1,1);
p1 = (unsigned int)std::sqrt((float)_cimg_mp_size(arg1));
pos = vector((p1 + 1)*p1);
CImg<ulongT>::vector((ulongT)mp_matrix_eig,pos,arg1,p1).move_to(code);
_cimg_mp_return(pos);
}
if (!std::strncmp(ss,"end(",4)) { // End
_cimg_mp_op("Function 'end()'");
code.swap(code_end);
compile(ss4,se1,depth1,p_ref,true);
code.swap(code_end);
_cimg_mp_return_nan();
}
if (!std::strncmp(ss,"ext(",4)) { // Extern
_cimg_mp_op("Function 'ext()'");
if (!is_single) is_parallelizable = false;
CImg<ulongT>::vector((ulongT)mp_ext,0,0).move_to(_opcode);
pos = 1;
for (s = ss4; s<se; ++s) {
ns = s; while (ns<se && (*ns!=',' || level[ns - expr._data]!=clevel1) &&
(*ns!=')' || level[ns - expr._data]!=clevel)) ++ns;
arg1 = compile(s,ns,depth1,0,is_single);
CImg<ulongT>::vector(arg1,_cimg_mp_size(arg1)).move_to(_opcode);
s = ns;
}
(_opcode>'y').move_to(opcode);
pos = scalar();
opcode[1] = pos;
opcode[2] = opcode._height;
opcode.move_to(code);
_cimg_mp_return(pos);
}
if (!std::strncmp(ss,"exp(",4)) { // Exponential
_cimg_mp_op("Function 'exp()'");
arg1 = compile(ss4,se1,depth1,0,is_single);
if (_cimg_mp_is_vector(arg1)) _cimg_mp_vector1_v(mp_exp,arg1);
if (_cimg_mp_is_constant(arg1)) _cimg_mp_constant(std::exp(mem[arg1]));
_cimg_mp_scalar1(mp_exp,arg1);
}
if (!std::strncmp(ss,"eye(",4)) { // Identity matrix
_cimg_mp_op("Function 'eye()'");
arg1 = compile(ss4,se1,depth1,0,is_single);
_cimg_mp_check_constant(arg1,1,3);
p1 = (unsigned int)mem[arg1];
pos = vector(p1*p1);
CImg<ulongT>::vector((ulongT)mp_eye,pos,p1).move_to(code);
_cimg_mp_return(pos);
}
break;
case 'f' :
if (!std::strncmp(ss,"fact(",5)) { // Factorial
_cimg_mp_op("Function 'fact()'");
arg1 = compile(ss5,se1,depth1,0,is_single);
if (_cimg_mp_is_vector(arg1)) _cimg_mp_vector1_v(mp_factorial,arg1);
if (_cimg_mp_is_constant(arg1)) _cimg_mp_constant(cimg::factorial(mem[arg1]));
_cimg_mp_scalar1(mp_factorial,arg1);
}
if (!std::strncmp(ss,"fibo(",5)) { // Fibonacci
_cimg_mp_op("Function 'fibo()'");
arg1 = compile(ss5,se1,depth1,0,is_single);
if (_cimg_mp_is_vector(arg1)) _cimg_mp_vector1_v(mp_fibonacci,arg1);
if (_cimg_mp_is_constant(arg1)) _cimg_mp_constant(cimg::fibonacci(mem[arg1]));
_cimg_mp_scalar1(mp_fibonacci,arg1);
}
if (!std::strncmp(ss,"find(",5)) { // Find
_cimg_mp_op("Function 'find()'");
// First argument: data to look at.
s0 = ss5; while (s0<se1 && (*s0!=',' || level[s0 - expr._data]!=clevel1)) ++s0;
if (*ss5=='#') { // Index specified
p1 = compile(ss6,s0,depth1,0,is_single);
_cimg_mp_check_list(false);
arg1 = ~0U;
} else { // Vector specified
arg1 = compile(ss5,s0,depth1,0,is_single);
_cimg_mp_check_type(arg1,1,2,0);
p1 = ~0U;
}
// Second argument: data to find.
s1 = ++s0; while (s1<se1 && (*s1!=',' || level[s1 - expr._data]!=clevel1)) ++s1;
arg2 = compile(s0,s1,depth1,0,is_single);
// Third and fourth arguments: search direction and starting index.
arg3 = 1; arg4 = _cimg_mp_slot_nan;
if (s1<se1) {
s0 = s1 + 1; while (s0<se1 && (*s0!=',' || level[s0 - expr._data]!=clevel1)) ++s0;
arg3 = compile(++s1,s0,depth1,0,is_single);
_cimg_mp_check_type(arg3,3,1,0);
if (s0<se1) {
arg4 = compile(++s0,se1,depth1,0,is_single);
_cimg_mp_check_type(arg4,4,1,0);
}
}
if (p1!=~0U) {
if (_cimg_mp_is_vector(arg2))
_cimg_mp_scalar5(mp_list_find_seq,p1,arg2,_cimg_mp_size(arg2),arg3,arg4);
_cimg_mp_scalar4(mp_list_find,p1,arg2,arg3,arg4);
}
if (_cimg_mp_is_vector(arg2))
_cimg_mp_scalar6(mp_find_seq,arg1,_cimg_mp_size(arg1),arg2,_cimg_mp_size(arg2),arg3,arg4);
_cimg_mp_scalar5(mp_find,arg1,_cimg_mp_size(arg1),arg2,arg3,arg4);
}
if (*ss1=='o' && *ss2=='r' && *ss3=='(') { // For loop
_cimg_mp_op("Function 'for()'");
s1 = ss4; while (s1<se1 && (*s1!=',' || level[s1 - expr._data]!=clevel1)) ++s1;
s2 = s1 + 1; while (s2<se1 && (*s2!=',' || level[s2 - expr._data]!=clevel1)) ++s2;
s3 = s2 + 1; while (s3<se1 && (*s3!=',' || level[s3 - expr._data]!=clevel1)) ++s3;
arg1 = code._width;
p1 = compile(ss4,s1,depth1,0,is_single); // Init
arg2 = code._width;
p2 = compile(++s1,s2,depth1,0,is_single); // Cond
arg3 = code._width;
arg6 = mempos;
if (s3<se1) { // Body + post
p3 = compile(s3 + 1,se1,depth1,0,is_single); // Body
arg4 = code._width;
pos = compile(++s2,s3,depth1,0,is_single); // Post
} else {
p3 = compile(++s2,se1,depth1,0,is_single); // Body only
arg4 = pos = code._width;
}
_cimg_mp_check_type(p2,2,1,0);
arg5 = _cimg_mp_size(pos);
CImg<ulongT>::vector((ulongT)mp_for,p3,(ulongT)_cimg_mp_size(p3),p2,arg2 - arg1,arg3 - arg2,
arg4 - arg3,code._width - arg4,
p3>=arg6 && !_cimg_mp_is_constant(p3),
p2>=arg6 && !_cimg_mp_is_constant(p2)).move_to(code,arg1);
_cimg_mp_return(p3);
}
if (!std::strncmp(ss,"floor(",6)) { // Floor
_cimg_mp_op("Function 'floor()'");
arg1 = compile(ss6,se1,depth1,0,is_single);
if (_cimg_mp_is_vector(arg1)) _cimg_mp_vector1_v(mp_floor,arg1);
if (_cimg_mp_is_constant(arg1)) _cimg_mp_constant(std::floor(mem[arg1]));
_cimg_mp_scalar1(mp_floor,arg1);
}
if (!std::strncmp(ss,"fsize(",6)) { // File size
_cimg_mp_op("Function 'fsize()'");
*se1 = 0;
variable_name.assign(CImg<charT>::string(ss6,true,true).unroll('y'),true);
cimg::strpare(variable_name,false,true);
pos = scalar();
((CImg<ulongT>::vector((ulongT)mp_fsize,pos,0),variable_name)>'y').move_to(opcode);
*se1 = ')';
opcode[2] = opcode._height;
opcode.move_to(code);
_cimg_mp_return(pos);
}
break;
case 'g' :
if (!std::strncmp(ss,"gauss(",6)) { // Gaussian function
_cimg_mp_op("Function 'gauss()'");
s1 = ss6; while (s1<se1 && (*s1!=',' || level[s1 - expr._data]!=clevel1)) ++s1;
arg1 = compile(ss6,s1,depth1,0,is_single);
arg2 = s1<se1?compile(++s1,se1,depth1,0,is_single):1;
_cimg_mp_check_type(arg2,2,1,0);
if (_cimg_mp_is_vector(arg1)) _cimg_mp_vector2_vs(mp_gauss,arg1,arg2);
if (_cimg_mp_is_constant(arg1) && _cimg_mp_is_constant(arg2)) {
val1 = mem[arg1];
val2 = mem[arg2];
_cimg_mp_constant(std::exp(-val1*val1/(2*val2*val2))/std::sqrt(2*val2*val2*cimg::PI));
}
_cimg_mp_scalar2(mp_gauss,arg1,arg2);
}
if (!std::strncmp(ss,"gcd(",4)) { // Gcd
_cimg_mp_op("Function 'gcd()'");
s1 = ss4; while (s1<se1 && (*s1!=',' || level[s1 - expr._data]!=clevel1)) ++s1;
arg1 = compile(ss4,s1,depth1,0,is_single);
arg2 = compile(++s1,se1,depth1,0,is_single);
_cimg_mp_check_type(arg1,1,1,0);
_cimg_mp_check_type(arg2,2,1,0);
if (_cimg_mp_is_constant(arg1) && _cimg_mp_is_constant(arg2))
_cimg_mp_constant(cimg::gcd((long)mem[arg1],(long)mem[arg2]));
_cimg_mp_scalar2(mp_gcd,arg1,arg2);
}
break;
case 'h' :
if (*ss1=='(') { // Image height
_cimg_mp_op("Function 'h()'");
if (*ss2=='#') { // Index specified
p1 = compile(ss3,se1,depth1,0,is_single);
_cimg_mp_check_list(false);
} else { if (ss2!=se1) break; p1 = ~0U; }
pos = scalar();
CImg<ulongT>::vector((ulongT)mp_image_h,pos,p1).move_to(code);
_cimg_mp_return(pos);
}
break;
case 'i' :
if (*ss1=='c' && *ss2=='(') { // Image median
_cimg_mp_op("Function 'ic()'");
if (*ss3=='#') { // Index specified
p1 = compile(ss4,se1,depth1,0,is_single);
_cimg_mp_check_list(false);
} else { if (ss3!=se1) break; p1 = ~0U; }
pos = scalar();
CImg<ulongT>::vector((ulongT)mp_image_median,pos,p1).move_to(code);
_cimg_mp_return(pos);
}
if (*ss1=='f' && *ss2=='(') { // If..then[..else.]
_cimg_mp_op("Function 'if()'");
s1 = ss3; while (s1<se1 && (*s1!=',' || level[s1 - expr._data]!=clevel1)) ++s1;
s2 = s1 + 1; while (s2<se1 && (*s2!=',' || level[s2 - expr._data]!=clevel1)) ++s2;
arg1 = compile(ss3,s1,depth1,0,is_single);
_cimg_mp_check_type(arg1,1,1,0);
if (_cimg_mp_is_constant(arg1)) {
if ((bool)mem[arg1]) return compile(++s1,s2,depth1,0,is_single);
else return s2<se1?compile(++s2,se1,depth1,0,is_single):0;
}
p2 = code._width;
arg2 = compile(++s1,s2,depth1,0,is_single);
p3 = code._width;
arg3 = s2<se1?compile(++s2,se1,depth1,0,is_single):
_cimg_mp_is_vector(arg2)?vector(_cimg_mp_size(arg2),0):0;
_cimg_mp_check_type(arg3,3,_cimg_mp_is_vector(arg2)?2:1,_cimg_mp_size(arg2));
arg4 = _cimg_mp_size(arg2);
if (arg4) pos = vector(arg4); else pos = scalar();
CImg<ulongT>::vector((ulongT)mp_if,pos,arg1,arg2,arg3,
p3 - p2,code._width - p3,arg4).move_to(code,p2);
_cimg_mp_return(pos);
}
if (!std::strncmp(ss,"init(",5)) { // Init
_cimg_mp_op("Function 'init()'");
code.swap(code_init);
arg1 = compile(ss5,se1,depth1,p_ref,true);
code.swap(code_init);
_cimg_mp_return(arg1);
}
if (!std::strncmp(ss,"int(",4)) { // Integer cast
_cimg_mp_op("Function 'int()'");
arg1 = compile(ss4,se1,depth1,0,is_single);
if (_cimg_mp_is_vector(arg1)) _cimg_mp_vector1_v(mp_int,arg1);
if (_cimg_mp_is_constant(arg1)) _cimg_mp_constant((longT)mem[arg1]);
_cimg_mp_scalar1(mp_int,arg1);
}
if (!std::strncmp(ss,"inv(",4)) { // Matrix/scalar inversion
_cimg_mp_op("Function 'inv()'");
arg1 = compile(ss4,se1,depth1,0,is_single);
if (_cimg_mp_is_vector(arg1)) {
_cimg_mp_check_matrix_square(arg1,1);
p1 = (unsigned int)std::sqrt((float)_cimg_mp_size(arg1));
pos = vector(p1*p1);
CImg<ulongT>::vector((ulongT)mp_matrix_inv,pos,arg1,p1).move_to(code);
_cimg_mp_return(pos);
}
if (_cimg_mp_is_constant(arg1)) _cimg_mp_constant(1/mem[arg1]);
_cimg_mp_scalar2(mp_div,1,arg1);
}
if (*ss1=='s') { // Family of 'is_?()' functions
if (!std::strncmp(ss,"isbool(",7)) { // Is boolean?
_cimg_mp_op("Function 'isbool()'");
if (ss7==se1) _cimg_mp_return(0);
arg1 = compile(ss7,se1,depth1,0,is_single);
if (_cimg_mp_is_vector(arg1)) _cimg_mp_vector1_v(mp_isbool,arg1);
if (_cimg_mp_is_constant(arg1)) _cimg_mp_return(mem[arg1]==0.0 || mem[arg1]==1.0);
_cimg_mp_scalar1(mp_isbool,arg1);
}
if (!std::strncmp(ss,"isdir(",6)) { // Is directory?
_cimg_mp_op("Function 'isdir()'");
*se1 = 0;
is_sth = cimg::is_directory(ss6);
*se1 = ')';
_cimg_mp_return(is_sth?1U:0U);
}
if (!std::strncmp(ss,"isfile(",7)) { // Is file?
_cimg_mp_op("Function 'isfile()'");
*se1 = 0;
is_sth = cimg::is_file(ss7);
*se1 = ')';
_cimg_mp_return(is_sth?1U:0U);
}
if (!std::strncmp(ss,"isin(",5)) { // Is in sequence/vector?
if (ss5>=se1) _cimg_mp_return(0);
_cimg_mp_op("Function 'isin()'");
pos = scalar();
CImg<ulongT>::vector((ulongT)mp_isin,pos,0).move_to(_opcode);
for (s = ss5; s<se; ++s) {
ns = s; while (ns<se && (*ns!=',' || level[ns - expr._data]!=clevel1) &&
(*ns!=')' || level[ns - expr._data]!=clevel)) ++ns;
arg1 = compile(s,ns,depth1,0,is_single);
if (_cimg_mp_is_vector(arg1))
CImg<ulongT>::sequence(_cimg_mp_size(arg1),arg1 + 1,
arg1 + (ulongT)_cimg_mp_size(arg1)).
move_to(_opcode);
else CImg<ulongT>::vector(arg1).move_to(_opcode);
s = ns;
}
(_opcode>'y').move_to(opcode);
opcode[2] = opcode._height;
opcode.move_to(code);
_cimg_mp_return(pos);
}
if (!std::strncmp(ss,"isinf(",6)) { // Is infinite?
_cimg_mp_op("Function 'isinf()'");
if (ss6==se1) _cimg_mp_return(0);
arg1 = compile(ss6,se1,depth1,0,is_single);
if (_cimg_mp_is_vector(arg1)) _cimg_mp_vector1_v(mp_isinf,arg1);
if (_cimg_mp_is_constant(arg1)) _cimg_mp_return((unsigned int)cimg::type<double>::is_inf(mem[arg1]));
_cimg_mp_scalar1(mp_isinf,arg1);
}
if (!std::strncmp(ss,"isint(",6)) { // Is integer?
_cimg_mp_op("Function 'isint()'");
if (ss6==se1) _cimg_mp_return(0);
arg1 = compile(ss6,se1,depth1,0,is_single);
if (_cimg_mp_is_vector(arg1)) _cimg_mp_vector1_v(mp_isint,arg1);
if (_cimg_mp_is_constant(arg1)) _cimg_mp_return((unsigned int)(cimg::mod(mem[arg1],1.0)==0));
_cimg_mp_scalar1(mp_isint,arg1);
}
if (!std::strncmp(ss,"isnan(",6)) { // Is NaN?
_cimg_mp_op("Function 'isnan()'");
if (ss6==se1) _cimg_mp_return(0);
arg1 = compile(ss6,se1,depth1,0,is_single);
if (_cimg_mp_is_vector(arg1)) _cimg_mp_vector1_v(mp_isnan,arg1);
if (_cimg_mp_is_constant(arg1)) _cimg_mp_return((unsigned int)cimg::type<double>::is_nan(mem[arg1]));
_cimg_mp_scalar1(mp_isnan,arg1);
}
if (!std::strncmp(ss,"isval(",6)) { // Is value?
_cimg_mp_op("Function 'isval()'");
val = 0;
if (cimg_sscanf(ss6,"%lf%c%c",&val,&sep,&end)==2 && sep==')') _cimg_mp_return(1);
_cimg_mp_return(0);
}
}
break;
case 'l' :
if (*ss1=='(') { // Size of image list
_cimg_mp_op("Function 'l()'");
if (ss2!=se1) break;
_cimg_mp_scalar0(mp_list_l);
}
if (!std::strncmp(ss,"log(",4)) { // Natural logarithm
_cimg_mp_op("Function 'log()'");
arg1 = compile(ss4,se1,depth1,0,is_single);
if (_cimg_mp_is_vector(arg1)) _cimg_mp_vector1_v(mp_log,arg1);
if (_cimg_mp_is_constant(arg1)) _cimg_mp_constant(std::log(mem[arg1]));
_cimg_mp_scalar1(mp_log,arg1);
}
if (!std::strncmp(ss,"log2(",5)) { // Base-2 logarithm
_cimg_mp_op("Function 'log2()'");
arg1 = compile(ss5,se1,depth1,0,is_single);
if (_cimg_mp_is_vector(arg1)) _cimg_mp_vector1_v(mp_log2,arg1);
if (_cimg_mp_is_constant(arg1)) _cimg_mp_constant(cimg::log2(mem[arg1]));
_cimg_mp_scalar1(mp_log2,arg1);
}
if (!std::strncmp(ss,"log10(",6)) { // Base-10 logarithm
_cimg_mp_op("Function 'log10()'");
arg1 = compile(ss6,se1,depth1,0,is_single);
if (_cimg_mp_is_vector(arg1)) _cimg_mp_vector1_v(mp_log10,arg1);
if (_cimg_mp_is_constant(arg1)) _cimg_mp_constant(std::log10(mem[arg1]));
_cimg_mp_scalar1(mp_log10,arg1);
}
if (!std::strncmp(ss,"lowercase(",10)) { // Lower case
_cimg_mp_op("Function 'lowercase()'");
arg1 = compile(ss + 10,se1,depth1,0,is_single);
if (_cimg_mp_is_vector(arg1)) _cimg_mp_vector1_v(mp_lowercase,arg1);
if (_cimg_mp_is_constant(arg1)) _cimg_mp_constant(cimg::lowercase(mem[arg1]));
_cimg_mp_scalar1(mp_lowercase,arg1);
}
break;
case 'm' :
if (!std::strncmp(ss,"mul(",4)) { // Matrix multiplication
_cimg_mp_op("Function 'mul()'");
s1 = ss4; while (s1<se1 && (*s1!=',' || level[s1 - expr._data]!=clevel1)) ++s1;
arg1 = compile(ss4,s1,depth1,0,is_single);
s2 = s1 + 1; while (s2<se1 && (*s2!=',' || level[s2 - expr._data]!=clevel1)) ++s2;
arg2 = compile(++s1,s2,depth1,0,is_single);
arg3 = s2<se1?compile(++s2,se1,depth1,0,is_single):1;
_cimg_mp_check_type(arg1,1,2,0);
_cimg_mp_check_type(arg2,2,2,0);
_cimg_mp_check_constant(arg3,3,3);
p1 = _cimg_mp_size(arg1);
p2 = _cimg_mp_size(arg2);
p3 = (unsigned int)mem[arg3];
arg5 = p2/p3;
arg4 = p1/arg5;
if (arg4*arg5!=p1 || arg5*p3!=p2) {
*se = saved_char;
s0 = ss - 4>expr._data?ss - 4:expr._data;
cimg::strellipsize(s0,64);
throw CImgArgumentException("[" cimg_appname "_math_parser] "
"CImg<%s>::%s: %s: Types of first and second arguments ('%s' and '%s') "
"do not match with third argument 'nb_colsB=%u', "
"in expression '%s%s%s'.",
pixel_type(),_cimg_mp_calling_function,s_op,
s_type(arg1)._data,s_type(arg2)._data,p3,
s0!=expr._data?"...":"",s0,se<&expr.back()?"...":"");
}
pos = vector(arg4*p3);
CImg<ulongT>::vector((ulongT)mp_matrix_mul,pos,arg1,arg2,arg4,arg5,p3).move_to(code);
_cimg_mp_return(pos);
}
break;
case 'n' :
if (!std::strncmp(ss,"narg(",5)) { // Number of arguments
_cimg_mp_op("Function 'narg()'");
if (ss5>=se1) _cimg_mp_return(0);
arg1 = 0;
for (s = ss5; s<se; ++s) {
ns = s; while (ns<se && (*ns!=',' || level[ns - expr._data]!=clevel1) &&
(*ns!=')' || level[ns - expr._data]!=clevel)) ++ns;
++arg1; s = ns;
}
_cimg_mp_constant(arg1);
}
if ((cimg_sscanf(ss,"norm%u%c",&(arg1=~0U),&sep)==2 && sep=='(') ||
!std::strncmp(ss,"norminf(",8) || !std::strncmp(ss,"norm(",5) ||
(!std::strncmp(ss,"norm",4) && ss5<se1 && (s=std::strchr(ss5,'('))!=0)) { // Lp norm
_cimg_mp_op("Function 'normP()'");
if (*ss4=='(') { arg1 = 2; s = ss5; }
else if (*ss4=='i' && *ss5=='n' && *ss6=='f' && *ss7=='(') { arg1 = ~0U; s = ss8; }
else if (arg1==~0U) {
arg1 = compile(ss4,s++,depth1,0,is_single);
_cimg_mp_check_constant(arg1,0,2);
arg1 = (unsigned int)mem[arg1];
} else s = std::strchr(ss4,'(') + 1;
pos = scalar();
switch (arg1) {
case 0 :
CImg<ulongT>::vector((ulongT)mp_norm0,pos,0).move_to(_opcode); break;
case 1 :
CImg<ulongT>::vector((ulongT)mp_norm1,pos,0).move_to(_opcode); break;
case 2 :
CImg<ulongT>::vector((ulongT)mp_norm2,pos,0).move_to(_opcode); break;
case ~0U :
CImg<ulongT>::vector((ulongT)mp_norminf,pos,0).move_to(_opcode); break;
default :
CImg<ulongT>::vector((ulongT)mp_normp,pos,0,(ulongT)(arg1==~0U?-1:(int)arg1)).
move_to(_opcode);
}
for ( ; s<se; ++s) {
ns = s; while (ns<se && (*ns!=',' || level[ns - expr._data]!=clevel1) &&
(*ns!=')' || level[ns - expr._data]!=clevel)) ++ns;
arg2 = compile(s,ns,depth1,0,is_single);
if (_cimg_mp_is_vector(arg2))
CImg<ulongT>::sequence(_cimg_mp_size(arg2),arg2 + 1,
arg2 + (ulongT)_cimg_mp_size(arg2)).
move_to(_opcode);
else CImg<ulongT>::vector(arg2).move_to(_opcode);
s = ns;
}
(_opcode>'y').move_to(opcode);
if (arg1>0 && opcode._height==4) // Special case with one argument and p>=1
_cimg_mp_scalar1(mp_abs,opcode[3]);
opcode[2] = opcode._height;
opcode.move_to(code);
_cimg_mp_return(pos);
}
break;
case 'p' :
if (!std::strncmp(ss,"permut(",7)) { // Number of permutations
_cimg_mp_op("Function 'permut()'");
s1 = ss7; while (s1<se1 && (*s1!=',' || level[s1 - expr._data]!=clevel1)) ++s1;
s2 = s1 + 1; while (s2<se1 && (*s2!=',' || level[s2 - expr._data]!=clevel1)) ++s2;
arg1 = compile(ss7,s1,depth1,0,is_single);
arg2 = compile(++s1,s2,depth1,0,is_single);
arg3 = compile(++s2,se1,depth1,0,is_single);
_cimg_mp_check_type(arg1,1,1,0);
_cimg_mp_check_type(arg2,2,1,0);
_cimg_mp_check_type(arg3,3,1,0);
if (_cimg_mp_is_constant(arg1) && _cimg_mp_is_constant(arg2) && _cimg_mp_is_constant(arg3))
_cimg_mp_constant(cimg::permutations(mem[arg1],mem[arg2],(bool)mem[arg3]));
_cimg_mp_scalar3(mp_permutations,arg1,arg2,arg3);
}
if (!std::strncmp(ss,"pseudoinv(",10)) { // Matrix/scalar pseudo-inversion
_cimg_mp_op("Function 'pseudoinv()'");
s1 = ss + 10; while (s1<se1 && (*s1!=',' || level[s1 - expr._data]!=clevel1)) ++s1;
arg1 = compile(ss + 10,s1,depth1,0,is_single);
arg2 = s1<se1?compile(++s1,se1,depth1,0,is_single):1;
_cimg_mp_check_type(arg1,1,2,0);
_cimg_mp_check_constant(arg2,2,3);
p1 = _cimg_mp_size(arg1);
p2 = (unsigned int)mem[arg2];
p3 = p1/p2;
if (p3*p2!=p1) {
*se = saved_char;
s0 = ss - 4>expr._data?ss - 4:expr._data;
cimg::strellipsize(s0,64);
throw CImgArgumentException("[" cimg_appname "_math_parser] "
"CImg<%s>::%s: %s: Type of first argument ('%s') "
"does not match with second argument 'nb_colsA=%u', "
"in expression '%s%s%s'.",
pixel_type(),_cimg_mp_calling_function,s_op,
s_type(arg1)._data,p2,
s0!=expr._data?"...":"",s0,se<&expr.back()?"...":"");
}
pos = vector(p1);
CImg<ulongT>::vector((ulongT)mp_matrix_pseudoinv,pos,arg1,p2,p3).move_to(code);
_cimg_mp_return(pos);
}
if (!std::strncmp(ss,"print(",6) || !std::strncmp(ss,"prints(",7)) { // Print expressions
is_sth = ss[5]=='s'; // is prints()
_cimg_mp_op(is_sth?"Function 'prints()'":"Function 'print()'");
s0 = is_sth?ss7:ss6;
if (*s0!='#' || is_sth) { // Regular expression
for (s = s0; s<se; ++s) {
ns = s; while (ns<se && (*ns!=',' || level[ns - expr._data]!=clevel1) &&
(*ns!=')' || level[ns - expr._data]!=clevel)) ++ns;
pos = compile(s,ns,depth1,p_ref,is_single);
c1 = *ns; *ns = 0;
variable_name.assign(CImg<charT>::string(s,true,true).unroll('y'),true);
cimg::strpare(variable_name,false,true);
if (_cimg_mp_is_vector(pos)) // Vector
((CImg<ulongT>::vector((ulongT)mp_vector_print,pos,0,(ulongT)_cimg_mp_size(pos),is_sth?1:0),
variable_name)>'y').move_to(opcode);
else // Scalar
((CImg<ulongT>::vector((ulongT)mp_print,pos,0,is_sth?1:0),
variable_name)>'y').move_to(opcode);
opcode[2] = opcode._height;
opcode.move_to(code);
*ns = c1; s = ns;
}
_cimg_mp_return(pos);
} else { // Image
p1 = compile(ss7,se1,depth1,0,is_single);
_cimg_mp_check_list(true);
CImg<ulongT>::vector((ulongT)mp_image_print,_cimg_mp_slot_nan,p1).move_to(code);
_cimg_mp_return_nan();
}
}
break;
case 'r' :
if (!std::strncmp(ss,"resize(",7)) { // Vector or image resize
_cimg_mp_op("Function 'resize()'");
if (*ss7!='#') { // Vector
s1 = ss7; while (s1<se1 && (*s1!=',' || level[s1 - expr._data]!=clevel1)) ++s1;
arg1 = compile(ss7,s1,depth1,0,is_single);
s2 = ++s1; while (s2<se1 && (*s2!=',' || level[s2 - expr._data]!=clevel1)) ++s2;
arg2 = compile(s1,s2,depth1,0,is_single);
arg3 = 1;
arg4 = 0;
if (s2<se1) {
s1 = ++s2; while (s1<se1 && (*s1!=',' || level[s1 - expr._data]!=clevel1)) ++s1;
arg3 = compile(s2,s1,depth1,0,is_single);
arg4 = s1<se1?compile(++s1,se1,depth1,0,is_single):0;
}
_cimg_mp_check_constant(arg2,2,3);
arg2 = (unsigned int)mem[arg2];
_cimg_mp_check_type(arg3,3,1,0);
_cimg_mp_check_type(arg4,4,1,0);
pos = vector(arg2);
CImg<ulongT>::vector((ulongT)mp_vector_resize,pos,arg2,arg1,(ulongT)_cimg_mp_size(arg1),
arg3,arg4).move_to(code);
_cimg_mp_return(pos);
} else { // Image
if (!is_single) is_parallelizable = false;
s0 = ss8; while (s0<se1 && (*s0!=',' || level[s0 - expr._data]!=clevel1)) ++s0;
p1 = compile(ss8,s0++,depth1,0,is_single);
_cimg_mp_check_list(true);
CImg<ulongT>::vector((ulongT)mp_image_resize,_cimg_mp_slot_nan,p1,~0U,~0U,~0U,~0U,1,0,0,0,0,0).
move_to(opcode);
pos = 0;
for (s = s0; s<se && pos<10; ++s) {
ns = s; while (ns<se && (*ns!=',' || level[ns - expr._data]!=clevel1) &&
(*ns!=')' || level[ns - expr._data]!=clevel)) ++ns;
arg1 = compile(s,ns,depth1,0,is_single);
_cimg_mp_check_type(arg1,pos + 2,1,0);
opcode[pos + 3] = arg1;
s = ns;
++pos;
}
if (pos<1 || pos>10) {
*se = saved_char;
s0 = ss - 4>expr._data?ss - 4:expr._data;
cimg::strellipsize(s0,64);
throw CImgArgumentException("[" cimg_appname "_math_parser] "
"CImg<%s>::%s: %s: %s arguments, in expression '%s%s%s'.",
pixel_type(),_cimg_mp_calling_function,s_op,
pos<1?"Missing":"Too much",
s0!=expr._data?"...":"",s0,se<&expr.back()?"...":"");
}
opcode.move_to(code);
_cimg_mp_return_nan();
}
}
if (!std::strncmp(ss,"reverse(",8)) { // Vector reverse
_cimg_mp_op("Function 'reverse()'");
arg1 = compile(ss8,se1,depth1,0,is_single);
if (!_cimg_mp_is_vector(arg1)) _cimg_mp_return(arg1);
p1 = _cimg_mp_size(arg1);
pos = vector(p1);
CImg<ulongT>::vector((ulongT)mp_vector_reverse,pos,arg1,p1).move_to(code);
_cimg_mp_return(pos);
}
if (!std::strncmp(ss,"rol(",4) || !std::strncmp(ss,"ror(",4)) { // Bitwise rotation
_cimg_mp_op(ss[2]=='l'?"Function 'rol()'":"Function 'ror()'");
s1 = ss4; while (s1<se1 && (*s1!=',' || level[s1-expr._data]!=clevel1)) ++s1;
arg1 = compile(ss4,s1,depth1,0,is_single);
arg2 = s1<se1?compile(++s1,se1,depth1,0,is_single):1;
_cimg_mp_check_type(arg2,2,1,0);
if (_cimg_mp_is_vector(arg1)) _cimg_mp_vector2_vs(*ss2=='l'?mp_rol:mp_ror,arg1,arg2);
if (_cimg_mp_is_constant(arg1) && _cimg_mp_is_constant(arg2))
_cimg_mp_constant(*ss2=='l'?cimg::rol(mem[arg1],(unsigned int)mem[arg2]):
cimg::ror(mem[arg1],(unsigned int)mem[arg2]));
_cimg_mp_scalar2(*ss2=='l'?mp_rol:mp_ror,arg1,arg2);
}
if (!std::strncmp(ss,"rot(",4)) { // 2d/3d rotation matrix
_cimg_mp_op("Function 'rot()'");
s1 = ss4; while (s1<se1 && (*s1!=',' || level[s1 - expr._data]!=clevel1)) ++s1;
arg1 = compile(ss4,s1,depth1,0,is_single);
if (s1<se1) { // 3d rotation
_cimg_mp_check_type(arg1,1,3,3);
is_sth = false; // Is coordinates as vector?
if (_cimg_mp_is_vector(arg1)) { // Coordinates specified as a vector
is_sth = true;
p2 = _cimg_mp_size(arg1);
++arg1;
arg2 = arg3 = 0;
if (p2>1) {
arg2 = arg1 + 1;
if (p2>2) arg3 = arg2 + 1;
}
arg4 = compile(++s1,se1,depth1,0,is_single);
} else {
s2 = s1 + 1; while (s2<se1 && (*s2!=',' || level[s2 - expr._data]!=clevel1)) ++s2;
arg2 = compile(++s1,s2,depth1,0,is_single);
s3 = s2 + 1; while (s3<se1 && (*s3!=',' || level[s3 - expr._data]!=clevel1)) ++s3;
arg3 = compile(++s2,s3,depth1,0,is_single);
arg4 = compile(++s3,se1,depth1,0,is_single);
_cimg_mp_check_type(arg2,2,1,0);
_cimg_mp_check_type(arg3,3,1,0);
}
_cimg_mp_check_type(arg4,is_sth?2:4,1,0);
pos = vector(9);
CImg<ulongT>::vector((ulongT)mp_rot3d,pos,arg1,arg2,arg3,arg4).move_to(code);
} else { // 2d rotation
_cimg_mp_check_type(arg1,1,1,0);
pos = vector(4);
CImg<ulongT>::vector((ulongT)mp_rot2d,pos,arg1).move_to(code);
}
_cimg_mp_return(pos);
}
if (!std::strncmp(ss,"round(",6)) { // Value rounding
_cimg_mp_op("Function 'round()'");
s1 = ss6; while (s1<se1 && (*s1!=',' || level[s1 - expr._data]!=clevel1)) ++s1;
arg1 = compile(ss6,s1,depth1,0,is_single);
arg2 = 1;
arg3 = 0;
if (s1<se1) {
s2 = s1 + 1; while (s2<se1 && (*s2!=',' || level[s2 - expr._data]!=clevel1)) ++s2;
arg2 = compile(++s1,s2,depth1,0,is_single);
arg3 = s2<se1?compile(++s2,se1,depth1,0,is_single):0;
}
_cimg_mp_check_type(arg2,2,1,0);
_cimg_mp_check_type(arg3,3,1,0);
if (_cimg_mp_is_vector(arg1)) _cimg_mp_vector3_vss(mp_round,arg1,arg2,arg3);
if (_cimg_mp_is_constant(arg1) && _cimg_mp_is_constant(arg2) && _cimg_mp_is_constant(arg3))
_cimg_mp_constant(cimg::round(mem[arg1],mem[arg2],(int)mem[arg3]));
_cimg_mp_scalar3(mp_round,arg1,arg2,arg3);
}
break;
case 's' :
if (*ss1=='(') { // Image spectrum
_cimg_mp_op("Function 's()'");
if (*ss2=='#') { // Index specified
p1 = compile(ss3,se1,depth1,0,is_single);
_cimg_mp_check_list(false);
} else { if (ss2!=se1) break; p1 = ~0U; }
pos = scalar();
CImg<ulongT>::vector((ulongT)mp_image_s,pos,p1).move_to(code);
_cimg_mp_return(pos);
}
if (!std::strncmp(ss,"same(",5)) { // Test if operands have the same values
_cimg_mp_op("Function 'same()'");
s1 = ss5; while (s1<se1 && (*s1!=',' || level[s1 - expr._data]!=clevel1)) ++s1;
arg1 = compile(ss5,s1,depth1,0,is_single);
s2 = s1 + 1; while (s2<se1 && (*s2!=',' || level[s2 - expr._data]!=clevel1)) ++s2;
arg2 = compile(++s1,s2,depth1,0,is_single);
arg3 = 11;
arg4 = 1;
if (s2<se1) {
s3 = s2 + 1; while (s3<se1 && (*s3!=',' || level[s3 - expr._data]!=clevel1)) ++s3;
arg3 = compile(++s2,s3,depth1,0,is_single);
_cimg_mp_check_type(arg3,3,1,0);
arg4 = s3<se1?compile(++s3,se1,depth1,0,is_single):1;
}
p1 = _cimg_mp_size(arg1);
p2 = _cimg_mp_size(arg2);
_cimg_mp_scalar6(mp_vector_eq,arg1,p1,arg2,p2,arg3,arg4);
}
if (!std::strncmp(ss,"shift(",6)) { // Shift vector
_cimg_mp_op("Function 'shift()'");
s1 = ss6; while (s1<se1 && (*s1!=',' || level[s1 - expr._data]!=clevel1)) ++s1;
arg1 = compile(ss6,s1,depth1,0,is_single);
arg2 = 1; arg3 = 0;
if (s1<se1) {
s0 = ++s1; while (s0<se1 && (*s0!=',' || level[s0 - expr._data]!=clevel1)) ++s0;
arg2 = compile(s1,s0,depth1,0,is_single);
arg3 = s0<se1?compile(++s0,se1,depth1,0,is_single):0;
}
_cimg_mp_check_type(arg1,1,2,0);
_cimg_mp_check_type(arg2,2,1,0);
_cimg_mp_check_type(arg3,3,1,0);
p1 = _cimg_mp_size(arg1);
pos = vector(p1);
CImg<ulongT>::vector((ulongT)mp_shift,pos,arg1,p1,arg2,arg3).move_to(code);
_cimg_mp_return(pos);
}
if (!std::strncmp(ss,"sign(",5)) { // Sign
_cimg_mp_op("Function 'sign()'");
arg1 = compile(ss5,se1,depth1,0,is_single);
if (_cimg_mp_is_vector(arg1)) _cimg_mp_vector1_v(mp_sign,arg1);
if (_cimg_mp_is_constant(arg1)) _cimg_mp_constant(cimg::sign(mem[arg1]));
_cimg_mp_scalar1(mp_sign,arg1);
}
if (!std::strncmp(ss,"sin(",4)) { // Sine
_cimg_mp_op("Function 'sin()'");
arg1 = compile(ss4,se1,depth1,0,is_single);
if (_cimg_mp_is_vector(arg1)) _cimg_mp_vector1_v(mp_sin,arg1);
if (_cimg_mp_is_constant(arg1)) _cimg_mp_constant(std::sin(mem[arg1]));
_cimg_mp_scalar1(mp_sin,arg1);
}
if (!std::strncmp(ss,"sinc(",5)) { // Sine cardinal
_cimg_mp_op("Function 'sinc()'");
arg1 = compile(ss5,se1,depth1,0,is_single);
if (_cimg_mp_is_vector(arg1)) _cimg_mp_vector1_v(mp_sinc,arg1);
if (_cimg_mp_is_constant(arg1)) _cimg_mp_constant(cimg::sinc(mem[arg1]));
_cimg_mp_scalar1(mp_sinc,arg1);
}
if (!std::strncmp(ss,"sinh(",5)) { // Hyperbolic sine
_cimg_mp_op("Function 'sinh()'");
arg1 = compile(ss5,se1,depth1,0,is_single);
if (_cimg_mp_is_vector(arg1)) _cimg_mp_vector1_v(mp_sinh,arg1);
if (_cimg_mp_is_constant(arg1)) _cimg_mp_constant(std::sinh(mem[arg1]));
_cimg_mp_scalar1(mp_sinh,arg1);
}
if (!std::strncmp(ss,"size(",5)) { // Vector size.
_cimg_mp_op("Function 'size()'");
arg1 = compile(ss5,se1,depth1,0,is_single);
_cimg_mp_constant(_cimg_mp_is_scalar(arg1)?0:_cimg_mp_size(arg1));
}
if (!std::strncmp(ss,"solve(",6)) { // Solve linear system
_cimg_mp_op("Function 'solve()'");
s1 = ss6; while (s1<se1 && (*s1!=',' || level[s1 - expr._data]!=clevel1)) ++s1;
arg1 = compile(ss6,s1,depth1,0,is_single);
s2 = s1 + 1; while (s2<se1 && (*s2!=',' || level[s2 - expr._data]!=clevel1)) ++s2;
arg2 = compile(++s1,s2,depth1,0,is_single);
arg3 = s2<se1?compile(++s2,se1,depth1,0,is_single):1;
_cimg_mp_check_type(arg1,1,2,0);
_cimg_mp_check_type(arg2,2,2,0);
_cimg_mp_check_constant(arg3,3,3);
p1 = _cimg_mp_size(arg1);
p2 = _cimg_mp_size(arg2);
p3 = (unsigned int)mem[arg3];
arg5 = p2/p3;
arg4 = p1/arg5;
if (arg4*arg5!=p1 || arg5*p3!=p2) {
*se = saved_char;
s0 = ss - 4>expr._data?ss - 4:expr._data;
cimg::strellipsize(s0,64);
throw CImgArgumentException("[" cimg_appname "_math_parser] "
"CImg<%s>::%s: %s: Types of first and second arguments ('%s' and '%s') "
"do not match with third argument 'nb_colsB=%u', "
"in expression '%s%s%s'.",
pixel_type(),_cimg_mp_calling_function,s_op,
s_type(arg1)._data,s_type(arg2)._data,p3,
s0!=expr._data?"...":"",s0,se<&expr.back()?"...":"");
}
pos = vector(arg4*p3);
CImg<ulongT>::vector((ulongT)mp_solve,pos,arg1,arg2,arg4,arg5,p3).move_to(code);
_cimg_mp_return(pos);
}
if (!std::strncmp(ss,"sort(",5)) { // Sort vector
_cimg_mp_op("Function 'sort()'");
if (*ss5!='#') { // Vector
s1 = ss5; while (s1<se1 && (*s1!=',' || level[s1 - expr._data]!=clevel1)) ++s1;
arg1 = compile(ss5,s1,depth1,0,is_single);
arg2 = arg3 = 1;
if (s1<se1) {
s0 = ++s1; while (s0<se1 && (*s0!=',' || level[s0 - expr._data]!=clevel1)) ++s0;
arg2 = compile(s1,s0,depth1,0,is_single);
arg3 = s0<se1?compile(++s0,se1,depth1,0,is_single):1;
}
_cimg_mp_check_type(arg1,1,2,0);
_cimg_mp_check_type(arg2,2,1,0);
_cimg_mp_check_constant(arg3,3,3);
arg3 = (unsigned int)mem[arg3];
p1 = _cimg_mp_size(arg1);
if (p1%arg3) {
*se = saved_char;
s0 = ss - 4>expr._data?ss - 4:expr._data;
cimg::strellipsize(s0,64);
throw CImgArgumentException("[" cimg_appname "_math_parser] "
"CImg<%s>::%s: %s: Invalid specified chunk size (%u) for first argument "
"('%s'), in expression '%s%s%s'.",
pixel_type(),_cimg_mp_calling_function,s_op,
arg3,s_type(arg1)._data,
s0!=expr._data?"...":"",s0,se<&expr.back()?"...":"");
}
pos = vector(p1);
CImg<ulongT>::vector((ulongT)mp_sort,pos,arg1,p1,arg2,arg3).move_to(code);
_cimg_mp_return(pos);
} else { // Image
s1 = ss6; while (s1<se1 && (*s1!=',' || level[s1 - expr._data]!=clevel1)) ++s1;
p1 = compile(ss6,s1,depth1,0,is_single);
arg1 = 1;
arg2 = constant(-1.0);
if (s1<se1) {
s2 = s1 + 1; while (s2<se1 && (*s2!=',' || level[s2 - expr._data]!=clevel1)) ++s2;
arg1 = compile(++s1,s2,depth1,0,is_single);
if (s2<se1) arg2 = compile(++s2,se1,depth1,0,is_single);
}
_cimg_mp_check_type(arg1,2,1,0);
_cimg_mp_check_type(arg2,3,1,0);
_cimg_mp_check_list(true);
CImg<ulongT>::vector((ulongT)mp_image_sort,_cimg_mp_slot_nan,p1,arg1,arg2).move_to(code);
_cimg_mp_return_nan();
}
}
if (!std::strncmp(ss,"sqr(",4)) { // Square
_cimg_mp_op("Function 'sqr()'");
arg1 = compile(ss4,se1,depth1,0,is_single);
if (_cimg_mp_is_vector(arg1)) _cimg_mp_vector1_v(mp_sqr,arg1);
if (_cimg_mp_is_constant(arg1)) _cimg_mp_constant(cimg::sqr(mem[arg1]));
_cimg_mp_scalar1(mp_sqr,arg1);
}
if (!std::strncmp(ss,"sqrt(",5)) { // Square root
_cimg_mp_op("Function 'sqrt()'");
arg1 = compile(ss5,se1,depth1,0,is_single);
if (_cimg_mp_is_vector(arg1)) _cimg_mp_vector1_v(mp_sqrt,arg1);
if (_cimg_mp_is_constant(arg1)) _cimg_mp_constant(std::sqrt(mem[arg1]));
_cimg_mp_scalar1(mp_sqrt,arg1);
}
if (!std::strncmp(ss,"srand(",6)) { // Set RNG seed
_cimg_mp_op("Function 'srand()'");
arg1 = ss6<se1?compile(ss6,se1,depth1,0,is_single):~0U;
if (arg1!=~0U) { _cimg_mp_check_type(arg1,1,1,0); _cimg_mp_scalar1(mp_srand,arg1); }
_cimg_mp_scalar0(mp_srand0);
}
if (!std::strncmp(ss,"stats(",6)) { // Image statistics
_cimg_mp_op("Function 'stats()'");
if (*ss6=='#') { // Index specified
p1 = compile(ss7,se1,depth1,0,is_single);
_cimg_mp_check_list(false);
} else { if (ss6!=se1) break; p1 = ~0U; }
pos = vector(14);
CImg<ulongT>::vector((ulongT)mp_image_stats,pos,p1).move_to(code);
_cimg_mp_return(pos);
}
if (!std::strncmp(ss,"stov(",5)) { // String to double
_cimg_mp_op("Function 'stov()'");
s1 = ss5; while (s1<se1 && (*s1!=',' || level[s1 - expr._data]!=clevel1)) ++s1;
arg1 = compile(ss5,s1,depth1,0,is_single);
arg2 = arg3 = 0;
if (s1<se1) {
s2 = s1 + 1; while (s2<se1 && (*s2!=',' || level[s2 - expr._data]!=clevel1)) ++s2;
arg2 = compile(++s1,s2,depth1,0,is_single);
arg3 = s2<se1?compile(++s2,se1,depth1,0,is_single):0;
}
_cimg_mp_check_type(arg2,2,1,0);
_cimg_mp_check_type(arg3,3,1,0);
p1 = _cimg_mp_size(arg1);
_cimg_mp_scalar4(mp_stov,arg1,p1,arg2,arg3);
}
if (!std::strncmp(ss,"svd(",4)) { // Matrix SVD
_cimg_mp_op("Function 'svd()'");
s1 = ss4; while (s1<se1 && (*s1!=',' || level[s1 - expr._data]!=clevel1)) ++s1;
arg1 = compile(ss4,s1,depth1,0,is_single);
arg2 = s1<se1?compile(++s1,se1,depth1,0,is_single):1;
_cimg_mp_check_type(arg1,1,2,0);
_cimg_mp_check_constant(arg2,2,3);
p1 = _cimg_mp_size(arg1);
p2 = (unsigned int)mem[arg2];
p3 = p1/p2;
if (p3*p2!=p1) {
*se = saved_char;
s0 = ss - 4>expr._data?ss - 4:expr._data;
cimg::strellipsize(s0,64);
throw CImgArgumentException("[" cimg_appname "_math_parser] "
"CImg<%s>::%s: %s: Type of first argument ('%s') "
"does not match with second argument 'nb_colsA=%u', "
"in expression '%s%s%s'.",
pixel_type(),_cimg_mp_calling_function,s_op,
s_type(arg1)._data,p2,
s0!=expr._data?"...":"",s0,se<&expr.back()?"...":"");
}
pos = vector(p1 + p2 + p2*p2);
CImg<ulongT>::vector((ulongT)mp_matrix_svd,pos,arg1,p2,p3).move_to(code);
_cimg_mp_return(pos);
}
break;
case 't' :
if (!std::strncmp(ss,"tan(",4)) { // Tangent
_cimg_mp_op("Function 'tan()'");
arg1 = compile(ss4,se1,depth1,0,is_single);
if (_cimg_mp_is_vector(arg1)) _cimg_mp_vector1_v(mp_tan,arg1);
if (_cimg_mp_is_constant(arg1)) _cimg_mp_constant(std::tan(mem[arg1]));
_cimg_mp_scalar1(mp_tan,arg1);
}
if (!std::strncmp(ss,"tanh(",5)) { // Hyperbolic tangent
_cimg_mp_op("Function 'tanh()'");
arg1 = compile(ss5,se1,depth1,0,is_single);
if (_cimg_mp_is_vector(arg1)) _cimg_mp_vector1_v(mp_tanh,arg1);
if (_cimg_mp_is_constant(arg1)) _cimg_mp_constant(std::tanh(mem[arg1]));
_cimg_mp_scalar1(mp_tanh,arg1);
}
if (!std::strncmp(ss,"trace(",6)) { // Matrix trace
_cimg_mp_op("Function 'trace()'");
arg1 = compile(ss6,se1,depth1,0,is_single);
_cimg_mp_check_matrix_square(arg1,1);
p1 = (unsigned int)std::sqrt((float)_cimg_mp_size(arg1));
_cimg_mp_scalar2(mp_trace,arg1,p1);
}
if (!std::strncmp(ss,"transp(",7)) { // Matrix transpose
_cimg_mp_op("Function 'transp()'");
s1 = ss7; while (s1<se1 && (*s1!=',' || level[s1 - expr._data]!=clevel1)) ++s1;
arg1 = compile(ss7,s1,depth1,0,is_single);
arg2 = compile(++s1,se1,depth1,0,is_single);
_cimg_mp_check_type(arg1,1,2,0);
_cimg_mp_check_constant(arg2,2,3);
p1 = _cimg_mp_size(arg1);
p2 = (unsigned int)mem[arg2];
p3 = p1/p2;
if (p2*p3!=p1) {
*se = saved_char;
s0 = ss - 4>expr._data?ss - 4:expr._data;
cimg::strellipsize(s0,64);
throw CImgArgumentException("[" cimg_appname "_math_parser] "
"CImg<%s>::%s: %s: Size of first argument ('%s') does not match "
"second argument 'nb_cols=%u', in expression '%s%s%s'.",
pixel_type(),_cimg_mp_calling_function,s_op,
s_type(arg1)._data,p2,
s0!=expr._data?"...":"",s0,se<&expr.back()?"...":"");
}
pos = vector(p3*p2);
CImg<ulongT>::vector((ulongT)mp_transp,pos,arg1,p2,p3).move_to(code);
_cimg_mp_return(pos);
}
break;
case 'u' :
if (*ss1=='(') { // Random value with uniform distribution
_cimg_mp_op("Function 'u()'");
if (*ss2==')') _cimg_mp_scalar2(mp_u,0,1);
s1 = ss2; while (s1<se1 && (*s1!=',' || level[s1 - expr._data]!=clevel1)) ++s1;
arg1 = compile(ss2,s1,depth1,0,is_single);
if (s1<se1) arg2 = compile(++s1,se1,depth1,0,is_single); else { arg2 = arg1; arg1 = 0; }
_cimg_mp_check_type(arg2,2,3,_cimg_mp_size(arg1));
if (_cimg_mp_is_vector(arg1) && _cimg_mp_is_vector(arg2)) _cimg_mp_vector2_vv(mp_u,arg1,arg2);
if (_cimg_mp_is_vector(arg1) && _cimg_mp_is_scalar(arg2)) _cimg_mp_vector2_vs(mp_u,arg1,arg2);
if (_cimg_mp_is_scalar(arg1) && _cimg_mp_is_vector(arg2)) _cimg_mp_vector2_sv(mp_u,arg1,arg2);
_cimg_mp_scalar2(mp_u,arg1,arg2);
}
if (!std::strncmp(ss,"unref(",6)) { // Un-reference variable
_cimg_mp_op("Function 'unref()'");
arg1 = ~0U;
for (s0 = ss6; s0<se1; s0 = s1) {
if (s0>ss6 && *s0==',') ++s0;
s1 = s0; while (s1<se1 && *s1!=',') ++s1;
c1 = *s1;
if (s1>s0) {
*s1 = 0;
arg2 = arg3 = ~0U;
if (s0[0]=='w' && s0[1]=='h' && !s0[2]) arg1 = reserved_label[arg3 = 0];
else if (s0[0]=='w' && s0[1]=='h' && s0[2]=='d' && !s0[3]) arg1 = reserved_label[arg3 = 1];
else if (s0[0]=='w' && s0[1]=='h' && s0[2]=='d' && s0[3]=='s' && !s0[4])
arg1 = reserved_label[arg3 = 2];
else if (s0[0]=='p' && s0[1]=='i' && !s0[2]) arg1 = reserved_label[arg3 = 3];
else if (s0[0]=='i' && s0[1]=='m' && !s0[2]) arg1 = reserved_label[arg3 = 4];
else if (s0[0]=='i' && s0[1]=='M' && !s0[2]) arg1 = reserved_label[arg3 = 5];
else if (s0[0]=='i' && s0[1]=='a' && !s0[2]) arg1 = reserved_label[arg3 = 6];
else if (s0[0]=='i' && s0[1]=='v' && !s0[2]) arg1 = reserved_label[arg3 = 7];
else if (s0[0]=='i' && s0[1]=='s' && !s0[2]) arg1 = reserved_label[arg3 = 8];
else if (s0[0]=='i' && s0[1]=='p' && !s0[2]) arg1 = reserved_label[arg3 = 9];
else if (s0[0]=='i' && s0[1]=='c' && !s0[2]) arg1 = reserved_label[arg3 = 10];
else if (s0[0]=='x' && s0[1]=='m' && !s0[2]) arg1 = reserved_label[arg3 = 11];
else if (s0[0]=='y' && s0[1]=='m' && !s0[2]) arg1 = reserved_label[arg3 = 12];
else if (s0[0]=='z' && s0[1]=='m' && !s0[2]) arg1 = reserved_label[arg3 = 13];
else if (s0[0]=='c' && s0[1]=='m' && !s0[2]) arg1 = reserved_label[arg3 = 14];
else if (s0[0]=='x' && s0[1]=='M' && !s0[2]) arg1 = reserved_label[arg3 = 15];
else if (s0[0]=='y' && s0[1]=='M' && !s0[2]) arg1 = reserved_label[arg3 = 16];
else if (s0[0]=='z' && s0[1]=='M' && !s0[2]) arg1 = reserved_label[arg3 = 17];
else if (s0[0]=='c' && s0[1]=='M' && !s0[2]) arg1 = reserved_label[arg3 = 18];
else if (s0[0]=='i' && s0[1]>='0' && s0[1]<='9' && !s0[2])
arg1 = reserved_label[arg3 = 19 + s0[1] - '0'];
else if (!std::strcmp(s0,"interpolation")) arg1 = reserved_label[arg3 = 29];
else if (!std::strcmp(s0,"boundary")) arg1 = reserved_label[arg3 = 30];
else if (s0[1]) { // Multi-char variable
cimglist_for(variable_def,i) if (!std::strcmp(s0,variable_def[i])) {
arg1 = variable_pos[i]; arg2 = i; break;
}
} else arg1 = reserved_label[arg3 = *s0]; // Single-char variable
if (arg1!=~0U) {
if (arg2==~0U) { if (arg3!=~0U) reserved_label[arg3] = ~0U; }
else {
variable_def.remove(arg2);
if (arg2<variable_pos._width - 1)
std::memmove(variable_pos._data + arg2,variable_pos._data + arg2 + 1,
sizeof(uintT)*(variable_pos._width - arg2 - 1));
--variable_pos._width;
}
}
*s1 = c1;
} else compile(s0,s1,depth1,0,is_single); // Will throw a 'missing argument' exception
}
_cimg_mp_return(arg1!=~0U?arg1:_cimg_mp_slot_nan); // Return value of last specified variable.
}
if (!std::strncmp(ss,"uppercase(",10)) { // Upper case
_cimg_mp_op("Function 'uppercase()'");
arg1 = compile(ss + 10,se1,depth1,0,is_single);
if (_cimg_mp_is_vector(arg1)) _cimg_mp_vector1_v(mp_uppercase,arg1);
if (_cimg_mp_is_constant(arg1)) _cimg_mp_constant(cimg::uppercase(mem[arg1]));
_cimg_mp_scalar1(mp_uppercase,arg1);
}
break;
case 'v' :
if ((cimg_sscanf(ss,"vector%u%c",&(arg1=~0U),&sep)==2 && sep=='(' && arg1>0) ||
!std::strncmp(ss,"vector(",7) ||
(!std::strncmp(ss,"vector",6) && ss7<se1 && (s=std::strchr(ss7,'('))!=0)) { // Vector
_cimg_mp_op("Function 'vector()'");
arg2 = 0; // Number of specified values.
if (arg1==~0U && *ss6!='(') {
arg1 = compile(ss6,s++,depth1,0,is_single);
_cimg_mp_check_constant(arg1,0,3);
arg1 = (unsigned int)mem[arg1];
} else s = std::strchr(ss6,'(') + 1;
if (s<se1 || arg1==~0U) for ( ; s<se; ++s) {
ns = s; while (ns<se && (*ns!=',' || level[ns - expr._data]!=clevel1) &&
(*ns!=')' || level[ns - expr._data]!=clevel)) ++ns;
arg3 = compile(s,ns,depth1,0,is_single);
if (_cimg_mp_is_vector(arg3)) {
arg4 = _cimg_mp_size(arg3);
CImg<ulongT>::sequence(arg4,arg3 + 1,arg3 + arg4).move_to(_opcode);
arg2+=arg4;
} else { CImg<ulongT>::vector(arg3).move_to(_opcode); ++arg2; }
s = ns;
}
if (arg1==~0U) arg1 = arg2;
_cimg_mp_check_vector0(arg1);
pos = vector(arg1);
_opcode.insert(CImg<ulongT>::vector((ulongT)mp_vector_init,pos,0,arg1),0);
(_opcode>'y').move_to(opcode);
opcode[2] = opcode._height;
opcode.move_to(code);
_cimg_mp_return(pos);
}
if (!std::strncmp(ss,"vtos(",5)) { // Double(s) to string
_cimg_mp_op("Function 'vtos()'");
s1 = ss5; while (s1<se1 && (*s1!=',' || level[s1 - expr._data]!=clevel1)) ++s1;
arg1 = compile(ss5,s1,depth1,0,is_single);
arg2 = 0; arg3 = ~0U;
if (s1<se1) {
s2 = s1 + 1; while (s2<se1 && (*s2!=',' || level[s2 - expr._data]!=clevel1)) ++s2;
arg2 = compile(++s1,s2,depth1,0,is_single);
arg3 = s2<se1?compile(++s2,se1,depth1,0,is_single):~0U;
}
_cimg_mp_check_type(arg2,2,1,0);
if (arg3==~0U) { // Auto-guess best output vector size
p1 = _cimg_mp_size(arg1);
p1 = p1?19*p1 - 1:18;
} else {
_cimg_mp_check_constant(arg3,3,3);
p1 = (unsigned int)mem[arg3];
}
pos = vector(p1);
CImg<ulongT>::vector((ulongT)mp_vtos,pos,p1,arg1,_cimg_mp_size(arg1),arg2).move_to(code);
_cimg_mp_return(pos);
}
break;
case 'w' :
if (*ss1=='(') { // Image width
_cimg_mp_op("Function 'w()'");
if (*ss2=='#') { // Index specified
p1 = compile(ss3,se1,depth1,0,is_single);
_cimg_mp_check_list(false);
} else { if (ss2!=se1) break; p1 = ~0U; }
pos = scalar();
CImg<ulongT>::vector((ulongT)mp_image_w,pos,p1).move_to(code);
_cimg_mp_return(pos);
}
if (*ss1=='h' && *ss2=='(') { // Image width*height
_cimg_mp_op("Function 'wh()'");
if (*ss3=='#') { // Index specified
p1 = compile(ss4,se1,depth1,0,is_single);
_cimg_mp_check_list(false);
} else { if (ss3!=se1) break; p1 = ~0U; }
pos = scalar();
CImg<ulongT>::vector((ulongT)mp_image_wh,pos,p1).move_to(code);
_cimg_mp_return(pos);
}
if (*ss1=='h' && *ss2=='d' && *ss3=='(') { // Image width*height*depth
_cimg_mp_op("Function 'whd()'");
if (*ss4=='#') { // Index specified
p1 = compile(ss5,se1,depth1,0,is_single);
_cimg_mp_check_list(false);
} else { if (ss4!=se1) break; p1 = ~0U; }
pos = scalar();
CImg<ulongT>::vector((ulongT)mp_image_whd,pos,p1).move_to(code);
_cimg_mp_return(pos);
}
if (*ss1=='h' && *ss2=='d' && *ss3=='s' && *ss4=='(') { // Image width*height*depth*spectrum
_cimg_mp_op("Function 'whds()'");
if (*ss5=='#') { // Index specified
p1 = compile(ss6,se1,depth1,0,is_single);
_cimg_mp_check_list(false);
} else { if (ss5!=se1) break; p1 = ~0U; }
pos = scalar();
CImg<ulongT>::vector((ulongT)mp_image_whds,pos,p1).move_to(code);
_cimg_mp_return(pos);
}
if (!std::strncmp(ss,"while(",6) || !std::strncmp(ss,"whiledo(",8)) { // While...do
_cimg_mp_op("Function 'whiledo()'");
s0 = *ss5=='('?ss6:ss8;
s1 = s0; while (s1<se1 && (*s1!=',' || level[s1 - expr._data]!=clevel1)) ++s1;
p1 = code._width;
arg1 = compile(s0,s1,depth1,0,is_single);
p2 = code._width;
arg6 = mempos;
pos = compile(++s1,se1,depth1,0,is_single);
_cimg_mp_check_type(arg1,1,1,0);
arg2 = _cimg_mp_size(pos);
CImg<ulongT>::vector((ulongT)mp_whiledo,pos,arg1,p2 - p1,code._width - p2,arg2,
pos>=arg6 && !_cimg_mp_is_constant(pos),
arg1>=arg6 && !_cimg_mp_is_constant(arg1)).move_to(code,p1);
_cimg_mp_return(pos);
}
break;
case 'x' :
if (!std::strncmp(ss,"xor(",4)) { // Xor
_cimg_mp_op("Function 'xor()'");
s1 = ss4; while (s1<se1 && (*s1!=',' || level[s1 - expr._data]!=clevel1)) ++s1;
arg1 = compile(ss4,s1,depth1,0,is_single);
arg2 = compile(++s1,se1,depth1,0,is_single);
_cimg_mp_check_type(arg2,2,3,_cimg_mp_size(arg1));
if (_cimg_mp_is_vector(arg1) && _cimg_mp_is_vector(arg2)) _cimg_mp_vector2_vv(mp_bitwise_xor,arg1,arg2);
if (_cimg_mp_is_vector(arg1) && _cimg_mp_is_scalar(arg2)) _cimg_mp_vector2_vs(mp_bitwise_xor,arg1,arg2);
if (_cimg_mp_is_scalar(arg1) && _cimg_mp_is_vector(arg2)) _cimg_mp_vector2_sv(mp_bitwise_xor,arg1,arg2);
if (_cimg_mp_is_constant(arg1) && _cimg_mp_is_constant(arg2))
_cimg_mp_constant((longT)mem[arg1] ^ (longT)mem[arg2]);
_cimg_mp_scalar2(mp_bitwise_xor,arg1,arg2);
}
break;
}
if (!std::strncmp(ss,"min(",4) || !std::strncmp(ss,"max(",4) ||
!std::strncmp(ss,"med(",4) || !std::strncmp(ss,"kth(",4) ||
!std::strncmp(ss,"sum(",4) || !std::strncmp(ss,"avg(",4) ||
!std::strncmp(ss,"std(",4) || !std::strncmp(ss,"variance(",9) ||
!std::strncmp(ss,"prod(",5) || !std::strncmp(ss,"mean(",5) ||
!std::strncmp(ss,"argmin(",7) || !std::strncmp(ss,"argmax(",7) ||
!std::strncmp(ss,"argkth(",7)) { // Multi-argument functions
_cimg_mp_op(*ss=='a'?(ss[1]=='v'?"Function 'avg()'":
ss[3]=='k'?"Function 'argkth()'":
ss[4]=='i'?"Function 'argmin()'":
"Function 'argmax()'"):
*ss=='s'?(ss[1]=='u'?"Function 'sum()'":"Function 'std()'"):
*ss=='k'?"Function 'kth()'":
*ss=='p'?"Function 'prod()'":
*ss=='v'?"Function 'variance()'":
ss[1]=='i'?"Function 'min()'":
ss[1]=='a'?"Function 'max()'":
ss[2]=='a'?"Function 'mean()'":"Function 'med()'");
op = *ss=='a'?(ss[1]=='v'?mp_avg:ss[3]=='k'?mp_argkth:ss[4]=='i'?mp_argmin:mp_argmax):
*ss=='s'?(ss[1]=='u'?mp_sum:mp_std):
*ss=='k'?mp_kth:
*ss=='p'?mp_prod:
*ss=='v'?mp_variance:
ss[1]=='i'?mp_min:
ss[1]=='a'?mp_max:
ss[2]=='a'?mp_mean:
mp_median;
is_sth = true; // Tell if all arguments are constant
pos = scalar();
CImg<ulongT>::vector((ulongT)op,pos,0).move_to(_opcode);
for (s = std::strchr(ss,'(') + 1; s<se; ++s) {
ns = s; while (ns<se && (*ns!=',' || level[ns - expr._data]!=clevel1) &&
(*ns!=')' || level[ns - expr._data]!=clevel)) ++ns;
arg2 = compile(s,ns,depth1,0,is_single);
if (_cimg_mp_is_vector(arg2))
CImg<ulongT>::sequence(_cimg_mp_size(arg2),arg2 + 1,
arg2 + (ulongT)_cimg_mp_size(arg2)).
move_to(_opcode);
else CImg<ulongT>::vector(arg2).move_to(_opcode);
is_sth&=_cimg_mp_is_constant(arg2);
s = ns;
}
(_opcode>'y').move_to(opcode);
opcode[2] = opcode._height;
if (is_sth) _cimg_mp_constant(op(*this));
opcode.move_to(code);
_cimg_mp_return(pos);
}
// No corresponding built-in function -> Look for a user-defined macro call.
s0 = strchr(ss,'(');
if (s0) {
variable_name.assign(ss,(unsigned int)(s0 - ss + 1)).back() = 0;
// Count number of specified arguments.
p1 = 0;
for (s = s0 + 1; s<=se1; ++p1, s = ns + 1) {
while (*s && (signed char)*s<=' ') ++s;
if (*s==')' && !p1) break;
ns = s; while (ns<se && (*ns!=',' || level[ns - expr._data]!=clevel1) &&
(*ns!=')' || level[ns - expr._data]!=clevel)) ++ns;
}
arg3 = 0; // Number of possible name matches
cimglist_for(macro_def,l) if (!std::strcmp(macro_def[l],variable_name) && ++arg3 &&
macro_def[l].back()==(char)p1) {
p2 = (unsigned int)macro_def[l].back(); // Number of required arguments
CImg<charT> _expr = macro_body[l]; // Expression to be substituted
p1 = 1; // Indice of current parsed argument
for (s = s0 + 1; s<=se1; ++p1, s = ns + 1) { // Parse function arguments
while (*s && (signed char)*s<=' ') ++s;
if (*s==')' && p1==1) break; // Function has no arguments
if (p1>p2) { ++p1; break; }
ns = s; while (ns<se && (*ns!=',' || level[ns - expr._data]!=clevel1) &&
(*ns!=')' || level[ns - expr._data]!=clevel)) ++ns;
variable_name.assign(s,(unsigned int)(ns - s + 1)).back() = 0; // Argument to write
arg2 = 0;
cimg_forX(_expr,k) {
if (_expr[k]==(char)p1) { // Perform argument substitution
arg1 = _expr._width;
_expr.resize(arg1 + variable_name._width - 2,1,1,1,0);
std::memmove(_expr._data + k + variable_name._width - 1,_expr._data + k + 1,arg1 - k - 1);
std::memcpy(_expr._data + k,variable_name,variable_name._width - 1);
k+=variable_name._width - 2;
}
++arg2;
}
}
// Recompute 'pexpr' and 'level' for evaluating substituted expression.
CImg<charT> _pexpr(_expr._width);
ns = _pexpr._data;
for (ps = _expr._data, c1 = ' '; *ps; ++ps) {
if ((signed char)*ps>' ') c1 = *ps;
*(ns++) = c1;
}
*ns = 0;
CImg<uintT> _level = get_level(_expr);
expr.swap(_expr);
pexpr.swap(_pexpr);
level.swap(_level);
s0 = user_macro;
user_macro = macro_def[l];
pos = compile(expr._data,expr._data + expr._width - 1,depth1,p_ref,is_single);
user_macro = s0;
level.swap(_level);
pexpr.swap(_pexpr);
expr.swap(_expr);
_cimg_mp_return(pos);
}
if (arg3) { // Macro name matched but number of arguments does not
CImg<uintT> sig_nargs(arg3);
arg1 = 0;
cimglist_for(macro_def,l) if (!std::strcmp(macro_def[l],variable_name))
sig_nargs[arg1++] = (unsigned int)macro_def[l].back();
*se = saved_char;
cimg::strellipsize(variable_name,64);
s0 = ss - 4>expr._data?ss - 4:expr._data;
cimg::strellipsize(s0,64);
if (sig_nargs._width>1) {
sig_nargs.sort();
arg1 = sig_nargs.back();
--sig_nargs._width;
throw CImgArgumentException("[" cimg_appname "_math_parser] "
"CImg<%s>::%s: Function '%s()': Number of specified arguments (%u) "
"does not match macro declaration (defined for %s or %u arguments), "
"in expression '%s%s%s'.",
pixel_type(),_cimg_mp_calling_function,variable_name._data,
p1,sig_nargs.value_string()._data,arg1,
s0!=expr._data?"...":"",s0,se<&expr.back()?"...":"");
} else
throw CImgArgumentException("[" cimg_appname "_math_parser] "
"CImg<%s>::%s: Function '%s()': Number of specified arguments (%u) "
"does not match macro declaration (defined for %u argument%s), "
"in expression '%s%s%s'.",
pixel_type(),_cimg_mp_calling_function,variable_name._data,
p1,*sig_nargs,*sig_nargs!=1?"s":"",
s0!=expr._data?"...":"",s0,se<&expr.back()?"...":"");
}
}
} // if (se1==')')
// Char / string initializer.
if (*se1=='\'' &&
((se1>ss && *ss=='\'') ||
(se1>ss1 && *ss=='_' && *ss1=='\''))) {
if (*ss=='_') { _cimg_mp_op("Char initializer"); s1 = ss2; }
else { _cimg_mp_op("String initializer"); s1 = ss1; }
arg1 = (unsigned int)(se1 - s1); // Original string length.
if (arg1) {
CImg<charT>(s1,arg1 + 1).move_to(variable_name).back() = 0;
cimg::strunescape(variable_name);
arg1 = (unsigned int)std::strlen(variable_name);
}
if (!arg1) _cimg_mp_return(0); // Empty string -> 0
if (*ss=='_') {
if (arg1==1) _cimg_mp_constant(*variable_name);
*se = saved_char;
cimg::strellipsize(variable_name,64);
s0 = ss - 4>expr._data?ss - 4:expr._data;
cimg::strellipsize(s0,64);
throw CImgArgumentException("[" cimg_appname "_math_parser] "
"CImg<%s>::%s: %s: Literal %s contains more than one character, "
"in expression '%s%s%s'.",
pixel_type(),_cimg_mp_calling_function,s_op,
ss1,
s0!=expr._data?"...":"",s0,se<&expr.back()?"...":"");
}
pos = vector(arg1);
CImg<ulongT>::vector((ulongT)mp_string_init,pos,arg1).move_to(_opcode);
CImg<ulongT>(1,arg1/sizeof(ulongT) + (arg1%sizeof(ulongT)?1:0)).move_to(_opcode);
std::memcpy((char*)_opcode[1]._data,variable_name,arg1);
(_opcode>'y').move_to(code);
_cimg_mp_return(pos);
}
// Vector initializer [ ... ].
if (*ss=='[' && *se1==']') {
_cimg_mp_op("Vector initializer");
s1 = ss1; while (s1<se2 && (signed char)*s1<=' ') ++s1;
s2 = se2; while (s2>s1 && (signed char)*s2<=' ') --s2;
if (s2>s1 && *s1=='\'' && *s2=='\'') { // Vector values provided as a string
arg1 = (unsigned int)(s2 - s1 - 1); // Original string length.
if (arg1) {
CImg<charT>(s1 + 1,arg1 + 1).move_to(variable_name).back() = 0;
cimg::strunescape(variable_name);
arg1 = (unsigned int)std::strlen(variable_name);
}
if (!arg1) _cimg_mp_return(0); // Empty string -> 0
pos = vector(arg1);
CImg<ulongT>::vector((ulongT)mp_string_init,pos,arg1).move_to(_opcode);
CImg<ulongT>(1,arg1/sizeof(ulongT) + (arg1%sizeof(ulongT)?1:0)).move_to(_opcode);
std::memcpy((char*)_opcode[1]._data,variable_name,arg1);
(_opcode>'y').move_to(code);
} else { // Vector values provided as list of items
arg1 = 0; // Number of specified values.
if (*ss1!=']') for (s = ss1; s<se; ++s) {
ns = s; while (ns<se && (*ns!=',' || level[ns - expr._data]!=clevel1) &&
(*ns!=']' || level[ns - expr._data]!=clevel)) ++ns;
arg2 = compile(s,ns,depth1,0,is_single);
if (_cimg_mp_is_vector(arg2)) {
arg3 = _cimg_mp_size(arg2);
CImg<ulongT>::sequence(arg3,arg2 + 1,arg2 + arg3).move_to(_opcode);
arg1+=arg3;
} else { CImg<ulongT>::vector(arg2).move_to(_opcode); ++arg1; }
s = ns;
}
_cimg_mp_check_vector0(arg1);
pos = vector(arg1);
_opcode.insert(CImg<ulongT>::vector((ulongT)mp_vector_init,pos,0,arg1),0);
(_opcode>'y').move_to(opcode);
opcode[2] = opcode._height;
opcode.move_to(code);
}
_cimg_mp_return(pos);
}
// Variables related to the input list of images.
if (*ss1=='#' && ss2<se) {
arg1 = compile(ss2,se,depth1,0,is_single);
p1 = (unsigned int)(listin._width && _cimg_mp_is_constant(arg1)?cimg::mod((int)mem[arg1],listin.width()):~0U);
switch (*ss) {
case 'w' : // w#ind
if (!listin) _cimg_mp_return(0);
if (p1!=~0U) _cimg_mp_constant(listin[p1]._width);
_cimg_mp_scalar1(mp_list_width,arg1);
case 'h' : // h#ind
if (!listin) _cimg_mp_return(0);
if (p1!=~0U) _cimg_mp_constant(listin[p1]._height);
_cimg_mp_scalar1(mp_list_height,arg1);
case 'd' : // d#ind
if (!listin) _cimg_mp_return(0);
if (p1!=~0U) _cimg_mp_constant(listin[p1]._depth);
_cimg_mp_scalar1(mp_list_depth,arg1);
case 'r' : // r#ind
if (!listin) _cimg_mp_return(0);
if (p1!=~0U) _cimg_mp_constant(listin[p1]._is_shared);
_cimg_mp_scalar1(mp_list_is_shared,arg1);
case 's' : // s#ind
if (!listin) _cimg_mp_return(0);
if (p1!=~0U) _cimg_mp_constant(listin[p1]._spectrum);
_cimg_mp_scalar1(mp_list_spectrum,arg1);
case 'i' : // i#ind
if (!listin) _cimg_mp_return(0);
_cimg_mp_scalar7(mp_list_ixyzc,arg1,_cimg_mp_slot_x,_cimg_mp_slot_y,_cimg_mp_slot_z,_cimg_mp_slot_c,
0,_cimg_mp_boundary);
case 'I' : // I#ind
p2 = p1!=~0U?listin[p1]._spectrum:listin._width?~0U:0;
_cimg_mp_check_vector0(p2);
pos = vector(p2);
CImg<ulongT>::vector((ulongT)mp_list_Joff,pos,p1,0,0,p2).move_to(code);
_cimg_mp_return(pos);
case 'R' : // R#ind
if (!listin) _cimg_mp_return(0);
_cimg_mp_scalar7(mp_list_ixyzc,arg1,_cimg_mp_slot_x,_cimg_mp_slot_y,_cimg_mp_slot_z,0,
0,_cimg_mp_boundary);
case 'G' : // G#ind
if (!listin) _cimg_mp_return(0);
_cimg_mp_scalar7(mp_list_ixyzc,arg1,_cimg_mp_slot_x,_cimg_mp_slot_y,_cimg_mp_slot_z,1,
0,_cimg_mp_boundary);
case 'B' : // B#ind
if (!listin) _cimg_mp_return(0);
_cimg_mp_scalar7(mp_list_ixyzc,arg1,_cimg_mp_slot_x,_cimg_mp_slot_y,_cimg_mp_slot_z,2,
0,_cimg_mp_boundary);
case 'A' : // A#ind
if (!listin) _cimg_mp_return(0);
_cimg_mp_scalar7(mp_list_ixyzc,arg1,_cimg_mp_slot_x,_cimg_mp_slot_y,_cimg_mp_slot_z,3,
0,_cimg_mp_boundary);
}
}
if (*ss1 && *ss2=='#' && ss3<se) {
arg1 = compile(ss3,se,depth1,0,is_single);
p1 = (unsigned int)(listin._width && _cimg_mp_is_constant(arg1)?cimg::mod((int)mem[arg1],listin.width()):~0U);
if (*ss=='w' && *ss1=='h') { // wh#ind
if (!listin) _cimg_mp_return(0);
if (p1!=~0U) _cimg_mp_constant(listin[p1]._width*listin[p1]._height);
_cimg_mp_scalar1(mp_list_wh,arg1);
}
arg2 = ~0U;
if (*ss=='i') {
if (*ss1=='c') { // ic#ind
if (!listin) _cimg_mp_return(0);
if (_cimg_mp_is_constant(arg1)) {
if (!list_median) list_median.assign(listin._width);
if (!list_median[p1]) CImg<doubleT>::vector(listin[p1].median()).move_to(list_median[p1]);
_cimg_mp_constant(*list_median[p1]);
}
_cimg_mp_scalar1(mp_list_median,arg1);
}
if (*ss1>='0' && *ss1<='9') { // i0#ind...i9#ind
if (!listin) _cimg_mp_return(0);
_cimg_mp_scalar7(mp_list_ixyzc,arg1,_cimg_mp_slot_x,_cimg_mp_slot_y,_cimg_mp_slot_z,*ss1 - '0',
0,_cimg_mp_boundary);
}
switch (*ss1) {
case 'm' : arg2 = 0; break; // im#ind
case 'M' : arg2 = 1; break; // iM#ind
case 'a' : arg2 = 2; break; // ia#ind
case 'v' : arg2 = 3; break; // iv#ind
case 's' : arg2 = 12; break; // is#ind
case 'p' : arg2 = 13; break; // ip#ind
}
} else if (*ss1=='m') switch (*ss) {
case 'x' : arg2 = 4; break; // xm#ind
case 'y' : arg2 = 5; break; // ym#ind
case 'z' : arg2 = 6; break; // zm#ind
case 'c' : arg2 = 7; break; // cm#ind
} else if (*ss1=='M') switch (*ss) {
case 'x' : arg2 = 8; break; // xM#ind
case 'y' : arg2 = 9; break; // yM#ind
case 'z' : arg2 = 10; break; // zM#ind
case 'c' : arg2 = 11; break; // cM#ind
}
if (arg2!=~0U) {
if (!listin) _cimg_mp_return(0);
if (_cimg_mp_is_constant(arg1)) {
if (!list_stats) list_stats.assign(listin._width);
if (!list_stats[p1]) list_stats[p1].assign(1,14,1,1,0).fill(listin[p1].get_stats(),false);
_cimg_mp_constant(list_stats(p1,arg2));
}
_cimg_mp_scalar2(mp_list_stats,arg1,arg2);
}
}
if (*ss=='w' && *ss1=='h' && *ss2=='d' && *ss3=='#' && ss4<se) { // whd#ind
arg1 = compile(ss4,se,depth1,0,is_single);
if (!listin) _cimg_mp_return(0);
p1 = (unsigned int)(_cimg_mp_is_constant(arg1)?cimg::mod((int)mem[arg1],listin.width()):~0U);
if (p1!=~0U) _cimg_mp_constant(listin[p1]._width*listin[p1]._height*listin[p1]._depth);
_cimg_mp_scalar1(mp_list_whd,arg1);
}
if (*ss=='w' && *ss1=='h' && *ss2=='d' && *ss3=='s' && *ss4=='#' && ss5<se) { // whds#ind
arg1 = compile(ss5,se,depth1,0,is_single);
if (!listin) _cimg_mp_return(0);
p1 = (unsigned int)(_cimg_mp_is_constant(arg1)?cimg::mod((int)mem[arg1],listin.width()):~0U);
if (p1!=~0U) _cimg_mp_constant(listin[p1]._width*listin[p1]._height*listin[p1]._depth*listin[p1]._spectrum);
_cimg_mp_scalar1(mp_list_whds,arg1);
}
if (!std::strcmp(ss,"interpolation")) _cimg_mp_return(_cimg_mp_interpolation); // interpolation
if (!std::strcmp(ss,"boundary")) _cimg_mp_return(_cimg_mp_boundary); // boundary
// No known item found, assuming this is an already initialized variable.
variable_name.assign(ss,(unsigned int)(se - ss + 1)).back() = 0;
if (variable_name[1]) { // Multi-char variable
cimglist_for(variable_def,i) if (!std::strcmp(variable_name,variable_def[i]))
_cimg_mp_return(variable_pos[i]);
} else if (reserved_label[*variable_name]!=~0U) // Single-char variable
_cimg_mp_return(reserved_label[*variable_name]);
// Reached an unknown item -> error.
is_sth = true; // is_valid_variable_name
if (*variable_name>='0' && *variable_name<='9') is_sth = false;
else for (ns = variable_name._data; *ns; ++ns)
if (!is_varchar(*ns)) { is_sth = false; break; }
*se = saved_char;
c1 = *se1;
cimg::strellipsize(variable_name,64);
s0 = ss - 4>expr._data?ss - 4:expr._data;
cimg::strellipsize(s0,64);
if (is_sth)
throw CImgArgumentException("[" cimg_appname "_math_parser] "
"CImg<%s>::%s: Undefined variable '%s' in expression '%s%s%s'.",
pixel_type(),_cimg_mp_calling_function,
variable_name._data,
s0!=expr._data?"...":"",s0,se<&expr.back()?"...":"");
s1 = std::strchr(ss,'(');
s_op = s1 && c1==')'?"function call":"item";
throw CImgArgumentException("[" cimg_appname "_math_parser] "
"CImg<%s>::%s: Unrecognized %s '%s' in expression '%s%s%s'.",
pixel_type(),_cimg_mp_calling_function,
s_op,variable_name._data,
s0!=expr._data?"...":"",s0,se<&expr.back()?"...":"");
| 0
|
30,786
|
static void ac3_decode_transform_coeffs_ch ( AC3DecodeContext * s , int ch_index , mant_groups * m ) {
int start_freq = s -> start_freq [ ch_index ] ;
int end_freq = s -> end_freq [ ch_index ] ;
uint8_t * baps = s -> bap [ ch_index ] ;
int8_t * exps = s -> dexps [ ch_index ] ;
int * coeffs = s -> fixed_coeffs [ ch_index ] ;
int dither = ( ch_index == CPL_CH ) || s -> dither_flag [ ch_index ] ;
GetBitContext * gbc = & s -> gbc ;
int freq ;
for ( freq = start_freq ;
freq < end_freq ;
freq ++ ) {
int bap = baps [ freq ] ;
int mantissa ;
switch ( bap ) {
case 0 : if ( dither ) mantissa = ( av_lfg_get ( & s -> dith_state ) / 362 ) - 5932275 ;
else mantissa = 0 ;
break ;
case 1 : if ( m -> b1 ) {
m -> b1 -- ;
mantissa = m -> b1_mant [ m -> b1 ] ;
}
else {
int bits = get_bits ( gbc , 5 ) ;
mantissa = b1_mantissas [ bits ] [ 0 ] ;
m -> b1_mant [ 1 ] = b1_mantissas [ bits ] [ 1 ] ;
m -> b1_mant [ 0 ] = b1_mantissas [ bits ] [ 2 ] ;
m -> b1 = 2 ;
}
break ;
case 2 : if ( m -> b2 ) {
m -> b2 -- ;
mantissa = m -> b2_mant [ m -> b2 ] ;
}
else {
int bits = get_bits ( gbc , 7 ) ;
mantissa = b2_mantissas [ bits ] [ 0 ] ;
m -> b2_mant [ 1 ] = b2_mantissas [ bits ] [ 1 ] ;
m -> b2_mant [ 0 ] = b2_mantissas [ bits ] [ 2 ] ;
m -> b2 = 2 ;
}
break ;
case 3 : mantissa = b3_mantissas [ get_bits ( gbc , 3 ) ] ;
break ;
case 4 : if ( m -> b4 ) {
m -> b4 = 0 ;
mantissa = m -> b4_mant ;
}
else {
int bits = get_bits ( gbc , 7 ) ;
mantissa = b4_mantissas [ bits ] [ 0 ] ;
m -> b4_mant = b4_mantissas [ bits ] [ 1 ] ;
m -> b4 = 1 ;
}
break ;
case 5 : mantissa = b5_mantissas [ get_bits ( gbc , 4 ) ] ;
break ;
default : mantissa = get_sbits ( gbc , quantization_tab [ bap ] ) ;
mantissa <<= 24 - quantization_tab [ bap ] ;
break ;
}
coeffs [ freq ] = mantissa >> exps [ freq ] ;
}
}
| 0
|
72,756
|
static int kvm_vm_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
{
struct page *page[1];
unsigned long addr;
int npages;
gfn_t gfn = vmf->pgoff;
struct kvm *kvm = vma->vm_file->private_data;
addr = gfn_to_hva(kvm, gfn);
if (kvm_is_error_hva(addr))
return VM_FAULT_SIGBUS;
npages = get_user_pages(current, current->mm, addr, 1, 1, 0, page,
NULL);
if (unlikely(npages != 1))
return VM_FAULT_SIGBUS;
vmf->page = page[0];
return 0;
}
| 0
|
505,750
|
rsvg_acquire_data_data (const char *uri,
const char *base_uri,
char **out_mime_type,
gsize *out_len,
GError **error)
{
const char *comma, *start, *end;
char *mime_type;
char *data;
gsize data_len;
gboolean base64 = FALSE;
g_assert (out_len != NULL);
g_assert (strncmp (uri, "data:", 5) == 0);
mime_type = NULL;
start = uri + 5;
comma = strchr (start, ',');
if (comma && comma != start) {
/* Deal with MIME type / params */
if (comma > start + BASE64_INDICATOR_LEN &&
!g_ascii_strncasecmp (comma - BASE64_INDICATOR_LEN, BASE64_INDICATOR, BASE64_INDICATOR_LEN)) {
end = comma - BASE64_INDICATOR_LEN;
base64 = TRUE;
} else {
end = comma;
}
if (end != start) {
mime_type = uri_decoded_copy (start, end - start);
}
}
if (comma)
start = comma + 1;
if (*start) {
data = uri_decoded_copy (start, strlen (start));
if (base64)
data = g_base64_decode_inplace ((char*) data, &data_len);
else
data_len = strlen ((const char *) data);
} else {
data = NULL;
data_len = 0;
}
if (out_mime_type)
*out_mime_type = mime_type;
else
g_free (mime_type);
*out_len = data_len;
return data;
}
| 0
|
316,041
|
static void pdf_run_TL(fz_context *ctx, pdf_processor *proc, float leading)
{
pdf_run_processor *pr = (pdf_run_processor *)proc;
pdf_gstate *gstate = pr->gstate + pr->gtop;
gstate->text.leading = leading;
}
| 0
|
149,275
|
static int cuse_channel_open(struct inode *inode, struct file *file)
{
struct fuse_dev *fud;
struct cuse_conn *cc;
int rc;
/* set up cuse_conn */
cc = kzalloc(sizeof(*cc), GFP_KERNEL);
if (!cc)
return -ENOMEM;
fuse_conn_init(&cc->fc);
fud = fuse_dev_alloc(&cc->fc);
if (!fud) {
kfree(cc);
return -ENOMEM;
}
INIT_LIST_HEAD(&cc->list);
cc->fc.release = cuse_fc_release;
cc->fc.initialized = 1;
rc = cuse_send_init(cc);
if (rc) {
fuse_dev_free(fud);
return rc;
}
file->private_data = fud;
return 0;
}
| 0
|
107,562
|
cdataSectionProcessor(XML_Parser parser, const char *start, const char *end,
const char **endPtr) {
enum XML_Error result
= doCdataSection(parser, parser->m_encoding, &start, end, endPtr,
(XML_Bool)! parser->m_parsingStatus.finalBuffer);
if (result != XML_ERROR_NONE)
return result;
if (start) {
if (parser->m_parentParser) { /* we are parsing an external entity */
parser->m_processor = externalEntityContentProcessor;
return externalEntityContentProcessor(parser, start, end, endPtr);
} else {
parser->m_processor = contentProcessor;
return contentProcessor(parser, start, end, endPtr);
}
}
return result;
}
| 0
|
403,020
|
ptp_unpack_OI (PTPParams *params, unsigned char* data, PTPObjectInfo *oi, unsigned int len)
{
uint8_t filenamelen;
uint8_t capturedatelen;
char *capture_date;
if (len < PTP_oi_SequenceNumber)
return;
oi->Filename = oi->Keywords = NULL;
/* FIXME: also handle length with all the strings at the end */
oi->StorageID=dtoh32a(&data[PTP_oi_StorageID]);
oi->ObjectFormat=dtoh16a(&data[PTP_oi_ObjectFormat]);
oi->ProtectionStatus=dtoh16a(&data[PTP_oi_ProtectionStatus]);
oi->ObjectCompressedSize=dtoh32a(&data[PTP_oi_ObjectCompressedSize]);
/* Stupid Samsung Galaxy developers emit a 64bit objectcompressedsize */
if ((data[PTP_oi_filenamelen] == 0) && (data[PTP_oi_filenamelen+4] != 0)) {
params->ocs64 = 1;
data += 4;
}
oi->ThumbFormat=dtoh16a(&data[PTP_oi_ThumbFormat]);
oi->ThumbCompressedSize=dtoh32a(&data[PTP_oi_ThumbCompressedSize]);
oi->ThumbPixWidth=dtoh32a(&data[PTP_oi_ThumbPixWidth]);
oi->ThumbPixHeight=dtoh32a(&data[PTP_oi_ThumbPixHeight]);
oi->ImagePixWidth=dtoh32a(&data[PTP_oi_ImagePixWidth]);
oi->ImagePixHeight=dtoh32a(&data[PTP_oi_ImagePixHeight]);
oi->ImageBitDepth=dtoh32a(&data[PTP_oi_ImageBitDepth]);
oi->ParentObject=dtoh32a(&data[PTP_oi_ParentObject]);
oi->AssociationType=dtoh16a(&data[PTP_oi_AssociationType]);
oi->AssociationDesc=dtoh32a(&data[PTP_oi_AssociationDesc]);
oi->SequenceNumber=dtoh32a(&data[PTP_oi_SequenceNumber]);
oi->Filename= ptp_unpack_string(params, data, PTP_oi_filenamelen, len, &filenamelen);
capture_date = ptp_unpack_string(params, data,
PTP_oi_filenamelen+filenamelen*2+1, len, &capturedatelen);
/* subset of ISO 8601, without '.s' tenths of second and
* time zone
*/
oi->CaptureDate = ptp_unpack_PTPTIME(capture_date);
free(capture_date);
/* now the modification date ... */
capture_date = ptp_unpack_string(params, data,
PTP_oi_filenamelen+filenamelen*2
+capturedatelen*2+2, len, &capturedatelen);
oi->ModificationDate = ptp_unpack_PTPTIME(capture_date);
free(capture_date);
}
| 0
|
445,055
|
AdminFilterChain() {} // NOLINT(modernize-use-equals-default)
| 0
|
286,896
|
error_t lpc546xxEthUpdateMacConfig(NetInterface *interface)
{
uint32_t config;
//Read current MAC configuration
config = ENET->MAC_CONFIG;
//10BASE-T or 100BASE-TX operation mode?
if(interface->linkSpeed == NIC_LINK_SPEED_100MBPS)
{
config |= ENET_MAC_CONFIG_FES_MASK;
}
else
{
config &= ~ENET_MAC_CONFIG_FES_MASK;
}
//Half-duplex or full-duplex mode?
if(interface->duplexMode == NIC_FULL_DUPLEX_MODE)
{
config |= ENET_MAC_CONFIG_DM_MASK;
}
else
{
config &= ~ENET_MAC_CONFIG_DM_MASK;
}
//Update MAC configuration register
ENET->MAC_CONFIG = config;
//Successful processing
return NO_ERROR;
}
| 1
|
406,610
|
Item_cache(enum_field_types field_type_arg):
example(0), used_table_map(0), cached_field(0),
cached_field_type(field_type_arg),
value_cached(0)
{
fixed= 1;
null_value= 1;
}
| 0
|
137,238
|
free_blocks(sblock_T *bl)
{
sblock_T *next;
while (bl != NULL)
{
next = bl->sb_next;
vim_free(bl);
bl = next;
}
}
| 0
|
111,041
|
inline bool StringData::empty() const { return size() == 0; }
| 0
|
516,154
|
int SSL_add_store_cert_subjects_to_stack(STACK_OF(X509_NAME) *stack,
const char *store)
{
int (*oldcmp) (const X509_NAME *const *a, const X509_NAME *const *b)
= sk_X509_NAME_set_cmp_func(stack, xname_sk_cmp);
int ret = add_uris_recursive(stack, store, 1);
(void)sk_X509_NAME_set_cmp_func(stack, oldcmp);
return ret;
}
| 0
|
137,303
|
lengthOfLines(TScreen *screen, int firstRow, int lastRow)
{
unsigned length = 0;
int n;
for (n = firstRow; n <= lastRow; ++n) {
LineData *ld = GET_LINEDATA(screen, n);
int value = LastTextCol(screen, ld, n);
if (value >= 0)
length += (unsigned) (value + 1);
}
return length;
}
| 0
|
364,352
|
static void log_option(const char *pfx, const uint8_t *opt)
{
if (dhcp_verbose >= 2) {
char buf[256 * 2 + 2];
*bin2hex(buf, (void*) (opt + OPT_DATA), opt[OPT_LEN]) = '\0';
bb_info_msg("%s: 0x%02x %s", pfx, opt[OPT_CODE], buf);
}
}
| 0
|
257,795
|
size_t WriteOffset ( ArchiveHandle * AH , pgoff_t o , int wasSet ) {
int off ;
( * AH -> WriteBytePtr ) ( AH , wasSet ) ;
for ( off = 0 ;
off < sizeof ( pgoff_t ) ;
off ++ ) {
( * AH -> WriteBytePtr ) ( AH , o & 0xFF ) ;
o >>= 8 ;
}
return sizeof ( pgoff_t ) + 1 ;
}
| 0
|
65,841
|
bool bounded_iostream::chkerr() {
return err != Sirikata::JpegError::nil();
}
| 0
|
445,112
|
TEST_P(ProxyProtocolTest, NotEnoughFields) {
connect(false);
write("PROXY TCP6 1:2:3::4 5:6::7:8 1234\r\nmore data");
expectProxyProtoError();
}
| 0
|
143,633
|
static int fwnet_change_mtu(struct net_device *net, int new_mtu)
{
if (new_mtu < 68)
return -EINVAL;
net->mtu = new_mtu;
return 0;
}
| 0
|
396,481
|
dotraplinkage void do_double_fault(struct pt_regs *regs, long error_code)
{
static const char str[] = "double fault";
struct task_struct *tsk = current;
#ifdef CONFIG_X86_ESPFIX64
extern unsigned char native_irq_return_iret[];
/*
* If IRET takes a non-IST fault on the espfix64 stack, then we
* end up promoting it to a doublefault. In that case, modify
* the stack to make it look like we just entered the #GP
* handler from user space, similar to bad_iret.
*
* No need for ist_enter here because we don't use RCU.
*/
if (((long)regs->sp >> PGDIR_SHIFT) == ESPFIX_PGD_ENTRY &&
regs->cs == __KERNEL_CS &&
regs->ip == (unsigned long)native_irq_return_iret)
{
struct pt_regs *normal_regs = task_pt_regs(current);
/* Fake a #GP(0) from userspace. */
memmove(&normal_regs->ip, (void *)regs->sp, 5*8);
normal_regs->orig_ax = 0; /* Missing (lost) #GP error code */
regs->ip = (unsigned long)general_protection;
regs->sp = (unsigned long)&normal_regs->orig_ax;
return;
}
#endif
ist_enter(regs);
notify_die(DIE_TRAP, str, regs, error_code, X86_TRAP_DF, SIGSEGV);
tsk->thread.error_code = error_code;
tsk->thread.trap_nr = X86_TRAP_DF;
#ifdef CONFIG_DOUBLEFAULT
df_debug(regs, error_code);
#endif
/*
* This is always a kernel trap and never fixable (and thus must
* never return).
*/
for (;;)
die(str, regs, error_code);
}
| 0
|
428,564
|
g_file_set_attribute_byte_string (GFile *file,
const gchar *attribute,
const gchar *value,
GFileQueryInfoFlags flags,
GCancellable *cancellable,
GError **error)
{
return g_file_set_attribute (file, attribute,
G_FILE_ATTRIBUTE_TYPE_BYTE_STRING, (gpointer)value,
flags, cancellable, error);
}
| 0
|
64,590
|
f_ch_read(typval_T *argvars, typval_T *rettv)
{
common_channel_read(argvars, rettv, FALSE, FALSE);
}
| 0
|
320,799
|
static inline void t_gen_mov_preg_TN(DisasContext *dc, int r, TCGv tn)
{
if (r < 0 || r > 15) {
fprintf(stderr, "wrong register write $p%d\n", r);
}
if (r == PR_BZ || r == PR_WZ || r == PR_DZ) {
return;
} else if (r == PR_SRS) {
tcg_gen_andi_tl(cpu_PR[r], tn, 3);
} else {
if (r == PR_PID) {
gen_helper_tlb_flush_pid(cpu_env, tn);
}
if (dc->tb_flags & S_FLAG && r == PR_SPC) {
gen_helper_spc_write(cpu_env, tn);
} else if (r == PR_CCS) {
dc->cpustate_changed = 1;
}
tcg_gen_mov_tl(cpu_PR[r], tn);
}
}
| 1
|
426,097
|
qb_ipcs_connection_get_buffer_size(qb_ipcs_connection_t *c)
{
if (c == NULL) {
return -EINVAL;
}
/* request, response, and event shoud all have the same
* buffer size allocated. It doesn't matter which we return
* here. */
return c->response.max_msg_size;
}
| 0
|
164,709
|
void PaintLayerScrollableArea::InvalidatePaintForScrollOffsetChange() {
InvalidatePaintForStickyDescendants();
auto* box = GetLayoutBox();
auto* frame_view = box->GetFrameView();
frame_view->InvalidateBackgroundAttachmentFixedDescendantsOnScroll(*box);
if (box->IsLayoutView() && frame_view->HasViewportConstrainedObjects() &&
!frame_view->InvalidateViewportConstrainedObjects()) {
box->SetShouldDoFullPaintInvalidation();
box->SetSubtreeShouldCheckForPaintInvalidation();
}
if (Layer()->EnclosingPaginationLayer())
box->SetSubtreeShouldCheckForPaintInvalidation();
bool background_paint_in_graphics_layer = true;
bool background_paint_in_scrolling_contents = false;
if (RuntimeEnabledFeatures::CompositeAfterPaintEnabled() ||
UsesCompositedScrolling()) {
auto background_paint_location = box->GetBackgroundPaintLocation();
background_paint_in_graphics_layer =
background_paint_location & kBackgroundPaintInGraphicsLayer;
background_paint_in_scrolling_contents =
background_paint_location & kBackgroundPaintInScrollingContents;
}
auto background_layers = box->StyleRef().BackgroundLayers();
if ((background_layers.AnyLayerHasLocalAttachmentImage() &&
background_paint_in_graphics_layer) ||
(background_layers.AnyLayerHasDefaultAttachmentImage() &&
background_paint_in_scrolling_contents))
box->SetBackgroundNeedsFullPaintInvalidation();
if (RuntimeEnabledFeatures::CompositeAfterPaintEnabled() ||
!UsesCompositedScrolling())
Layer()->SetNeedsRepaint();
}
| 0
|
82,070
|
R_API RBinObject *r_bin_file_object_get_cur(RBinFile *binfile) {
return binfile? binfile->o: NULL;
}
| 0
|
349,664
|
TEST_P(Http2CodecImplTest, HeaderNameWithUnderscoreAreRejectedByDefault) {
headers_with_underscores_action_ = envoy::config::core::v3::HttpProtocolOptions::REJECT_REQUEST;
initialize();
TestRequestHeaderMapImpl request_headers;
HttpTestUtility::addDefaultHeaders(request_headers);
request_headers.addCopy("bad_header", "something");
EXPECT_CALL(server_stream_callbacks_, onResetStream(_, _)).Times(1);
request_encoder_->encodeHeaders(request_headers, false);
EXPECT_EQ(1, stats_store_.counter("http2.requests_rejected_with_underscores_in_headers").value());
}
| 1
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.